prefs_widgets.m 89.6 KB
Newer Older
1 2 3
/*****************************************************************************
 * prefs_widgets.m: Preferences controls
 *****************************************************************************
Felix Paul Kühne's avatar
Felix Paul Kühne committed
4
 * Copyright (C) 2002-2011 VLC authors and VideoLAN
5
 * $Id$
6
 *
7
 * Authors: Derk-Jan Hartman <hartman at videolan.org>
8
 *          Jérôme Decoodt <djc at videolan.org>
9 10 11 12 13
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
14
 *
15 16 17 18 19 20 21
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
Antoine Cellerier's avatar
Antoine Cellerier committed
22
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 24 25 26 27 28 29 30
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
#include <stdlib.h>                                      /* malloc(), free() */
#include <string.h>

31 32 33 34
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

35
#include <vlc_common.h>
36
#include <vlc_modules.h>
37
#include <vlc_keys.h>
38 39 40 41 42 43

#include "intf.h"
#include "prefs_widgets.h"

#define PREFS_WRAP 300
#define OFFSET_RIGHT 20
44
#define OFFSET_BETWEEN 2
45

46
#define UPWARDS_WHITE_ARROW                 "\xE2\x87\xA7"
47 48 49 50 51 52 53 54
#define OPTION_KEY                          "\xE2\x8C\xA5"
#define UP_ARROWHEAD                        "\xE2\x8C\x83"
#define PLACE_OF_INTEREST_SIGN              "\xE2\x8C\x98"

#define POPULATE_A_KEY( o_menu, string, value )                             \
{                                                                           \
    NSMenuItem *o_mi;                                                       \
/*  Normal */                                                               \
55 56
    o_mi = [[NSMenuItem alloc] initWithTitle:string                         \
        action:nil keyEquivalent:@""];                                      \
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
    [o_mi setKeyEquivalentModifierMask:                                     \
        0];                                                                 \
    [o_mi setAlternate: NO];                                                \
    [o_mi setTag:                                                           \
        ( value )];                                                         \
    [o_menu addItem: o_mi];                                                 \
/*  Ctrl */                                                                 \
    o_mi = [[NSMenuItem alloc] initWithTitle:                               \
        [[NSString stringWithUTF8String:                                    \
            UP_ARROWHEAD                                                    \
        ] stringByAppendingString: string]                                  \
        action:nil keyEquivalent:@""];                                      \
    [o_mi setKeyEquivalentModifierMask:                                     \
        NSControlKeyMask];                                                  \
    [o_mi setAlternate: YES];                                               \
    [o_mi setTag:                                                           \
        KEY_MODIFIER_CTRL | ( value )];                                     \
    [o_menu addItem: o_mi];                                                 \
/* Ctrl+Alt */                                                              \
    o_mi = [[NSMenuItem alloc] initWithTitle:                               \
        [[NSString stringWithUTF8String:                                    \
            UP_ARROWHEAD OPTION_KEY                                         \
        ] stringByAppendingString: string]                                  \
        action:nil keyEquivalent:@""];                                      \
    [o_mi setKeyEquivalentModifierMask:                                     \
        NSControlKeyMask | NSAlternateKeyMask];                             \
    [o_mi setAlternate: YES];                                               \
    [o_mi setTag:                                                           \
        (KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT) | ( value )];                \
    [o_menu addItem: o_mi];                                                 \
/* Ctrl+Shift */                                                            \
    o_mi = [[NSMenuItem alloc] initWithTitle:                               \
        [[NSString stringWithUTF8String:                                    \
            UP_ARROWHEAD UPWARDS_WHITE_ARROW                                \
        ] stringByAppendingString: string]                                  \
        action:nil keyEquivalent:@""];                                      \
    [o_mi setKeyEquivalentModifierMask:                                     \
       NSControlKeyMask | NSShiftKeyMask];                                  \
    [o_mi setAlternate: YES];                                               \
    [o_mi setTag:                                                           \
        (KEY_MODIFIER_CTRL | KEY_MODIFIER_SHIFT) | ( value )];              \
    [o_menu addItem: o_mi];                                                 \
/* Ctrl+Apple */                                                            \
    o_mi = [[NSMenuItem alloc] initWithTitle:                               \
        [[NSString stringWithUTF8String:                                    \
            UP_ARROWHEAD PLACE_OF_INTEREST_SIGN                             \
        ] stringByAppendingString: string]                                  \
        action:nil keyEquivalent:@""];                                      \
    [o_mi setKeyEquivalentModifierMask:                                     \
        NSControlKeyMask | NSCommandKeyMask];                               \
    [o_mi setAlternate: YES];                                               \
    [o_mi setTag:                                                           \
        (KEY_MODIFIER_CTRL | KEY_MODIFIER_COMMAND) | ( value )];            \
    [o_menu addItem: o_mi];                                                 \
/* Ctrl+Alt+Shift */                                                        \
    o_mi = [[NSMenuItem alloc] initWithTitle:                               \
        [[NSString stringWithUTF8String:                                    \
            UP_ARROWHEAD OPTION_KEY UPWARDS_WHITE_ARROW                     \
        ] stringByAppendingString: string]                                  \
        action:nil keyEquivalent:@""];                                      \
    [o_mi setKeyEquivalentModifierMask:                                     \
        NSControlKeyMask | NSAlternateKeyMask | NSShiftKeyMask];            \
    [o_mi setAlternate: YES];                                               \
    [o_mi setTag:                                                           \
121 122
        (KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT | KEY_MODIFIER_SHIFT) |       \
             ( value )];                                                    \
123 124 125 126 127 128 129 130 131 132 133
    [o_menu addItem: o_mi];                                                 \
/* Ctrl+Alt+Apple */                                                        \
    o_mi = [[NSMenuItem alloc] initWithTitle:                               \
        [[NSString stringWithUTF8String:                                    \
            UP_ARROWHEAD OPTION_KEY PLACE_OF_INTEREST_SIGN                  \
        ] stringByAppendingString: string]                                  \
        action:nil keyEquivalent:@""];                                      \
    [o_mi setKeyEquivalentModifierMask:                                     \
        NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask];          \
    [o_mi setAlternate: YES];                                               \
    [o_mi setTag:                                                           \
134 135
        (KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT | KEY_MODIFIER_COMMAND) |     \
            ( value )];                                                     \
136 137 138 139 140 141 142 143 144 145 146
    [o_menu addItem: o_mi];                                                 \
/* Ctrl+Shift+Apple */                                                      \
    o_mi = [[NSMenuItem alloc] initWithTitle:                               \
        [[NSString stringWithUTF8String:                                    \
            UP_ARROWHEAD UPWARDS_WHITE_ARROW PLACE_OF_INTEREST_SIGN         \
        ] stringByAppendingString: string]                                  \
        action:nil keyEquivalent:@""];                                      \
    [o_mi setKeyEquivalentModifierMask:                                     \
        NSControlKeyMask | NSShiftKeyMask | NSCommandKeyMask];              \
    [o_mi setAlternate: YES];                                               \
    [o_mi setTag:                                                           \
147 148
        (KEY_MODIFIER_CTRL | KEY_MODIFIER_SHIFT | KEY_MODIFIER_COMMAND) |   \
            ( value )];                                                     \
149 150 151 152
    [o_menu addItem: o_mi];                                                 \
/* Ctrl+Alt+Shift+Apple */                                                  \
    o_mi = [[NSMenuItem alloc] initWithTitle:                               \
        [[NSString stringWithUTF8String:                                    \
153 154
            UP_ARROWHEAD OPTION_KEY UPWARDS_WHITE_ARROW                     \
                PLACE_OF_INTEREST_SIGN                                      \
155 156 157
        ] stringByAppendingString: string]                                  \
        action:nil keyEquivalent:@""];                                      \
    [o_mi setKeyEquivalentModifierMask:                                     \
158 159
        NSControlKeyMask | NSAlternateKeyMask | NSShiftKeyMask |            \
            NSCommandKeyMask];                                              \
160 161
    [o_mi setAlternate: YES];                                               \
    [o_mi setTag:                                                           \
162 163
        (KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT | KEY_MODIFIER_SHIFT |        \
            KEY_MODIFIER_COMMAND) | ( value )];                             \
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
    [o_menu addItem: o_mi];                                                 \
/* Alt */                                                                   \
    o_mi = [[NSMenuItem alloc] initWithTitle:                               \
        [[NSString stringWithUTF8String:                                    \
            OPTION_KEY                                                      \
        ] stringByAppendingString: string]                                  \
        action:nil keyEquivalent:@""];                                      \
    [o_mi setKeyEquivalentModifierMask:                                     \
        NSAlternateKeyMask];                                                \
    [o_mi setAlternate: YES];                                               \
    [o_mi setTag:                                                           \
        KEY_MODIFIER_ALT | ( value )];                                      \
    [o_menu addItem: o_mi];                                                 \
/* Alt+Shift */                                                             \
    o_mi = [[NSMenuItem alloc] initWithTitle:                               \
        [[NSString stringWithUTF8String:                                    \
            OPTION_KEY UPWARDS_WHITE_ARROW                                  \
        ] stringByAppendingString: string]                                  \
        action:nil keyEquivalent:@""];                                      \
    [o_mi setKeyEquivalentModifierMask:                                     \
        NSAlternateKeyMask | NSShiftKeyMask];                               \
    [o_mi setAlternate: YES];                                               \
    [o_mi setTag:                                                           \
        (KEY_MODIFIER_ALT | KEY_MODIFIER_SHIFT) | ( value )];               \
    [o_menu addItem: o_mi];                                                 \
/* Alt+Apple */                                                             \
    o_mi = [[NSMenuItem alloc] initWithTitle:                               \
        [[NSString stringWithUTF8String:                                    \
            OPTION_KEY PLACE_OF_INTEREST_SIGN                               \
        ] stringByAppendingString: string]                                  \
        action:nil keyEquivalent:@""];                                      \
    [o_mi setKeyEquivalentModifierMask:                                     \
        NSAlternateKeyMask | NSCommandKeyMask];                             \
    [o_mi setAlternate: YES];                                               \
    [o_mi setTag:                                                           \
        (KEY_MODIFIER_ALT | KEY_MODIFIER_COMMAND) | ( value )];             \
    [o_menu addItem: o_mi];                                                 \
/* Alt+Shift+Apple */                                                       \
    o_mi = [[NSMenuItem alloc] initWithTitle:                               \
        [[NSString stringWithUTF8String:                                    \
            OPTION_KEY UPWARDS_WHITE_ARROW PLACE_OF_INTEREST_SIGN           \
        ] stringByAppendingString: string]                                  \
        action:nil keyEquivalent:@""];                                      \
    [o_mi setKeyEquivalentModifierMask:                                     \
        NSAlternateKeyMask | NSShiftKeyMask | NSCommandKeyMask];            \
    [o_mi setAlternate: YES];                                               \
    [o_mi setTag:                                                           \
211 212
        (KEY_MODIFIER_ALT | KEY_MODIFIER_SHIFT | KEY_MODIFIER_COMMAND) |    \
            ( value )];                                                     \
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
    [o_menu addItem: o_mi];                                                 \
/* Shift */                                                                 \
    o_mi = [[NSMenuItem alloc] initWithTitle:                               \
        [[NSString stringWithUTF8String:                                    \
            UPWARDS_WHITE_ARROW                                             \
        ] stringByAppendingString: string]                                  \
        action:nil keyEquivalent:@""];                                      \
    [o_mi setKeyEquivalentModifierMask:                                     \
        NSShiftKeyMask];                                                    \
    [o_mi setAlternate: YES];                                               \
    [o_mi setTag:                                                           \
        KEY_MODIFIER_SHIFT | ( value )];                                    \
    [o_menu addItem: o_mi];                                                 \
/* Shift+Apple */                                                           \
    o_mi = [[NSMenuItem alloc] initWithTitle:                               \
        [[NSString stringWithUTF8String:                                    \
            UPWARDS_WHITE_ARROW PLACE_OF_INTEREST_SIGN                      \
        ] stringByAppendingString: string]                                  \
        action:nil keyEquivalent:@""];                                      \
    [o_mi setKeyEquivalentModifierMask:                                     \
        NSShiftKeyMask | NSCommandKeyMask];                                 \
    [o_mi setAlternate: YES];                                               \
    [o_mi setTag:                                                           \
        (KEY_MODIFIER_SHIFT | KEY_MODIFIER_COMMAND) | ( value )];           \
    [o_menu addItem: o_mi];                                                 \
/* Apple */                                                                 \
    o_mi = [[NSMenuItem alloc] initWithTitle:                               \
        [[NSString stringWithUTF8String:                                    \
        PLACE_OF_INTEREST_SIGN                                              \
        ] stringByAppendingString: string]                                  \
        action:nil keyEquivalent:@""];                                      \
    [o_mi setKeyEquivalentModifierMask:                                     \
        NSCommandKeyMask];                                                  \
    [o_mi setAlternate: YES];                                               \
    [o_mi setTag:                                                           \
        KEY_MODIFIER_COMMAND | ( value )];                                  \
    [o_menu addItem: o_mi];                                                 \
}

252 253
#define ADD_LABEL( o_label, superFrame, x_offset, my_y_offset, label,       \
    tooltip )                                                               \
254 255 256 257 258 259 260 261 262 263 264
{                                                                           \
    NSRect s_rc = superFrame;                                               \
    s_rc.size.height = 17;                                                  \
    s_rc.origin.x = x_offset - 3;                                           \
    s_rc.origin.y = superFrame.size.height - 17 + my_y_offset;              \
    o_label = [[[NSTextField alloc] initWithFrame: s_rc] retain];           \
    [o_label setDrawsBackground: NO];                                       \
    [o_label setBordered: NO];                                              \
    [o_label setEditable: NO];                                              \
    [o_label setSelectable: NO];                                            \
    [o_label setStringValue: label];                                        \
265
    [o_label setToolTip: tooltip];                                          \
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
    [o_label setFont:[NSFont systemFontOfSize:0]];                          \
    [o_label sizeToFit];                                                    \
}

#define ADD_TEXTFIELD( o_textfield, superFrame, x_offset, my_y_offset,      \
    my_width, tooltip, init_value )                                         \
{                                                                           \
    NSRect s_rc = superFrame;                                               \
    s_rc.origin.x = x_offset;                                               \
    s_rc.origin.y = my_y_offset;                                            \
    s_rc.size.height = 22;                                                  \
    s_rc.size.width = my_width;                                             \
    o_textfield = [[[NSTextField alloc] initWithFrame: s_rc] retain];       \
    [o_textfield setFont:[NSFont systemFontOfSize:0]];                      \
    [o_textfield setToolTip: tooltip];                                      \
    [o_textfield setStringValue: init_value];                               \
}

284 285 286 287 288 289 290 291 292 293 294 295 296 297
#define ADD_SECURETEXTFIELD( o_textfield, superFrame, x_offset, my_y_offset,      \
my_width, tooltip, init_value )                                         \
{                                                                           \
NSRect s_rc = superFrame;                                               \
s_rc.origin.x = x_offset;                                               \
s_rc.origin.y = my_y_offset;                                            \
s_rc.size.height = 22;                                                  \
s_rc.size.width = my_width;                                             \
o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];       \
[o_textfield setFont:[NSFont systemFontOfSize:0]];                      \
[o_textfield setToolTip: tooltip];                                      \
[o_textfield setStringValue: init_value];                               \
}

298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
#define ADD_COMBO( o_combo, superFrame, x_offset, my_y_offset, x2_offset,   \
    tooltip )                                                               \
{                                                                           \
    NSRect s_rc = superFrame;                                               \
    s_rc.origin.x = x_offset + 2;                                           \
    s_rc.origin.y = my_y_offset;                                            \
    s_rc.size.height = 26;                                                  \
    s_rc.size.width = superFrame.size.width + 2 - s_rc.origin.x -           \
        (x2_offset);                                                        \
    o_combo = [[[NSComboBox alloc] initWithFrame: s_rc] retain];            \
    [o_combo setFont:[NSFont systemFontOfSize:0]];                          \
    [o_combo setToolTip: tooltip];                                          \
    [o_combo setUsesDataSource:TRUE];                                       \
    [o_combo setDataSource:self];                                           \
    [o_combo setNumberOfVisibleItems:10];                                   \
    [o_combo setCompletes:YES];                                             \
}

#define ADD_RIGHT_BUTTON( o_button, superFrame, x_offset, my_y_offset,      \
    tooltip, title )                                                        \
{                                                                           \
    NSRect s_rc = superFrame;                                               \
    o_button = [[[NSButton alloc] initWithFrame: s_rc] retain];             \
    [o_button setButtonType: NSMomentaryPushInButton];                      \
    [o_button setBezelStyle: NSRoundedBezelStyle];                          \
    [o_button setTitle: title];                                             \
    [o_button setFont:[NSFont systemFontOfSize:0]];                         \
    [o_button sizeToFit];                                                   \
    s_rc = [o_button frame];                                                \
    s_rc.origin.x = superFrame.size.width - [o_button frame].size.width - 6;\
    s_rc.origin.y = my_y_offset - 6;                                        \
    s_rc.size.width += 12;                                                  \
    [o_button setFrame: s_rc];                                              \
    [o_button setToolTip: tooltip];                                         \
    [o_button setTarget: self];                                             \
    [o_button setAction: @selector(openFileDialog:)];                       \
}

#define ADD_POPUP( o_popup, superFrame, x_offset, my_y_offset, x2_offset,   \
    tooltip )                                                               \
{                                                                           \
    NSRect s_rc = superFrame;                                               \
    s_rc.origin.x = x_offset - 1;                                           \
    s_rc.origin.y = my_y_offset;                                            \
    s_rc.size.height = 26;                                                  \
    s_rc.size.width = superFrame.size.width + 2 - s_rc.origin.x -           \
        (x2_offset);                                                        \
    o_popup = [[[NSPopUpButton alloc] initWithFrame: s_rc] retain];         \
    [o_popup setFont:[NSFont systemFontOfSize:0]];                          \
    [o_popup setToolTip: tooltip];                                          \
}

#define ADD_STEPPER( o_stepper, superFrame, x_offset, my_y_offset, tooltip, \
    lower, higher )                                                         \
{                                                                           \
    NSRect s_rc = superFrame;                                               \
    s_rc.origin.x = x_offset;                                               \
    s_rc.origin.y = my_y_offset;                                            \
    s_rc.size.height = 23;                                                  \
    s_rc.size.width = 23;                                                   \
    o_stepper = [[[NSStepper alloc] initWithFrame: s_rc] retain];           \
    [o_stepper setFont:[NSFont systemFontOfSize:0]];                        \
    [o_stepper setToolTip: tooltip];                                        \
    [o_stepper setMaxValue: higher];                                        \
    [o_stepper setMinValue: lower];                                         \
    [o_stepper setTarget: self];                                            \
    [o_stepper setAction: @selector(stepperChanged:)];                      \
    [o_stepper sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |       \
        NSLeftMouseDraggedMask];                                            \
}

#define ADD_SLIDER( o_slider, superFrame, x_offset, my_y_offset, my_width,  \
    tooltip, lower, higher )                                                \
{                                                                           \
    NSRect s_rc = superFrame;                                               \
    s_rc.origin.x = x_offset;                                               \
    s_rc.origin.y = my_y_offset;                                            \
    s_rc.size.height = 21;                                                  \
    s_rc.size.width = my_width;                                             \
    o_slider = [[[NSSlider alloc] initWithFrame: s_rc] retain];             \
    [o_slider setFont:[NSFont systemFontOfSize:0]];                         \
    [o_slider setToolTip: tooltip];                                         \
    [o_slider setMaxValue: higher];                                         \
    [o_slider setMinValue: lower];                                          \
}

#define ADD_CHECKBOX( o_checkbox, superFrame, x_offset, my_y_offset, label, \
    tooltip, init_value, position )                                         \
{                                                                           \
    NSRect s_rc = superFrame;                                               \
    s_rc.size.height = 18;                                                  \
    s_rc.origin.x = x_offset - 2;                                           \
    s_rc.origin.y = superFrame.size.height - 18 + my_y_offset;              \
    o_checkbox = [[[NSButton alloc] initWithFrame: s_rc] retain];           \
    [o_checkbox setFont:[NSFont systemFontOfSize:0]];                       \
    [o_checkbox setButtonType: NSSwitchButton];                             \
    [o_checkbox setImagePosition: position];                                \
    [o_checkbox setIntValue: init_value];                                   \
    [o_checkbox setTitle: label];                                           \
    [o_checkbox setToolTip: tooltip];                                       \
    [o_checkbox sizeToFit];                                                 \
}

401 402 403 404
@implementation VLCConfigControl
- (id)initWithFrame: (NSRect)frame
{
    return [self initWithFrame: frame
405
                    item: nil];
406 407 408
}

- (id)initWithFrame: (NSRect)frame
409
        item: (module_config_t *)_p_item
410 411 412 413 414
{
    self = [super initWithFrame: frame];

    if( self != nil )
    {
415
        p_item = _p_item;
416
        psz_name = p_item->psz_name;
417
        o_label = NULL;
418
        i_type = p_item->i_type;
419
        i_view_type = 0;
420 421 422 423 424 425
        b_advanced = p_item->b_advanced;
        [self setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin ];
    }
    return (self);
}

426 427 428 429 430 431 432
- (void)setYPos:(int)i_yPos
{
    NSRect frame = [self frame];
    frame.origin.y = i_yPos;
    [self setFrame:frame];
}

433 434 435
- (void)dealloc
{
    if( o_label ) [o_label release];
436
    free( psz_name );
437 438 439
    [super dealloc];
}

440 441 442 443 444 445
+ (int)calcVerticalMargin: (int)i_curItem lastItem: (int)i_lastItem
{
    int i_margin;
    switch( i_curItem )
    {
    case CONFIG_ITEM_STRING:
446 447 448 449 450 451 452 453 454 455
    case CONFIG_ITEM_PASSWORD:
        switch( i_lastItem )
        {
        case CONFIG_ITEM_STRING:
        case CONFIG_ITEM_PASSWORD:
            i_margin = 8;
            break;
        case CONFIG_ITEM_STRING_LIST:
            i_margin = 7;
            break;
456 457
        case CONFIG_ITEM_LOADFILE:
        case CONFIG_ITEM_SAVEFILE:
458 459 460 461 462 463 464 465 466 467 468 469 470 471
            i_margin = 8;
            break;
        case CONFIG_ITEM_MODULE:
            i_margin = 4;
            break;
        case CONFIG_ITEM_INTEGER:
            i_margin = 7;
            break;
        case CONFIG_ITEM_RANGED_INTEGER:
            i_margin = 5;
            break;
        case CONFIG_ITEM_BOOL:
            i_margin = 7;
            break;
472
        case CONFIG_ITEM_KEY:
473 474 475 476 477 478 479 480 481 482
            i_margin = 6;
            break;
        case CONFIG_ITEM_MODULE_LIST:
            i_margin = 8;
            break;
        default:
            i_margin = 20;
            break;
        }
        break;
483 484 485 486
    case CONFIG_ITEM_STRING_LIST:
        switch( i_lastItem )
        {
        case CONFIG_ITEM_STRING:
487
        case CONFIG_ITEM_PASSWORD:
488 489 490 491 492
            i_margin = 8;
            break;
        case CONFIG_ITEM_STRING_LIST:
            i_margin = 7;
            break;
493 494
        case CONFIG_ITEM_LOADFILE:
        case CONFIG_ITEM_SAVEFILE:
495 496 497 498 499 500 501 502 503 504 505 506 507 508
            i_margin = 6;
            break;
        case CONFIG_ITEM_MODULE:
            i_margin = 4;
            break;
        case CONFIG_ITEM_INTEGER:
            i_margin = 7;
            break;
        case CONFIG_ITEM_RANGED_INTEGER:
            i_margin = 5;
            break;
        case CONFIG_ITEM_BOOL:
            i_margin = 7;
            break;
509
        case CONFIG_ITEM_KEY:
510 511 512 513 514 515 516 517 518 519
            i_margin = 6;
            break;
        case CONFIG_ITEM_MODULE_LIST:
            i_margin = 8;
            break;
        default:
            i_margin = 20;
            break;
        }
        break;
520 521
    case CONFIG_ITEM_LOADFILE:
    case CONFIG_ITEM_SAVEFILE:
522 523 524
        switch( i_lastItem )
        {
        case CONFIG_ITEM_STRING:
525
        case CONFIG_ITEM_PASSWORD:
526 527 528 529 530
            i_margin = 13;
            break;
        case CONFIG_ITEM_STRING_LIST:
            i_margin = 10;
            break;
531 532
        case CONFIG_ITEM_LOADFILE:
        case CONFIG_ITEM_SAVEFILE:
533 534 535 536 537 538 539 540 541 542 543 544 545 546
            i_margin = 9;
            break;
        case CONFIG_ITEM_MODULE:
            i_margin = 9;
            break;
        case CONFIG_ITEM_INTEGER:
            i_margin = 10;
            break;
        case CONFIG_ITEM_RANGED_INTEGER:
            i_margin = 8;
            break;
        case CONFIG_ITEM_BOOL:
            i_margin = 10;
            break;
547
        case CONFIG_ITEM_KEY:
548 549 550 551 552 553 554 555 556 557 558 559 560 561
            i_margin = 9;
            break;
        case CONFIG_ITEM_MODULE_LIST:
            i_margin = 11;
            break;
        default:
            i_margin = 23;
            break;
        }
        break;
    case CONFIG_ITEM_MODULE:
        switch( i_lastItem )
        {
        case CONFIG_ITEM_STRING:
562
        case CONFIG_ITEM_PASSWORD:
563 564 565 566 567
            i_margin = 8;
            break;
        case CONFIG_ITEM_STRING_LIST:
            i_margin = 7;
            break;
568 569
        case CONFIG_ITEM_LOADFILE:
        case CONFIG_ITEM_SAVEFILE:
570 571 572 573 574 575 576 577 578 579 580 581 582 583
            i_margin = 6;
            break;
        case CONFIG_ITEM_MODULE:
            i_margin = 5;
            break;
        case CONFIG_ITEM_INTEGER:
            i_margin = 7;
            break;
        case CONFIG_ITEM_RANGED_INTEGER:
            i_margin = 6;
            break;
        case CONFIG_ITEM_BOOL:
            i_margin = 8;
            break;
584
        case CONFIG_ITEM_KEY:
585 586 587 588 589 590 591 592 593 594 595 596 597 598
            i_margin = 7;
            break;
        case CONFIG_ITEM_MODULE_LIST:
            i_margin = 9;
            break;
        default:
            i_margin = 20;
            break;
        }
        break;
    case CONFIG_ITEM_INTEGER:
        switch( i_lastItem )
        {
        case CONFIG_ITEM_STRING:
599
        case CONFIG_ITEM_PASSWORD:
600 601 602 603 604
            i_margin = 8;
            break;
        case CONFIG_ITEM_STRING_LIST:
            i_margin = 7;
            break;
605 606
        case CONFIG_ITEM_LOADFILE:
        case CONFIG_ITEM_SAVEFILE:
607 608 609 610 611 612 613 614 615 616 617 618 619 620
            i_margin = 6;
            break;
        case CONFIG_ITEM_MODULE:
            i_margin = 4;
            break;
        case CONFIG_ITEM_INTEGER:
            i_margin = 7;
            break;
        case CONFIG_ITEM_RANGED_INTEGER:
            i_margin = 5;
            break;
        case CONFIG_ITEM_BOOL:
            i_margin = 7;
            break;
621
        case CONFIG_ITEM_KEY:
622 623 624 625 626 627 628 629 630 631 632 633 634 635
            i_margin = 6;
            break;
        case CONFIG_ITEM_MODULE_LIST:
            i_margin = 8;
            break;
        default:
            i_margin = 20;
            break;
        }
        break;
    case CONFIG_ITEM_RANGED_INTEGER:
        switch( i_lastItem )
        {
        case CONFIG_ITEM_STRING:
636
        case CONFIG_ITEM_PASSWORD:
637 638 639 640 641
            i_margin = 8;
            break;
        case CONFIG_ITEM_STRING_LIST:
            i_margin = 7;
            break;
642 643
        case CONFIG_ITEM_LOADFILE:
        case CONFIG_ITEM_SAVEFILE:
644 645 646 647 648 649 650 651 652 653 654 655 656 657
            i_margin = 8;
            break;
        case CONFIG_ITEM_MODULE:
            i_margin = 4;
            break;
        case CONFIG_ITEM_INTEGER:
            i_margin = 7;
            break;
        case CONFIG_ITEM_RANGED_INTEGER:
            i_margin = 5;
            break;
        case CONFIG_ITEM_BOOL:
            i_margin = 7;
            break;
658
        case CONFIG_ITEM_KEY:
659 660 661 662 663 664 665 666 667 668 669 670 671 672
            i_margin = 6;
            break;
        case CONFIG_ITEM_MODULE_LIST:
            i_margin = 8;
            break;
        default:
            i_margin = 20;
            break;
        }
        break;
    case CONFIG_ITEM_BOOL:
        switch( i_lastItem )
        {
        case CONFIG_ITEM_STRING:
673
        case CONFIG_ITEM_PASSWORD:
674
            i_margin = 10;
675 676
            break;
        case CONFIG_ITEM_STRING_LIST:
677
            i_margin = 9;
678
            break;
679 680
        case CONFIG_ITEM_LOADFILE:
        case CONFIG_ITEM_SAVEFILE:
681
            i_margin = 8;
682 683
            break;
        case CONFIG_ITEM_MODULE:
684
            i_margin = 6;
685 686
            break;
        case CONFIG_ITEM_INTEGER:
687
            i_margin = 9;
688 689
            break;
        case CONFIG_ITEM_RANGED_INTEGER:
690
            i_margin = 7;
691 692
            break;
        case CONFIG_ITEM_BOOL:
693
            i_margin = 7;
694
            break;
695
        case CONFIG_ITEM_KEY:
696
            i_margin = 5;
697 698
            break;
        case CONFIG_ITEM_MODULE_LIST:
699
            i_margin = 10;
700 701
            break;
        default:
702
            i_margin = 20;
703 704 705
            break;
        }
        break;
706
    case CONFIG_ITEM_KEY:
707 708 709
        switch( i_lastItem )
        {
        case CONFIG_ITEM_STRING:
710
        case CONFIG_ITEM_PASSWORD:
711 712 713 714 715
            i_margin = 8;
            break;
        case CONFIG_ITEM_STRING_LIST:
            i_margin = 7;
            break;
716 717
        case CONFIG_ITEM_LOADFILE:
        case CONFIG_ITEM_SAVEFILE:
718 719 720 721 722 723 724 725 726 727 728 729 730 731
            i_margin = 6;
            break;
        case CONFIG_ITEM_MODULE:
            i_margin = 6;
            break;
        case CONFIG_ITEM_INTEGER:
            i_margin = 7;
            break;
        case CONFIG_ITEM_RANGED_INTEGER:
            i_margin = 5;
            break;
        case CONFIG_ITEM_BOOL:
            i_margin = 7;
            break;
732
        case CONFIG_ITEM_KEY:
733 734 735 736 737 738 739 740 741 742 743 744 745 746
            i_margin = 8;
            break;
        case CONFIG_ITEM_MODULE_LIST:
            i_margin = 10;
            break;
        default:
            i_margin = 20;
            break;
        }
        break;
    case CONFIG_ITEM_MODULE_LIST:
        switch( i_lastItem )
        {
        case CONFIG_ITEM_STRING:
747
        case CONFIG_ITEM_PASSWORD:
748 749 750 751 752
            i_margin = 10;
            break;
        case CONFIG_ITEM_STRING_LIST:
            i_margin = 7;
            break;
753 754
        case CONFIG_ITEM_LOADFILE:
        case CONFIG_ITEM_SAVEFILE:
755 756 757 758 759 760 761 762 763 764 765 766 767 768
            i_margin = 6;
            break;
        case CONFIG_ITEM_MODULE:
            i_margin = 6;
            break;
        case CONFIG_ITEM_INTEGER:
            i_margin = 9;
            break;
        case CONFIG_ITEM_RANGED_INTEGER:
            i_margin = 5;
            break;
        case CONFIG_ITEM_BOOL:
            i_margin = 7;
            break;
769
        case CONFIG_ITEM_KEY:
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785
            i_margin = 5;
            break;
        case CONFIG_ITEM_MODULE_LIST:
            i_margin = 8;
            break;
        default:
            i_margin = 20;
            break;
        }
        break;
    default:
        i_margin = 20;
        break;
    }
    return i_margin;
}
786

787 788
+ (VLCConfigControl *)newControl: (module_config_t *)_p_item
                      withView: (NSView *)o_parent_view
789 790
{
    VLCConfigControl *p_control = NULL;
791

792
    switch( _p_item->i_type )
793 794
    {
    case CONFIG_ITEM_STRING:
795
    case CONFIG_ITEM_PASSWORD:
796
        if( !_p_item->i_list )
797
        {
798 799
            p_control = [[StringConfigControl alloc]
                    initWithItem: _p_item
Jérome Decoodt's avatar
Jérome Decoodt committed
800
                    withView: o_parent_view];
801 802 803
        }
        else
        {
804 805
            p_control = [[StringListConfigControl alloc]
                    initWithItem: _p_item
Jérome Decoodt's avatar
Jérome Decoodt committed
806
                    withView: o_parent_view];
807 808
        }
        break;
809 810
    case CONFIG_ITEM_LOADFILE:
    case CONFIG_ITEM_SAVEFILE:
811
    case CONFIG_ITEM_DIRECTORY:
812 813
        p_control = [[FileConfigControl alloc]
                    initWithItem: _p_item
Jérome Decoodt's avatar
Jérome Decoodt committed
814
                    withView: o_parent_view];
815 816 817
        break;
    case CONFIG_ITEM_MODULE:
    case CONFIG_ITEM_MODULE_CAT:
818 819
        p_control = [[ModuleConfigControl alloc]
                    initWithItem: _p_item
Jérome Decoodt's avatar
Jérome Decoodt committed
820
                    withView: o_parent_view];
821 822
        break;
    case CONFIG_ITEM_INTEGER:
823
        if( _p_item->i_list )
824
        {
825 826
            p_control = [[IntegerListConfigControl alloc]
                        initWithItem: _p_item
Jérome Decoodt's avatar
Jérome Decoodt committed
827
                        withView: o_parent_view];
828
        }
829
        else if( (_p_item->min.i != 0 || _p_item->max.i != 0) && (_p_item->min.i != INT_MIN || _p_item->max.i != INT_MAX) )
830
        {
831 832
            p_control = [[RangedIntegerConfigControl alloc]
                        initWithItem: _p_item
Jérome Decoodt's avatar
Jérome Decoodt committed
833
                        withView: o_parent_view];
834 835 836
        }
        else
        {
837 838
            p_control = [[IntegerConfigControl alloc]
                        initWithItem: _p_item
Jérome Decoodt's avatar
Jérome Decoodt committed
839
                        withView: o_parent_view];
840 841
        }
        break;
842
    case CONFIG_ITEM_BOOL:
843 844
        p_control = [[BoolConfigControl alloc]
                    initWithItem: _p_item
Jérome Decoodt's avatar
Jérome Decoodt committed
845
                    withView: o_parent_view];
846 847
        break;
    case CONFIG_ITEM_FLOAT:
848
        if( (_p_item->min.i != 0 || _p_item->max.i != 0) && (_p_item->min.i != INT_MIN || _p_item->max.i != INT_MAX) )
849
        {
850 851
            p_control = [[RangedFloatConfigControl alloc]
                        initWithItem: _p_item
Jérome Decoodt's avatar
Jérome Decoodt committed
852
                        withView: o_parent_view];
853 854 855
        }
        else
        {
856 857
            p_control = [[FloatConfigControl alloc]
                        initWithItem: _p_item
Jérome Decoodt's avatar
Jérome Decoodt committed
858
                        withView: o_parent_view];
859 860
        }
        break;
861 862 863
    /* don't display keys in the advanced settings, since the current controls 
    are broken by design. The user is required to change hotkeys in the sprefs
    and can only change really advanced stuff here..
864
    case CONFIG_ITEM_KEY:
865
        p_control = [[KeyConfigControl alloc]
866
                        initWithItem: _p_item
Jérome Decoodt's avatar
Jérome Decoodt committed
867
                        withView: o_parent_view];
868
        break; */
869 870
    case CONFIG_ITEM_MODULE_LIST:
    case CONFIG_ITEM_MODULE_LIST_CAT:
871 872
        p_control = [[ModuleListConfigControl alloc]
                    initWithItem: _p_item
Jérome Decoodt's avatar
Jérome Decoodt committed
873
                    withView: o_parent_view];
874 875 876 877 878 879 880
        break;
    default:
        break;
    }
    return p_control;
}

881
- (NSString *)name
882
{
883
    return [[VLCMain sharedInstance] localizedString: psz_name];
884 885
}

886
- (int)type
887 888 889 890
{
    return i_type;
}

891
- (int)viewType
892 893 894 895
{
    return i_view_type;
}

896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915
- (BOOL)isAdvanced
{
    return b_advanced;
}

- (int)intValue
{
    return 0;
}

- (float)floatValue
{
    return 0;
}

- (char *)stringValue
{
    return NULL;
}

916
- (void)applyChanges
917
{
918 919
    vlc_value_t val;
    switch( p_item->i_type )
920
    {
921
    case CONFIG_ITEM_STRING:
922
    case CONFIG_ITEM_PASSWORD:
923 924
    case CONFIG_ITEM_LOADFILE:
    case CONFIG_ITEM_SAVEFILE:
925 926 927 928 929 930 931 932 933
    case CONFIG_ITEM_DIRECTORY:
    case CONFIG_ITEM_MODULE:
    case CONFIG_ITEM_MODULE_LIST:
    case CONFIG_ITEM_MODULE_LIST_CAT:
        config_PutPsz( VLCIntf, psz_name, [self stringValue] );
        break;
    case CONFIG_ITEM_KEY:
        /* So you don't need to restart to have the changes take effect */
        val.i_int = [self intValue];
934
        var_Set( VLCIntf->p_libvlc, psz_name, val );
935 936 937 938 939 940 941
    case CONFIG_ITEM_INTEGER:
    case CONFIG_ITEM_BOOL:
        config_PutInt( VLCIntf, psz_name, [self intValue] );
        break;
    case CONFIG_ITEM_FLOAT:
        config_PutFloat( VLCIntf, psz_name, [self floatValue] );
        break;
942 943
    }
}
944

945 946 947 948
- (void)resetValues
{
}

949
- (int)labelSize
950 951 952
{
    return [o_label frame].size.width;
}
953 954 955 956 957 958

- (void) alignWithXPosition:(int)i_xPos;
{
    /* FIXME: not implemented atm, but created to shut up the warning
     * about "method definition not found" -- FK @ 7/24/05 */
}
959 960 961
@end

@implementation StringConfigControl
962 963
- (id) initWithItem: (module_config_t *)_p_item
           withView: (NSView *)o_parent_view
964
{
965 966 967 968 969
    NSRect mainFrame = [o_parent_view frame];
    NSString *o_labelString, *o_textfieldString, *o_textfieldTooltip;
    mainFrame.size.height = 22;
    mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
    mainFrame.origin.x = LEFTMARGIN;
Jérome Decoodt's avatar
Jérome Decoodt committed
970
    mainFrame.origin.y = 0;
971 972

    if( [super initWithFrame: mainFrame item: _p_item] != nil )
973
    {
974 975 976 977 978
        if( p_item->i_type == CONFIG_ITEM_PASSWORD )
            i_view_type = CONFIG_ITEM_PASSWORD;
        else
            i_view_type = CONFIG_ITEM_STRING;

979 980 981 982
        o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
                              [[VLCMain sharedInstance] localizedString: (char *)p_item->psz_longtext]
                                                          toWidth: PREFS_WRAP];

983 984
        /* add the label */
        if( p_item->psz_text )
985
            o_labelString = [[VLCMain sharedInstance]
986
                                localizedString: (char *)p_item->psz_text];
987 988
        else
            o_labelString = [NSString stringWithString:@""];
989
        ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_textfieldTooltip )
990
        [o_label setAutoresizingMask:NSViewNotSizable ];
991
        [self addSubview: o_label];
992

993
        /* build the textfield */
994
        if( p_item->value.psz )
995
            o_textfieldString = [[VLCMain sharedInstance]
996
                                    localizedString: (char *)p_item->value.psz];
997 998
        else
            o_textfieldString = [NSString stringWithString: @""];
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010
        if( p_item->i_type == CONFIG_ITEM_PASSWORD )
        {
            ADD_SECURETEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
                          0, mainFrame.size.width - [o_label frame].size.width -
                          2, o_textfieldTooltip, o_textfieldString )
        }
        else
        {
            ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
                            0, mainFrame.size.width - [o_label frame].size.width -
                            2, o_textfieldTooltip, o_textfieldString )
        }
1011
        [o_textfield setAutoresizingMask:NSViewWidthSizable ];
1012

1013
        [self addSubview: o_textfield];
1014 1015 1016 1017
    }
    return self;
}

1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
- (void) alignWithXPosition:(int)i_xPos
{
    NSRect frame;
    NSRect superFrame = [self frame];
    frame = [o_label frame];
    frame.origin.x = i_xPos - frame.size.width - 3;
    [o_label setFrame:frame];

    frame = [o_textfield frame];
    frame.origin.x = i_xPos + 2;
    frame.size.width = superFrame.size.width - frame.origin.x - 1;
    [o_textfield setFrame:frame];
}

1032 1033 1034 1035 1036 1037 1038 1039
- (void)dealloc
{
    [o_textfield release];
    [super dealloc];
}

- (char *)stringValue
{
1040 1041
    return [[VLCMain sharedInstance] delocalizeString:
                        [o_textfield stringValue]];
1042
}
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055

- (void)resetValues
{
    NSString *o_textfieldString;
    char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );
    if( psz_value )
        o_textfieldString = [[VLCMain sharedInstance]
                                localizedString: psz_value];
    else
        o_textfieldString = [NSString stringWithString: @""];
    free( psz_value );
    [super resetValues];
}
1056 1057 1058
@end

@implementation StringListConfigControl
1059 1060
- (id) initWithItem: (module_config_t *)_p_item
           withView: (NSView *)o_parent_view
1061
{
1062 1063 1064 1065 1066
    NSRect mainFrame = [o_parent_view frame];
    NSString *o_labelString, *o_textfieldTooltip;
    mainFrame.size.height = 22;
    mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
    mainFrame.origin.x = LEFTMARGIN;
Jérome Decoodt's avatar
Jérome Decoodt committed
1067
    mainFrame.origin.y = 0;
1068 1069

    if( [super initWithFrame: mainFrame item: _p_item] != nil )
1070 1071
    {
        int i_index;
1072
        i_view_type = CONFIG_ITEM_STRING_LIST;
1073 1074 1075 1076 1077

        o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
                              [[VLCMain sharedInstance]
                               localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];

1078 1079
        /* add the label */
        if( p_item->psz_text )
1080
            o_labelString = [[VLCMain sharedInstance]
1081
                                localizedString: (char *)p_item->psz_text];
1082 1083
        else
            o_labelString = [NSString stringWithString:@""];
1084
        ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_textfieldTooltip )
1085
        [o_label setAutoresizingMask:NSViewNotSizable ];
1086
        [self addSubview: o_label];
1087

1088 1089 1090 1091
        /* build the textfield */
        ADD_COMBO( o_combo, mainFrame, [o_label frame].size.width,
            -2, 0, o_textfieldTooltip )
        [o_combo setAutoresizingMask:NSViewWidthSizable ];
1092
        for( i_index = 0; i_index < p_item->i_list; i_index++ )
1093 1094 1095 1096
        {
            if( !p_item->value.psz && !p_item->ppsz_list[i_index] )
                [o_combo selectItemAtIndex: i_index];
            else if( p_item->value.psz && p_item->ppsz_list[i_index] &&
1097
                !strcmp( p_item->value.psz, p_item->ppsz_list[i_index] ) )
1098
                [o_combo selectItemAtIndex: i_index];
1099
       }
1100
        [self addSubview: o_combo];
1101 1102 1103 1104
    }
    return self;
}

1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118
- (void) alignWithXPosition:(int)i_xPos
{
    NSRect frame;
    NSRect superFrame = [self frame];
    frame = [o_label frame];
    frame.origin.x = i_xPos - frame.size.width - 3;
    [o_label setFrame:frame];

    frame = [o_combo frame];
    frame.origin.x = i_xPos + 2;
    frame.size.width = superFrame.size.width - frame.origin.x + 2;
    [o_combo setFrame:frame];
}

1119 1120 1121 1122 1123 1124 1125 1126
- (void)dealloc
{
    [o_combo release];
    [super dealloc];
}

- (char *)stringValue
{
1127 1128 1129 1130 1131 1132 1133 1134
    if( [o_combo indexOfSelectedItem] >= 0 ) {
        if( p_item->ppsz_list[[o_combo indexOfSelectedItem]] != NULL )
            return strdup( p_item->ppsz_list[[o_combo indexOfSelectedItem]] );
    } else {
        if( [[VLCMain sharedInstance] delocalizeString: [o_combo stringValue]] != NULL )
            return strdup( [[VLCMain sharedInstance] delocalizeString: [o_combo stringValue]] );
    }
    return NULL;
1135
}
1136 1137 1138 1139 1140 1141 1142 1143

- (void)resetValues
{
    int i_index;
    [o_combo reloadData];
    char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );

    for( i_index = 0; i_index < p_item->i_list; i_index++ )
1144 1145 1146 1147
    {
        if( !psz_value && !p_item->ppsz_list[i_index] )
            [o_combo selectItemAtIndex: i_index];
        else if( psz_value && p_item->ppsz_list[i_index] &&
1148 1149
            !strcmp( psz_value, p_item->ppsz_list[i_index] ) )
            [o_combo selectItemAtIndex: i_index];
1150
    }
1151 1152 1153 1154

    free( psz_value );
    [super resetValues];
}
1155 1156 1157
@end

@implementation StringListConfigControl (NSComboBoxDataSource)
1158
- (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox
1159
{
1160
        return p_item->i_list;
1161 1162
}

1163
- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)i_index
1164 1165 1166
{
    if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
    {
1167
        return [[VLCMain sharedInstance]
1168
                    localizedString: (char *)p_item->ppsz_list_text[i_index]];
1169
    } else return [[VLCMain sharedInstance]
1170
                    localizedString: (char *)p_item->ppsz_list[i_index]];
1171 1172
}
@end
1173

1174
@implementation FileConfigControl
1175 1176
- (id) initWithItem: (module_config_t *)_p_item
           withView: (NSView *)o_parent_view
1177
{
1178
    NSRect mainFrame = [o_parent_view frame];
1179
    NSString *o_labelString, *o_itemTooltip, *o_textfieldString;
1180 1181 1182
    mainFrame.size.height = 46;
    mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
    mainFrame.origin.x = LEFTMARGIN;
Jérome Decoodt's avatar
Jérome Decoodt committed
1183
    mainFrame.origin.y = 0;
1184 1185

    if( [super initWithFrame: mainFrame item: _p_item] != nil )
1186
    {
1187
        i_view_type = CONFIG_ITEM_LOADFILE;
1188

1189 1190 1191 1192
        o_itemTooltip = [[VLCMain sharedInstance]
                           wrapString: [[VLCMain sharedInstance]
                                        localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];

1193
        /* is it a directory */
1194
        b_directory = ( [self type] == CONFIG_ITEM_DIRECTORY ) ? YES : NO;
1195 1196 1197

        /* add the label */
        if( p_item->psz_text )
1198
            o_labelString = [[VLCMain sharedInstance]
1199
                                localizedString: (char *)p_item->psz_text];
1200 1201
        else
            o_labelString = [NSString stringWithString:@""];
1202
        ADD_LABEL( o_label, mainFrame, 0, 3, o_labelString, o_itemTooltip )
1203
        [o_label setAutoresizingMask:NSViewNotSizable ];
1204
        [self addSubview: o_label];
1205

1206
        /* build the button */
1207
        ADD_RIGHT_BUTTON( o_button, mainFrame, 0, 0, o_itemTooltip,
1208
                            _NS("Browse...") )
1209 1210
        [o_button setAutoresizingMask:NSViewMinXMargin ];
        [self addSubview: o_button];
1211

1212
        /* build the textfield */
1213
        if( p_item->value.psz )
1214
            o_textfieldString = [NSString stringWithFormat: @"%s", (char *)p_item->value.psz];
1215 1216
        else
            o_textfieldString = [NSString stringWithString: @""];
1217 1218
        ADD_TEXTFIELD( o_textfield, mainFrame, 12, 2, mainFrame.size.width -
                        8 - [o_button frame].size.width,
1219
                        o_itemTooltip, o_textfieldString )
1220
        [o_textfield setAutoresizingMask:NSViewWidthSizable ];
1221
        [self addSubview: o_textfield];
1222 1223 1224 1225
    }
    return self;
}

1226 1227 1228 1229 1230
- (void) alignWithXPosition:(int)i_xPos
{
    ;
}

1231 1232 1233 1234 1235 1236 1237 1238 1239 1240
- (void)dealloc
{
    [o_textfield release];
    [o_button release];
    [super dealloc];
}

- (IBAction)openFileDialog: (id)sender
{
    NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1241 1242 1243

    [o_open_panel setTitle: (b_directory)?
        _NS("Select a directory"):_NS("Select a file")];
1244 1245
    [o_open_panel setPrompt: _NS("Select")];
    [o_open_panel setAllowsMultipleSelection: NO];
1246 1247
    [o_open_panel setCanChooseFiles: !b_directory];
    [o_open_panel setCanChooseDirectories: b_directory];
1248 1249 1250 1251 1252
    [o_open_panel beginSheetForDirectory:nil
        file:nil
        types:nil
        modalForWindow:[sender window]
        modalDelegate: self
1253
        didEndSelector: @selector(pathChosenInPanel:
1254 1255 1256 1257 1258
                        withReturn:
                        contextInfo:)
        contextInfo: nil];
}

1259 1260
- (void)pathChosenInPanel:(NSOpenPanel *)o_sheet
    withReturn:(int)i_return_code contextInfo:(void  *)o_context_info
1261 1262 1263
{
    if( i_return_code == NSOKButton )
    {
1264
        NSString *o_path = [[[o_sheet URLs] objectAtIndex: 0] path];
1265 1266 1267 1268 1269 1270
        [o_textfield setStringValue: o_path];
    }
}

- (char *)stringValue
{
1271 1272 1273 1274
    if( [[o_textfield stringValue] length] != 0)
        return strdup( [[o_textfield stringValue] fileSystemRepresentation] );
    else
        return NULL;
1275
}
1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288

-(void)resetValues
{
    NSString *o_textfieldString;
    char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );
    if( psz_value )
        o_textfieldString = [NSString stringWithFormat: @"%s", psz_value];
    else
        o_textfieldString = [NSString stringWithString: @""];

    free(psz_value);
    [super resetValues];
}
1289 1290
@end

1291 1292 1293
@implementation ModuleConfigControl
- (id) initWithItem: (module_config_t *)_p_item
           withView: (NSView *)o_parent_view
1294
{
1295 1296 1297 1298 1299
    NSRect mainFrame = [o_parent_view frame];
    NSString *o_labelString, *o_popupTooltip;
    mainFrame.size.height = 22;
    mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
    mainFrame.origin.x = LEFTMARGIN;
Jérome Decoodt's avatar
Jérome Decoodt committed
1300
    mainFrame.origin.y = 0;
1301 1302

    if( [super initWithFrame: mainFrame item: _p_item] != nil )
1303
    {
1304 1305
        i_view_type = CONFIG_ITEM_MODULE;

1306 1307 1308 1309
        o_popupTooltip = [[VLCMain sharedInstance] wrapString:
                          [[VLCMain sharedInstance]
                           localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];

1310 1311
        /* add the label */
        if( p_item->psz_text )
1312
            o_labelString = [[VLCMain sharedInstance]
1313
                                localizedString: (char *)p_item->psz_text];
1314 1315
        else
            o_labelString = [NSString stringWithString:@""];
1316
        ADD_LABEL( o_label, mainFrame, 0, -1, o_labelString, o_popupTooltip )
1317
        [o_label setAutoresizingMask:NSViewNotSizable ];
1318
        [self addSubview: o_label];
1319

1320 1321 1322 1323 1324 1325 1326
        /* build the popup */
        ADD_POPUP( o_popup, mainFrame, [o_label frame].size.width,
            -2, 0, o_popupTooltip )
        [o_popup setAutoresizingMask:NSViewWidthSizable ];
        [o_popup addItemWithTitle: _NS("Default")];
        [[o_popup lastItem] setTag: -1];
        [o_popup selectItem: [o_popup lastItem]];
1327

1328
        [self resetValues];
1329 1330 1331 1332 1333
        [self addSubview: o_popup];
    }
    return self;
}

1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347
- (void) alignWithXPosition:(int)i_xPos
{
    NSRect frame;
    NSRect superFrame = [self frame];
    frame = [o_label frame];
    frame.origin.x = i_xPos - frame.size.width - 3;
    [o_label setFrame:frame];

    frame = [o_popup frame];
    frame.origin.x = i_xPos - 1;
    frame.size.width = superFrame.size.width - frame.origin.x + 2;
    [o_popup setFrame:frame];
}

1348 1349 1350 1351 1352 1353 1354 1355 1356 1357
- (void)dealloc
{
    [o_popup release];
    [super dealloc];
}

- (char *)stringValue
{
    NSString *newval = [o_popup titleOfSelectedItem];
    char *returnval = NULL;
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
1358 1359
    size_t i_module_index;
    module_t *p_parser, **p_list;
1360

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
1361 1362
    p_list = module_list_get( NULL );
    for( i_module_index = 0; p_list[i_module_index]; i_module_index++ )
1363
    {
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
1364
        p_parser = p_list[i_module_index];
1365

1366 1367
        if( p_item->i_type == CONFIG_ITEM_MODULE )
        {
1368
            if( module_provides( p_parser, p_item->psz_type ) )
1369 1370
            {
                NSString *o_description = [[VLCMain sharedInstance]
1371
                    localizedString: module_get_name( p_parser, TRUE )];
1372 1373
                if( [newval isEqualToString: o_description] )
                {
1374
                    returnval = strdup( module_get_object( p_parser ));
1375 1376 1377 1378 1379 1380
                    break;
                }
            }
        }
        else
        {
1381 1382
            int i;

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
1383
            if( module_is_main( p_parser) )
1384
                continue;
1385
            unsigned int confsize, unused;
1386
            module_config_t *p_config = module_config_get( p_parser, &confsize );
1387
            for ( i = 0; i < confsize; i++ )
1388
            {
1389
                module_config_t *p_item = p_config + i;
1390
                /* Hack: required subcategory is stored in i_min */
1391 1392
                if( p_item->i_type == CONFIG_SUBCATEGORY &&
                    p_item->value.i == p_item->min.i )
1393 1394
                {
                    NSString *o_description = [[VLCMain sharedInstance]
1395
                        localizedString: module_get_name( p_parser, TRUE )];
1396 1397
                    if( [newval isEqualToString: o_description] )
                    {
1398
                        returnval = strdup(module_get_object( p_parser ));
1399 1400 1401
                        break;
                    }
                }
1402
            }
1403
            module_config_free( p_config );
1404 1405
        }
    }
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
1406
    module_list_free( p_list );
1407 1408
    return returnval;
}
1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425

-(void)resetValues
{
    /* build a list of available modules */
    size_t i_index;
    module_t *p_parser, **p_list;

    p_list = module_list_get( NULL );
    for( i_index = 0; p_list[i_index]; i_index++ )
    {
        p_parser = p_list[i_index];

        if( p_item->i_type == CONFIG_ITEM_MODULE )
        {
            if( module_provides( p_parser, p_item->psz_type ) )
            {
                NSString *o_description = [[VLCMain sharedInstance]
1426
                    localizedString: module_get_name( p_parser, TRUE )];
1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453
                [o_popup addItemWithTitle: o_description];
                char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );

                if( psz_value &&
                    !strcmp( psz_value, module_get_object( p_parser ) ) )
                    [o_popup selectItem:[o_popup lastItem]];

                free(psz_value);
            }
        }
        else
        {
            int i;

            if( module_is_main( p_parser ) )
                continue;
            unsigned int confsize;
            unsigned int unused;
            module_config_t *p_configlist = module_config_get( p_parser, &confsize );
            for ( i = 0; i < confsize; i++ )
            {
                module_config_t *p_config = &p_configlist[i];
                /* Hack: required subcategory is stored in i_min */
                if( p_config->i_type == CONFIG_SUBCATEGORY &&
                    config_GetInt( VLCIntf, p_item->psz_name) == p_item->min.i )
                {
                    NSString *o_description = [[VLCMain sharedInstance]
1454
                        localizedString: module_get_name( p_parser, TRUE )];
1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470
                    [o_popup addItemWithTitle: o_description];
                    char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );

                    if( psz_value && !strcmp(psz_value,
                                            module_get_object( p_parser )) )
                        [o_popup selectItem:[o_popup lastItem]];

                    free( psz_value );
                }
            }
            module_config_free( p_configlist );
        }
    }
    module_list_free( p_list );
    [super resetValues];
}
1471 1472 1473 1474 1475 1476 1477
@end

@implementation IntegerConfigControl
- (id) initWithItem: (module_config_t *)_p_item
           withView: (NSView *)o_parent_view
{
    NSRect mainFrame = [o_parent_view frame];
1478
    NSString *o_labelString, *o_tooltip;
1479 1480 1481
    mainFrame.size.height = 23;
    mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
    mainFrame.origin.x = LEFTMARGIN;
Jérome Decoodt's avatar
Jérome Decoodt committed
1482
    mainFrame.origin.y = 0;
1483 1484 1485

    if( [super initWithFrame: mainFrame item: _p_item] != nil )
    {
1486 1487
        i_view_type = CONFIG_ITEM_INTEGER;

1488
        o_tooltip = [[VLCMain sharedInstance] wrapString:
1489
            [[VLCMain sharedInstance]
1490
                localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1491 1492 1493

        /* add the label */
        if( p_item->psz_text )
1494
            o_labelString = [[VLCMain sharedInstance]
1495
                                localizedString: (char *)p_item->psz_text];
1496 1497
        else
            o_labelString = [NSString stringWithString:@""];
1498
        ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_tooltip )
1499 1500 1501 1502 1503
        [o_label setAutoresizingMask:NSViewNotSizable ];
        [self addSubview: o_label];

        /* build the stepper */
        ADD_STEPPER( o_stepper, mainFrame, mainFrame.size.width - 19,
1504
            0, o_tooltip, -100000, 100000)
1505
        [o_stepper setIntValue: p_item->value.i];
1506
        [o_stepper setAutoresizingMask:NSViewMaxXMargin ];
1507 1508 1509 1510
        [self addSubview: o_stepper];

        ADD_TEXTFIELD( o_textfield, mainFrame, mainFrame.size.width - 19 - 52,
            1, 49, o_tooltip, @"" )
1511
        [o_textfield setIntValue: p_item->value.i];
1512 1513 1514 1515 1516
        [o_textfield setDelegate: self];
        [[NSNotificationCenter defaultCenter] addObserver: self
            selector: @selector(textfieldChanged:)
            name: NSControlTextDidChangeNotification
            object: o_textfield];
1517
        [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1518
        [self addSubview: o_textfield];
1519 1520 1521 1522
    }
    return self;
}

1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538
- (void) alignWithXPosition:(int)i_xPos
{
    NSRect frame;
    frame = [o_label frame];
    frame.origin.x = i_xPos - frame.size.width - 3;
    [o_label setFrame:frame];

    frame = [o_textfield frame];
    frame.origin.x = i_xPos + 2;
    [o_textfield setFrame:frame];

    frame = [o_stepper frame];
    frame.origin.x = i_xPos + [o_textfield frame].size.width + 5;
    [o_stepper setFrame:frame];
}

1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555
- (void)dealloc
{
    [o_stepper release];
    [o_textfield release];
    [super dealloc];
}

- (IBAction)stepperChanged:(id)sender
{
    [o_textfield setIntValue: [o_stepper intValue]];
}

- (void)textfieldChanged:(NSNotification *)o_notification
{
    [o_stepper setIntValue: [o_textfield intValue]];
}

1556
- (int)intValue
1557
{
1558
    return [o_textfield intValue];
1559 1560
}

1561 1562 1563 1564 1565 1566
-(void)resetValues
{
    [o_textfield setIntValue: config_GetInt(VLCIntf, p_item->psz_name)];
    [super resetValues];
}

1567 1568 1569 1570
@end

@implementation IntegerListConfigControl

1571 1572
- (id) initWithItem: (module_config_t *)_p_item
           withView: (NSView *)o_parent_view
1573
{
1574 1575 1576 1577 1578
    NSRect mainFrame = [o_parent_view frame];
    NSString *o_labelString, *o_textfieldTooltip;
    mainFrame.size.height = 22;
    mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
    mainFrame.origin.x = LEFTMARGIN;
Jérome Decoodt's avatar
Jérome Decoodt committed
1579
    mainFrame.origin.y = 0;
1580 1581

    if( [super initWithFrame: mainFrame item: _p_item] != nil )
1582 1583
    {
        int i_index;
1584 1585
        i_view_type = CONFIG_ITEM_STRING_LIST;

1586 1587 1588 1589
        o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
                              [[VLCMain sharedInstance]
                               localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];        

1590 1591
        /* add the label */
        if( p_item->psz_text )
1592
            o_labelString = [[VLCMain sharedInstance]
1593
                localizedString: (char *)p_item->psz_text];
1594 1595
        else
            o_labelString = [NSString stringWithString:@""];
1596
        ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_textfieldTooltip )
1597
        [o_label setAutoresizingMask:NSViewNotSizable ];
1598
        [self addSubview: o_label];
1599

1600 1601 1602 1603
        /* build the textfield */
        ADD_COMBO( o_combo, mainFrame, [o_label frame].size.width,
            -2, 0, o_textfieldTooltip )
        [o_combo setAutoresizingMask:NSViewWidthSizable ];
1604 1605
        for( i_index = 0; i_index < p_item->i_list; i_index++ )
        {
1606
            if( p_item->value.i == p_item->pi_list[i_index] )
1607 1608 1609 1610
            {
                [o_combo selectItemAtIndex: i_index];
            }
        }
1611
        [self addSubview: o_combo];
1612 1613 1614 1615
    }
    return self;
}

1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629
- (void) alignWithXPosition:(int)i_xPos
{
    NSRect frame;
    NSRect superFrame = [self frame];
    frame = [o_label frame];
    frame.origin.x = i_xPos - frame.size.width - 3;
    [o_label setFrame:frame];

    frame = [o_combo frame];
    frame.origin.x = i_xPos + 2;
    frame.size.width = superFrame.size.width - frame.origin.x + 2;
    [o_combo setFrame:frame];
}

1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642
- (void)dealloc
{
    [o_combo release];
    [super dealloc];
}

- (int)intValue
{
    if( [o_combo indexOfSelectedItem] >= 0 )
        return p_item->pi_list[[o_combo indexOfSelectedItem]];
    else
        return [o_combo intValue];
}
1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656

-(void)resetValues
{
    int i_index;
    [o_combo reloadData];
    for( i_index = 0; i_index < p_item->i_list; i_index++ )
    {
        if( config_GetInt( VLCIntf, p_item->psz_name) == p_item->pi_list[i_index] )
        {
            [o_combo selectItemAtIndex: i_index];
        }
    }

}
1657 1658 1659
@end

@implementation IntegerListConfigControl (NSComboBoxDataSource)
1660
- (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox
1661 1662 1663 1664
{
    return p_item->i_list;
}

1665
- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)i_index
1666 1667
{
    if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
1668
        return [[VLCMain sharedInstance]
1669
                    localizedString: (char *)p_item->ppsz_list_text[i_index]];
1670 1671
    else
        return [NSString stringWithFormat: @"%i", p_item->pi_list[i_index]];
1672 1673 1674 1675
}
@end

@implementation RangedIntegerConfigControl
1676 1677
- (id) initWithItem: (module_config_t *)_p_item
           withView: (NSView *)o_parent_view
1678
{
1679 1680 1681 1682 1683
    NSRect mainFrame = [o_parent_view frame];
    NSString *o_labelString, *o_tooltip;
    mainFrame.size.height = 50;
    mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
    mainFrame.origin.x = LEFTMARGIN;
Jérome Decoodt's avatar
Jérome Decoodt committed
1684
    mainFrame.origin.y = 0;
1685 1686

    if( [super initWithFrame: mainFrame item: _p_item] != nil )
1687
    {
1688 1689
        i_view_type = CONFIG_ITEM_RANGED_INTEGER;

1690 1691 1692 1693
        o_tooltip = [[VLCMain sharedInstance] wrapString:
                     [[VLCMain sharedInstance]
                      localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];

1694 1695
        /* add the label */
        if( p_item->psz_text )
1696
            o_labelString = [[VLCMain sharedInstance]
1697
                                localizedString: (char *)p_item->psz_text];
1698 1699
        else
            o_labelString = [NSString stringWithString:@""];
1700
        ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_tooltip )
1701
        [o_label setAutoresizingMask:NSViewNotSizable ];
1702 1703
        [self addSubview: o_label];

1704 1705 1706
        /* build the textfield */
        ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
            28, 49, o_tooltip, @"" )
1707
        [o_textfield setIntValue: p_item->value.i];
1708
        [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1709 1710 1711 1712 1713 1714 1715
        [o_textfield setDelegate: self];
        [[NSNotificationCenter defaultCenter] addObserver: self
            selector: @selector(textfieldChanged:)
            name: NSControlTextDidChangeNotification
            object: o_textfield];
        [self addSubview: o_textfield];

1716
        /* build the mintextfield */
1717
        ADD_LABEL( o_textfield_min, mainFrame, 12, -30, @"-8888", @"" )
1718
        [o_textfield_min setIntValue: p_item->min.i];
1719
        [o_textfield_min setAutoresizingMask:NSViewMaxXMargin ];
1720
        [o_textfield_min setAlignment:NSRightTextAlignment];
1721
        [self addSubview: o_textfield_min];
1722

1723
        /* build the maxtextfield */
1724
        ADD_LABEL( o_textfield_max, mainFrame,
1725
                    mainFrame.size.width - 31, -30, @"8888", @"" )
1726
        [o_textfield_max setIntValue: p_item->max.i];
1727
        [o_textfield_max setAutoresizingMask:NSViewMinXMargin ];
1728
        [self addSubview: o_textfield_max];
1729

1730
        /* build the slider */
1731 1732 1733 1734 1735
        ADD_SLIDER( o_slider, mainFrame, [o_textfield_min frame].origin.x +
            [o_textfield_min frame].size.width + 6, -1, mainFrame.size.width -
            [o_textfield_max frame].size.width -
            [o_textfield_max frame].size.width - 14 -
            [o_textfield_min frame].origin.x, o_tooltip,
1736 1737
            p_item->min.i, p_item->max.i )
        [o_slider setIntValue: p_item->value.i];
1738
        [o_slider setAutoresizingMask:NSViewWidthSizable ];
1739 1740
        [o_slider setTarget: self];
        [o_slider setAction: @selector(sliderChanged:)];
1741 1742
        [o_slider sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
            NSLeftMouseDraggedMask];
1743
        [self addSubview: o_slider];
1744

1745 1746 1747 1748
    }
    return self;
}

1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760
- (void) alignWithXPosition:(int)i_xPos
{
    NSRect frame;
    frame = [o_label frame];
    frame.origin.x = i_xPos - frame.size.width - 3;
    [o_label setFrame:frame];

    frame = [o_textfield frame];
    frame.origin.x = i_xPos + 2;
    [o_textfield setFrame:frame];
}

1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783
- (void)dealloc
{
    [o_textfield release];
    [o_textfield_min release];
    [o_textfield_max release];
    [o_slider release];
    [super dealloc];
}

- (IBAction)sliderChanged:(id)sender
{
    [o_textfield setIntValue: [o_slider intValue]];
}

- (void)textfieldChanged:(NSNotification *)o_notification
{
    [o_slider setIntValue: [o_textfield intValue]];
}

- (int)intValue
{
    return [o_slider intValue];
}
1784 1785 1786 1787 1788 1789 1790 1791

- (void)resetValues
{
    int value = config_GetInt( VLCIntf, p_item->psz_name );
    [o_textfield setIntValue:value];
    [o_slider setIntValue:value];
    [super resetValues];
}
1792 1793 1794
@end

@implementation FloatConfigControl
1795 1796
- (id) initWithItem: (module_config_t *)_p_item
           withView: (NSView *)o_parent_view
1797
{
1798
    NSRect mainFrame = [o_parent_view frame];
1799
    NSString *o_labelString, *o_tooltip;
1800 1801 1802
    mainFrame.size.height = 23;
    mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
    mainFrame.origin.x = LEFTMARGIN;
Jérome Decoodt's avatar
Jérome Decoodt committed
1803
    mainFrame.origin.y = 0;
1804 1805

    if( [super initWithFrame: mainFrame item: _p_item] != nil )
1806
    {
1807 1808
        i_view_type = CONFIG_ITEM_INTEGER;

1809
        o_tooltip = [[VLCMain sharedInstance] wrapString:
1810
            [[VLCMain sharedInstance]
1811
                localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1812 1813 1814

        /* add the label */
        if( p_item->psz_text )
1815
            o_labelString = [[VLCMain sharedInstance]
1816
                                localizedString: (char *)p_item->psz_text];
1817 1818
        else
            o_labelString = [NSString stringWithString:@""];
1819
        ADD_LABEL( o_label, mainFrame, 0, -2, o_labelString, o_tooltip )
1820
        [o_label setAutoresizingMask:NSViewNotSizable ];
1821
        [self addSubview: o_label];
1822

1823 1824
        /* build the stepper */
        ADD_STEPPER( o_stepper, mainFrame, mainFrame.size.width - 19,
1825
            0, o_tooltip, -100000, 100000)
1826
        [o_stepper setFloatValue: p_item->value.f];
1827
        [o_stepper setAutoresizingMask:NSViewMaxXMargin ];
1828
        [self addSubview: o_stepper];
1829

1830 1831 1832
        /* build the textfield */
        ADD_TEXTFIELD( o_textfield, mainFrame, mainFrame.size.width - 19 - 52,
            1, 49, o_tooltip, @"" )
1833
        [o_textfield setFloatValue: p_item->value.f];
1834 1835 1836 1837 1838
        [o_textfield setDelegate: self];
        [[NSNotificationCenter defaultCenter] addObserver: self
            selector: @selector(textfieldChanged:)
            name: NSControlTextDidChangeNotification
            object: o_textfield];
1839
        [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1840
        [self addSubview: o_textfield];
1841 1842 1843 1844
    }
    return self;
}

1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860
- (void) alignWithXPosition:(int)i_xPos
{
    NSRect frame;
    frame = [o_label frame];
    frame.origin.x = i_xPos - frame.size.width - 3;
    [o_label setFrame:frame];

    frame = [o_textfield frame];
    frame.origin.x = i_xPos + 2;
    [o_textfield setFrame:frame];

    frame = [o_stepper frame];
    frame.origin.x = i_xPos + [o_textfield frame].size.width + 5;
    [o_stepper setFrame:frame];
}

1861 1862
- (void)dealloc
{
1863
    [o_stepper release];
1864 1865 1866 1867
    [o_textfield release];
    [super dealloc];
}

1868 1869 1870 1871 1872 1873 1874 1875 1876 1877
- (IBAction)stepperChanged:(id)sender
{
    [o_textfield setFloatValue: [o_stepper floatValue]];
}

- (void)textfieldChanged:(NSNotification *)o_notification
{
    [o_stepper setFloatValue: [o_textfield floatValue]];
}

1878
- (float)floatValue
1879
{
1880
    return [o_stepper floatValue];
1881
}
1882 1883 1884 1885 1886 1887

- (void)resetValues
{
    [o_textfield setFloatValue: config_GetFloat( VLCIntf, p_item->psz_name)];
    [super resetValues];
}
1888 1889 1890
@end

@implementation RangedFloatConfigControl
1891 1892
- (id) initWithItem: (module_config_t *)_p_item
           withView: (NSView *)o_parent_view
1893
{
1894 1895 1896 1897 1898
    NSRect mainFrame = [o_parent_view frame];
    NSString *o_labelString, *o_tooltip;
    mainFrame.size.height = 50;
    mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
    mainFrame.origin.x = LEFTMARGIN;
Jérome Decoodt's avatar
Jérome Decoodt committed
1899
    mainFrame.origin.y = 0;
1900 1901

    if( [super initWithFrame: mainFrame item: _p_item] != nil )
1902
    {
1903 1904
        i_view_type = CONFIG_ITEM_RANGED_INTEGER;

1905 1906 1907 1908
        o_tooltip = [[VLCMain sharedInstance] wrapString:
                     [[VLCMain sharedInstance]
                      localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];        

1909 1910
        /* add the label */
        if( p_item->psz_text )
1911
            o_labelString = [[VLCMain sharedInstance]
1912
                                localizedString: (char *)p_item->psz_text];
1913 1914
        else
            o_labelString = [NSString stringWithString:@""];
1915
        ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_tooltip )
1916
        [o_label setAutoresizingMask:NSViewNotSizable ];
1917
        [self addSubview: o_label];
1918

1919 1920 1921
        /* build the textfield */
        ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
            28, 49, o_tooltip, @"" )
1922
        [o_textfield setFloatValue: p_item->value.f];
1923 1924 1925 1926 1927 1928 1929
        [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
        [o_textfield setDelegate: self];
        [[NSNotificationCenter defaultCenter] addObserver: self
            selector: @selector(textfieldChanged:)
            name: NSControlTextDidChangeNotification
            object: o_textfield];
        [self addSubview: o_textfield];
1930

1931
        /* build the mintextfield */
1932
        ADD_LABEL( o_textfield_min, mainFrame, 12, -30, @"-8888", @"" )
1933
        [o_textfield_min setFloatValue: p_item->min.f];
1934
        [o_textfield_min setAutoresizingMask:NSViewMaxXMargin ];
1935
        [o_textfield_min setAlignment:NSRightTextAlignment];
1936
        [self addSubview: o_textfield_min];
1937

1938
        /* build the maxtextfield */
1939
        ADD_LABEL( o_textfield_max, mainFrame, mainFrame.size.width - 31,
1940
            -30, @"8888", @"" )
1941
        [o_textfield_max setFloatValue: p_item->max.f];
1942 1943
        [o_textfield_max setAutoresizingMask:NSViewMinXMargin ];
        [self addSubview: o_textfield_max];
1944

1945
        /* build the slider */
1946 1947 1948 1949
        ADD_SLIDER( o_slider, mainFrame, [o_textfield_min frame].origin.x +
            [o_textfield_min frame].size.width + 6, -1, mainFrame.size.width -
            [o_textfield_max frame].size.width -
            [o_textfield_max frame].size.width - 14 -
1950 1951 1952
            [o_textfield_min frame].origin.x, o_tooltip, p_item->min.f,
            p_item->max.f )
        [o_slider setFloatValue: p_item->value.f];
1953
        [o_slider setAutoresizingMask:NSViewWidthSizable ];
1954 1955
        [o_slider setTarget: self];
        [o_slider setAction: @selector(sliderChanged:)];
1956 1957
        [o_slider sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
            NSLeftMouseDraggedMask];
1958
        [self addSubview: o_slider];
1959 1960 1961 1962 1963

    }
    return self;
}

1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975
- (void) alignWithXPosition:(int)i_xPos
{
    NSRect frame;
    frame = [o_label frame];
    frame.origin.x = i_xPos - frame.size.width - 3;
    [o_label setFrame:frame];

    frame = [o_textfield frame];
    frame.origin.x = i_xPos + 2;
    [o_textfield setFrame:frame];
}

1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994
- (void)dealloc
{
    [o_textfield release];
    [o_textfield_min release];
    [o_textfield_max release];
    [o_slider release];
    [super dealloc];
}

- (IBAction)sliderChanged:(id)sender
{
    [o_textfield setFloatValue: [o_slider floatValue]];
}

- (void)textfieldChanged:(NSNotification *)o_notification
{
    [o_slider setFloatValue: [o_textfield floatValue]];
}

1995
- (float)floatValue
1996 1997 1998 1999
{
    return [o_slider floatValue];
}

2000 2001 2002 2003 2004 2005
- (void)resetValues
{
    [o_textfield setFloatValue: config_GetFloat(VLCIntf, p_item->psz_name)];
    [o_slider setFloatValue: config_GetFloat(VLCIntf, p_item->psz_name)];
    [super resetValues];
}
2006 2007 2008 2009
@end

@implementation BoolConfigControl

2010 2011
- (id) initWithItem: (module_config_t *)_p_item
           withView: (NSView *)o_parent_view
2012
{
2013 2014 2015 2016 2017
    NSRect mainFrame = [o_parent_view frame];
    NSString *o_labelString, *o_tooltip;
    mainFrame.size.height = 17;
    mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
    mainFrame.origin.x = LEFTMARGIN;
Jérome Decoodt's avatar
Jérome Decoodt committed
2018
    mainFrame.origin.y = 0;
2019 2020

    if( [super initWithFrame: mainFrame item: _p_item] != nil )
2021
    {
2022 2023
        i_view_type = CONFIG_ITEM_BOOL;

2024 2025 2026
        /* add the checkbox */
        o_tooltip = [[VLCMain sharedInstance]
            wrapString: [[VLCMain sharedInstance]
2027
            localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
2028
        ADD_CHECKBOX( o_checkbox, mainFrame, 0,
2029
                        0, @"", o_tooltip, p_item->value.i, NSImageLeft)
2030 2031
        [o_checkbox setAutoresizingMask:NSViewNotSizable ];
        [self addSubview: o_checkbox];
2032
        /* add the label */
2033
        if( p_item->psz_text )
2034
            o_labelString = [[VLCMain sharedInstance]
2035
                                localizedString: (char *)p_item->psz_text];
2036 2037
        else
            o_labelString = [NSString stringWithString:@""];
2038
        ADD_LABEL( o_label, mainFrame, [o_checkbox frame].size.width, 0, o_labelString, o_tooltip )
2039 2040
        [o_label setAutoresizingMask:NSViewNotSizable ];
        [self addSubview: o_label];
2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052
    }
    return self;
}

- (void)dealloc
{
    [o_checkbox release];
    [super dealloc];
}

- (int)intValue
{
2053
    return [o_checkbox intValue];
2054 2055
}

2056 2057 2058 2059 2060
- (void)resetValues
{
    [o_checkbox setState: config_GetInt( VLCIntf, p_item->psz_name)];
    [super resetValues];
}
2061
@end
2062

2063
@implementation KeyConfigControl
2064 2065 2066 2067 2068 2069 2070 2071
- (id) initWithItem: (module_config_t *)_p_item
           withView: (NSView *)o_parent_view
{
    NSRect mainFrame = [o_parent_view frame];
    NSString *o_labelString, *o_tooltip;
    mainFrame.size.height = 22;
    mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
    mainFrame.origin.x = LEFTMARGIN;
Jérome Decoodt's avatar
Jérome Decoodt committed
2072
    mainFrame.origin.y = 0;
2073 2074 2075

    if( [super initWithFrame: mainFrame item: _p_item] != nil )
    {
2076
        i_view_type = CONFIG_ITEM_KEY;
2077

2078 2079 2080 2081
        o_tooltip = [[VLCMain sharedInstance] wrapString:
                     [[VLCMain sharedInstance]
                      localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];

2082 2083
        /* add the label */
        if( p_item->psz_text )
2084
            o_labelString = [[VLCMain sharedInstance]
2085
                localizedString: (char *)p_item->psz_text];
2086 2087
        else
            o_labelString = [NSString stringWithString:@""];
2088
        ADD_LABEL( o_label, mainFrame, 0, -1, o_labelString, o_tooltip )
2089 2090 2091 2092
        [o_label setAutoresizingMask:NSViewNotSizable ];
        [self addSubview: o_label];

        /* build the popup */
2093 2094
        ADD_POPUP( o_popup, mainFrame, [o_label frame].origin.x +
            [o_label frame].size.width + 3,
2095 2096
            -2, 0, o_tooltip )
        [o_popup setAutoresizingMask:NSViewWidthSizable ];
2097

2098 2099 2100 2101
        if( o_keys_menu == nil )
        {
            unsigned int i;
            o_keys_menu = [[NSMenu alloc] initWithTitle: @"Keys Menu"];
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
2102
#warning This does not work anymore. FIXME.
2103
#if 0
2104 2105
            for ( i = 0; i < sizeof(vlc_key) / sizeof(key_descriptor_t); i++)
                if( vlc_key[i].psz_key_string )
2106
                    POPULATE_A_KEY( o_keys_menu,
2107 2108
                        [NSString stringWithUTF8String:vlc_key[i].psz_key_string]
                        , vlc_key[i].i_key_code)
2109
#endif
2110 2111
        }
        [o_popup setMenu:[o_keys_menu copyWithZone:nil]];
2112
        [o_popup selectItem:[[o_popup menu] itemWithTag:p_item->value.i]];
2113 2114 2115 2116 2117 2118
        [self addSubview: o_popup];

    }
    return self;
}

2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132
- (void) alignWithXPosition:(int)i_xPos
{
    NSRect frame;
    NSRect superFrame = [self frame];
    frame = [o_label frame];
    frame.origin.x = i_xPos - frame.size.width - 3;
    [o_label setFrame:frame];

    frame = [o_popup frame];
    frame.origin.x = i_xPos - 1;
    frame.size.width = superFrame.size.width - frame.origin.x + 2;
    [o_popup setFrame:frame];
}

2133 2134 2135 2136 2137 2138 2139 2140 2141 2142
- (void)dealloc
{
    [o_popup release];
    [super dealloc];
}

- (int)intValue
{
    return [o_popup selectedTag];
}
2143 2144 2145 2146 2147 2148

- (void)resetValues
{
    [o_popup selectItem:[[o_popup menu] itemWithTag:config_GetInt( VLCIntf, p_item->psz_name )]];
    [super resetValues];
}
2149 2150 2151 2152 2153 2154
@end

@implementation ModuleListConfigControl
- (id) initWithItem: (module_config_t *)_p_item
           withView: (NSView *)o_parent_view
{
2155
    if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
2156
        //TODO....
2157
        return nil;
2158 2159
    
    //Fill our array to know how may items we have...
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
2160 2161
    module_t *p_parser, **p_list;
    size_t i_module_index;
2162 2163
    NSRect mainFrame = [o_parent_view frame];
    NSString *o_labelString, *o_textfieldString, *o_tooltip;
2164
    
2165 2166
    o_modulearray = [[NSMutableArray alloc] initWithCapacity:10];
    /* build a list of available modules */
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
2167
    p_list = module_list_get( NULL );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
2168
    for( i_module_index = 0; p_list[i_module_index]; i_module_index++ )
2169
    {
2170
        int i;
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
2171
        p_parser = p_list[i_module_index];
2172
        
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
2173
        if( module_is_main( p_parser ) )
2174
            continue;
2175
        
2176
        unsigned int confsize;
2177
        module_config_t *p_configlist = module_config_get( p_parser, &confsize );
2178
        
2179
        for ( i = 0; i < confsize; i++ )
2180
        {
2181
            unsigned int unused;
2182
            module_config_t *p_config = &p_configlist[i];
2183 2184
            NSString *o_modulelongname, *o_modulename;
            NSNumber *o_moduleenabled = nil;
2185
            
2186 2187
            /* Hack: required subcategory is stored in i_min */
            if( p_config->i_type == CONFIG_SUBCATEGORY &&
2188
               p_config->value.i == _p_item->min.i )
2189
            {
2190
                o_modulelongname = [NSString stringWithUTF8String:
2191
                                    module_get_name( p_parser, TRUE )];
2192
                o_modulename = [NSString stringWithUTF8String:
2193 2194
                                module_get_object( p_parser )];
                
2195
                if( _p_item->value.psz &&
2196
                   strstr( _p_item->value.psz, module_get_object( p_parser ) ) )
2197 2198 2199
                    o_moduleenabled = [NSNumber numberWithBool:YES];
                else
                    o_moduleenabled = [NSNumber numberWithBool:NO];
2200
                
2201
                [o_modulearray addObject:[NSMutableArray
2202 2203
                                          arrayWithObjects: o_modulename, o_modulelongname,
                                          o_moduleenabled, nil]];
2204
            }
2205
        }
2206
        module_config_free( p_configlist );
2207
    }
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
2208
    module_list_free( p_list );
2209 2210
    
    mainFrame.size.height = 30 + 20 * [o_modulearray count];
2211 2212
    mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
    mainFrame.origin.x = LEFTMARGIN;
Jérome Decoodt's avatar
Jérome Decoodt committed
2213
    mainFrame.origin.y = 0;
2214 2215
    if( [super initWithFrame: mainFrame item: _p_item] != nil )
    {
2216
        i_view_type = CONFIG_ITEM_MODULE_LIST;
2217
        
2218 2219 2220
        o_tooltip = [[VLCMain sharedInstance] wrapString:
                     [[VLCMain sharedInstance]
                      localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
2221
        
2222 2223
        /* add the label */
        if( p_item->psz_text )
2224
            o_labelString = [[VLCMain sharedInstance]
2225
                             localizedString: (char *)p_item->psz_text];
2226 2227
        else
            o_labelString = [NSString stringWithString:@""];
2228
        ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_tooltip )
2229 2230
        [o_label setAutoresizingMask:NSViewNotSizable ];
        [self addSubview: o_label];
2231
        
2232
        /* build the textfield */
2233
        if( p_item->value.psz )
2234
            o_textfieldString = [[VLCMain sharedInstance]
2235
                                 localizedString: (char *)p_item->value.psz];
2236 2237 2238
        else
            o_textfieldString = [NSString stringWithString: @""];
        ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
2239 2240
                      mainFrame.size.height - 22, mainFrame.size.width -
                      [o_label frame].size.width - 2, o_tooltip, o_textfieldString )
2241 2242
        [o_textfield setAutoresizingMask:NSViewWidthSizable ];
        [self addSubview: o_textfield];
2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297
        
        
        {
            NSRect s_rc = mainFrame;
            s_rc.size.height = mainFrame.size.height - 30;
            s_rc.size.width = mainFrame.size.width - 12;
            s_rc.origin.x = 12;
            s_rc.origin.y = 0;
            o_scrollview = [[[NSScrollView alloc] initWithFrame: s_rc] retain];
            [o_scrollview setDrawsBackground: NO];
            [o_scrollview setBorderType: NSBezelBorder];
            [o_scrollview setAutohidesScrollers:YES];
            
            NSTableView *o_tableview;
            o_tableview = [[NSTableView alloc] initWithFrame : s_rc];
            [o_tableview setUsesAlternatingRowBackgroundColors:YES];
            [o_tableview setHeaderView:nil];
            /* TODO: find a good way to fix the row height and text size*/
            /* FIXME: support for multiple selection... */
            //    [o_tableview setAllowsMultipleSelection:YES];
            
            NSCell *o_headerCell = [[NSCell alloc] initTextCell:@"Enabled"];
            NSCell *o_dataCell = [[NSButtonCell alloc] init];
            [(NSButtonCell*)o_dataCell setButtonType:NSSwitchButton];
            [o_dataCell setTitle:@""];
            [o_dataCell setFont:[NSFont systemFontOfSize:0]];
            NSTableColumn *o_tableColumn = [[NSTableColumn alloc]
                                            initWithIdentifier:@"Enabled"];
            [o_tableColumn setHeaderCell: o_headerCell];
            [o_tableColumn setDataCell: o_dataCell];
            [o_tableColumn setWidth:17];
            [o_tableview addTableColumn: o_tableColumn];
            
            o_headerCell = [[NSCell alloc] initTextCell:@"Module Name"];
            o_dataCell = [[NSTextFieldCell alloc] init];
            [o_dataCell setFont:[NSFont systemFontOfSize:12]];
            o_tableColumn = [[NSTableColumn alloc]
                             initWithIdentifier:@"Module"];
            [o_tableColumn setHeaderCell: o_headerCell];
            [o_tableColumn setDataCell: o_dataCell];
            [o_tableColumn setWidth:s_rc.size.width - 34];
            [o_tableview addTableColumn: o_tableColumn];
            [o_tableview registerForDraggedTypes:[NSArray arrayWithObjects:
                                                  @"VLC media player module", nil]];
            
            [o_tableview setDataSource:self];
            [o_tableview setTarget: self];
            [o_tableview setAction: @selector(tableChanged:)];
            [o_tableview sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
             NSLeftMouseDraggedMask];
            [o_scrollview setDocumentView: o_tableview];
        }
        [o_scrollview setAutoresizingMask:NSViewWidthSizable ];
        [o_scrollview setAutohidesScrollers:YES];
        [self addSubview: o_scrollview];
2298 2299 2300 2301 2302

    }
    return self;
}

2303 2304 2305 2306 2307
- (void) alignWithXPosition:(int)i_xPos
{
    ;
}

2308 2309 2310
- (IBAction)tableChanged:(id)sender
{
    NSString *o_newstring = @"";
2311 2312
    NSUInteger count = [o_modulearray count];
    for( NSUInteger i = 0 ; i < count ; i++ )
2313 2314
        if( [[[o_modulearray objectAtIndex:i] objectAtIndex:2]
            boolValue] != NO )
2315
        {
2316 2317
            o_newstring = [o_newstring stringByAppendingString:
                [[o_modulearray objectAtIndex:i] objectAtIndex:0]];
2318
            o_newstring = [o_newstring stringByAppendingString:@":"];
2319
        }
2320 2321 2322

    [o_textfield setStringValue: [o_newstring
        substringToIndex: ([o_newstring length])?[o_newstring length] - 1:0]];
2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333
}

- (void)dealloc
{
    [o_scrollview release];
    [super dealloc];
}


- (char *)stringValue
{
2334
    return strdup( [[o_textfield stringValue] UTF8String] );
2335 2336
}

2337 2338 2339 2340 2341 2342 2343
-(void)resetValues
{
#warning Reset prefs of the module selector is broken atm. 
    NSLog( @"don't forget about modulelistconfig" );
    [super resetValues];
}

2344 2345 2346 2347
@end

@implementation ModuleListConfigControl (NSTableDataSource)

2348 2349
- (BOOL)tableView:(NSTableView*)table writeRows:(NSArray*)rows
    toPasteboard:(NSPasteboard*)pb
2350
{
2351 2352 2353 2354 2355 2356 2357 2358
    // We only want to allow dragging of selected rows.
    NSEnumerator    *iter = [rows objectEnumerator];
    NSNumber        *row;
    while ((row = [iter nextObject]) != nil)
    {
        if (![table isRowSelected:[row intValue]])
            return NO;
    }
2359

2360 2361 2362 2363
    [pb declareTypes:[NSArray
        arrayWithObject:@"VLC media player module"] owner:nil];
    [pb setPropertyList:rows forType:@"VLC media player module"];
    return YES;
2364 2365
}

2366
- (NSDragOperation)tableView:(NSTableView*)table
2367
    validateDrop:(id <NSDraggingInfo>)info proposedRow:(NSInteger)row
2368
    proposedDropOperation:(NSTableViewDropOperation)op
2369
{
2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381
    // Make drops at the end of the table go to the end.
    if (row == -1)
    {
        row = [table numberOfRows];
        op = NSTableViewDropAbove;
        [table setDropRow:row dropOperation:op];
    }

    // We don't ever want to drop onto a row, only between rows.
    if (op == NSTableViewDropOn)
        [table setDropRow:(row+1) dropOperation:NSTableViewDropAbove];
    return NSTableViewDropAbove;
2382 2383
}

2384
- (BOOL)tableView:(NSTableView*)table acceptDrop:(id <NSDraggingInfo>)info
2385
    row:(NSInteger)dropRow dropOperation:(NSTableViewDropOperation)op;
2386
{
2387 2388 2389
    NSPasteboard    *pb = [info draggingPasteboard];
    NSDragOperation srcMask = [info draggingSourceOperationMask];
    BOOL accepted = NO;
2390

2391 2392 2393
    NS_DURING

        NSArray *array;
2394 2395

        // Intra-table drag - data is the array of rows.
2396 2397
        if (!accepted && (array =
            [pb propertyListForType:@"VLC media player module"]) != NULL)
2398
        {
2399
            NSEnumerator *iter = nil;
2400
            id val;
2401
            BOOL isCopy = (srcMask & NSDragOperationMove) ? NO:YES;
2402
            // Move the modules
2403 2404 2405 2406 2407
            iter = [array objectEnumerator];
            while ((val = [iter nextObject]) != NULL)
            {
                NSArray *o_tmp = [[o_modulearray objectAtIndex:
                    [val intValue]] mutableCopyWithZone:nil];
2408
                [o_modulearray removeObject:o_tmp];
2409 2410
                [o_modulearray insertObject:o_tmp
                    atIndex:(dropRow>[val intValue]) ? dropRow - 1 : dropRow];
2411 2412 2413 2414 2415 2416
                dropRow++;
            }

            // Select the newly-dragged items.
            iter = [array objectEnumerator];
//TODO...
2417
            [table deselectAll:self];
2418 2419 2420

            [self tableChanged:self];
            [table setNeedsDisplay:YES];
2421 2422 2423
            // Indicate that we finished the drag.
            accepted = YES;
        }
2424 2425
        [table reloadData];
        [table setNeedsDisplay:YES];
2426 2427 2428 2429 2430 2431 2432

        NS_HANDLER

            // An exception occurred. Uh-oh. Update the track table so that
            // it stays consistent, and re-raise the exception.
            [table reloadData];
            [localException raise];
2433 2434
            [table setNeedsDisplay:YES];
    NS_ENDHANDLER
2435 2436

    return accepted;
2437 2438
}

2439
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
2440 2441 2442 2443
{
    return [o_modulearray count];
}

2444
- (id)tableView:(NSTableView *)aTableView
2445
    objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
2446
{
2447
    if( [[aTableColumn identifier] isEqualToString: @"Enabled"] )
2448
        return [[o_modulearray objectAtIndex:rowIndex] objectAtIndex:2];
2449
    if( [[aTableColumn identifier] isEqualToString: @"Module"] )
2450
        return [[o_modulearray objectAtIndex:rowIndex] objectAtIndex:1];
2451

2452 2453 2454
    return nil;
}

2455
- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject
2456
    forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
2457
{
2458 2459
    [[o_modulearray objectAtIndex:rowIndex] replaceObjectAtIndex:2
        withObject: anObject];
2460 2461
}
@end