1 /*****************************************************************************
2 * preferences_widgets.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@videolan.org>
8 * Sigmund Augdal Helberg <dnumgis@videolan.org>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #include "wxwidgets.hpp"
26 #include "preferences_widgets.h"
28 #include <vlc_config_cat.h>
30 #include <wx/statline.h>
31 #include <wx/spinctrl.h>
33 /*****************************************************************************
34 * CreateConfigControl wrapper
35 *****************************************************************************/
36 ConfigControl *CreateConfigControl( vlc_object_t *p_this,
37 module_config_t *p_item, wxWindow *parent )
39 ConfigControl *p_control = NULL;
41 /*Skip deprecated options */
42 if( p_item->psz_current || p_item->b_unsaveable )
47 switch( p_item->i_type )
49 case CONFIG_ITEM_MODULE:
50 p_control = new ModuleConfigControl( p_this, p_item, parent );
52 case CONFIG_ITEM_MODULE_CAT:
53 p_control = new ModuleCatConfigControl( p_this, p_item, parent );
55 case CONFIG_ITEM_MODULE_LIST_CAT:
56 p_control = new ModuleListCatConfigControl( p_this, p_item, parent );
59 case CONFIG_ITEM_STRING:
62 p_control = new StringConfigControl( p_this, p_item, parent );
66 p_control = new StringListConfigControl( p_this, p_item, parent );
70 case CONFIG_ITEM_FILE:
71 case CONFIG_ITEM_DIRECTORY:
72 p_control = new FileConfigControl( p_this, p_item, parent );
75 case CONFIG_ITEM_INTEGER:
78 p_control = new IntegerListConfigControl( p_this, p_item, parent );
80 else if( p_item->min.i != 0 || p_item->max.i != 0 )
82 p_control = new RangedIntConfigControl( p_this, p_item, parent );
86 p_control = new IntegerConfigControl( p_this, p_item, parent );
91 p_control = new KeyConfigControl( p_this, p_item, parent );
94 case CONFIG_ITEM_FLOAT:
95 p_control = new FloatConfigControl( p_this, p_item, parent );
98 case CONFIG_ITEM_BOOL:
99 p_control = new BoolConfigControl( p_this, p_item, parent );
103 p_control = new SectionConfigControl( p_this, p_item, parent );
113 /*****************************************************************************
114 * ConfigControl implementation
115 *****************************************************************************/
116 ConfigControl::ConfigControl( vlc_object_t *_p_this,
117 module_config_t *p_item, wxWindow *parent )
118 : wxPanel( parent ), p_this( _p_this ),
119 pf_update_callback( NULL ), p_update_data( NULL ),
120 name( wxU(p_item->psz_name) ), i_type( p_item->i_type ),
121 b_advanced( p_item->b_advanced )
124 sizer = new wxBoxSizer( wxHORIZONTAL );
127 ConfigControl::~ConfigControl()
131 wxSizer *ConfigControl::Sizer()
136 wxString ConfigControl::GetName()
141 int ConfigControl::GetType()
146 vlc_bool_t ConfigControl::IsAdvanced()
151 void ConfigControl::SetUpdateCallback( void (*p_callback)( void * ),
154 pf_update_callback = p_callback;
155 p_update_data = p_data;
158 void ConfigControl::OnUpdate( wxCommandEvent& WXUNUSED(event) )
160 if( pf_update_callback )
162 pf_update_callback( p_update_data );
166 void ConfigControl::OnUpdateScroll( wxScrollEvent& WXUNUSED(event) )
168 wxCommandEvent cevent;
173 /*****************************************************************************
174 * KeyConfigControl implementation
175 *****************************************************************************/
176 wxString *KeyConfigControl::m_keysList = NULL;
178 KeyConfigControl::KeyConfigControl( vlc_object_t *p_this,
179 module_config_t *p_item, wxWindow *parent )
180 : ConfigControl( p_this, p_item, parent )
182 // Number of keys descriptions
183 unsigned int i_keys = sizeof(vlc_keys)/sizeof(key_descriptor_t);
185 // Init the keys decriptions array
186 if( m_keysList == NULL )
188 m_keysList = new wxString[i_keys];
189 for( unsigned int i = 0; i < i_keys; i++ )
191 m_keysList[i] = wxU(vlc_keys[i].psz_key_string);
195 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
196 alt = new wxCheckBox( this, -1, wxU(_("Alt")) );
197 alt->SetValue( p_item->value.i & KEY_MODIFIER_ALT );
198 ctrl = new wxCheckBox( this, -1, wxU(_("Ctrl")) );
199 ctrl->SetValue( p_item->value.i & KEY_MODIFIER_CTRL );
200 shift = new wxCheckBox( this, -1, wxU(_("Shift")) );
201 shift->SetValue( p_item->value.i & KEY_MODIFIER_SHIFT );
202 combo = new wxComboBox( this, -1, wxT(""), wxDefaultPosition,
203 wxDefaultSize, i_keys, m_keysList,
205 for( unsigned int i = 0; i < i_keys; i++ )
207 combo->SetClientData( i, (void*)vlc_keys[i].i_key_code );
208 if( (unsigned int)vlc_keys[i].i_key_code ==
209 ( ((unsigned int)p_item->value.i) & ~KEY_MODIFIER ) )
211 combo->SetSelection( i );
212 combo->SetValue( wxU(_(vlc_keys[i].psz_key_string)) );
216 sizer->Add( label, 2, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
217 sizer->Add( alt, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
218 sizer->Add( ctrl, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
219 sizer->Add( shift, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
220 sizer->Add( combo, 2, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
222 this->SetSizerAndFit( sizer );
225 KeyConfigControl::~KeyConfigControl()
234 int KeyConfigControl::GetIntValue()
237 if( alt->IsChecked() )
239 result |= KEY_MODIFIER_ALT;
241 if( ctrl->IsChecked() )
243 result |= KEY_MODIFIER_CTRL;
245 if( shift->IsChecked() )
247 result |= KEY_MODIFIER_SHIFT;
249 int selected = combo->GetSelection();
252 result |= (int)combo->GetClientData( selected );
257 /*****************************************************************************
258 * ModuleConfigControl implementation
259 *****************************************************************************/
260 ModuleConfigControl::ModuleConfigControl( vlc_object_t *p_this,
261 module_config_t *p_item,
263 : ConfigControl( p_this, p_item, parent )
268 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
269 combo = new wxComboBox( this, -1, wxL2U(p_item->value.psz),
270 wxDefaultPosition, wxDefaultSize,
271 0, NULL, wxCB_READONLY | wxCB_SORT );
273 /* build a list of available modules */
274 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
275 combo->Append( wxU(_("Default")), (void *)NULL );
276 combo->SetSelection( 0 );
277 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
279 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
281 if( module_IsCapable( p_parser, p_item->psz_type ) )
283 combo->Append( wxU(module_GetLongName(p_parser)),
284 (char *)module_GetObjName(p_parser) );
285 if( p_item->value.psz && !strcmp(p_item->value.psz,
286 module_GetObjName(p_parser)) )
287 combo->SetValue( wxU(module_GetLongName(p_parser)) );
290 vlc_list_release( p_list );
292 combo->SetToolTip( wxU(p_item->psz_longtext) );
293 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
294 sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
296 this->SetSizerAndFit( sizer );
299 ModuleCatConfigControl::~ModuleCatConfigControl()
304 wxString ModuleCatConfigControl::GetPszValue()
306 return wxU( (char *)combo->GetClientData( combo->GetSelection() ));
309 /*****************************************************************************
310 * ModuleCatConfigControl implementation
311 *****************************************************************************/
312 ModuleCatConfigControl::ModuleCatConfigControl( vlc_object_t *p_this,
313 module_config_t *p_item,
315 : ConfigControl( p_this, p_item, parent )
320 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
321 combo = new wxComboBox( this, -1, wxL2U(p_item->value.psz),
322 wxDefaultPosition, wxDefaultSize,
323 0, NULL, wxCB_READONLY | wxCB_SORT );
325 combo->Append( wxU(_("Default")), (void *)NULL );
326 combo->SetSelection( 0 );
328 /* build a list of available modules */
329 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
330 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
332 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
334 if( !strcmp( module_GetObjName(p_parser), "main" ) )
337 unsigned int i_confsize;
338 module_config_t *p_config, *p_start, *p_end;
339 p_start = module_GetConfig( p_parser, &i_confsize );
340 p_end = p_start + i_confsize;
342 for( p_config = p_start; p_config < p_end; p_config++ )
344 /* Hack: required subcategory is stored in min.i */
345 if( p_config->i_type == CONFIG_SUBCATEGORY &&
346 p_config->value.i == p_item->min.i )
348 combo->Append( wxU(module_GetLongName(p_parser)),
349 (char *)module_GetObjName(p_parser) );
350 if( p_item->value.psz &&
351 !strcmp(p_item->value.psz, module_GetObjName(p_parser)) )
352 combo->SetValue( wxU(module_GetLongName(p_parser)) );
356 module_PutConfig( p_start );
358 vlc_list_release( p_list );
360 combo->SetToolTip( wxU(p_item->psz_longtext) );
361 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
362 sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
364 this->SetSizerAndFit( sizer );
367 ModuleConfigControl::~ModuleConfigControl()
372 wxString ModuleConfigControl::GetPszValue()
374 return wxU( (char *)combo->GetClientData( combo->GetSelection() ));
378 /*****************************************************************************
379 * ModuleListCatonfigControl implementation
380 *****************************************************************************/
381 BEGIN_EVENT_TABLE(ModuleListCatConfigControl, wxPanel)
382 EVT_CHECKBOX( wxID_HIGHEST , ModuleListCatConfigControl::OnUpdate )
386 ModuleListCatConfigControl::ModuleListCatConfigControl( vlc_object_t *p_this,
387 module_config_t *p_item,
389 : ConfigControl( p_this, p_item, parent )
395 sizer = new wxBoxSizer( wxVERTICAL );
396 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
399 text = new wxTextCtrl( this, -1, wxU(p_item->value.psz),
400 wxDefaultPosition,wxSize( 300, 20 ) );
403 /* build a list of available modules */
404 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
405 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
407 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
409 if( !strcmp( module_GetObjName(p_parser), "main" ) )
412 unsigned int i_confsize;
413 module_config_t *p_config, *p_start, *p_end;
415 p_start = module_GetConfig( p_parser, &i_confsize );
416 p_end = p_start + i_confsize;
418 for( p_config = p_start; p_config < p_end; p_config++ )
420 /* Hack: required subcategory is stored in min.i */
421 if( p_config->i_type == CONFIG_SUBCATEGORY &&
422 p_config->value.i == p_item->min.i )
424 moduleCheckBox *mc = new moduleCheckBox;
426 new wxCheckBox( this, wxID_HIGHEST,
427 wxU(module_GetLongName(p_parser)) );
429 mc->psz_module = strdup( module_GetObjName(p_parser) );
430 pp_checkboxes.push_back( mc );
432 if( p_item->value.psz &&
433 strstr( p_item->value.psz, mc->psz_module ) )
435 mc->checkbox->SetValue( true );
437 sizer->Add( mc->checkbox );
441 module_PutConfig( p_start );
443 vlc_list_release( p_list );
445 text->SetToolTip( wxU(p_item->psz_longtext) );
446 sizer->Add(text, 0, wxEXPAND|wxALL, 5 );
448 sizer->Add (new wxStaticText( this, -1, wxU( vlc_wraptext( _("Select "
449 "the desired modules. For more advanced control, the "
450 "resulting \"chain\" can be modified.") , 72 ) ) ) );
453 this->SetSizerAndFit( sizer );
456 ModuleListCatConfigControl::~ModuleListCatConfigControl()
461 wxString ModuleListCatConfigControl::GetPszValue()
463 return text->GetValue() ;
466 void ModuleListCatConfigControl::OnUpdate( wxCommandEvent &event )
468 bool b_waschecked = false;
469 wxString newtext = text->GetValue();
471 for( unsigned int i = 0 ; i< pp_checkboxes.size() ; i++ )
473 b_waschecked = newtext.Find( wxT(":")+wxU(pp_checkboxes[i]->psz_module)+wxT(":")) != -1 || newtext.BeforeFirst( ':' ) == wxString(wxU(pp_checkboxes[i]->psz_module)) || newtext.AfterLast( ':' ) == wxString(wxU(pp_checkboxes[i]->psz_module));
474 /* For some reasons, ^^ doesn't compile :( */
475 if( (pp_checkboxes[i]->checkbox->IsChecked() && ! b_waschecked )||
476 (! pp_checkboxes[i]->checkbox->IsChecked() && b_waschecked) )
480 /* Maybe not the clest solution */
481 if( ! newtext.Replace(wxString(wxT(":"))
482 +wxU(pp_checkboxes[i]->psz_module)+wxT(":"),
485 if( newtext.BeforeFirst( ':' ) == wxString(wxU(pp_checkboxes[i]->psz_module)) )
487 newtext = newtext.AfterFirst( ':' );
489 else if( newtext.AfterLast( ':' ) == wxString(wxU(pp_checkboxes[i]->psz_module)) )
491 newtext = newtext.BeforeLast( ':' );
493 else if( newtext == wxString(wxU(pp_checkboxes[i]->psz_module)) )
499 newtext.Replace(wxU(pp_checkboxes[i]->psz_module),wxU(""));
505 if( newtext.Len() == 0 )
507 newtext = wxU(pp_checkboxes[i]->psz_module);
511 newtext += wxU( ":" );
512 newtext += wxU(pp_checkboxes[i]->psz_module);
517 text->SetValue( newtext );
520 /*****************************************************************************
521 * StringConfigControl implementation
522 *****************************************************************************/
523 StringConfigControl::StringConfigControl( vlc_object_t *p_this,
524 module_config_t *p_item,
526 : ConfigControl( p_this, p_item, parent )
528 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
529 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
530 textctrl = new wxTextCtrl( this, -1,
531 wxL2U(p_item->value.psz),
535 textctrl->SetToolTip( wxU(p_item->psz_longtext) );
536 sizer->Add( textctrl, 1, wxALL, 5 );
538 this->SetSizerAndFit( sizer );
541 StringConfigControl::~StringConfigControl()
546 wxString StringConfigControl::GetPszValue()
548 return textctrl->GetValue();
551 BEGIN_EVENT_TABLE(StringConfigControl, wxPanel)
553 EVT_TEXT(-1, StringConfigControl::OnUpdate)
556 /*****************************************************************************
557 * StringListConfigControl implementation
558 *****************************************************************************/
559 StringListConfigControl::StringListConfigControl( vlc_object_t *p_this,
560 module_config_t *p_item,
562 : ConfigControl( p_this, p_item, parent )
564 psz_default_value = (char *)p_item->value.psz;
565 if( psz_default_value ) psz_default_value = strdup( psz_default_value );
567 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
568 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
569 combo = new wxComboBox( this, -1, wxT(""),
570 wxDefaultPosition, wxDefaultSize,
571 0, NULL, wxCB_READONLY );
572 UpdateCombo( p_item );
574 combo->SetToolTip( wxU(p_item->psz_longtext) );
575 sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
577 for( int i = 0; i < p_item->i_action; i++ )
580 new wxButton( this, wxID_HIGHEST+i,
581 wxU(_(p_item->ppsz_action_text[i])) );
582 sizer->Add( button, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
586 this->SetSizerAndFit( sizer );
589 StringListConfigControl::~StringListConfigControl()
591 if( psz_default_value ) free( psz_default_value );
594 void StringListConfigControl::UpdateCombo( module_config_t *p_item )
596 vlc_bool_t b_found = VLC_FALSE;
599 /* build a list of available options */
600 for( i_index = 0; i_index < p_item->i_list; i_index++ )
602 combo->Append( ( p_item->ppsz_list_text &&
603 p_item->ppsz_list_text[i_index] ) ?
604 wxU(p_item->ppsz_list_text[i_index]) :
605 wxL2U(p_item->ppsz_list[i_index]) );
606 combo->SetClientData( i_index, (void *)p_item->ppsz_list[i_index] );
607 if( ( p_item->value.psz &&
608 !strcmp( p_item->value.psz, p_item->ppsz_list[i_index] ) ) ||
609 ( !p_item->value.psz && !*p_item->ppsz_list[i_index] ) )
611 combo->SetSelection( i_index );
612 combo->SetValue( ( p_item->ppsz_list_text &&
613 p_item->ppsz_list_text[i_index] ) ?
614 wxU(p_item->ppsz_list_text[i_index]) :
615 wxL2U(p_item->ppsz_list[i_index]) );
620 if( p_item->value.psz && !b_found )
622 /* Add custom entry to list */
623 combo->Append( wxL2U(p_item->value.psz) );
624 combo->SetClientData( i_index, (void *)psz_default_value );
625 combo->SetSelection( i_index );
626 combo->SetValue( wxL2U(p_item->value.psz) );
630 BEGIN_EVENT_TABLE(StringListConfigControl, wxPanel)
632 EVT_BUTTON(-1, StringListConfigControl::OnAction)
635 EVT_TEXT(-1, StringListConfigControl::OnUpdate)
638 void StringListConfigControl::OnAction( wxCommandEvent& event )
640 int i_action = event.GetId() - wxID_HIGHEST;
642 module_config_t *p_item = config_FindConfig( p_this, GetName().mb_str(wxConvUTF8) );
643 if( !p_item ) return;
645 if( i_action < 0 || i_action >= p_item->i_action ) return;
648 wxString value = GetPszValue();
649 *((const char **)&val.psz_string) = value.mb_str(wxConvUTF8);
650 p_item->ppf_action[i_action]( p_this, GetName().mb_str(wxConvUTF8), val, val, 0 );
652 if( p_item->b_dirty )
655 UpdateCombo( p_item );
656 p_item->b_dirty = VLC_FALSE;
660 wxString StringListConfigControl::GetPszValue()
662 int selected = combo->GetSelection();
665 return wxL2U((char *)combo->GetClientData( selected ));
670 /*****************************************************************************
671 * FileConfigControl implementation
672 *****************************************************************************/
673 FileConfigControl::FileConfigControl( vlc_object_t *p_this,
674 module_config_t *p_item,
676 : ConfigControl( p_this, p_item, parent )
678 directory = p_item->i_type == CONFIG_ITEM_DIRECTORY;
679 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
680 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
681 textctrl = new wxTextCtrl( this, -1,
682 wxL2U(p_item->value.psz),
686 textctrl->SetToolTip( wxU(p_item->psz_longtext) );
687 sizer->Add( textctrl, 1, wxALL, 5 );
688 browse = new wxButton( this, wxID_HIGHEST, wxU(_("Browse...")) );
689 sizer->Add( browse, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
691 this->SetSizerAndFit( sizer );
694 BEGIN_EVENT_TABLE(FileConfigControl, wxPanel)
696 EVT_BUTTON(wxID_HIGHEST, FileConfigControl::OnBrowse)
699 void FileConfigControl::OnBrowse( wxCommandEvent& event )
703 wxDirDialog dialog( this, wxU(_("Choose directory")) );
705 if( dialog.ShowModal() == wxID_OK )
707 textctrl->SetValue( dialog.GetPath() );
712 wxFileDialog dialog( this, wxU(_("Choose file")),
713 wxT(""), wxT(""), wxT("*.*"),
714 #if defined( __WXMSW__ )
720 if( dialog.ShowModal() == wxID_OK )
722 textctrl->SetValue( dialog.GetPath() );
727 FileConfigControl::~FileConfigControl()
732 wxString FileConfigControl::GetPszValue()
734 return textctrl->GetValue();
737 /*****************************************************************************
738 * IntegerConfigControl implementation
739 *****************************************************************************/
740 BEGIN_EVENT_TABLE(IntegerConfigControl, wxPanel)
741 EVT_TEXT(-1, IntegerConfigControl::OnUpdate)
742 EVT_COMMAND_SCROLL(-1, IntegerConfigControl::OnUpdateScroll)
745 IntegerConfigControl::IntegerConfigControl( vlc_object_t *p_this,
746 module_config_t *p_item,
748 : ConfigControl( p_this, p_item, parent )
750 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
751 spin = new wxSpinCtrl( this, -1,
752 wxString::Format(wxT("%d"),
754 wxDefaultPosition, wxDefaultSize,
756 -100000000, 100000000, p_item->value.i);
757 spin->SetToolTip( wxU(p_item->psz_longtext) );
758 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
759 sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
761 this->SetSizerAndFit( sizer );
762 i_value = p_item->value.i;
765 IntegerConfigControl::~IntegerConfigControl()
770 int IntegerConfigControl::GetIntValue()
772 /* We avoid using GetValue because of a recursion bug with wxSpinCtrl with
774 return spin->GetValue();
777 void IntegerConfigControl::OnUpdate( wxCommandEvent &event )
779 ConfigControl::OnUpdate( event );
781 void IntegerConfigControl::OnUpdateScroll( wxScrollEvent &event )
783 wxCommandEvent cevent;
784 cevent.SetInt(event.GetPosition());
788 /*****************************************************************************
789 * IntegerListConfigControl implementation
790 *****************************************************************************/
791 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *p_this,
792 module_config_t *p_item,
794 : ConfigControl( p_this, p_item, parent )
796 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
797 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
798 combo = new wxComboBox( this, -1, wxT(""),
799 wxDefaultPosition, wxDefaultSize,
800 0, NULL, wxCB_READONLY );
802 UpdateCombo( p_item );
804 combo->SetToolTip( wxU(p_item->psz_longtext) );
805 sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
808 this->SetSizerAndFit( sizer );
811 IntegerListConfigControl::~IntegerListConfigControl()
815 void IntegerListConfigControl::UpdateCombo( module_config_t *p_item )
817 /* build a list of available options */
818 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
820 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
822 combo->Append( wxU(p_item->ppsz_list_text[i_index]) );
826 combo->Append( wxString::Format(wxT("%i"),
827 p_item->pi_list[i_index]) );
829 combo->SetClientData( i_index, (void *)p_item->pi_list[i_index] );
830 if( p_item->value.i == p_item->pi_list[i_index] )
832 combo->SetSelection( i_index );
833 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
835 combo->SetValue( wxU(p_item->ppsz_list_text[i_index]) );
839 combo->SetValue( wxString::Format(wxT("%i"),
840 p_item->pi_list[i_index]) );
846 BEGIN_EVENT_TABLE(IntegerListConfigControl, wxPanel)
848 EVT_BUTTON(-1, IntegerListConfigControl::OnAction)
851 EVT_TEXT(-1, IntegerListConfigControl::OnUpdate)
854 void IntegerListConfigControl::OnAction( wxCommandEvent& event )
856 int i_action = event.GetId() - wxID_HIGHEST;
858 module_config_t *p_item;
859 p_item = config_FindConfig( p_this, GetName().mb_str(wxConvUTF8) );
860 if( !p_item ) return;
862 if( i_action < 0 || i_action >= p_item->i_action ) return;
865 val.i_int = GetIntValue();
866 p_item->ppf_action[i_action]( p_this, GetName().mb_str(wxConvUTF8), val, val, 0 );
868 if( p_item->b_dirty )
871 UpdateCombo( p_item );
872 p_item->b_dirty = VLC_FALSE;
876 int IntegerListConfigControl::GetIntValue()
878 int selected = combo->GetSelection();
881 return (int)combo->GetClientData( selected );
886 /*****************************************************************************
887 * RangedIntConfigControl implementation
888 *****************************************************************************/
889 BEGIN_EVENT_TABLE(RangedIntConfigControl, wxPanel)
890 EVT_COMMAND_SCROLL(-1, RangedIntConfigControl::OnUpdateScroll)
893 RangedIntConfigControl::RangedIntConfigControl( vlc_object_t *p_this,
894 module_config_t *p_item,
896 : ConfigControl( p_this, p_item, parent )
898 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
899 slider = new wxSlider( this, -1, p_item->value.i, p_item->min.i,
900 p_item->max.i, wxDefaultPosition, wxDefaultSize,
901 wxSL_LABELS | wxSL_HORIZONTAL );
902 slider->SetToolTip( wxU(p_item->psz_longtext) );
903 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
904 sizer->Add( slider, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
906 this->SetSizerAndFit( sizer );
909 RangedIntConfigControl::~RangedIntConfigControl()
914 int RangedIntConfigControl::GetIntValue()
916 return slider->GetValue();
920 /*****************************************************************************
921 * FloatConfigControl implementation
922 *****************************************************************************/
923 BEGIN_EVENT_TABLE(FloatConfigControl, wxPanel)
924 EVT_TEXT(-1, FloatConfigControl::OnUpdate)
927 FloatConfigControl::FloatConfigControl( vlc_object_t *p_this,
928 module_config_t *p_item,
930 : ConfigControl( p_this, p_item, parent )
932 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
933 textctrl = new wxTextCtrl( this, -1,
934 wxString::Format(wxT("%f"),
936 wxDefaultPosition, wxDefaultSize,
937 wxTE_PROCESS_ENTER );
938 textctrl->SetToolTip( wxU(p_item->psz_longtext) );
939 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
940 sizer->Add( textctrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
942 this->SetSizerAndFit( sizer );
945 FloatConfigControl::~FloatConfigControl()
950 float FloatConfigControl::GetFloatValue()
953 if( (wxSscanf(textctrl->GetValue(), wxT("%f"), &f_value) == 1) )
958 /*****************************************************************************
959 * BoolConfigControl implementation
960 *****************************************************************************/
961 BEGIN_EVENT_TABLE(BoolConfigControl, wxPanel)
962 EVT_CHECKBOX(-1, BoolConfigControl::OnUpdate)
965 BoolConfigControl::BoolConfigControl( vlc_object_t *p_this,
966 module_config_t *p_item,
968 : ConfigControl( p_this, p_item, parent )
970 checkbox = new wxCheckBox( this, -1, wxU(p_item->psz_text) );
971 if( p_item->value.i ) checkbox->SetValue(TRUE);
972 checkbox->SetToolTip( wxU(p_item->psz_longtext) );
973 sizer->Add( checkbox, 0, wxALL, 5 );
975 this->SetSizerAndFit( sizer );
978 BoolConfigControl::~BoolConfigControl()
983 int BoolConfigControl::GetIntValue()
985 if( checkbox->IsChecked() ) return 1;
989 /*****************************************************************************
990 * SectionConfigControl implementation
991 *****************************************************************************/
992 SectionConfigControl::SectionConfigControl( vlc_object_t *p_this,
993 module_config_t *p_item,
995 : ConfigControl( p_this, p_item, parent )
998 sizer = new wxBoxSizer( wxVERTICAL );
999 sizer->Add( new wxStaticText( this, -1, wxU( p_item->psz_text ) ) );
1000 sizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND, 5 );
1002 this->SetSizerAndFit( sizer );
1005 SectionConfigControl::~SectionConfigControl()