prefs_widgets.m 86.7 KB
Newer Older
1
2
3
/*****************************************************************************
 * prefs_widgets.m: Preferences controls
 *****************************************************************************
4
 * Copyright (C) 2002-2012 VLC authors and VideoLAN
5
 * $Id$
6
 *
Jérome Decoodt's avatar
Jérome Decoodt committed
7
 * Authors: Derk-Jan Hartman <hartman at videolan.org>
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
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
dionoea's avatar
dionoea 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_plugin.h>
38
#include <vlc_actions.h>
39

40
#include "VLCMain.h"
41
42
#include "prefs_widgets.h"

43
44
45
46
47
#define CONFIG_ITEM_STRING_LIST (CONFIG_ITEM_STRING + 10)
#define CONFIG_ITEM_RANGED_INTEGER (CONFIG_ITEM_INTEGER + 10)

#define LEFTMARGIN  18
#define RIGHTMARGIN 18
48
49
#define PREFS_WRAP 300
#define OFFSET_RIGHT 20
50
#define OFFSET_BETWEEN 2
51

52
#define UPWARDS_WHITE_ARROW                 "\xE2\x87\xA7"
Jérome Decoodt's avatar
Jérome Decoodt committed
53
54
55
56
#define OPTION_KEY                          "\xE2\x8C\xA5"
#define UP_ARROWHEAD                        "\xE2\x8C\x83"
#define PLACE_OF_INTEREST_SIGN              "\xE2\x8C\x98"

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

239
240
#define ADD_LABEL(o_label, superFrame, x_offset, my_y_offset, label,        \
    tooltip)                                                                \
241
242
243
244
245
{                                                                           \
    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;              \
246
    o_label = [[NSTextField alloc] initWithFrame: s_rc];                    \
247
248
249
250
251
    [o_label setDrawsBackground: NO];                                       \
    [o_label setBordered: NO];                                              \
    [o_label setEditable: NO];                                              \
    [o_label setSelectable: NO];                                            \
    [o_label setStringValue: label];                                        \
252
    [o_label setToolTip: tooltip];                                          \
253
254
255
256
    [o_label setFont:[NSFont systemFontOfSize:0]];                          \
    [o_label sizeToFit];                                                    \
}

257
258
#define ADD_TEXTFIELD(o_textfield, superFrame, x_offset, my_y_offset,       \
    my_width, tooltip, init_value)                                          \
259
260
261
262
263
264
{                                                                           \
    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;                                             \
265
    o_textfield = [[NSTextField alloc] initWithFrame: s_rc];                \
266
267
268
269
270
    [o_textfield setFont:[NSFont systemFontOfSize:0]];                      \
    [o_textfield setToolTip: tooltip];                                      \
    [o_textfield setStringValue: init_value];                               \
}

271
272
#define ADD_SECURETEXTFIELD(o_textfield, superFrame, x_offset, my_y_offset, \
my_width, tooltip, init_value)                                              \
273
{                                                                           \
274
275
276
277
278
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;                                                 \
279
o_textfield = [[NSSecureTextField alloc] initWithFrame: s_rc];              \
280
281
282
283
284
285
286
[o_textfield setFont:[NSFont systemFontOfSize:0]];                          \
[o_textfield setToolTip: tooltip];                                          \
[o_textfield setStringValue: init_value];                                   \
}

#define ADD_COMBO(o_combo, superFrame, x_offset, my_y_offset, x2_offset,    \
    tooltip)                                                                \
287
288
289
290
291
292
293
{                                                                           \
    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);                                                        \
294
    o_combo = [[NSComboBox alloc] initWithFrame: s_rc];                     \
295
296
297
298
299
300
301
302
    [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];                                             \
}

303
304
#define ADD_RIGHT_BUTTON(o_button, superFrame, x_offset, my_y_offset,       \
    tooltip, title)                                                         \
305
306
{                                                                           \
    NSRect s_rc = superFrame;                                               \
307
    o_button = [[NSButton alloc] initWithFrame: s_rc];                      \
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
    [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:)];                       \
}

323
324
#define ADD_POPUP(o_popup, superFrame, x_offset, my_y_offset, x2_offset,    \
    tooltip)                                                                \
325
326
327
328
329
330
331
{                                                                           \
    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);                                                        \
332
    o_popup = [[NSPopUpButton alloc] initWithFrame: s_rc];                  \
333
334
335
336
    [o_popup setFont:[NSFont systemFontOfSize:0]];                          \
    [o_popup setToolTip: tooltip];                                          \
}

337
338
#define ADD_STEPPER(o_stepper, superFrame, x_offset, my_y_offset, tooltip,  \
    lower, higher)                                                          \
339
340
341
342
343
344
{                                                                           \
    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;                                                   \
345
    o_stepper = [[NSStepper alloc] initWithFrame: s_rc];                    \
346
347
348
349
350
351
352
353
354
355
    [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];                                            \
}

356
357
#define ADD_SLIDER(o_slider, superFrame, x_offset, my_y_offset, my_width,   \
    tooltip, lower, higher)                                                 \
358
359
360
361
362
363
{                                                                           \
    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;                                             \
364
    o_slider = [[NSSlider alloc] initWithFrame: s_rc];                      \
365
366
367
368
369
370
    [o_slider setFont:[NSFont systemFontOfSize:0]];                         \
    [o_slider setToolTip: tooltip];                                         \
    [o_slider setMaxValue: higher];                                         \
    [o_slider setMinValue: lower];                                          \
}

371
372
#define ADD_CHECKBOX(o_checkbox, superFrame, x_offset, my_y_offset, label,  \
    tooltip, init_value, position)                                          \
373
374
375
376
377
{                                                                           \
    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;              \
378
    o_checkbox = [[NSButton alloc] initWithFrame: s_rc];                    \
379
380
381
382
383
384
385
386
387
    [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];                                                 \
}

388
389
@interface VLCConfigControl()
{
390
    const char *psz_name;
391
392
393
}
@end

394
@implementation VLCConfigControl
395

396
- (id)initWithFrame:(NSRect)frame
397
398
{
    return [self initWithFrame: frame
399
                          item: nil];
400
401
}

402
403
- (id)initWithFrame:(NSRect)frame
               item:(module_config_t *)p_item
404
405
406
{
    self = [super initWithFrame: frame];

407
    if (self != nil) {
408
        _p_item = p_item;
409
        psz_name = p_item->psz_name;
410
        _type = p_item->i_type;
411
412
413
414
415
        [self setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin ];
    }
    return (self);
}

416
417
418
419
420
421
422
- (void)setYPos:(int)i_yPos
{
    NSRect frame = [self frame];
    frame.origin.y = i_yPos;
    [self setFrame:frame];
}

423
+ (int)calcVerticalMargin:(int)i_curItem lastItem:(int)i_lastItem
Jérome Decoodt's avatar
Jérome Decoodt committed
424
425
{
    int i_margin;
426
    switch(i_curItem) {
Jérome Decoodt's avatar
Jérome Decoodt committed
427
        case CONFIG_ITEM_STRING:
428
        case CONFIG_ITEM_PASSWORD:
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
            switch(i_lastItem) {
                case CONFIG_ITEM_STRING:
                case CONFIG_ITEM_PASSWORD:
                    i_margin = 8;
                    break;
                case CONFIG_ITEM_STRING_LIST:
                    i_margin = 7;
                    break;
                case CONFIG_ITEM_LOADFILE:
                case CONFIG_ITEM_SAVEFILE:
                    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;
                case CONFIG_ITEM_KEY:
                    i_margin = 6;
                    break;
                case CONFIG_ITEM_MODULE_LIST:
                    i_margin = 8;
                    break;
                default:
                    i_margin = 20;
                    break;
            }
Jérome Decoodt's avatar
Jérome Decoodt committed
463
464
            break;
        case CONFIG_ITEM_STRING_LIST:
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
            switch(i_lastItem) {
                case CONFIG_ITEM_STRING:
                case CONFIG_ITEM_PASSWORD:
                    i_margin = 8;
                    break;
                case CONFIG_ITEM_STRING_LIST:
                    i_margin = 7;
                    break;
                case CONFIG_ITEM_LOADFILE:
                case CONFIG_ITEM_SAVEFILE:
                    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;
                case CONFIG_ITEM_KEY:
                    i_margin = 6;
                    break;
                case CONFIG_ITEM_MODULE_LIST:
                    i_margin = 8;
                    break;
                default:
                    i_margin = 20;
                    break;
            }
Jérome Decoodt's avatar
Jérome Decoodt committed
499
            break;
500
501
        case CONFIG_ITEM_LOADFILE:
        case CONFIG_ITEM_SAVEFILE:
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
            switch(i_lastItem) {
                case CONFIG_ITEM_STRING:
                case CONFIG_ITEM_PASSWORD:
                    i_margin = 13;
                    break;
                case CONFIG_ITEM_STRING_LIST:
                    i_margin = 10;
                    break;
                case CONFIG_ITEM_LOADFILE:
                case CONFIG_ITEM_SAVEFILE:
                    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;
                case CONFIG_ITEM_KEY:
                    i_margin = 9;
                    break;
                case CONFIG_ITEM_MODULE_LIST:
                    i_margin = 11;
                    break;
                default:
                    i_margin = 23;
                    break;
            }
Jérome Decoodt's avatar
Jérome Decoodt committed
536
537
            break;
        case CONFIG_ITEM_MODULE:
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
            switch(i_lastItem) {
                case CONFIG_ITEM_STRING:
                case CONFIG_ITEM_PASSWORD:
                    i_margin = 8;
                    break;
                case CONFIG_ITEM_STRING_LIST:
                    i_margin = 7;
                    break;
                case CONFIG_ITEM_LOADFILE:
                case CONFIG_ITEM_SAVEFILE:
                    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;
                case CONFIG_ITEM_KEY:
                    i_margin = 7;
                    break;
                case CONFIG_ITEM_MODULE_LIST:
                    i_margin = 9;
                    break;
                default:
                    i_margin = 20;
                    break;
            }
Jérome Decoodt's avatar
Jérome Decoodt committed
572
573
            break;
        case CONFIG_ITEM_INTEGER:
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
            switch(i_lastItem) {
                case CONFIG_ITEM_STRING:
                case CONFIG_ITEM_PASSWORD:
                    i_margin = 8;
                    break;
                case CONFIG_ITEM_STRING_LIST:
                    i_margin = 7;
                    break;
                case CONFIG_ITEM_LOADFILE:
                case CONFIG_ITEM_SAVEFILE:
                    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;
                case CONFIG_ITEM_KEY:
                    i_margin = 6;
                    break;
                case CONFIG_ITEM_MODULE_LIST:
                    i_margin = 8;
                    break;
                default:
                    i_margin = 20;
                    break;
            }
Jérome Decoodt's avatar
Jérome Decoodt committed
608
609
            break;
        case CONFIG_ITEM_RANGED_INTEGER:
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
            switch(i_lastItem) {
                case CONFIG_ITEM_STRING:
                case CONFIG_ITEM_PASSWORD:
                    i_margin = 8;
                    break;
                case CONFIG_ITEM_STRING_LIST:
                    i_margin = 7;
                    break;
                case CONFIG_ITEM_LOADFILE:
                case CONFIG_ITEM_SAVEFILE:
                    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;
                case CONFIG_ITEM_KEY:
                    i_margin = 6;
                    break;
                case CONFIG_ITEM_MODULE_LIST:
                    i_margin = 8;
                    break;
                default:
                    i_margin = 20;
                    break;
            }
Jérome Decoodt's avatar
Jérome Decoodt committed
644
645
            break;
        case CONFIG_ITEM_BOOL:
646
647
648
649
650
651
652
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
            switch(i_lastItem) {
                case CONFIG_ITEM_STRING:
                case CONFIG_ITEM_PASSWORD:
                    i_margin = 10;
                    break;
                case CONFIG_ITEM_STRING_LIST:
                    i_margin = 9;
                    break;
                case CONFIG_ITEM_LOADFILE:
                case CONFIG_ITEM_SAVEFILE:
                    i_margin = 8;
                    break;
                case CONFIG_ITEM_MODULE:
                    i_margin = 6;
                    break;
                case CONFIG_ITEM_INTEGER:
                    i_margin = 9;
                    break;
                case CONFIG_ITEM_RANGED_INTEGER:
                    i_margin = 7;
                    break;
                case CONFIG_ITEM_BOOL:
                    i_margin = 7;
                    break;
                case CONFIG_ITEM_KEY:
                    i_margin = 5;
                    break;
                case CONFIG_ITEM_MODULE_LIST:
                    i_margin = 10;
                    break;
                default:
                    i_margin = 20;
                    break;
            }
Jérome Decoodt's avatar
Jérome Decoodt committed
680
            break;
681
        case CONFIG_ITEM_KEY:
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
            switch(i_lastItem) {
                case CONFIG_ITEM_STRING:
                case CONFIG_ITEM_PASSWORD:
                    i_margin = 8;
                    break;
                case CONFIG_ITEM_STRING_LIST:
                    i_margin = 7;
                    break;
                case CONFIG_ITEM_LOADFILE:
                case CONFIG_ITEM_SAVEFILE:
                    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;
                case CONFIG_ITEM_KEY:
                    i_margin = 8;
                    break;
                case CONFIG_ITEM_MODULE_LIST:
                    i_margin = 10;
                    break;
                default:
                    i_margin = 20;
                    break;
            }
Jérome Decoodt's avatar
Jérome Decoodt committed
716
717
            break;
        case CONFIG_ITEM_MODULE_LIST:
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
            switch(i_lastItem) {
                case CONFIG_ITEM_STRING:
                case CONFIG_ITEM_PASSWORD:
                    i_margin = 10;
                    break;
                case CONFIG_ITEM_STRING_LIST:
                    i_margin = 7;
                    break;
                case CONFIG_ITEM_LOADFILE:
                case CONFIG_ITEM_SAVEFILE:
                    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;
                case CONFIG_ITEM_KEY:
                    i_margin = 5;
                    break;
                case CONFIG_ITEM_MODULE_LIST:
                    i_margin = 8;
                    break;
                default:
                    i_margin = 20;
                    break;
            }
Jérome Decoodt's avatar
Jérome Decoodt committed
752
753
754
755
            break;
        default:
            i_margin = 20;
            break;
756
757
758
759
760
    }
    return i_margin;
}

+ (VLCConfigControl *)newControl:(module_config_t *)_p_item
761
                        withView:(NSView *)parentView
762
{
763
    VLCConfigControl *control = NULL;
764
765

    switch(_p_item->i_type) {
Jérome Decoodt's avatar
Jérome Decoodt committed
766
        case CONFIG_ITEM_STRING:
767
        case CONFIG_ITEM_PASSWORD:
768
            if (!_p_item->list_count) {
769
                control = [[StringConfigControl alloc]
770
                             initWithItem: _p_item
771
                             withView: parentView];
772
            } else {
773
                control = [[StringListConfigControl alloc]
774
                             initWithItem: _p_item
775
                             withView: parentView];
776
            }
Jérome Decoodt's avatar
Jérome Decoodt committed
777
            break;
778
779
        case CONFIG_ITEM_LOADFILE:
        case CONFIG_ITEM_SAVEFILE:
780
        case CONFIG_ITEM_DIRECTORY:
781
            control = [[FileConfigControl alloc]
782
                         initWithItem: _p_item
783
                         withView: parentView];
Jérome Decoodt's avatar
Jérome Decoodt committed
784
785
            break;
        case CONFIG_ITEM_MODULE:
786
            control = [[StringListConfigControl alloc]
787
                         initWithItem: _p_item
788
                         withView: parentView];
Jérome Decoodt's avatar
Jérome Decoodt committed
789
            break;
790
        case CONFIG_ITEM_MODULE_CAT:
791
            control = [[ModuleConfigControl alloc]
792
                         initWithItem: _p_item
793
                         withView: parentView];
Jérome Decoodt's avatar
Jérome Decoodt committed
794
795
            break;
        case CONFIG_ITEM_INTEGER:
796
            if (_p_item->list_count)
797
                control = [[IntegerListConfigControl alloc] initWithItem: _p_item withView: parentView];
798
            else if (_p_item->min.i > INT32_MIN && _p_item->max.i < INT32_MAX)
799
                control = [[RangedIntegerConfigControl alloc] initWithItem: _p_item withView: parentView];
800
            else
801
                control = [[IntegerConfigControl alloc] initWithItem: _p_item withView: parentView];
Jérome Decoodt's avatar
Jérome Decoodt committed
802
803
            break;
        case CONFIG_ITEM_BOOL:
804
805
            control = [[BoolConfigControl alloc] initWithItem: _p_item
                                                     withView: parentView];
Jérome Decoodt's avatar
Jérome Decoodt committed
806
            break;
807
        case CONFIG_ITEM_FLOAT:
808
            if (_p_item->min.f > FLT_MIN && _p_item->max.f < FLT_MAX)
809
                control = [[RangedFloatConfigControl alloc] initWithItem: _p_item withView: parentView];
810
            else
811
                control = [[FloatConfigControl alloc] initWithItem: _p_item withView: parentView];
812
813
814
815
816
            break;
            /* 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..
             case CONFIG_ITEM_KEY:
817
             control = [[KeyConfigControl alloc]
818
             initWithItem: _p_item
819
             withView: parentView];
820
             break; */
Jérome Decoodt's avatar
Jérome Decoodt committed
821
        case CONFIG_ITEM_MODULE_LIST:
822
        case CONFIG_ITEM_MODULE_LIST_CAT:
823
            control = [[ModuleListConfigControl alloc] initWithItem: _p_item withView: parentView];
Jérome Decoodt's avatar
Jérome Decoodt committed
824
            break;
825
        case CONFIG_SECTION:
826
            control = [[SectionControl alloc] initWithItem: _p_item withView: parentView];
Jérome Decoodt's avatar
Jérome Decoodt committed
827
828
829
            break;
        default:
            break;
830
    }
831
832

    return control;
833
834
}

835
- (NSString *)name
836
{
837
    return _NS(psz_name);
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
}

- (int)intValue
{
    return 0;
}

- (float)floatValue
{
    return 0;
}

- (char *)stringValue
{
    return NULL;
}

Jérome Decoodt's avatar
Jérome Decoodt committed
855
- (void)applyChanges
856
{
Jérome Decoodt's avatar
Jérome Decoodt committed
857
    vlc_value_t val;
858
859
860
861
862
863
864
865
866
867
    switch(self.p_item->i_type) {
        case CONFIG_ITEM_STRING:
        case CONFIG_ITEM_PASSWORD:
        case CONFIG_ITEM_LOADFILE:
        case CONFIG_ITEM_SAVEFILE:
        case CONFIG_ITEM_DIRECTORY:
        case CONFIG_ITEM_MODULE:
        case CONFIG_ITEM_MODULE_LIST:
        case CONFIG_ITEM_MODULE_LIST_CAT: {
            char *psz_val = [self stringValue];
868
            config_PutPsz(psz_name, psz_val);
869
870
871
872
873
874
            free(psz_val);
            break;
        }
        case CONFIG_ITEM_KEY:
            /* So you don't need to restart to have the changes take effect */
            val.i_int = [self intValue];
875
            var_Set(getIntf()->obj.libvlc, psz_name, val);
876
877
        case CONFIG_ITEM_INTEGER:
        case CONFIG_ITEM_BOOL:
878
            config_PutInt(psz_name, [self intValue]);
879
880
            break;
        case CONFIG_ITEM_FLOAT:
881
            config_PutFloat(psz_name, [self floatValue]);
882
            break;
883
884
    }
}
Jérome Decoodt's avatar
Jérome Decoodt committed
885

886
887
888
889
- (void)resetValues
{
}

890
- (int)labelSize
Jérome Decoodt's avatar
Jérome Decoodt committed
891
{
892
    return self.label.frame.size.width;
Jérome Decoodt's avatar
Jérome Decoodt committed
893
}
894
895
896
897
898
899

- (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 */
}
900
901
@end

902
903
904
905
906
907
@interface StringConfigControl()
{
    NSTextField     *o_textfield;
}
@end

908
@implementation StringConfigControl
909
910
- (id)initWithItem:(module_config_t *)p_item
          withView:(NSView *)parentView
911
{
912
913
    NSRect mainFrame = [parentView frame];
    NSString *labelString, *o_textfieldString, *o_textfieldTooltip;
Jérome Decoodt's avatar
Jérome Decoodt committed
914
915
916
    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
917
    mainFrame.origin.y = 0;
Jérome Decoodt's avatar
Jérome Decoodt committed
918

919
    if ([super initWithFrame:mainFrame item:p_item] != nil) {
920
        if (p_item->i_type == CONFIG_ITEM_PASSWORD)
921
            self.viewType = CONFIG_ITEM_PASSWORD;
922
        else
923
            self.viewType = CONFIG_ITEM_STRING;
924

925
        o_textfieldTooltip = [[VLCStringUtility sharedInstance] wrapString: _NS(p_item->psz_longtext) toWidth: PREFS_WRAP];
926

927
        /* add the label */
928
        labelString = _NS(p_item->psz_text);
929
        ADD_LABEL(self.label, mainFrame, 0, -3, labelString, o_textfieldTooltip)
930
931
        [self.label setAutoresizingMask:NSViewNotSizable ];
        [self addSubview: self.label];
932

Jérome Decoodt's avatar
Jérome Decoodt committed
933
        /* build the textfield */
934
        if (p_item->value.psz)
935
            o_textfieldString = toNSStr(p_item->value.psz);
Jérome Decoodt's avatar
Jérome Decoodt committed
936
        else
937
            o_textfieldString = @"";
938
        if (p_item->i_type == CONFIG_ITEM_PASSWORD) {
939
940
941
            ADD_SECURETEXTFIELD(o_textfield, mainFrame, [self.label frame].size.width + 2,
                                0, mainFrame.size.width - [self.label frame].size.width -
                                2, o_textfieldTooltip, o_textfieldString)
942
        } else {
943
944
945
            ADD_TEXTFIELD(o_textfield, mainFrame, [self.label frame].size.width + 2,
                          0, mainFrame.size.width - [self.label frame].size.width -
                          2, o_textfieldTooltip, o_textfieldString)
946
        }
Jérome Decoodt's avatar
Jérome Decoodt committed
947
        [o_textfield setAutoresizingMask:NSViewWidthSizable ];
948

949
        [self addSubview: o_textfield];
950
951
952
953
    }
    return self;
}

Jérome Decoodt's avatar
Jérome Decoodt committed
954
955
956
957
- (void) alignWithXPosition:(int)i_xPos
{
    NSRect frame;
    NSRect superFrame = [self frame];
958
    frame = [self.label frame];
Jérome Decoodt's avatar
Jérome Decoodt committed
959
    frame.origin.x = i_xPos - frame.size.width - 3;
960
    [self.label setFrame:frame];
Jérome Decoodt's avatar
Jérome Decoodt committed
961
962
963
964
965
966
967

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

968
969
- (char *)stringValue
{
970
    return strdup([[o_textfield stringValue] UTF8String]);
971
}
972
973
974
975

- (void)resetValues
{
    NSString *o_textfieldString;
976
    char *psz_value = config_GetPsz(self.p_item->psz_name);
977
    if (psz_value)
978
        o_textfieldString = _NS(psz_value);
979
    else
980
        o_textfieldString = @"";
981
    free(psz_value);
982
983
    [super resetValues];
}
984
985
@end

986
987
988
989
990
991
@interface StringListConfigControl()
{
    NSPopUpButton      *o_popup;
}
@end

992
@implementation StringListConfigControl
993
994
- (id)initWithItem:(module_config_t *)p_item
          withView:(NSView *)parentView
995
{
996
997
    NSRect mainFrame = [parentView frame];
    NSString *labelString, *o_textfieldTooltip;
Jérome Decoodt's avatar
Jérome Decoodt committed
998
999
1000
    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
1001
    mainFrame.origin.y = 0;
Jérome Decoodt's avatar
Jérome Decoodt committed
1002

1003
    if ([super initWithFrame: mainFrame item:p_item] != nil) {
1004
        if (p_item->i_type == CONFIG_ITEM_STRING)
1005
            self.viewType = CONFIG_ITEM_STRING_LIST;
1006
        else
1007
            self.viewType = CONFIG_ITEM_MODULE;
1008

1009
        o_textfieldTooltip = [[VLCStringUtility sharedInstance] wrapString: _NS(p_item->psz_longtext) toWidth: PREFS_WRAP];
1010

1011
        /* add the label */
1012
        labelString = _NS(p_item->psz_text);
1013
        ADD_LABEL(self.label, mainFrame, 0, -3, labelString, o_textfieldTooltip)
1014
1015
        [self.label setAutoresizingMask:NSViewNotSizable ];
        [self addSubview: self.label];
1016

Jérome Decoodt's avatar
Jérome Decoodt committed
1017
        /* build the textfield */
1018
1019
        ADD_POPUP(o_popup, mainFrame, [self.label frame].size.width,
                  -2, 0, o_textfieldTooltip)
1020
1021
1022
        [o_popup setAutoresizingMask:NSViewWidthSizable];

        /* add items */
1023
        [self resetValues];
1024
1025

        [self addSubview: o_popup];
1026
1027
1028
1029
    }
    return self;
}

Jérome Decoodt's avatar
Jérome Decoodt committed
1030
1031
1032
1033
- (void) alignWithXPosition:(int)i_xPos
{
    NSRect frame;
    NSRect superFrame = [self frame];
1034
    frame = [self.label frame];
Jérome Decoodt's avatar
Jérome Decoodt committed
1035
    frame.origin.x = i_xPos - frame.size.width - 3;
1036
    [self.label setFrame:frame];
Jérome Decoodt's avatar
Jérome Decoodt committed
1037

1038
    frame = [o_popup frame];
Jérome Decoodt's avatar
Jérome Decoodt committed
1039
1040
    frame.origin.x = i_xPos + 2;
    frame.size.width = superFrame.size.width - frame.origin.x + 2;
1041
    [o_popup setFrame:frame];
Jérome Decoodt's avatar
Jérome Decoodt committed
1042
1043
}

1044
1045
- (char *)stringValue
{
1046
1047
    if ([o_popup indexOfSelectedItem] < 0)
        return NULL;
1048

1049
1050
    NSString *o_data = [[o_popup selectedItem] representedObject];
    return strdup([o_data UTF8String]);
1051
}
1052
1053
1054

- (void)resetValues
{
1055
1056
    [o_popup removeAllItems];

1057
    char *psz_value = config_GetPsz(self.p_item->psz_name);
1058

1059
    char **values, **texts;
1060
    ssize_t count = config_GetPszChoices(self.p_item->psz_name,
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
                                         &values, &texts);
    for (ssize_t i = 0; i < count && texts; i++) {
        if (texts[i] == NULL || values[i] == NULL)
            continue;

        [o_popup addItemWithTitle: toNSStr(texts[i])];
        NSMenuItem *lastItem = [o_popup lastItem];
        [lastItem setRepresentedObject: toNSStr(values[i])];

        if (!strcmp(psz_value ? psz_value : "", values[i]))
            [o_popup selectItem: [o_popup lastItem]];

        free(texts[i]);
        free(values[i]);
1075
    }
1076
1077
    free(texts);
    free(values);
1078

1079
    free(psz_value);
1080

1081
1082
    [super resetValues];
}
1083
1084
@end

1085
1086
1087
1088
1089
1090
1091
1092
@interface FileConfigControl()
{
    NSTextField     *o_textfield;
    NSButton        *o_button;
    BOOL            b_directory;
}
@end

1093
@implementation FileConfigControl
1094
1095
- (id)initWithItem:(module_config_t *)p_item
          withView:(NSView *)parentView
1096
{
1097
1098
    NSRect mainFrame = [parentView frame];
    NSString *labelString, *o_itemTooltip, *o_textfieldString;
Jérome Decoodt's avatar
Jérome Decoodt committed
1099
1100
1101
    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
1102
    mainFrame.origin.y = 0;
Jérome Decoodt's avatar
Jérome Decoodt committed
1103

1104
1105
    if ([super initWithFrame:mainFrame item:p_item] != nil) {
        self.viewType = CONFIG_ITEM_LOADFILE;
1106

1107
        o_itemTooltip = [[VLCStringUtility sharedInstance] wrapString: _NS(p_item->psz_longtext) toWidth: PREFS_WRAP];
1108

1109
        /* is it a directory */
1110
        b_directory = ([self type] == CONFIG_ITEM_DIRECTORY) ? YES : NO;
1111
1112

        /* add the label */
1113
        labelString = _NS(p_item->psz_text);
1114
        ADD_LABEL(self.label, mainFrame, 0, 3, labelString, o_itemTooltip)
1115
1116
        [self.label setAutoresizingMask:NSViewNotSizable ];
        [self addSubview: self.label];
Jérome Decoodt's avatar
Jérome Decoodt committed
1117

1118
        /* build the button */
1119
        ADD_RIGHT_BUTTON(o_button, mainFrame, 0, 0, o_itemTooltip,
1120
                         _NS("Browse..."))
Jérome Decoodt's avatar
Jérome Decoodt committed
1121
1122
        [o_button setAutoresizingMask:NSViewMinXMargin ];
        [self addSubview: o_button];
1123

Jérome Decoodt's avatar
Jérome Decoodt committed
1124
        /* build the textfield */
1125
        if (p_item->value.psz)
1126
            o_textfieldString = [NSString stringWithFormat: @"%s", (char *)p_item->value.psz];
Jérome Decoodt's avatar
Jérome Decoodt committed
1127
        else
1128
            o_textfieldString = @"";
1129
        ADD_TEXTFIELD(o_textfield, mainFrame, 12, 2, mainFrame.size.width -
1130
1131
                      8 - [o_button frame].size.width,
                      o_itemTooltip, o_textfieldString)
Jérome Decoodt's avatar
Jérome Decoodt committed
1132
        [o_textfield setAutoresizingMask:NSViewWidthSizable ];
1133
        [self addSubview: o_textfield];
1134
1135
1136
1137
    }
    return self;
}