1 /*****************************************************************************
2 * preferences_widgets.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: preferences_widgets.cpp,v 1.9 2003/11/02 22:16:32 gbazin Exp $
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
8 * Sigmund Augdal <sigmunau@idi.ntnu.no>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
29 #include <errno.h> /* ENOMEM */
30 #include <string.h> /* strerror() */
38 #include "wxwindows.h"
39 #include "preferences_widgets.h"
41 /*****************************************************************************
42 * CreateConfigControl wrapper
43 *****************************************************************************/
44 ConfigControl *CreateConfigControl( vlc_object_t *p_this,
45 module_config_t *p_item, wxWindow *parent )
47 ConfigControl *p_control = NULL;
49 switch( p_item->i_type )
51 case CONFIG_ITEM_MODULE:
52 p_control = new ModuleConfigControl( p_this, p_item, parent );
55 case CONFIG_ITEM_STRING:
56 if( !p_item->ppsz_list )
58 p_control = new StringConfigControl( p_item, parent );
62 p_control = new StringListConfigControl( p_item, parent );
66 case CONFIG_ITEM_FILE:
67 case CONFIG_ITEM_DIRECTORY:
68 p_control = new FileConfigControl( p_item, parent );
71 case CONFIG_ITEM_INTEGER:
72 if( p_item->i_min != 0 || p_item->i_max != 0 )
74 p_control = new RangedIntConfigControl( p_item, parent );
78 p_control = new IntegerConfigControl( p_item, parent );
83 p_control = new KeyConfigControl( p_item, parent );
86 case CONFIG_ITEM_FLOAT:
87 p_control = new FloatConfigControl( p_item, parent );
90 case CONFIG_ITEM_BOOL:
91 p_control = new BoolConfigControl( p_item, parent );
101 /*****************************************************************************
102 * ConfigControl implementation
103 *****************************************************************************/
104 ConfigControl::ConfigControl( module_config_t *p_item, wxWindow *parent )
105 : wxPanel( parent ), name( wxU(p_item->psz_name) ),
106 i_type( p_item->i_type ), b_advanced( p_item->b_advanced )
108 sizer = new wxBoxSizer( wxHORIZONTAL );
111 ConfigControl::~ConfigControl()
115 wxSizer *ConfigControl::Sizer()
120 wxString ConfigControl::GetName()
125 int ConfigControl::GetType()
130 vlc_bool_t ConfigControl::IsAdvanced()
135 /*****************************************************************************
136 * KeyConfigControl implementation
137 *****************************************************************************/
138 static wxString KeysList[] =
210 KeyConfigControl::KeyConfigControl( module_config_t *p_item, wxWindow *parent )
211 : ConfigControl( p_item, parent )
213 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
214 alt = new wxCheckBox( this, -1, wxU(_("Alt")) );
215 alt->SetValue( p_item->i_value & KEY_MODIFIER_ALT );
216 ctrl = new wxCheckBox( this, -1, wxU(_("Ctrl")) );
217 ctrl->SetValue( p_item->i_value & KEY_MODIFIER_CTRL );
218 shift = new wxCheckBox( this, -1, wxU(_("Shift")) );
219 shift->SetValue( p_item->i_value & KEY_MODIFIER_SHIFT );
220 combo = new wxComboBox( this, -1, wxT(""), wxDefaultPosition,
221 wxDefaultSize, WXSIZEOF(KeysList), KeysList,
223 for( unsigned int i = 0; i < WXSIZEOF(KeysList); i++ )
225 combo->SetClientData( i, (void*)keys[i].i_key_code );
226 if( keys[i].i_key_code ==
227 ( ((unsigned int)p_item->i_value) & ~KEY_MODIFIER ) )
229 combo->SetSelection( i );
230 combo->SetValue( wxU(_(keys[i].psz_key_string)) );
234 sizer->Add( label, 2, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
235 sizer->Add( alt, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
236 sizer->Add( ctrl, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
237 sizer->Add( shift, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
238 sizer->Add( combo, 2, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
240 this->SetSizerAndFit( sizer );
243 KeyConfigControl::~KeyConfigControl()
248 int KeyConfigControl::GetIntValue()
251 if( alt->IsChecked() )
253 result |= KEY_MODIFIER_ALT;
255 if( ctrl->IsChecked() )
257 result |= KEY_MODIFIER_CTRL;
259 if( shift->IsChecked() )
261 result |= KEY_MODIFIER_SHIFT;
263 int selected = combo->GetSelection();
266 result |= (int)combo->GetClientData( selected );
271 /*****************************************************************************
272 * ModuleConfigControl implementation
273 *****************************************************************************/
274 ModuleConfigControl::ModuleConfigControl( vlc_object_t *p_this,
275 module_config_t *p_item,
277 : ConfigControl( p_item, parent )
282 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
283 combo = new wxComboBox( this, -1, wxU(p_item->psz_value),
284 wxDefaultPosition, wxDefaultSize,
285 0, NULL, wxCB_READONLY | wxCB_SORT );
287 /* build a list of available modules */
288 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
289 combo->Append( wxU(_("Default")), (void *)NULL );
290 combo->SetSelection( 0 );
291 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
293 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
295 if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
297 combo->Append( wxU(p_parser->psz_longname),
298 p_parser->psz_object_name );
299 if( p_item->psz_value && !strcmp(p_item->psz_value,
300 p_parser->psz_object_name) )
301 combo->SetValue( wxU(p_parser->psz_longname) );
304 vlc_list_release( p_list );
306 combo->SetToolTip( wxU(p_item->psz_longtext) );
307 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
308 sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
310 this->SetSizerAndFit( sizer );
313 ModuleConfigControl::~ModuleConfigControl()
318 wxString ModuleConfigControl::GetPszValue()
320 return wxU( (char *)combo->GetClientData( combo->GetSelection() ));
323 /*****************************************************************************
324 * StringConfigControl implementation
325 *****************************************************************************/
326 StringConfigControl::StringConfigControl( module_config_t *p_item,
328 : ConfigControl( p_item, parent )
330 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
331 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
332 textctrl = new wxTextCtrl( this, -1,
333 wxU(p_item->psz_value),
337 textctrl->SetToolTip( wxU(p_item->psz_longtext) );
338 sizer->Add( textctrl, 1, wxALL, 5 );
340 this->SetSizerAndFit( sizer );
343 StringConfigControl::~StringConfigControl()
348 wxString StringConfigControl::GetPszValue()
350 return textctrl->GetValue();
353 /*****************************************************************************
354 * StringListConfigControl implementation
355 *****************************************************************************/
356 StringListConfigControl::StringListConfigControl( module_config_t *p_item,
358 : ConfigControl( p_item, parent )
360 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
361 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
362 combo = new wxComboBox( this, -1, wxU(p_item->psz_value),
363 wxDefaultPosition, wxDefaultSize,
364 0, NULL, wxCB_READONLY );
366 /* build a list of available options */
367 for( int i_index = 0; p_item->ppsz_list[i_index];
370 combo->Append( wxU(p_item->ppsz_list[i_index]) );
371 if( p_item->psz_value && !strcmp( p_item->psz_value,
372 p_item->ppsz_list[i_index] ) )
373 combo->SetSelection( i_index );
376 if( p_item->psz_value )
377 combo->SetValue( wxU(p_item->psz_value) );
378 combo->SetToolTip( wxU(p_item->psz_longtext) );
379 sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
381 this->SetSizerAndFit( sizer );
384 StringListConfigControl::~StringListConfigControl()
389 wxString StringListConfigControl::GetPszValue()
391 return combo->GetStringSelection();
394 /*****************************************************************************
395 * FileConfigControl implementation
396 *****************************************************************************/
397 FileConfigControl::FileConfigControl( module_config_t *p_item,
399 : ConfigControl( p_item, parent )
401 directory = p_item->i_type == CONFIG_ITEM_DIRECTORY;
402 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
403 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
404 textctrl = new wxTextCtrl( this, -1,
405 wxU(p_item->psz_value),
409 textctrl->SetToolTip( wxU(p_item->psz_longtext) );
410 sizer->Add( textctrl, 1, wxALL, 5 );
411 browse = new wxButton( this, wxID_HIGHEST, wxU(_("Browse...")) );
412 sizer->Add( browse, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
414 this->SetSizerAndFit( sizer );
417 BEGIN_EVENT_TABLE(FileConfigControl, wxPanel)
419 EVT_BUTTON(wxID_HIGHEST, FileConfigControl::OnBrowse)
422 void FileConfigControl::OnBrowse( wxCommandEvent& event )
426 wxDirDialog dialog( this, wxU(_("Choose Directory")) );
428 if( dialog.ShowModal() == wxID_OK )
430 textctrl->SetValue( dialog.GetPath() );
435 wxFileDialog dialog( this, wxU(_("Choose File")),
436 wxT(""), wxT(""), wxT("*.*"),
437 #if defined( __WXMSW__ )
446 FileConfigControl::~FileConfigControl()
451 wxString FileConfigControl::GetPszValue()
453 return textctrl->GetValue();
456 /*****************************************************************************
457 * IntegerConfigControl implementation
458 *****************************************************************************/
459 IntegerConfigControl::IntegerConfigControl( module_config_t *p_item,
461 : ConfigControl( p_item, parent )
463 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
464 spin = new wxSpinCtrl( this, -1,
465 wxString::Format(wxT("%d"),
467 wxDefaultPosition, wxDefaultSize,
469 -16000, 16000, p_item->i_value);
470 spin->SetToolTip( wxU(p_item->psz_longtext) );
471 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
472 sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
474 this->SetSizerAndFit( sizer );
477 IntegerConfigControl::~IntegerConfigControl()
482 int IntegerConfigControl::GetIntValue()
484 return spin->GetValue();
487 /*****************************************************************************
488 * RangedIntConfigControl implementation
489 *****************************************************************************/
490 RangedIntConfigControl::RangedIntConfigControl( module_config_t *p_item,
492 : ConfigControl( p_item, parent )
494 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
495 slider = new wxSlider( this, -1, p_item->i_value, p_item->i_min,
496 p_item->i_max, wxDefaultPosition, wxDefaultSize,
497 wxSL_LABELS | wxSL_HORIZONTAL );
498 slider->SetToolTip( wxU(p_item->psz_longtext) );
499 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
500 sizer->Add( slider, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
502 this->SetSizerAndFit( sizer );
505 RangedIntConfigControl::~RangedIntConfigControl()
510 int RangedIntConfigControl::GetIntValue()
512 return slider->GetValue();
515 /*****************************************************************************
516 * FloatConfigControl implementation
517 *****************************************************************************/
518 FloatConfigControl::FloatConfigControl( module_config_t *p_item,
520 : ConfigControl( p_item, parent )
522 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
523 textctrl = new wxTextCtrl( this, -1,
524 wxString::Format(wxT("%f"),
526 wxDefaultPosition, wxDefaultSize,
527 wxTE_PROCESS_ENTER );
528 textctrl->SetToolTip( wxU(p_item->psz_longtext) );
529 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
530 sizer->Add( textctrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
532 this->SetSizerAndFit( sizer );
535 FloatConfigControl::~FloatConfigControl()
540 float FloatConfigControl::GetFloatValue()
543 if( (wxSscanf(textctrl->GetValue(), wxT("%f"), &f_value) == 1) )
548 /*****************************************************************************
549 * BoolConfigControl implementation
550 *****************************************************************************/
551 BoolConfigControl::BoolConfigControl( module_config_t *p_item,
553 : ConfigControl( p_item, parent )
555 checkbox = new wxCheckBox( this, -1, wxU(p_item->psz_text) );
556 if( p_item->i_value ) checkbox->SetValue(TRUE);
557 checkbox->SetToolTip( wxU(p_item->psz_longtext) );
558 sizer->Add( checkbox, 0, wxALL, 5 );
560 this->SetSizerAndFit( sizer );
563 BoolConfigControl::~BoolConfigControl()
568 int BoolConfigControl::GetIntValue()
570 if( checkbox->IsChecked() )