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 )
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( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
283 combo->Append( wxU(p_parser->psz_longname),
284 p_parser->psz_object_name );
285 if( p_item->value.psz && !strcmp(p_item->value.psz,
286 p_parser->psz_object_name) )
287 combo->SetValue( wxU(p_parser->psz_longname) );
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( p_parser->psz_object_name, "main" ) )
337 module_config_t *p_config = p_parser->p_config;
338 module_config_t *p_end = p_config + p_parser->confsize;
342 /* Hack: required subcategory is stored in min.i */
343 if( p_config->i_type == CONFIG_SUBCATEGORY &&
344 p_config->value.i == p_item->min.i )
346 combo->Append( wxU(p_parser->psz_longname),
347 p_parser->psz_object_name );
348 if( p_item->value.psz && !strcmp(p_item->value.psz,
349 p_parser->psz_object_name) )
350 combo->SetValue( wxU(p_parser->psz_longname) );
352 } while( p_config < p_end && p_config++ );
354 vlc_list_release( p_list );
356 combo->SetToolTip( wxU(p_item->psz_longtext) );
357 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
358 sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
360 this->SetSizerAndFit( sizer );
363 ModuleConfigControl::~ModuleConfigControl()
368 wxString ModuleConfigControl::GetPszValue()
370 return wxU( (char *)combo->GetClientData( combo->GetSelection() ));
374 /*****************************************************************************
375 * ModuleListCatonfigControl implementation
376 *****************************************************************************/
377 BEGIN_EVENT_TABLE(ModuleListCatConfigControl, wxPanel)
378 EVT_CHECKBOX( wxID_HIGHEST , ModuleListCatConfigControl::OnUpdate )
382 ModuleListCatConfigControl::ModuleListCatConfigControl( vlc_object_t *p_this,
383 module_config_t *p_item,
385 : ConfigControl( p_this, p_item, parent )
391 sizer = new wxBoxSizer( wxVERTICAL );
392 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
395 text = new wxTextCtrl( this, -1, wxU(p_item->value.psz),
396 wxDefaultPosition,wxSize( 300, 20 ) );
399 /* build a list of available modules */
400 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
401 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
403 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
405 if( !strcmp( p_parser->psz_object_name, "main" ) )
408 module_config_t *p_config, *p_end;
409 if( p_parser->b_submodule )
410 p_config = ((module_t*)p_parser->p_parent)->p_config;
412 p_config = p_parser->p_config;
413 p_end = p_config + p_parser->confsize;
417 /* Hack: required subcategory is stored in min.i */
418 if( p_config->i_type == CONFIG_SUBCATEGORY &&
419 p_config->value.i == p_item->min.i )
421 moduleCheckBox *mc = new moduleCheckBox;
422 mc->checkbox = new wxCheckBox( this, wxID_HIGHEST,
423 wxU(p_parser->psz_longname));
424 /* hack to handle submodules properly */
426 while( p_parser->pp_shortcuts[++i] != NULL );
428 mc->psz_module = strdup( i>=0?p_parser->pp_shortcuts[i]
429 :p_parser->psz_object_name );
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 );
439 } while( p_config < p_end && p_config++ );
441 vlc_list_release( p_list );
443 text->SetToolTip( wxU(p_item->psz_longtext) );
444 sizer->Add(text, 0, wxEXPAND|wxALL, 5 );
446 sizer->Add (new wxStaticText( this, -1, wxU( vlc_wraptext( _("Select "
447 "the desired modules. For more advanced control, the "
448 "resulting \"chain\" can be modified.") , 72 ) ) ) );
451 this->SetSizerAndFit( sizer );
454 ModuleListCatConfigControl::~ModuleListCatConfigControl()
459 wxString ModuleListCatConfigControl::GetPszValue()
461 return text->GetValue() ;
464 void ModuleListCatConfigControl::OnUpdate( wxCommandEvent &event )
466 bool b_waschecked = false;
467 wxString newtext = text->GetValue();
469 for( unsigned int i = 0 ; i< pp_checkboxes.size() ; i++ )
471 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));
472 /* For some reasons, ^^ doesn't compile :( */
473 if( (pp_checkboxes[i]->checkbox->IsChecked() && ! b_waschecked )||
474 (! pp_checkboxes[i]->checkbox->IsChecked() && b_waschecked) )
478 /* Maybe not the clest solution */
479 if( ! newtext.Replace(wxString(wxT(":"))
480 +wxU(pp_checkboxes[i]->psz_module)+wxT(":"),
483 if( newtext.BeforeFirst( ':' ) == wxString(wxU(pp_checkboxes[i]->psz_module)) )
485 newtext = newtext.AfterFirst( ':' );
487 else if( newtext.AfterLast( ':' ) == wxString(wxU(pp_checkboxes[i]->psz_module)) )
489 newtext = newtext.BeforeLast( ':' );
491 else if( newtext == wxString(wxU(pp_checkboxes[i]->psz_module)) )
497 newtext.Replace(wxU(pp_checkboxes[i]->psz_module),wxU(""));
503 if( newtext.Len() == 0 )
505 newtext = wxU(pp_checkboxes[i]->psz_module);
509 newtext += wxU( ":" );
510 newtext += wxU(pp_checkboxes[i]->psz_module);
515 text->SetValue( newtext );
518 /*****************************************************************************
519 * StringConfigControl implementation
520 *****************************************************************************/
521 StringConfigControl::StringConfigControl( vlc_object_t *p_this,
522 module_config_t *p_item,
524 : ConfigControl( p_this, p_item, parent )
526 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
527 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
528 textctrl = new wxTextCtrl( this, -1,
529 wxL2U(p_item->value.psz),
533 textctrl->SetToolTip( wxU(p_item->psz_longtext) );
534 sizer->Add( textctrl, 1, wxALL, 5 );
536 this->SetSizerAndFit( sizer );
539 StringConfigControl::~StringConfigControl()
544 wxString StringConfigControl::GetPszValue()
546 return textctrl->GetValue();
549 BEGIN_EVENT_TABLE(StringConfigControl, wxPanel)
551 EVT_TEXT(-1, StringConfigControl::OnUpdate)
554 /*****************************************************************************
555 * StringListConfigControl implementation
556 *****************************************************************************/
557 StringListConfigControl::StringListConfigControl( vlc_object_t *p_this,
558 module_config_t *p_item,
560 : ConfigControl( p_this, p_item, parent )
562 psz_default_value = p_item->value.psz;
563 if( psz_default_value ) psz_default_value = strdup( psz_default_value );
565 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
566 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
567 combo = new wxComboBox( this, -1, wxT(""),
568 wxDefaultPosition, wxDefaultSize,
569 0, NULL, wxCB_READONLY );
570 UpdateCombo( p_item );
572 combo->SetToolTip( wxU(p_item->psz_longtext) );
573 sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
575 for( int i = 0; i < p_item->i_action; i++ )
578 new wxButton( this, wxID_HIGHEST+i,
579 wxU(_(p_item->ppsz_action_text[i])) );
580 sizer->Add( button, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
584 this->SetSizerAndFit( sizer );
587 StringListConfigControl::~StringListConfigControl()
589 if( psz_default_value ) free( psz_default_value );
592 void StringListConfigControl::UpdateCombo( module_config_t *p_item )
594 vlc_bool_t b_found = VLC_FALSE;
597 /* build a list of available options */
598 for( i_index = 0; i_index < p_item->i_list; i_index++ )
600 combo->Append( ( p_item->ppsz_list_text &&
601 p_item->ppsz_list_text[i_index] ) ?
602 wxU(p_item->ppsz_list_text[i_index]) :
603 wxL2U(p_item->ppsz_list[i_index]) );
604 combo->SetClientData( i_index, (void *)p_item->ppsz_list[i_index] );
605 if( ( p_item->value.psz &&
606 !strcmp( p_item->value.psz, p_item->ppsz_list[i_index] ) ) ||
607 ( !p_item->value.psz && !*p_item->ppsz_list[i_index] ) )
609 combo->SetSelection( i_index );
610 combo->SetValue( ( p_item->ppsz_list_text &&
611 p_item->ppsz_list_text[i_index] ) ?
612 wxU(p_item->ppsz_list_text[i_index]) :
613 wxL2U(p_item->ppsz_list[i_index]) );
618 if( p_item->value.psz && !b_found )
620 /* Add custom entry to list */
621 combo->Append( wxL2U(p_item->value.psz) );
622 combo->SetClientData( i_index, (void *)psz_default_value );
623 combo->SetSelection( i_index );
624 combo->SetValue( wxL2U(p_item->value.psz) );
628 BEGIN_EVENT_TABLE(StringListConfigControl, wxPanel)
630 EVT_BUTTON(-1, StringListConfigControl::OnAction)
633 EVT_TEXT(-1, StringListConfigControl::OnUpdate)
636 void StringListConfigControl::OnAction( wxCommandEvent& event )
638 int i_action = event.GetId() - wxID_HIGHEST;
640 module_config_t *p_item = config_FindConfig( p_this, GetName().mb_str() );
641 if( !p_item ) return;
643 if( i_action < 0 || i_action >= p_item->i_action ) return;
646 wxString value = GetPszValue();
647 *((const char **)&val.psz_string) = value.mb_str();
648 p_item->ppf_action[i_action]( p_this, GetName().mb_str(), val, val, 0 );
650 if( p_item->b_dirty )
653 UpdateCombo( p_item );
654 p_item->b_dirty = VLC_FALSE;
658 wxString StringListConfigControl::GetPszValue()
660 int selected = combo->GetSelection();
663 return wxL2U((char *)combo->GetClientData( selected ));
668 /*****************************************************************************
669 * FileConfigControl implementation
670 *****************************************************************************/
671 FileConfigControl::FileConfigControl( vlc_object_t *p_this,
672 module_config_t *p_item,
674 : ConfigControl( p_this, p_item, parent )
676 directory = p_item->i_type == CONFIG_ITEM_DIRECTORY;
677 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
678 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
679 textctrl = new wxTextCtrl( this, -1,
680 wxL2U(p_item->value.psz),
684 textctrl->SetToolTip( wxU(p_item->psz_longtext) );
685 sizer->Add( textctrl, 1, wxALL, 5 );
686 browse = new wxButton( this, wxID_HIGHEST, wxU(_("Browse...")) );
687 sizer->Add( browse, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
689 this->SetSizerAndFit( sizer );
692 BEGIN_EVENT_TABLE(FileConfigControl, wxPanel)
694 EVT_BUTTON(wxID_HIGHEST, FileConfigControl::OnBrowse)
697 void FileConfigControl::OnBrowse( wxCommandEvent& event )
701 wxDirDialog dialog( this, wxU(_("Choose directory")) );
703 if( dialog.ShowModal() == wxID_OK )
705 textctrl->SetValue( dialog.GetPath() );
710 wxFileDialog dialog( this, wxU(_("Choose file")),
711 wxT(""), wxT(""), wxT("*.*"),
712 #if defined( __WXMSW__ )
718 if( dialog.ShowModal() == wxID_OK )
720 textctrl->SetValue( dialog.GetPath() );
725 FileConfigControl::~FileConfigControl()
730 wxString FileConfigControl::GetPszValue()
732 return textctrl->GetValue();
735 /*****************************************************************************
736 * IntegerConfigControl implementation
737 *****************************************************************************/
738 BEGIN_EVENT_TABLE(IntegerConfigControl, wxPanel)
739 EVT_TEXT(-1, IntegerConfigControl::OnUpdate)
740 EVT_COMMAND_SCROLL(-1, IntegerConfigControl::OnUpdateScroll)
743 IntegerConfigControl::IntegerConfigControl( vlc_object_t *p_this,
744 module_config_t *p_item,
746 : ConfigControl( p_this, p_item, parent )
748 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
749 spin = new wxSpinCtrl( this, -1,
750 wxString::Format(wxT("%d"),
752 wxDefaultPosition, wxDefaultSize,
754 -100000000, 100000000, p_item->value.i);
755 spin->SetToolTip( wxU(p_item->psz_longtext) );
756 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
757 sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
759 this->SetSizerAndFit( sizer );
760 i_value = p_item->value.i;
763 IntegerConfigControl::~IntegerConfigControl()
768 int IntegerConfigControl::GetIntValue()
770 /* We avoid using GetValue because of a recursion bug with wxSpinCtrl with
772 return spin->GetValue();
775 void IntegerConfigControl::OnUpdate( wxCommandEvent &event )
777 ConfigControl::OnUpdate( event );
779 void IntegerConfigControl::OnUpdateScroll( wxScrollEvent &event )
781 wxCommandEvent cevent;
782 cevent.SetInt(event.GetPosition());
786 /*****************************************************************************
787 * IntegerListConfigControl implementation
788 *****************************************************************************/
789 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *p_this,
790 module_config_t *p_item,
792 : ConfigControl( p_this, p_item, parent )
794 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
795 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
796 combo = new wxComboBox( this, -1, wxT(""),
797 wxDefaultPosition, wxDefaultSize,
798 0, NULL, wxCB_READONLY );
800 UpdateCombo( p_item );
802 combo->SetToolTip( wxU(p_item->psz_longtext) );
803 sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
806 this->SetSizerAndFit( sizer );
809 IntegerListConfigControl::~IntegerListConfigControl()
813 void IntegerListConfigControl::UpdateCombo( module_config_t *p_item )
815 /* build a list of available options */
816 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
818 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
820 combo->Append( wxU(p_item->ppsz_list_text[i_index]) );
824 combo->Append( wxString::Format(wxT("%i"),
825 p_item->pi_list[i_index]) );
827 combo->SetClientData( i_index, (void *)p_item->pi_list[i_index] );
828 if( p_item->value.i == p_item->pi_list[i_index] )
830 combo->SetSelection( i_index );
831 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
833 combo->SetValue( wxU(p_item->ppsz_list_text[i_index]) );
837 combo->SetValue( wxString::Format(wxT("%i"),
838 p_item->pi_list[i_index]) );
844 BEGIN_EVENT_TABLE(IntegerListConfigControl, wxPanel)
846 EVT_BUTTON(-1, IntegerListConfigControl::OnAction)
849 EVT_TEXT(-1, IntegerListConfigControl::OnUpdate)
852 void IntegerListConfigControl::OnAction( wxCommandEvent& event )
854 int i_action = event.GetId() - wxID_HIGHEST;
856 module_config_t *p_item;
857 p_item = config_FindConfig( p_this, GetName().mb_str() );
858 if( !p_item ) return;
860 if( i_action < 0 || i_action >= p_item->i_action ) return;
863 val.i_int = GetIntValue();
864 p_item->ppf_action[i_action]( p_this, GetName().mb_str(), val, val, 0 );
866 if( p_item->b_dirty )
869 UpdateCombo( p_item );
870 p_item->b_dirty = VLC_FALSE;
874 int IntegerListConfigControl::GetIntValue()
876 int selected = combo->GetSelection();
879 return (int)combo->GetClientData( selected );
884 /*****************************************************************************
885 * RangedIntConfigControl implementation
886 *****************************************************************************/
887 BEGIN_EVENT_TABLE(RangedIntConfigControl, wxPanel)
888 EVT_COMMAND_SCROLL(-1, RangedIntConfigControl::OnUpdateScroll)
891 RangedIntConfigControl::RangedIntConfigControl( vlc_object_t *p_this,
892 module_config_t *p_item,
894 : ConfigControl( p_this, p_item, parent )
896 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
897 slider = new wxSlider( this, -1, p_item->value.i, p_item->min.i,
898 p_item->max.i, wxDefaultPosition, wxDefaultSize,
899 wxSL_LABELS | wxSL_HORIZONTAL );
900 slider->SetToolTip( wxU(p_item->psz_longtext) );
901 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
902 sizer->Add( slider, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
904 this->SetSizerAndFit( sizer );
907 RangedIntConfigControl::~RangedIntConfigControl()
912 int RangedIntConfigControl::GetIntValue()
914 return slider->GetValue();
918 /*****************************************************************************
919 * FloatConfigControl implementation
920 *****************************************************************************/
921 BEGIN_EVENT_TABLE(FloatConfigControl, wxPanel)
922 EVT_TEXT(-1, FloatConfigControl::OnUpdate)
925 FloatConfigControl::FloatConfigControl( vlc_object_t *p_this,
926 module_config_t *p_item,
928 : ConfigControl( p_this, p_item, parent )
930 label = new wxStaticText(this, -1, wxU(p_item->psz_text));
931 textctrl = new wxTextCtrl( this, -1,
932 wxString::Format(wxT("%f"),
934 wxDefaultPosition, wxDefaultSize,
935 wxTE_PROCESS_ENTER );
936 textctrl->SetToolTip( wxU(p_item->psz_longtext) );
937 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
938 sizer->Add( textctrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
940 this->SetSizerAndFit( sizer );
943 FloatConfigControl::~FloatConfigControl()
948 float FloatConfigControl::GetFloatValue()
951 if( (wxSscanf(textctrl->GetValue(), wxT("%f"), &f_value) == 1) )
956 /*****************************************************************************
957 * BoolConfigControl implementation
958 *****************************************************************************/
959 BEGIN_EVENT_TABLE(BoolConfigControl, wxPanel)
960 EVT_CHECKBOX(-1, BoolConfigControl::OnUpdate)
963 BoolConfigControl::BoolConfigControl( vlc_object_t *p_this,
964 module_config_t *p_item,
966 : ConfigControl( p_this, p_item, parent )
968 checkbox = new wxCheckBox( this, -1, wxU(p_item->psz_text) );
969 if( p_item->value.i ) checkbox->SetValue(TRUE);
970 checkbox->SetToolTip( wxU(p_item->psz_longtext) );
971 sizer->Add( checkbox, 0, wxALL, 5 );
973 this->SetSizerAndFit( sizer );
976 BoolConfigControl::~BoolConfigControl()
981 int BoolConfigControl::GetIntValue()
983 if( checkbox->IsChecked() ) return 1;
987 /*****************************************************************************
988 * SectionConfigControl implementation
989 *****************************************************************************/
990 SectionConfigControl::SectionConfigControl( vlc_object_t *p_this,
991 module_config_t *p_item,
993 : ConfigControl( p_this, p_item, parent )
996 sizer = new wxBoxSizer( wxVERTICAL );
997 sizer->Add( new wxStaticText( this, -1, wxU( p_item->psz_text ) ) );
998 sizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND, 5 );
1000 this->SetSizerAndFit( sizer );
1003 SectionConfigControl::~SectionConfigControl()