preferences_widgets.cpp 16.3 KB
Newer Older
1
2
3
4
/*****************************************************************************
 * preferences_widgets.cpp : wxWindows plugin for vlc
 *****************************************************************************
 * Copyright (C) 2000-2001 VideoLAN
5
 * $Id: preferences_widgets.cpp,v 1.5 2003/10/21 12:30:40 hartman Exp $
6
7
 *
 * Authors: Gildas Bazin <gbazin@netcourrier.com>
gbazin's avatar
   
gbazin committed
8
 *          Sigmund Augdal <sigmunau@idi.ntnu.no>
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
 *
 * 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 <errno.h>                                                 /* ENOMEM */
#include <string.h>                                            /* strerror() */
#include <stdio.h>

#include <vlc/vlc.h>
#include <vlc/intf.h>

#include <vlc_help.h>

#include "wxwindows.h"
#include "preferences_widgets.h"

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
/*****************************************************************************
 * CreateConfigControl wrapper
 *****************************************************************************/
ConfigControl *CreateConfigControl( vlc_object_t *p_this,
                                    module_config_t *p_item, wxWindow *parent )
{
    ConfigControl *p_control = NULL;

    switch( p_item->i_type )
    {
    case CONFIG_ITEM_MODULE:
        p_control = new ModuleConfigControl( p_this, p_item, parent );
        break;

    case CONFIG_ITEM_STRING:
        if( !p_item->ppsz_list )
        {
            p_control = new StringConfigControl( p_item, parent );
        }
        else
        {
            p_control = new StringListConfigControl( p_item, parent );
        }
        break;

    case CONFIG_ITEM_FILE:
    case CONFIG_ITEM_DIRECTORY:
        p_control = new FileConfigControl( p_item, parent );
        break;

    case CONFIG_ITEM_INTEGER:
        if( p_item->i_min != 0 || p_item->i_max != 0 )
        {
            p_control = new RangedIntConfigControl( p_item, parent );
        }
        else
        {
            p_control = new IntegerConfigControl( p_item, parent );
        }
        break;

    case CONFIG_ITEM_KEY:
        p_control = new KeyConfigControl( p_item, parent );
        break;

    case CONFIG_ITEM_FLOAT:
        p_control = new FloatConfigControl( p_item, parent );
        break;

    case CONFIG_ITEM_BOOL:
        p_control = new BoolConfigControl( p_item, parent );
        break;

    default:
        break;
    }

    return p_control;
}

101
102
103
/*****************************************************************************
 * ConfigControl implementation
 *****************************************************************************/
104
105
106
ConfigControl::ConfigControl( module_config_t *p_item, wxWindow *parent )
  : wxPanel( parent ), name( wxU(p_item->psz_name) ),
    i_type( p_item->i_type ), b_advanced( p_item->b_advanced )
107
108
109
110
111
112
113
114
115
116
117
118
119
{
    sizer = new wxBoxSizer( wxHORIZONTAL );
}

ConfigControl::~ConfigControl()
{
}

wxSizer *ConfigControl::Sizer()
{
    return sizer;
}

120
wxString ConfigControl::GetName()
121
{
122
    return name;
123
124
}

125
int ConfigControl::GetType()
126
{
127
    return i_type;
128
129
}

130
vlc_bool_t ConfigControl::IsAdvanced()
131
{
132
    return b_advanced;
133
134
135
136
137
}

/*****************************************************************************
 * KeyConfigControl implementation
 *****************************************************************************/
gbazin's avatar
   
gbazin committed
138
KeyConfigControl::KeyConfigControl( module_config_t *p_item, wxWindow *parent )
139
  : ConfigControl( p_item, parent )
140
141
142
143
144
145
146
147
148
149
150
{
    label = new wxStaticText(this, -1, wxU(p_item->psz_text));
    alt = new wxCheckBox( this, -1, wxU(_("Alt")) );
    alt->SetValue( p_item->i_value & KEY_MODIFIER_ALT );
    ctrl = new wxCheckBox( this, -1, wxU(_("Ctrl")) );
    ctrl->SetValue( p_item->i_value & KEY_MODIFIER_CTRL );
    shift = new wxCheckBox( this, -1, wxU(_("Shift")) );
    shift->SetValue( p_item->i_value & KEY_MODIFIER_SHIFT );
    combo = new wxComboBox( this, -1, wxU("f"), wxDefaultPosition,
                            wxDefaultSize, 0, NULL,
                            wxCB_READONLY | wxCB_SORT );
gbazin's avatar
   
gbazin committed
151
    for( unsigned int i = 0; i < sizeof(keys)/sizeof(key_descriptor_s); i++ )
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
    {
        /* HPReg says casting the int to void * is fine */
        combo->Append( wxU(_(keys[i].psz_key_string)),
                       (void*)keys[i].i_key_code );
        if( keys[i].i_key_code == ( p_item->i_value & ~KEY_MODIFIER ) )
        {
            combo->SetSelection( i );
        }
    }
    sizer->Add( label, 2, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
    sizer->Add( alt,   1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
    sizer->Add( ctrl,  1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
    sizer->Add( shift, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
    sizer->Add( combo, 2, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
    sizer->Layout();
    this->SetSizerAndFit( sizer );
}

KeyConfigControl::~KeyConfigControl()
{
    ;
}

int KeyConfigControl::GetIntValue()
{
    int result = 0;
    if( alt->IsChecked() )
    {
        result |= KEY_MODIFIER_ALT;
    }
    if( ctrl->IsChecked() )
    {
        result |= KEY_MODIFIER_CTRL;
    }
    if( shift->IsChecked() )
    {
        result |= KEY_MODIFIER_SHIFT;
    }
    int selected = combo->GetSelection();
    if( selected != -1 )
    {
        result |= (int)combo->GetClientData( selected );
    }
    return result;
}

/*****************************************************************************
 * ModuleConfigControl implementation
 *****************************************************************************/
201
ModuleConfigControl::ModuleConfigControl( vlc_object_t *p_this,
gbazin's avatar
   
gbazin committed
202
203
                                          module_config_t *p_item,
                                          wxWindow *parent )
204
  : ConfigControl( p_item, parent )
205
206
207
{
    vlc_list_t *p_list;
    module_t *p_parser;
208

209
210
211
212
    label = new wxStaticText(this, -1, wxU(p_item->psz_text));
    combo = new wxComboBox( this, -1, wxU(p_item->psz_value),
                            wxDefaultPosition, wxDefaultSize,
                            0, NULL, wxCB_READONLY | wxCB_SORT );
213

214
    /* build a list of available modules */
215
    p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
216
217
218
219
220
    combo->Append( wxU(_("Default")), (void *)NULL );
    combo->SetSelection( 0 );
    for( int i_index = 0; i_index < p_list->i_count; i_index++ )
    {
        p_parser = (module_t *)p_list->p_values[i_index].p_object ;
221

222
223
224
225
226
227
228
229
230
231
        if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
        {
            combo->Append( wxU(p_parser->psz_longname),
                           p_parser->psz_object_name );
            if( p_item->psz_value && !strcmp(p_item->psz_value, 
                                             p_parser->psz_object_name) )
                combo->SetValue( wxU(p_parser->psz_longname) );
        }
    }
    vlc_list_release( p_list );
232

233
234
235
236
237
238
239
240
241
242
243
244
    combo->SetToolTip( wxU(p_item->psz_longtext) );
    sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
    sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
    sizer->Layout();
    this->SetSizerAndFit( sizer );
}

ModuleConfigControl::~ModuleConfigControl()
{
    ;
}

gbazin's avatar
   
gbazin committed
245
wxString ModuleConfigControl::GetPszValue()
246
{
247
    return wxU( (char *)combo->GetClientData( combo->GetSelection() ));
248
249
250
251
252
}

/*****************************************************************************
 * StringConfigControl implementation
 *****************************************************************************/
gbazin's avatar
   
gbazin committed
253
254
StringConfigControl::StringConfigControl( module_config_t *p_item,
                                          wxWindow *parent )
255
  : ConfigControl( p_item, parent )
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
{
    label = new wxStaticText(this, -1, wxU(p_item->psz_text));
    sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
    textctrl = new wxTextCtrl( this, -1, 
                               wxU(p_item->psz_value),
                               wxDefaultPosition,
                               wxDefaultSize,
                               wxTE_PROCESS_ENTER);
    textctrl->SetToolTip( wxU(p_item->psz_longtext) );
    sizer->Add( textctrl, 1, wxALL, 5 );
    sizer->Layout();
    this->SetSizerAndFit( sizer );
}

StringConfigControl::~StringConfigControl()
{
    ;
}

gbazin's avatar
   
gbazin committed
275
wxString StringConfigControl::GetPszValue()
276
{
gbazin's avatar
   
gbazin committed
277
    return textctrl->GetValue();
278
279
280
281
282
}

/*****************************************************************************
 * StringListConfigControl implementation
 *****************************************************************************/
gbazin's avatar
   
gbazin committed
283
284
StringListConfigControl::StringListConfigControl( module_config_t *p_item,
                                                  wxWindow *parent )
285
  : ConfigControl( p_item, parent )
286
287
288
289
290
291
{
    label = new wxStaticText(this, -1, wxU(p_item->psz_text));
    sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
    combo = new wxComboBox( this, -1, wxU(p_item->psz_value),
                            wxDefaultPosition, wxDefaultSize,
                            0, NULL, wxCB_READONLY|wxCB_SORT );
292

293
294
295
296
297
298
299
300
301
    /* build a list of available options */
    for( int i_index = 0; p_item->ppsz_list[i_index];
         i_index++ )
    {
        combo->Append( wxU(p_item->ppsz_list[i_index]) );
        if( p_item->psz_value && !strcmp( p_item->psz_value,
                                          p_item->ppsz_list[i_index] ) )
            combo->SetSelection( i_index );
    }
302

303
304
305
306
307
308
309
310
311
312
313
314
315
    if( p_item->psz_value )
        combo->SetValue( wxU(p_item->psz_value) );
    combo->SetToolTip( wxU(p_item->psz_longtext) );
    sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );    
    sizer->Layout();
    this->SetSizerAndFit( sizer );
}

StringListConfigControl::~StringListConfigControl()
{
    ;
}

gbazin's avatar
   
gbazin committed
316
wxString StringListConfigControl::GetPszValue()
317
{
gbazin's avatar
   
gbazin committed
318
    return combo->GetStringSelection();
319
320
321
322
323
}

/*****************************************************************************
 * FileConfigControl implementation
 *****************************************************************************/
gbazin's avatar
   
gbazin committed
324
325
FileConfigControl::FileConfigControl( module_config_t *p_item,
                                      wxWindow *parent )
326
  : ConfigControl( p_item, parent )
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
{
    directory = p_item->i_type == CONFIG_ITEM_DIRECTORY;
    label = new wxStaticText(this, -1, wxU(p_item->psz_text));
    sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
    textctrl = new wxTextCtrl( this, -1, 
                               wxU(p_item->psz_value),
                               wxDefaultPosition,
                               wxDefaultSize,
                               wxTE_PROCESS_ENTER);
    textctrl->SetToolTip( wxU(p_item->psz_longtext) );
    sizer->Add( textctrl, 1, wxALL, 5 );
    browse = new wxButton( this, wxID_HIGHEST, wxU(_("Browse...")) );
    sizer->Add( browse, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
    sizer->Layout();
    this->SetSizerAndFit( sizer );
}

BEGIN_EVENT_TABLE(FileConfigControl, wxPanel)
    /* Button events */
    EVT_BUTTON(wxID_HIGHEST, FileConfigControl::OnBrowse)
END_EVENT_TABLE()

void FileConfigControl::OnBrowse( wxCommandEvent& event )
{
    if( directory )
    {
        wxDirDialog dialog( this, wxU(_("Choose Directory")) );

        if( dialog.ShowModal() == wxID_OK )
        {
            textctrl->SetValue( dialog.GetPath() );      
        }
    }
    else
    {
        wxFileDialog dialog( this, wxU(_("Choose File")),
                             wxT(""), wxT(""), wxT("*.*"),
#if defined( __WXMSW__ )
                             wxOPEN
#else
                             wxOPEN | wxSAVE
#endif
                           );
    }
}

FileConfigControl::~FileConfigControl()
{
    ;
}
    
gbazin's avatar
   
gbazin committed
378
wxString FileConfigControl::GetPszValue()
379
{
gbazin's avatar
   
gbazin committed
380
    return textctrl->GetValue();
381
382
383
384
385
}

/*****************************************************************************
 * IntegerConfigControl implementation
 *****************************************************************************/
gbazin's avatar
   
gbazin committed
386
387
IntegerConfigControl::IntegerConfigControl( module_config_t *p_item,
                                            wxWindow *parent )
388
  : ConfigControl( p_item, parent )
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
{
    label = new wxStaticText(this, -1, wxU(p_item->psz_text));
    spin = new wxSpinCtrl( this, -1,
                           wxString::Format(wxT("%d"),
                                            p_item->i_value),
                           wxDefaultPosition, wxDefaultSize,
                           wxSP_ARROW_KEYS,
                           -16000, 16000, p_item->i_value);
    spin->SetToolTip( wxU(p_item->psz_longtext) );
    sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
    sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );    
    sizer->Layout();
    this->SetSizerAndFit( sizer );
}

IntegerConfigControl::~IntegerConfigControl()
{
    ;
}

int IntegerConfigControl::GetIntValue()
{
    return spin->GetValue();
}

/*****************************************************************************
 * RangedIntConfigControl implementation
 *****************************************************************************/
gbazin's avatar
   
gbazin committed
417
418
RangedIntConfigControl::RangedIntConfigControl( module_config_t *p_item,
                                                wxWindow *parent )
419
  : ConfigControl( p_item, parent )
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
{
    label = new wxStaticText(this, -1, wxU(p_item->psz_text));
    slider = new wxSlider( this, -1, p_item->i_value, p_item->i_min,
                           p_item->i_max );
    slider->SetToolTip( wxU(p_item->psz_longtext) );
    sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
    sizer->Add( slider, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );    
    sizer->Layout();
    this->SetSizerAndFit( sizer );
}

RangedIntConfigControl::~RangedIntConfigControl()
{
    ;
}

int RangedIntConfigControl::GetIntValue()
{
    return slider->GetValue();
}

/*****************************************************************************
 * FloatConfigControl implementation
 *****************************************************************************/
gbazin's avatar
   
gbazin committed
444
445
FloatConfigControl::FloatConfigControl( module_config_t *p_item,
                                        wxWindow *parent )
446
  : ConfigControl( p_item, parent )
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
{
    label = new wxStaticText(this, -1, wxU(p_item->psz_text));
    textctrl = new wxTextCtrl( this, -1,
                               wxString::Format(wxT("%f"),
                                                p_item->f_value),
                               wxDefaultPosition, wxDefaultSize,
                               wxTE_PROCESS_ENTER );
    textctrl->SetToolTip( wxU(p_item->psz_longtext) );
    sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
    sizer->Add( textctrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
    sizer->Layout();
    this->SetSizerAndFit( sizer );
}

FloatConfigControl::~FloatConfigControl()
{
    ;
}

float FloatConfigControl::GetFloatValue()
{
    float f_value;
    if( (wxSscanf(textctrl->GetValue(), wxT("%f"), &f_value) == 1) )
        return f_value;
    else return 0.0;
}

/*****************************************************************************
 * BoolConfigControl implementation
 *****************************************************************************/
gbazin's avatar
   
gbazin committed
477
478
BoolConfigControl::BoolConfigControl( module_config_t *p_item,
                                      wxWindow *parent )
479
  : ConfigControl( p_item, parent )
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
{
    checkbox = new wxCheckBox( this, -1, wxU(p_item->psz_text) );
    if( p_item->i_value ) checkbox->SetValue(TRUE);
    checkbox->SetToolTip( wxU(p_item->psz_longtext) );
    sizer->Add( checkbox, 0, wxALL, 5 );
    sizer->Layout();
    this->SetSizerAndFit( sizer );
}

BoolConfigControl::~BoolConfigControl()
{
    ;
}

int BoolConfigControl::GetIntValue()
{
    if( checkbox->IsChecked() )
    {
        return 1;
    }
    else
    {
        return 0;
    }
}