prefs_widgets.m 36.3 KB
Newer Older
1
2
3
4
/*****************************************************************************
 * prefs_widgets.m: Preferences controls
 *****************************************************************************
 * Copyright (C) 2002-2003 VideoLAN
5
 * $Id$
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
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
211
212
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
 *
 * Authors: Derk-Jan Hartman <hartman at videolan.org> 
 *
 * 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.
 * 
 * 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
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

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

#include <vlc/vlc.h>
#include "vlc_keys.h"

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

#define PREFS_WRAP 300
#define OFFSET_RIGHT 20
#define OFFSET_BETWEEN 10

@implementation VLCConfigControl

- (id)initWithFrame: (NSRect)frame
{
    return [self initWithFrame: frame
                    item: nil
                    withObject: nil];
}

- (id)initWithFrame: (NSRect)frame
        item: (module_config_t *)p_item
        withObject: (vlc_object_t *)_p_this
{
    self = [super initWithFrame: frame];

    if( self != nil )
    {
        p_this = _p_this;
        o_label = NULL;
        psz_name = strdup( p_item->psz_name );
        i_type = p_item->i_type;
        b_advanced = p_item->b_advanced;
        [self setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin ];
    }
    return (self);
}

- (void)dealloc
{
    if( o_label ) [o_label release];
    if( psz_name ) free( psz_name );
    [super dealloc];
}


+ (VLCConfigControl *)newControl: (module_config_t *)p_item withView: (NSView *)o_parent_view withObject: (vlc_object_t *)_p_this
{
    VLCConfigControl *p_control = NULL;
    NSRect frame = [o_parent_view bounds];
    
    switch( p_item->i_type )
    {
    case CONFIG_ITEM_MODULE:
        p_control = [[ModuleConfigControl alloc] initWithFrame: frame item: p_item withObject: _p_this ];
        break;

    case CONFIG_ITEM_STRING:
        if( !p_item->i_list )
        {
            p_control = [[StringConfigControl alloc] initWithFrame: frame item: p_item withObject: _p_this ];
        }
        else
        {
            p_control = [[StringListConfigControl alloc] initWithFrame: frame item: p_item withObject: _p_this ];
        }
        break;
        
    case CONFIG_ITEM_FILE:
    case CONFIG_ITEM_DIRECTORY:
        p_control = [[FileConfigControl alloc] initWithFrame: frame item: p_item withObject: _p_this ];
        break;

    case CONFIG_ITEM_INTEGER:
        if( p_item->i_list )
        {
            p_control = [[IntegerListConfigControl alloc] initWithFrame: frame item: p_item withObject: _p_this ];
        }
        else if( p_item->i_min != 0 || p_item->i_max != 0 )
        {
            p_control = [[RangedIntegerConfigControl alloc] initWithFrame: frame item: p_item withObject: _p_this ];
        }
        else
        {
            p_control = [[IntegerConfigControl alloc] initWithFrame: frame item: p_item withObject: _p_this ];
        }
        break;

    case CONFIG_ITEM_KEY:
        p_control = [[KeyConfigControl alloc] initWithFrame: frame item: p_item withObject: _p_this ];
        break;

    case CONFIG_ITEM_FLOAT:
        if( p_item->f_min != 0 || p_item->f_max != 0 )
        {
            p_control = [[RangedFloatConfigControl alloc] initWithFrame: frame item: p_item withObject: _p_this ];
        }
        else
        {
            p_control = [[FloatConfigControl alloc] initWithFrame: frame item: p_item withObject: _p_this ];
        }
        break;

    case CONFIG_ITEM_BOOL:
        p_control = [[BoolConfigControl alloc] initWithFrame: frame item: p_item withObject: _p_this ];
        break;
        
    default:
        break;
    }
    return p_control;
}

- (NSString *)getName
{
    return [NSApp localizedString: psz_name];
}

- (int)getType
{
    return i_type;
}

- (BOOL)isAdvanced
{
    return b_advanced;
}

- (int)intValue
{
    return 0;
}

- (float)floatValue
{
    return 0;
}

- (char *)stringValue
{
    return NULL;
}

@end


@implementation KeyConfigControl

- (id)initWithFrame: (NSRect)frame
        item: (module_config_t *)p_item
        withObject: (vlc_object_t *)_p_this
{
    frame.size.height = 80;
    if( self = [super initWithFrame: frame item: p_item
                withObject: _p_this] )
    {
        NSRect s_rc = frame;
        unsigned int i;

        o_matrix = [[[NSMatrix alloc] initWithFrame: s_rc mode: NSHighlightModeMatrix cellClass: [NSButtonCell class] numberOfRows:2 numberOfColumns:2] retain];
        NSArray *o_cells = [o_matrix cells];
        for( i = 0; i < [o_cells count]; i++ )
        {
            NSButtonCell *o_current_cell = [o_cells objectAtIndex:i];
            [o_current_cell setButtonType: NSSwitchButton];
            [o_current_cell setControlSize: NSSmallControlSize];
            [o_matrix setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext] toWidth: PREFS_WRAP] forCell: o_current_cell];

            switch( i )
            {
                case 0:
                    [o_current_cell setTitle:_NS("Command")];
                    [o_current_cell setState: p_item->i_value & KEY_MODIFIER_COMMAND];
                    break;
                case 1:
                    [o_current_cell setTitle:_NS("Control")];
                    [o_current_cell setState: p_item->i_value & KEY_MODIFIER_CTRL];
                    break;
                case 2:
                    [o_current_cell setTitle:_NS("Option/Alt")];
                    [o_current_cell setState: p_item->i_value & KEY_MODIFIER_ALT];
                    break;
                case 3:
                    [o_current_cell setTitle:_NS("Shift")];
                    [o_current_cell setState: p_item->i_value & KEY_MODIFIER_SHIFT];
                    break;
            }
        }
        [o_matrix sizeToCells];
        [o_matrix setAutoresizingMask:NSViewMaxXMargin ];
        [[self contentView] addSubview: o_matrix];

        /* add the combo box */
        s_rc.origin.x += [o_matrix frame].size.width + OFFSET_BETWEEN;
        s_rc.size.height = 22;
        s_rc.size.width = 100;

        o_combo = [[[NSComboBox alloc] initWithFrame: s_rc] retain];
        [o_combo setAutoresizingMask:NSViewMaxXMargin ];
        [o_combo setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext] toWidth: PREFS_WRAP]];
        
        for( i = 0; i < sizeof(vlc_keys) / sizeof(key_descriptor_t); i++ )
        {
            
            if( vlc_keys[i].psz_key_string && *vlc_keys[i].psz_key_string )
            [o_combo addItemWithObjectValue: [NSApp localizedString:vlc_keys[i].psz_key_string]];
        }
        
        [o_combo setStringValue: [NSApp localizedString:KeyToString(( ((unsigned int)p_item->i_value) & ~KEY_MODIFIER ))]];
        [[self contentView] addSubview: o_combo];
        
        /* add the label */
        s_rc.origin.y += 50;
        
        o_label = [[[NSTextField alloc] initWithFrame: s_rc] retain];
        [o_label setDrawsBackground: NO];
        [o_label setBordered: NO];
        [o_label setEditable: NO];
        [o_label setSelectable: NO];
        if ( p_item->psz_text )
            [o_label setStringValue: [NSApp localizedString: p_item->psz_text]];

        [o_label sizeToFit];
        [[self contentView] addSubview: o_label];
        [o_label setAutoresizingMask:NSViewMaxXMargin ];
    }
    return self;
}

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

- (int)getIntValue
{
    unsigned int i, i_new_key = 0;
    NSButtonCell *o_current_cell;
    NSArray *o_cells = [o_matrix cells];

    for( i = 0; i < [o_cells count]; i++ )
    {
        o_current_cell = [o_cells objectAtIndex:i];
        if( [[o_current_cell title] isEqualToString:_NS("Command")] && 
            [o_current_cell state] == NSOnState )
        {
            i_new_key |= KEY_MODIFIER_COMMAND;
        }
        if( [[o_current_cell title] isEqualToString:_NS("Control")] && 
            [o_current_cell state] == NSOnState )
        {
            i_new_key |= KEY_MODIFIER_CTRL;
        }
        if( [[o_current_cell title] isEqualToString:_NS("Option/Alt")] && 
            [o_current_cell state] == NSOnState )
        {
            i_new_key |= KEY_MODIFIER_ALT;
        }
        if( [[o_current_cell title] isEqualToString:_NS("Shift")] && 
            [o_current_cell state] == NSOnState )
        {
            i_new_key |= KEY_MODIFIER_SHIFT;
        }
    }
    i_new_key |= StringToKey([[o_combo stringValue] cString]);
    return i_new_key;
}


@end

@implementation ModuleConfigControl

- (id)initWithFrame: (NSRect)frame
        item: (module_config_t *)p_item
        withObject: (vlc_object_t *)_p_this
{
    frame.size.height = 20;
    if( self = [super initWithFrame: frame item: p_item
                withObject: _p_this] )
    {
        vlc_list_t *p_list;
        module_t *p_parser;
        NSRect s_rc = frame;
        int i_index;

        /* add the label */
        o_label = [[[NSTextField alloc] initWithFrame: s_rc] retain];
        [o_label setDrawsBackground: NO];
        [o_label setBordered: NO];
        [o_label setEditable: NO];
        [o_label setSelectable: NO];
        if ( p_item->psz_text )
            [o_label setStringValue: [NSApp localizedString: p_item->psz_text]];

        [o_label sizeToFit];
        [[self contentView] addSubview: o_label];
        [o_label setAutoresizingMask:NSViewMaxXMargin ];
        
        /* build the popup */
        s_rc.origin.x = s_rc.size.width - 200 - OFFSET_RIGHT;
        s_rc.size.width = 200;
        
        o_popup = [[[NSPopUpButton alloc] initWithFrame: s_rc] retain];
        [[self contentView] addSubview: o_popup];
        [o_popup setAutoresizingMask:NSViewMinXMargin ];

        [o_popup setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]];
        [o_popup addItemWithTitle: _NS("Default")];
        [[o_popup lastItem] setTag: -1];
        [o_popup selectItem: [o_popup lastItem]];
        
        /* build a list of available modules */
        p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
        for( i_index = 0; i_index < p_list->i_count; i_index++ )
        {
            p_parser = (module_t *)p_list->p_values[i_index].p_object ;

            if( !strcmp( p_parser->psz_capability,
                        p_item->psz_type ) )
            {
                NSString *o_description = [NSApp
                    localizedString: p_parser->psz_longname];
                [o_popup addItemWithTitle: o_description];

                if( p_item->psz_value &&
                    !strcmp( p_item->psz_value, p_parser->psz_object_name ) )
                {
                    [o_popup selectItem:[o_popup lastItem]];
                }
            }
        }
        vlc_list_release( p_list );
    }
    return self;
}

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

- (char *)stringValue
{
    NSString *newval = [o_popup stringValue];
    char *returnval;
    int i_index;
    vlc_list_t *p_list;
    module_t *p_parser;
    module_config_t *p_item;

    p_item = config_FindConfig( p_this, psz_name );
    p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
    for( i_index = 0; i_index < p_list->i_count; i_index++ )
    {
        p_parser = (module_t *)p_list->p_values[i_index].p_object ;

        if( !strcmp( p_parser->psz_capability,
                    p_item->psz_type ) )
        {
            NSString *o_description = [NSApp
                localizedString: p_parser->psz_longname];
            
            if( [newval isEqualToString: o_description] )
            {
                returnval = strdup(p_parser->psz_object_name);
                break;
            }
        }
    }
    vlc_list_release( p_list );
    return returnval;
}

@end

@implementation StringConfigControl
- (id)initWithFrame: (NSRect)frame
        item: (module_config_t *)p_item
        withObject: (vlc_object_t *)_p_this
{
    frame.size.height = 22;
    if( self = [super initWithFrame: frame item: p_item
                withObject: _p_this] )
    {
        NSRect s_rc = frame;

        /* add the label */
        o_label = [[[NSTextField alloc] initWithFrame: s_rc] retain];
        [o_label setDrawsBackground: NO];
        [o_label setBordered: NO];
        [o_label setEditable: NO];
        [o_label setSelectable: NO];
        if( p_item->psz_text )
            [o_label setStringValue: [NSApp localizedString: p_item->psz_text]];

        [o_label sizeToFit];
        [[self contentView] addSubview: o_label];
        [o_label setAutoresizingMask:NSViewMaxXMargin ];
        
        /* build the textfield */
        s_rc.origin.x = s_rc.size.width - 200 - OFFSET_RIGHT;
        s_rc.size.width = 200;
        
        o_textfield = [[[NSTextField alloc] initWithFrame: s_rc] retain];
        [o_textfield setAutoresizingMask:NSViewMinXMargin | NSViewWidthSizable ];

        [o_textfield setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]];
        [o_textfield setStringValue: [NSApp localizedString: p_item->psz_value]];
        [[self contentView] addSubview: o_textfield];
    }
    return self;
}

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

- (char *)stringValue
{
    return strdup( [NSApp delocalizeString:[o_textfield stringValue]] );
}

@end

@implementation StringListConfigControl

- (id)initWithFrame: (NSRect)frame
        item: (module_config_t *)p_item
        withObject: (vlc_object_t *)_p_this
{
    frame.size.height = 20;
    if( self = [super initWithFrame: frame item: p_item
                withObject: _p_this] )
    {
        NSRect s_rc = frame;
        int i_index;

        /* add the label */
        o_label = [[[NSTextField alloc] initWithFrame: s_rc] retain];
        [o_label setDrawsBackground: NO];
        [o_label setBordered: NO];
        [o_label setEditable: NO];
        [o_label setSelectable: NO];
        if( p_item->psz_text )
            [o_label setStringValue: [NSApp localizedString: p_item->psz_text]];

        [o_label sizeToFit];
        [[self contentView] addSubview: o_label];
        [o_label setAutoresizingMask:NSViewMaxXMargin ];
        
        /* build the textfield */
        s_rc.origin.x = s_rc.size.width - 200 - OFFSET_RIGHT;
        s_rc.size.width = 200;
        
        o_combo = [[[NSComboBox alloc] initWithFrame: s_rc] retain];
        [o_combo setAutoresizingMask:NSViewMinXMargin | NSViewWidthSizable ];

        [o_combo setUsesDataSource:TRUE];
        [o_combo setDataSource:self];
        [o_combo setNumberOfVisibleItems:10];
        for( i_index = 0; i_index < p_item->i_list; i_index++ )
        {
            if( p_item->psz_value && !strcmp( p_item->psz_value, p_item->ppsz_list[i_index] ) )
            {
                [o_combo selectItemAtIndex: i_index];
            }
        }

        [o_combo setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]];
        [[self contentView] addSubview: o_combo];
    }
    return self;
}

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

- (char *)stringValue
{
    module_config_t *p_item;
    p_item = config_FindConfig( p_this, psz_name );

    if( [o_combo indexOfSelectedItem] >= 0 )
        return strdup( p_item->ppsz_list[[o_combo indexOfSelectedItem]] );
    else
        return strdup( [NSApp delocalizeString: [o_combo stringValue]] );
}

@end

@implementation StringListConfigControl (NSComboBoxDataSource)

- (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox
{
    module_config_t *p_item;
    p_item = config_FindConfig( p_this, psz_name );

    return p_item->i_list;
}

- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)i_index
{
    module_config_t *p_item;
    p_item = config_FindConfig( p_this, psz_name );

    if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
    {
        return [NSApp localizedString: p_item->ppsz_list_text[i_index]];
    } else return [NSApp localizedString: p_item->ppsz_list[i_index]];
}

@end

@implementation FileConfigControl

- (id)initWithFrame: (NSRect)frame
        item: (module_config_t *)p_item
        withObject: (vlc_object_t *)_p_this
{
    frame.size.height = 49;
    if( self = [super initWithFrame: frame item: p_item
                withObject: _p_this] )
    {
        NSRect s_rc = frame;
        s_rc.origin.y = 29;
        s_rc.size.height = 20;

        /* is it a directory */
        b_directory = ( [self getType] == CONFIG_ITEM_DIRECTORY ) ? YES : NO;

        /* add the label */
        o_label = [[[NSTextField alloc] initWithFrame: s_rc] retain];
        [o_label setDrawsBackground: NO];
        [o_label setBordered: NO];
        [o_label setEditable: NO];
        [o_label setSelectable: NO];
        if( p_item->psz_text )
            [o_label setStringValue: [NSApp localizedString: p_item->psz_text]];

        [o_label sizeToFit];
        [o_label setAutoresizingMask:NSViewMaxXMargin ];
        [[self contentView] addSubview: o_label];
        
        /* build the button */
        s_rc.origin.y = s_rc.origin.x = 0;
        s_rc.size.height = 22;

        o_button = [[[NSButton alloc] initWithFrame: s_rc] retain];
        [o_button setButtonType: NSMomentaryPushInButton];
        [o_button setBezelStyle: NSRoundedBezelStyle];
        [o_button setTitle: _NS("Browse...")];
        [o_button sizeToFit];
        [o_button setAutoresizingMask:NSViewMinXMargin];
        [o_button setFrameOrigin: NSMakePoint( s_rc.size.width - 
                    [o_button frame].size.width - OFFSET_RIGHT, s_rc.origin.y)];
        [o_button setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]];

        [o_button setTarget: self];
        [o_button setAction: @selector(openFileDialog:)];

        s_rc.size.height = 22;
        s_rc.size.width = s_rc.size.width - OFFSET_BETWEEN - [o_button frame].size.width - OFFSET_RIGHT;
        
        o_textfield = [[[NSTextField alloc] initWithFrame: s_rc] retain];
        
        [o_textfield setStringValue: [NSApp localizedString: p_item->psz_value]];
        [o_textfield setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]];

        [o_textfield setAutoresizingMask:NSViewWidthSizable];
               
        [[self contentView] addSubview: o_textfield];
        [[self contentView] addSubview: o_button];
    }
    return self;
}

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

- (IBAction)openFileDialog: (id)sender
{
    NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
    
    [o_open_panel setTitle: _NS("Select a file or directory")];
    [o_open_panel setPrompt: _NS("Select")];
    [o_open_panel setAllowsMultipleSelection: NO];
    [o_open_panel setCanChooseFiles: YES];
    [o_open_panel setCanChooseDirectories: b_advanced];
    [o_open_panel beginSheetForDirectory:nil
        file:nil
        types:nil
        modalForWindow:[sender window]
        modalDelegate: self
        didEndSelector: @selector(pathChosenInPanel: 
                        withReturn:
                        contextInfo:)
        contextInfo: nil];
}

- (void)pathChosenInPanel:(NSOpenPanel *)o_sheet withReturn:(int)i_return_code contextInfo:(void  *)o_context_info
{
    if( i_return_code == NSOKButton )
    {
        NSString *o_path = [[o_sheet filenames] objectAtIndex: 0];
        [o_textfield setStringValue: o_path];
    }
}

- (char *)stringValue
{
652
    return strdup( [[o_textfield stringValue] fileSystemRepresentation] );
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
}

@end

@implementation IntegerConfigControl
- (id)initWithFrame: (NSRect)frame
        item: (module_config_t *)p_item
        withObject: (vlc_object_t *)_p_this
{
    frame.size.height = 22;
    if( self = [super initWithFrame: frame item: p_item
                withObject: _p_this] )
    {
        NSRect s_rc = frame;

        /* add the label */
        o_label = [[[NSTextField alloc] initWithFrame: s_rc] retain];
        [o_label setDrawsBackground: NO];
        [o_label setBordered: NO];
        [o_label setEditable: NO];
        [o_label setSelectable: NO];
        if( p_item->psz_text )
            [o_label setStringValue: [NSApp localizedString: p_item->psz_text]];

        [o_label sizeToFit];
        [[self contentView] addSubview: o_label];
        [o_label setAutoresizingMask:NSViewMaxXMargin ];
        
        /* build the stepper */
        s_rc.origin.x = s_rc.size.width - 13 - OFFSET_RIGHT;
        
        o_stepper = [[[NSStepper alloc] initWithFrame: s_rc] retain];
        [o_stepper sizeToFit];
        [o_stepper setAutoresizingMask:NSViewMinXMargin];

        [o_stepper setMaxValue: 1600];
        [o_stepper setMinValue: -1600];
        [o_stepper setIntValue: p_item->i_value];
        [o_stepper setTarget: self];
        [o_stepper setAction: @selector(stepperChanged:)];
        [o_stepper sendActionOn:NSLeftMouseUpMask|NSLeftMouseDownMask|NSLeftMouseDraggedMask];
        [o_stepper setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]];
        [[self contentView] addSubview: o_stepper];
    
        /* build the textfield */
        s_rc.origin.x = s_rc.size.width - 60 - OFFSET_BETWEEN - 13 - OFFSET_RIGHT;
        s_rc.size.width = 60;
        
        o_textfield = [[[NSTextField alloc] initWithFrame: s_rc] retain];
        [o_textfield setAutoresizingMask:NSViewMinXMargin | NSViewWidthSizable ];

        [o_textfield setIntValue: p_item->i_value];
        [o_textfield setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]];
        [o_textfield setDelegate: self];
        [[NSNotificationCenter defaultCenter] addObserver: self
            selector: @selector(textfieldChanged:)
            name: NSControlTextDidChangeNotification
            object: o_textfield];
        [[self contentView] addSubview: o_textfield];
    }
    return self;
}

- (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]];
}

- (int)getIntValue
{
    return [o_stepper intValue];
}

@end

@implementation IntegerListConfigControl

- (id)initWithFrame: (NSRect)frame
        item: (module_config_t *)p_item
        withObject: (vlc_object_t *)_p_this
{
    frame.size.height = 20;
    if( self = [super initWithFrame: frame item: p_item
                withObject: _p_this] )
    {
        NSRect s_rc = frame;
        int i_index;

        /* add the label */
        o_label = [[[NSTextField alloc] initWithFrame: s_rc] retain];
        [o_label setDrawsBackground: NO];
        [o_label setBordered: NO];
        [o_label setEditable: NO];
        [o_label setSelectable: NO];
        if( p_item->psz_text )
            [o_label setStringValue: [NSApp localizedString: p_item->psz_text]];

        [o_label sizeToFit];
        [[self contentView] addSubview: o_label];
        [o_label setAutoresizingMask:NSViewMaxXMargin ];
        
        /* build the textfield */
        s_rc.origin.x = s_rc.size.width - 200 - OFFSET_RIGHT;
        s_rc.size.width = 200;
        
        o_combo = [[[NSComboBox alloc] initWithFrame: s_rc] retain];
        [o_combo setAutoresizingMask:NSViewMinXMargin | NSViewWidthSizable ];

        [o_combo setUsesDataSource:TRUE];
        [o_combo setDataSource:self];
        [o_combo setNumberOfVisibleItems:10];
        for( i_index = 0; i_index < p_item->i_list; i_index++ )
        {
            if( p_item->i_value == p_item->pi_list[i_index] )
            {
                [o_combo selectItemAtIndex: i_index];
            }
        }

        [o_combo setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]];
        [[self contentView] addSubview: o_combo];
    }
    return self;
}

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

- (int)intValue
{
    module_config_t *p_item;
    p_item = config_FindConfig( p_this, psz_name );

    if( [o_combo indexOfSelectedItem] >= 0 )
        return p_item->pi_list[[o_combo indexOfSelectedItem]];
    else
        return [o_combo intValue];
}

@end

@implementation IntegerListConfigControl (NSComboBoxDataSource)

- (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox
{
    module_config_t *p_item;
    p_item = config_FindConfig( p_this, psz_name );

    return p_item->i_list;
}

- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)i_index
{
    module_config_t *p_item;
    p_item = config_FindConfig( p_this, psz_name );

    if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
    {
        return [NSApp localizedString: p_item->ppsz_list_text[i_index]];
    } else return [NSString stringWithFormat: @"%i", p_item->pi_list[i_index]];
}

@end

@implementation RangedIntegerConfigControl

- (id)initWithFrame: (NSRect)frame
        item: (module_config_t *)p_item
        withObject: (vlc_object_t *)_p_this
{
    frame.size.height = 50;
    if( self = [super initWithFrame: frame item: p_item
                withObject: _p_this] )
    {
        NSRect s_rc = frame;
        s_rc.size.height = 20;
        s_rc.origin.y = 30;
    
        /* add the label */
        o_label = [[[NSTextField alloc] initWithFrame: s_rc] retain];
        [o_label setDrawsBackground: NO];
        [o_label setBordered: NO];
        [o_label setEditable: NO];
        [o_label setSelectable: NO];
        if( p_item->psz_text )
            [o_label setStringValue: [NSApp localizedString: p_item->psz_text]];

        [o_label sizeToFit];
        [[self contentView] addSubview: o_label];
        [o_label setAutoresizingMask:NSViewMaxXMargin ];

        /* build the slider */
        /* min value textfield */
        s_rc.origin.y = 0;
        s_rc.origin.x = 0;
        s_rc.size.width = 40;

        o_textfield_min = [[[NSTextField alloc] initWithFrame: s_rc] retain];
        [o_textfield_min setAutoresizingMask:NSViewMaxXMargin];
        [o_textfield_min setDrawsBackground: NO];
        [o_textfield_min setBordered: NO];
        [o_textfield_min setEditable: NO];
        [o_textfield_min setSelectable: NO];

        [o_textfield_min setIntValue: p_item->i_min];
        [o_textfield_min setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]];
        [[self contentView] addSubview: o_textfield_min];

        /* the slider */
        s_rc.size.width = [[self contentView] bounds].size.width - OFFSET_RIGHT - 2*OFFSET_BETWEEN - 3*40;
        s_rc.origin.x = 40 + OFFSET_BETWEEN;

        o_slider = [[[NSStepper alloc] initWithFrame: s_rc] retain];
        [o_slider setAutoresizingMask:NSViewWidthSizable];

        [o_slider setMaxValue: p_item->i_max];
        [o_slider setMinValue: p_item->i_min];
        [o_slider setIntValue: p_item->i_value];
        [o_slider setTarget: self];
        [o_slider setAction: @selector(sliderChanged:)];
        [o_slider sendActionOn:NSLeftMouseUpMask|NSLeftMouseDownMask|NSLeftMouseDraggedMask];
        [o_slider setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]];
        [[self contentView] addSubview: o_slider];
        
        /* max value textfield */
        s_rc.size.width = 40;
        s_rc.origin.x = [[self contentView] bounds].size.width - OFFSET_RIGHT - OFFSET_BETWEEN - 2*40;
        
        o_textfield_max = [[[NSTextField alloc] initWithFrame: s_rc] retain];
        [o_textfield_max setAutoresizingMask:NSViewMinXMargin ];

        [o_textfield_max setDrawsBackground: NO];
        [o_textfield_max setBordered: NO];
        [o_textfield_max setEditable: NO];
        [o_textfield_max setSelectable: NO];

        [o_textfield_max setIntValue: p_item->i_max];
        [o_textfield_max setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]];
        [[self contentView] addSubview: o_textfield_max];
        
        /* current value textfield */
        s_rc.size.width = 40;
        s_rc.origin.x = [[self contentView] bounds].size.width - OFFSET_RIGHT - 40;

        o_textfield = [[[NSTextField alloc] initWithFrame: s_rc] retain];
        [o_textfield setAutoresizingMask:NSViewMinXMargin];

        [o_textfield setIntValue: p_item->i_value];
        [o_textfield setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]];
        [o_textfield setDelegate: self];
        [[NSNotificationCenter defaultCenter] addObserver: self
            selector: @selector(textfieldChanged:)
            name: NSControlTextDidChangeNotification
            object: o_textfield];
        [[self contentView] addSubview: o_textfield];

    }
    return self;
}

- (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];
}

@end

@implementation FloatConfigControl

- (id)initWithFrame: (NSRect)frame
        item: (module_config_t *)p_item
        withObject: (vlc_object_t *)_p_this
{
    frame.size.height = 20;
    if( self = [super initWithFrame: frame item: p_item
                withObject: _p_this] )
    {
        NSRect s_rc = frame;

        /* add the label */
        o_label = [[[NSTextField alloc] initWithFrame: s_rc] retain];
        [o_label setDrawsBackground: NO];
        [o_label setBordered: NO];
        [o_label setEditable: NO];
        [o_label setSelectable: NO];
        if( p_item->psz_text )
            [o_label setStringValue: [NSApp localizedString: p_item->psz_text]];

        [o_label sizeToFit];
        [[self contentView] addSubview: o_label];
        [o_label setAutoresizingMask:NSViewMaxXMargin ];

        /* build the textfield */
        s_rc.origin.x = s_rc.size.width - 60 - OFFSET_RIGHT;
        s_rc.size.width = 60;
        
        o_textfield = [[[NSTextField alloc] initWithFrame: s_rc] retain];
        [o_textfield setAutoresizingMask:NSViewMinXMargin | NSViewWidthSizable ];

        [o_textfield setFloatValue: p_item->f_value];
        [o_textfield setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]];
        [[self contentView] addSubview: o_textfield];
    }
    return self;
}

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

- (float)floatValue
{
    return [o_textfield floatValue];
}

@end

@implementation RangedFloatConfigControl

- (id)initWithFrame: (NSRect)frame
        item: (module_config_t *)p_item
        withObject: (vlc_object_t *)_p_this
{
    frame.size.height = 50;
    if( self = [super initWithFrame: frame item: p_item
                withObject: _p_this] )
    {
        NSRect s_rc = frame;
        s_rc.size.height = 20;
        s_rc.origin.y = 30;
    
        /* add the label */
        o_label = [[[NSTextField alloc] initWithFrame: s_rc] retain];
        [o_label setDrawsBackground: NO];
        [o_label setBordered: NO];
        [o_label setEditable: NO];
        [o_label setSelectable: NO];
        if( p_item->psz_text )
            [o_label setStringValue: [NSApp localizedString: p_item->psz_text]];

        [o_label sizeToFit];
        [[self contentView] addSubview: o_label];
        [o_label setAutoresizingMask:NSViewMaxXMargin ];

        /* build the slider */
        /* min value textfield */
        s_rc.origin.y = 0;
        s_rc.origin.x = 0;
        s_rc.size.width = 40;

        o_textfield_min = [[[NSTextField alloc] initWithFrame: s_rc] retain];
        [o_textfield_min setAutoresizingMask:NSViewMaxXMargin];
        [o_textfield_min setDrawsBackground: NO];
        [o_textfield_min setBordered: NO];
        [o_textfield_min setEditable: NO];
        [o_textfield_min setSelectable: NO];

        [o_textfield_min setFloatValue: p_item->f_min];
        [o_textfield_min setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]];
        [[self contentView] addSubview: o_textfield_min];

        /* the slider */
        s_rc.size.width = [[self contentView] bounds].size.width - OFFSET_RIGHT - 2*OFFSET_BETWEEN - 3*40;
        s_rc.origin.x = 40 + OFFSET_BETWEEN;

        o_slider = [[[NSStepper alloc] initWithFrame: s_rc] retain];
        [o_slider setAutoresizingMask:NSViewWidthSizable];

        [o_slider setMaxValue: p_item->f_max];
        [o_slider setMinValue: p_item->f_min];
        [o_slider setFloatValue: p_item->f_value];
        [o_slider setTarget: self];
        [o_slider setAction: @selector(sliderChanged:)];
        [o_slider sendActionOn:NSLeftMouseUpMask|NSLeftMouseDownMask|NSLeftMouseDraggedMask];
        [o_slider setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]];
        [[self contentView] addSubview: o_slider];
        
        /* max value textfield */
        s_rc.size.width = 40;
        s_rc.origin.x = [[self contentView] bounds].size.width - OFFSET_RIGHT - OFFSET_BETWEEN - 2*40;
        
        o_textfield_max = [[[NSTextField alloc] initWithFrame: s_rc] retain];
        [o_textfield_max setAutoresizingMask:NSViewMinXMargin ];

        [o_textfield_max setDrawsBackground: NO];
        [o_textfield_max setBordered: NO];
        [o_textfield_max setEditable: NO];
        [o_textfield_max setSelectable: NO];

        [o_textfield_max setFloatValue: p_item->f_max];
        [o_textfield_max setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]];
        [[self contentView] addSubview: o_textfield_max];
        
        /* current value textfield */
        s_rc.size.width = 40;
        s_rc.origin.x = [[self contentView] bounds].size.width - OFFSET_RIGHT - 40;

        o_textfield = [[[NSTextField alloc] initWithFrame: s_rc] retain];
        [o_textfield setAutoresizingMask:NSViewMinXMargin];

        [o_textfield setFloatValue: p_item->f_value];
        [o_textfield setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]];
        [o_textfield setDelegate: self];
        [[NSNotificationCenter defaultCenter] addObserver: self
            selector: @selector(textfieldChanged:)
            name: NSControlTextDidChangeNotification
            object: o_textfield];
        [[self contentView] addSubview: o_textfield];

    }
    return self;
}

- (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]];
}

- (float)floatValue
{
    return [o_slider floatValue];
}

@end


@implementation BoolConfigControl

- (id)initWithFrame: (NSRect)frame
        item: (module_config_t *)p_item
        withObject: (vlc_object_t *)_p_this
{
    frame.size.height = 20;
    if( self = [super initWithFrame: frame item: p_item
            withObject: _p_this] )
    {
        NSRect s_rc = frame;
        s_rc.size.height = 20;
        
        o_checkbox = [[[NSButton alloc] initWithFrame: s_rc] retain];
        [o_checkbox setButtonType: NSSwitchButton];
        [o_checkbox setIntValue: p_item->i_value];
        [o_checkbox setTitle: [NSApp localizedString: p_item->psz_text]];
        [o_checkbox setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]];
        [[self contentView] addSubview: o_checkbox];
    }
    return self;
}

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

- (int)intValue
{
    [o_checkbox intValue];
}

@end