X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fwxwindows%2Fpreferences.cpp;h=bd6bbfa4d928749ff8a833877bc05086cbc203aa;hb=1ecc320869fa09ca48e630eb913ff725c843fa59;hp=16f7793351c640f8a5d223dae36fa7b298efdf76;hpb=86e2b37df571aab09b4634fa964d50fb9311d038;p=vlc diff --git a/modules/gui/wxwindows/preferences.cpp b/modules/gui/wxwindows/preferences.cpp index 16f7793351..bd6bbfa4d9 100644 --- a/modules/gui/wxwindows/preferences.cpp +++ b/modules/gui/wxwindows/preferences.cpp @@ -2,7 +2,7 @@ * preferences.cpp : wxWindows plugin for vlc ***************************************************************************** * Copyright (C) 2000-2001 VideoLAN - * $Id: preferences.cpp,v 1.14 2003/05/12 21:55:01 gbazin Exp $ + * $Id: preferences.cpp,v 1.35 2003/10/17 16:40:09 gbazin Exp $ * * Authors: Gildas Bazin * @@ -30,18 +30,11 @@ #include #include +#include -#ifdef WIN32 /* mingw32 hack */ -#undef Yield -#undef CreateDialog -#endif - -/* Let vlc take care of the i18n stuff */ -#define WXINTL_NO_GETTEXT_MACRO +#include -#include -#include -#include +#include "wxwindows.h" #include #include #include @@ -51,21 +44,18 @@ #include #include -#include - -#if defined MODULE_NAME_IS_skins -# include "../skins/src/skin_common.h" -#endif - -#include "wxwindows.h" - #ifndef wxRB_SINGLE # define wxRB_SINGLE 0 #endif +#define GENERAL_ID 1242 +#define PLUGIN_ID 1243 +#define CAPABILITY_ID 1244 + /***************************************************************************** * Classes declarations. *****************************************************************************/ +class ConfigTreeData; class PrefsTreeCtrl : public wxTreeCtrl { public: @@ -81,6 +71,9 @@ public: private: /* Event handlers (these functions should _not_ be virtual) */ void OnSelectTreeItem( wxTreeEvent& event ); + void OnAdvanced( wxCommandEvent& event ); + + ConfigTreeData *FindModuleConfig( ConfigTreeData *config_data ); DECLARE_EVENT_TABLE() @@ -88,8 +81,10 @@ private: PrefsDialog *p_prefs_dialog; wxBoxSizer *p_sizer; wxWindow *p_parent; + vlc_bool_t b_advanced; wxTreeItemId root_item; + wxTreeItemId general_item; wxTreeItemId plugins_item; }; @@ -126,15 +121,13 @@ public: PrefsPanel() { } PrefsPanel( wxWindow *parent, intf_thread_t *_p_intf, - PrefsDialog *_p_prefs_dialog, int i_object_id, char * ); + PrefsDialog *, int i_object_id, char *, char * ); virtual ~PrefsPanel() {} void ApplyChanges(); + void SwitchAdvanced( vlc_bool_t ); private: - void OnAdvanced( wxCommandEvent& WXUNUSED(event) ); - DECLARE_EVENT_TABLE() - intf_thread_t *p_intf; PrefsDialog *p_prefs_dialog; @@ -150,9 +143,13 @@ class ConfigTreeData : public wxTreeItemData { public: - ConfigTreeData() { panel = NULL; psz_section = NULL; } + ConfigTreeData() { b_submodule = 0; panel = NULL; psz_section = NULL; } virtual ~ConfigTreeData() { if( panel ) delete panel; } + vlc_bool_t b_submodule; + + char *psz_help; + PrefsPanel *panel; wxBoxSizer *sizer; int i_object_id; @@ -194,6 +191,7 @@ BEGIN_EVENT_TABLE(PrefsDialog, wxFrame) EVT_BUTTON(wxID_CANCEL, PrefsDialog::OnCancel) EVT_BUTTON(wxID_SAVE, PrefsDialog::OnSave) EVT_BUTTON(ResetAll_Event, PrefsDialog::OnResetAll) + EVT_CHECKBOX(Advanced_Event, PrefsDialog::OnAdvanced) /* Don't destroy the window when the user closes it */ EVT_CLOSE(PrefsDialog::OnCancel) @@ -207,12 +205,7 @@ enum BEGIN_EVENT_TABLE(PrefsTreeCtrl, wxTreeCtrl) EVT_TREE_SEL_CHANGED(PrefsTree_Ctrl, PrefsTreeCtrl::OnSelectTreeItem) -END_EVENT_TABLE() - -BEGIN_EVENT_TABLE(PrefsPanel, wxPanel) - /* Button events */ - EVT_BUTTON(Advanced_Event, PrefsPanel::OnAdvanced) - + EVT_COMMAND(Advanced_Event, wxEVT_USER_FIRST, PrefsTreeCtrl::OnAdvanced) END_EVENT_TABLE() BEGIN_EVENT_TABLE(ConfigEvtHandler, wxEvtHandler) @@ -225,13 +218,12 @@ END_EVENT_TABLE() /***************************************************************************** * Constructor. *****************************************************************************/ -PrefsDialog::PrefsDialog( intf_thread_t *_p_intf, Interface *_p_main_interface) - : wxFrame( _p_main_interface, -1, wxU(_("Preferences")), wxDefaultPosition, - wxSize(650,450), wxDEFAULT_FRAME_STYLE ) +PrefsDialog::PrefsDialog( intf_thread_t *_p_intf, wxWindow *p_parent) + : wxFrame( p_parent, -1, wxU(_("Preferences")), wxDefaultPosition, + wxSize(700,450), wxDEFAULT_FRAME_STYLE ) { /* Initializations */ p_intf = _p_intf; - p_main_interface = _p_main_interface; SetIcon( *p_intf->p_sys->p_icon ); /* Create a panel to put everything in */ @@ -255,12 +247,27 @@ PrefsDialog::PrefsDialog( intf_thread_t *_p_intf, Interface *_p_main_interface) wxButton *reset_button = new wxButton( panel, ResetAll_Event, wxU(_("Reset All")) ); + wxPanel *dummy_panel = new wxPanel( this, -1 ); + wxCheckBox *advanced_checkbox = + new wxCheckBox( panel, Advanced_Event, wxU(_("Advanced options")) ); + + if( config_GetInt( p_intf, "advanced" ) ) + { + advanced_checkbox->SetValue(TRUE); + wxCommandEvent dummy_event; + dummy_event.SetInt(TRUE); + OnAdvanced( dummy_event ); + } + /* Place everything in sizers */ wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL ); button_sizer->Add( ok_button, 0, wxALL, 5 ); button_sizer->Add( cancel_button, 0, wxALL, 5 ); button_sizer->Add( save_button, 0, wxALL, 5 ); button_sizer->Add( reset_button, 0, wxALL, 5 ); + button_sizer->Add( dummy_panel, 1, wxALL, 5 ); + button_sizer->Add( advanced_checkbox, 0, wxALL | wxALIGN_RIGHT | + wxALIGN_CENTER_VERTICAL, 0 ); button_sizer->Layout(); wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL ); @@ -268,7 +275,7 @@ PrefsDialog::PrefsDialog( intf_thread_t *_p_intf, Interface *_p_main_interface) panel_sizer->Add( controls_sizer, 1, wxEXPAND | wxALL, 5 ); panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 ); panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM | - wxALL, 5 ); + wxALL | wxEXPAND, 5 ); panel_sizer->Layout(); panel->SetSizer( panel_sizer ); main_sizer->Add( panel, 1, wxEXPAND, 0 ); @@ -305,6 +312,7 @@ void PrefsDialog::OnSave( wxCommandEvent& WXUNUSED(event) ) { prefs_tree->ApplyChanges(); config_SaveConfigFile( p_intf, NULL ); + this->Hide(); } void PrefsDialog::OnResetAll( wxCommandEvent& WXUNUSED(event) ) @@ -323,6 +331,49 @@ void PrefsDialog::OnResetAll( wxCommandEvent& WXUNUSED(event) ) } } +void PrefsDialog::OnAdvanced( wxCommandEvent& event ) +{ + wxCommandEvent newevent( wxEVT_USER_FIRST, Advanced_Event ); + newevent.SetInt( event.GetInt() ); + + prefs_tree->AddPendingEvent( newevent ); +} + +/***************************************************************************** + * GetCapabilityHelp: Display the help for one capability. + *****************************************************************************/ +static char * GetCapabilityHelp( char *psz_capability, int i_type) +{ + if( psz_capability == NULL) return ""; + + if( !strcasecmp(psz_capability,"access") ) + return i_type == 1 ? ACCESS_TITLE : ACCESS_HELP; + if( !strcasecmp(psz_capability,"audio filter") ) + return i_type == 1 ? AUDIO_FILTER_TITLE : AUDIO_FILTER_HELP; + if( !strcasecmp(psz_capability,"audio output") ) + return i_type == 1 ? AOUT_TITLE : AOUT_HELP; + if( !strcasecmp(psz_capability,"chroma") ) + return i_type == 1 ? CHROMA_TITLE : CHROMA_HELP; + if( !strcasecmp(psz_capability,"decoder") ) + return i_type == 1 ? DECODER_TITLE : DECODER_HELP; + if( !strcasecmp(psz_capability,"demux") ) + return i_type == 1 ? DEMUX_TITLE : DEMUX_HELP; + if( !strcasecmp(psz_capability,"interface") ) + return i_type == 1 ? INTERFACE_TITLE : INTERFACE_HELP; + if( !strcasecmp(psz_capability,"sout access") ) + return i_type == 1 ? SOUT_TITLE : SOUT_HELP; + if( !strcasecmp(psz_capability,"subtitle demux") ) + return i_type == 1 ? SUBTITLE_DEMUX_TITLE : SUBTITLE_DEMUX_HELP; + if( !strcasecmp(psz_capability,"text renderer") ) + return i_type == 1 ? TEXT_TITLE : TEXT_HELP; + if( !strcasecmp(psz_capability,"video output") ) + return i_type == 1 ? VOUT__TITLE : VOUT_HELP; + if( !strcasecmp(psz_capability,"video filter") ) + return i_type == 1 ? VIDEO_FILTER_TITLE : VIDEO_FILTER_HELP; + + return ""; +} + /***************************************************************************** * PrefsTreeCtrl class definition. *****************************************************************************/ @@ -344,6 +395,7 @@ PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf, p_prefs_dialog = _p_prefs_dialog; p_sizer = _p_sizer; p_parent = _p_parent; + b_advanced = VLC_FALSE; root_item = AddRoot( wxT("") ); @@ -354,6 +406,14 @@ PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf, /* * Build a tree of the main options */ + ConfigTreeData *config_data = new ConfigTreeData; + config_data->psz_section = NULL; + config_data->i_object_id = GENERAL_ID; + config_data->psz_help = wraptext( GENERAL_HELP, WRAPCOUNT, ISUTF8 ); + config_data->psz_section = strdup( GENERAL_TITLE ); + general_item = AppendItem( root_item, wxU(_("General Settings")), + -1, -1, config_data ); + for( i_index = 0; i_index < p_list->i_count; i_index++ ) { p_module = (module_t *)p_list->p_values[i_index].p_object; @@ -375,24 +435,39 @@ PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf, case CONFIG_HINT_CATEGORY: ConfigTreeData *config_data = new ConfigTreeData; config_data->psz_section = strdup(p_item->psz_text); + if( p_item->psz_longtext ) + { + config_data->psz_help = + wraptext( p_item->psz_longtext, WRAPCOUNT, ISUTF8 ); + } + else + { + config_data->psz_help = NULL; + } config_data->i_object_id = p_module->i_object_id; /* Add the category to the tree */ - AppendItem( root_item, wxU(p_item->psz_text), + AppendItem( general_item, wxU(p_item->psz_text), -1, -1, config_data ); break; } } while( p_item->i_type != CONFIG_HINT_END && p_item++ ); - SortChildren( root_item ); + SortChildren( general_item ); } /* * Build a tree of all the plugins */ - plugins_item = AppendItem( root_item, wxU(_("Plugins")) ); + config_data = new ConfigTreeData; + config_data->psz_section = NULL; + config_data->i_object_id = PLUGIN_ID; + config_data->psz_help = wraptext( PLUGIN_HELP, WRAPCOUNT, ISUTF8 ); + config_data->psz_section = strdup( PLUGIN_TITLE ); + plugins_item = AppendItem( root_item, wxU(_("Plugins")), + -1,-1,config_data ); for( i_index = 0; i_index < p_list->i_count; i_index++ ) { @@ -402,8 +477,13 @@ PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf, if( !strcmp( p_module->psz_object_name, "main" ) ) continue; - /* Exclude empty plugins */ - p_item = p_module->p_config; + /* Exclude empty plugins (submodules don't have config options, they + * are stored in the parent module) */ + if( p_module->b_submodule ) + p_item = ((module_t *)p_module->p_parent)->p_config; + else + p_item = p_module->p_config; + if( !p_item ) continue; do { @@ -432,13 +512,26 @@ PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf, p_module->psz_capability && *p_module->psz_capability ) { /* We didn't find it, add it */ + ConfigTreeData *config_data = new ConfigTreeData; + config_data->psz_section = + wraptext( GetCapabilityHelp( p_module->psz_capability , 1 ), + WRAPCOUNT, ISUTF8 ); + config_data->psz_help = + wraptext( GetCapabilityHelp( p_module->psz_capability , 2 ), + WRAPCOUNT, ISUTF8 ); + config_data->i_object_id = CAPABILITY_ID; capability_item = AppendItem( plugins_item, - wxU(p_module->psz_capability) ); + wxU(p_module->psz_capability), + -1,-1,config_data ); } /* Add the plugin to the tree */ ConfigTreeData *config_data = new ConfigTreeData; - config_data->i_object_id = p_module->i_object_id; + config_data->b_submodule = p_module->b_submodule; + config_data->i_object_id = p_module->b_submodule ? + ((module_t *)p_module->p_parent)->i_object_id : + p_module->i_object_id; + config_data->psz_help = NULL; AppendItem( capability_item, wxU(p_module->psz_object_name), -1, -1, config_data ); } @@ -465,6 +558,8 @@ PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf, #ifndef WIN32 /* Workaround a bug in win32 implementation */ SelectItem( GetFirstChild( root_item, cookie ) ); #endif + + Expand( general_item ); } PrefsTreeCtrl::~PrefsTreeCtrl() @@ -477,9 +572,9 @@ void PrefsTreeCtrl::ApplyChanges() ConfigTreeData *config_data; /* Apply changes to the main module */ - wxTreeItemId item = GetFirstChild( root_item, cookie ); + wxTreeItemId item = GetFirstChild( general_item, cookie ); for( size_t i_child_index = 0; - i_child_index < GetChildrenCount( root_item, FALSE ); + i_child_index < GetChildrenCount( general_item, FALSE ); i_child_index++ ) { config_data = (ConfigTreeData *)GetItemData( item ); @@ -488,7 +583,7 @@ void PrefsTreeCtrl::ApplyChanges() config_data->panel->ApplyChanges(); } - item = GetNextChild( root_item, cookie ); + item = GetNextChild( general_item, cookie ); } /* Apply changes to the plugins */ @@ -520,34 +615,28 @@ void PrefsTreeCtrl::CleanChanges() long cookie, cookie2; ConfigTreeData *config_data; + config_data = !GetSelection() ? NULL : + FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) ); + if( config_data ) + { + config_data->panel->Hide(); + p_sizer->Remove( config_data->panel ); + } + /* Clean changes for the main module */ - wxTreeItemId item = GetFirstChild( root_item, cookie ); + wxTreeItemId item = GetFirstChild( general_item, cookie ); for( size_t i_child_index = 0; - i_child_index < GetChildrenCount( root_item, FALSE ); + i_child_index < GetChildrenCount( general_item, FALSE ); i_child_index++ ) { config_data = (ConfigTreeData *)GetItemData( item ); if( config_data && config_data->panel ) { - if( item == GetSelection() ) - { - config_data->panel->Hide(); - p_sizer->Remove( config_data->panel ); - } - delete config_data->panel; config_data->panel = NULL; - - if( item == GetSelection() ) - { - wxTreeEvent event; - event.SetItem(item); - - OnSelectTreeItem( event ); - } } - item = GetNextChild( root_item, cookie ); + item = GetNextChild( general_item, cookie ); } /* Clean changes for the plugins */ @@ -565,22 +654,50 @@ void PrefsTreeCtrl::CleanChanges() if( config_data && config_data->panel ) { - if( item2 == GetSelection() ) - { - config_data->panel->Hide(); - p_sizer->Remove( config_data->panel ); - } - delete config_data->panel; config_data->panel = NULL; + } - if( item2 == GetSelection() ) - { - wxTreeEvent event; - event.SetItem(item2); + item2 = GetNextChild( item, cookie2 ); + } - OnSelectTreeItem( event ); - } + item = GetNextChild( plugins_item, cookie ); + } + + if( GetSelection() ) + { + wxTreeEvent event; + OnSelectTreeItem( event ); + } +} + +ConfigTreeData *PrefsTreeCtrl::FindModuleConfig( ConfigTreeData *config_data ) +{ + /* We need this complexity because submodules don't have their own config + * options. They use the parent module ones. */ + + if( !config_data || !config_data->b_submodule ) + { + return config_data; + } + + long cookie, cookie2; + ConfigTreeData *config_new; + wxTreeItemId item = GetFirstChild( plugins_item, cookie ); + for( size_t i_child_index = 0; + i_child_index < GetChildrenCount( plugins_item, FALSE ); + i_child_index++ ) + { + wxTreeItemId item2 = GetFirstChild( item, cookie2 ); + for( size_t i_child_index = 0; + i_child_index < GetChildrenCount( item, FALSE ); + i_child_index++ ) + { + config_new = (ConfigTreeData *)GetItemData( item2 ); + if( config_new && !config_new->b_submodule && + config_new->i_object_id == config_data->i_object_id ) + { + return config_new; } item2 = GetNextChild( item, cookie2 ); @@ -588,20 +705,26 @@ void PrefsTreeCtrl::CleanChanges() item = GetNextChild( plugins_item, cookie ); } + + /* Found nothing */ + return NULL; } void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event ) { ConfigTreeData *config_data; - config_data = (ConfigTreeData *)GetItemData( event.GetOldItem() ); + config_data = FindModuleConfig( (ConfigTreeData *)GetItemData( + event.GetOldItem() ) ); if( config_data && config_data->panel ) { config_data->panel->Hide(); p_sizer->Remove( config_data->panel ); } - config_data = (ConfigTreeData *)GetItemData( event.GetItem() ); + /* Don't use event.GetItem() because we also send fake events */ + config_data = FindModuleConfig( (ConfigTreeData *)GetItemData( + GetSelection() ) ); if( config_data ) { if( !config_data->panel ) @@ -610,24 +733,46 @@ void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event ) config_data->panel = new PrefsPanel( p_parent, p_intf, p_prefs_dialog, config_data->i_object_id, - config_data->psz_section ); + config_data->psz_section, + config_data->psz_help ); + config_data->panel->SwitchAdvanced( b_advanced ); } else { + config_data->panel->SwitchAdvanced( b_advanced ); config_data->panel->Show(); } - p_sizer->Add( config_data->panel, 2, wxEXPAND | wxALL, 0 ); + p_sizer->Add( config_data->panel, 3, wxEXPAND | wxALL, 0 ); p_sizer->Layout(); } } +void PrefsTreeCtrl::OnAdvanced( wxCommandEvent& event ) +{ + b_advanced = event.GetInt(); + + ConfigTreeData *config_data = !GetSelection() ? NULL : + FindModuleConfig( (ConfigTreeData *)GetItemData( GetSelection() ) ); + if( config_data ) + { + config_data->panel->Hide(); + p_sizer->Remove( config_data->panel ); + } + + if( GetSelection() ) + { + wxTreeEvent event; + OnSelectTreeItem( event ); + } +} + /***************************************************************************** * PrefsPanel class definition. *****************************************************************************/ PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf, PrefsDialog *_p_prefs_dialog, - int i_object_id, char *psz_section ) + int i_object_id, char *psz_section, char *psz_help ) : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize ) { module_config_t *p_item; @@ -635,6 +780,7 @@ PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf, module_t *p_parser; wxStaticText *label; + wxStaticText *help; wxComboBox *combo; wxSpinCtrl *spin; wxCheckBox *checkbox; @@ -642,6 +788,9 @@ PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf, wxButton *button; wxArrayString array; + vlc_bool_t b_has_advanced = VLC_FALSE; + module_t *p_module = NULL; + /* Initializations */ p_intf = _p_intf; p_prefs_dialog =_p_prefs_dialog, @@ -651,224 +800,291 @@ PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf, wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL ); - /* Get a pointer to the module */ - module_t *p_module = (module_t *)vlc_object_get( p_intf, i_object_id ); - if( p_module->i_object_type != VLC_OBJECT_MODULE ) + + if( i_object_id == PLUGIN_ID || i_object_id == GENERAL_ID || + i_object_id == CAPABILITY_ID ) { - /* 0OOoo something went really bad */ - return; + label = new wxStaticText( this, -1,wxU(_( psz_section ))); + wxFont heading_font = label->GetFont(); + heading_font.SetPointSize( heading_font.GetPointSize() + 5 ); + label->SetFont( heading_font ); + sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 ); + sizer->Add( new wxStaticLine( this, 0 ), 0, + wxEXPAND | wxLEFT | wxRIGHT, 2 ); + + help = new wxStaticText( this, -1, wxU(_( psz_help ) ) ); + sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 ); + + config_sizer = NULL; config_window = NULL; } - - /* Enumerate config options and add corresponding config boxes */ - p_item = p_module->p_config; - - /* Find the category if it has been specified */ - if( psz_section && p_item->i_type == CONFIG_HINT_CATEGORY ) + else { - while( !p_item->i_type == CONFIG_HINT_CATEGORY || - strcmp( psz_section, p_item->psz_text ) ) + /* Get a pointer to the module */ + p_module = (module_t *)vlc_object_get( p_intf, i_object_id ); + if( p_module->i_object_type != VLC_OBJECT_MODULE ) { - if( p_item->i_type == CONFIG_HINT_END ) - break; - p_item++; + /* 0OOoo something went really bad */ + return; } - } - - /* Add a head title to the panel */ - wxStaticBox *static_box = new wxStaticBox( this, -1, wxT("") ); - wxStaticBoxSizer *box_sizer = new wxStaticBoxSizer( static_box, - wxHORIZONTAL ); - label = new wxStaticText( this, -1, - wxU(psz_section ? p_item->psz_text : - p_module->psz_longname) ); - box_sizer->Add( label, 1, wxALL, 5 ); - sizer->Add( box_sizer, 0, wxEXPAND | wxALL, 5 ); - - /* Now put all the config options into a scrolled window */ - config_sizer = new wxBoxSizer( wxVERTICAL ); - config_window = new wxScrolledWindow( this, -1, wxDefaultPosition, - wxDefaultSize ); - config_window->SetAutoLayout( TRUE ); - config_window->SetScrollRate( 5, 5 ); - - if( p_item ) do - { - /* If a category has been specified, check we finished the job */ - if( psz_section && p_item->i_type == CONFIG_HINT_CATEGORY && - strcmp( psz_section, p_item->psz_text ) ) - break; - - /* put each config option in a separate panel so we can hide advanced - * options easily */ - wxPanel *panel = new wxPanel( config_window, -1, wxDefaultPosition, - wxDefaultSize ); - wxBoxSizer *panel_sizer = new wxBoxSizer( wxHORIZONTAL ); - ConfigData *config_data = - new ConfigData( panel, p_item->i_type, - p_item->b_advanced, p_item->psz_name ); + /* Enumerate config options and add corresponding config boxes + * (submodules don't have config options, they are stored in the + * parent module) */ + if( p_module->b_submodule ) + p_item = ((module_t *)p_module->p_parent)->p_config; + else + p_item = p_module->p_config; - switch( p_item->i_type ) + /* Find the category if it has been specified */ + if( psz_section && p_item->i_type == CONFIG_HINT_CATEGORY ) { - case CONFIG_ITEM_MODULE: - label = new wxStaticText(panel, -1, wxU(p_item->psz_text)); - combo = new wxComboBox( panel, -1, wxU(p_item->psz_value), - wxDefaultPosition, wxDefaultSize, - 0, NULL, wxCB_READONLY | wxCB_SORT ); - - /* build a list of available modules */ - p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE ); - combo->Append( wxU(_("Default")), (void *)NULL ); - combo->SetSelection( 0 ); - for( int i_index = 0; i_index < p_list->i_count; i_index++ ) + while( !p_item->i_type == CONFIG_HINT_CATEGORY || + strcmp( psz_section, p_item->psz_text ) ) { - p_parser = (module_t *)p_list->p_values[i_index].p_object ; - - 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) ); - } + if( p_item->i_type == CONFIG_HINT_END ) + break; + p_item++; } + } - combo->SetToolTip( wxU(p_item->psz_longtext) ); - config_data->control.combobox = combo; - panel_sizer->Add( label, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); - panel_sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); - break; + /* Add a head title to the panel */ + label = new wxStaticText( this, -1, + wxU(_(psz_section ? p_item->psz_text : + p_module->psz_longname ))); + wxFont heading_font = label->GetFont(); + heading_font.SetPointSize( heading_font.GetPointSize() + 5 ); + label->SetFont( heading_font ); + sizer->Add( label, 0, wxEXPAND | wxLEFT, 10 ); + sizer->Add( new wxStaticLine( this, 0 ), 0, + wxEXPAND | wxLEFT | wxRIGHT, 2 ); + + /* Now put all the config options into a scrolled window */ + config_sizer = new wxBoxSizer( wxVERTICAL ); + config_window = new wxScrolledWindow( this, -1, wxDefaultPosition, + wxDefaultSize, wxSTATIC_BORDER | wxHSCROLL | wxVSCROLL ); + config_window->SetAutoLayout( TRUE ); + config_window->SetScrollRate( 5, 5 ); - case CONFIG_ITEM_STRING: - case CONFIG_ITEM_FILE: - case CONFIG_ITEM_DIRECTORY: - label = new wxStaticText(panel, -1, wxU(p_item->psz_text)); - panel_sizer->Add( label, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); + if( p_item ) do + { + /* If a category has been specified, check we finished the job */ + if( psz_section && p_item->i_type == CONFIG_HINT_CATEGORY && + strcmp( psz_section, p_item->psz_text ) ) + break; - if( !p_item->ppsz_list ) - { - textctrl = new wxTextCtrl( panel, -1, wxU(p_item->psz_value), - wxDefaultPosition, wxDefaultSize, - wxTE_PROCESS_ENTER); - textctrl->SetToolTip( wxU(p_item->psz_longtext) ); - config_data->control.textctrl = textctrl; - panel_sizer->Add( textctrl, 1, wxALL, 5 ); - } - else + /* put each config option in a separate panel so we can hide + * advanced options easily */ + wxPanel *panel = new wxPanel( config_window, -1, wxDefaultPosition, + wxDefaultSize ); + wxBoxSizer *panel_sizer = new wxBoxSizer( wxHORIZONTAL ); + ConfigData *config_data = + new ConfigData( panel, p_item->i_type, + p_item->b_advanced, p_item->psz_name ); + + switch( p_item->i_type ) { + case CONFIG_ITEM_MODULE: + label = new wxStaticText(panel, -1, wxU(p_item->psz_text)); combo = new wxComboBox( panel, -1, wxU(p_item->psz_value), wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY | wxCB_SORT ); - /* build a list of available options */ - for( int i_index = 0; p_item->ppsz_list[i_index]; i_index++ ) + /* build a list of available modules */ + p_list = vlc_list_find( p_intf, + VLC_OBJECT_MODULE, FIND_ANYWHERE ); + combo->Append( wxU(_("Default")), (void *)NULL ); + combo->SetSelection( 0 ); + for( int i_index = 0; i_index < p_list->i_count; i_index++ ) { - combo->Append( wxU(p_item->ppsz_list[i_index]) ); + p_parser = (module_t *)p_list->p_values[i_index].p_object ; + + 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 ); - if( p_item->psz_value ) - combo->SetValue( wxU(p_item->psz_value) ); combo->SetToolTip( wxU(p_item->psz_longtext) ); config_data->control.combobox = combo; - config_data->b_config_list = VLC_TRUE; - panel_sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - } + panel_sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL + | wxALL, 5 ); + panel_sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL + | wxALL, 5 ); + break; - if( p_item->i_type == CONFIG_ITEM_FILE ) - { - button = new wxButton( panel, -1, wxU(_("Browse...")) ); - panel_sizer->Add( button, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); - button->SetClientData((void *)config_data); - } - break; + case CONFIG_ITEM_STRING: + case CONFIG_ITEM_FILE: + case CONFIG_ITEM_DIRECTORY: + label = new wxStaticText(panel, -1, wxU(p_item->psz_text)); + panel_sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL + | wxALL, 5 ); - case CONFIG_ITEM_INTEGER: - label = new wxStaticText(panel, -1, wxU(p_item->psz_text)); - spin = new wxSpinCtrl( panel, -1, - wxString::Format(wxT("%d"),p_item->i_value), - wxDefaultPosition, wxDefaultSize, - wxSP_ARROW_KEYS, - 0, 16000, p_item->i_value); - spin->SetToolTip( wxU(p_item->psz_longtext) ); - config_data->control.spinctrl = spin; - panel_sizer->Add( label, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); - panel_sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); - - spin->SetClientData((void *)config_data); - break; + if( !p_item->ppsz_list ) + { + textctrl = new wxTextCtrl( panel, -1, + wxU(p_item->psz_value), + wxDefaultPosition, + wxDefaultSize, + wxTE_PROCESS_ENTER); + textctrl->SetToolTip( wxU(p_item->psz_longtext) ); + config_data->control.textctrl = textctrl; + panel_sizer->Add( textctrl, 1, wxALL, 5 ); + } + else + { + combo = new wxComboBox( panel, -1, wxU(p_item->psz_value), + wxDefaultPosition, wxDefaultSize, + 0, NULL, wxCB_READONLY|wxCB_SORT ); + + /* 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 ); + } + + if( p_item->psz_value ) + combo->SetValue( wxU(p_item->psz_value) ); + combo->SetToolTip( wxU(p_item->psz_longtext) ); + config_data->control.combobox = combo; + config_data->b_config_list = VLC_TRUE; + panel_sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL + |wxALL, 5 ); + } - case CONFIG_ITEM_FLOAT: - label = new wxStaticText(panel, -1, wxU(p_item->psz_text)); - spin = new wxSpinCtrl( panel, -1, - wxString::Format(wxT("%f"),p_item->f_value), - wxDefaultPosition, wxDefaultSize, - wxSP_ARROW_KEYS, - 0, 16000, (int)p_item->f_value); - spin->SetToolTip( wxU(p_item->psz_longtext) ); - config_data->control.spinctrl = spin; - panel_sizer->Add( label, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); - panel_sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); - break; + if( p_item->i_type == CONFIG_ITEM_FILE ) + { + button = new wxButton( panel, -1, wxU(_("Browse...")) ); + panel_sizer->Add( button, 0, wxALIGN_CENTER_VERTICAL + |wxALL, 5); + button->SetClientData((void *)config_data); + } + if( p_item->b_advanced ) b_has_advanced = VLC_TRUE; + break; - case CONFIG_ITEM_BOOL: - checkbox = new wxCheckBox( panel, -1, wxU(p_item->psz_text) ); - if( p_item->i_value ) checkbox->SetValue(TRUE); - checkbox->SetToolTip( wxU(p_item->psz_longtext) ); - config_data->control.checkbox = checkbox; - panel_sizer->Add( checkbox, 0, wxALL, 5 ); - break; + case CONFIG_ITEM_INTEGER: + label = new wxStaticText(panel, -1, wxU(p_item->psz_text)); + spin = new wxSpinCtrl( panel, -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) ); + config_data->control.spinctrl = spin; + panel_sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL + | wxALL, 5 ); + panel_sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL + | wxALL, 5 ); + + spin->SetClientData((void *)config_data); + if( p_item->b_advanced ) b_has_advanced = VLC_TRUE; + break; - default: - delete panel; panel = NULL; - delete panel_sizer; - delete config_data; - break; - } + case CONFIG_ITEM_KEY: + { + label = new wxStaticText(panel, -1, wxU(p_item->psz_text)); + wxCheckBox *alt = new wxCheckBox( panel, -1, wxU(_("Alt")) ); + alt->SetValue( p_item->i_value & KEY_MODIFIER_ALT ); + wxCheckBox *ctrl = new wxCheckBox( panel, -1, wxU(_("Ctrl")) ); + ctrl->SetValue( p_item->i_value & KEY_MODIFIER_CTRL ); + wxCheckBox *shift = new wxCheckBox( panel, -1, + wxU(_("Shift")) ); + shift->SetValue( p_item->i_value & KEY_MODIFIER_SHIFT ); + combo = new wxComboBox( panel, -1, wxU("f"), + wxDefaultPosition, wxDefaultSize, 0 + , NULL, wxCB_READONLY | wxCB_SORT ); + for( int i=0; i < sizeof(keys)/sizeof(key_descriptor_s); i++ ) + { + combo->Append( wxU(_(keys[i].psz_key_string)), + (void*)&keys[i].i_key_code ); + } + combo->SetValue( wxU( KeyToString( + p_item->i_value&~KEY_MODIFIER ))); + config_data->control.combobox = combo; + panel_sizer->Add( label, 2, wxALIGN_CENTER_VERTICAL + | wxALL | wxEXPAND, 5 ); + panel_sizer->Add( alt, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 ); + panel_sizer->Add( ctrl, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5); + panel_sizer->Add( shift, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5); + panel_sizer->Add( combo, 2, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5); + break; + } - /* Don't add items that were not recognized */ - if( panel == NULL ) continue; + case CONFIG_ITEM_FLOAT: + label = new wxStaticText(panel, -1, wxU(p_item->psz_text)); + textctrl = new wxTextCtrl( panel, -1, + wxString::Format(wxT("%f"), + p_item->f_value), + wxDefaultPosition, wxDefaultSize, + wxTE_PROCESS_ENTER ); + textctrl->SetToolTip( wxU(p_item->psz_longtext) ); + config_data->control.textctrl = textctrl; + panel_sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL + | wxALL, 5 ); + panel_sizer->Add( textctrl, 0, wxALIGN_CENTER_VERTICAL + | wxALL, 5); + if( p_item->b_advanced ) b_has_advanced = VLC_TRUE; + break; - panel_sizer->Layout(); - panel->SetSizerAndFit( panel_sizer ); + case CONFIG_ITEM_BOOL: + checkbox = new wxCheckBox( panel, -1, wxU(p_item->psz_text) ); + if( p_item->i_value ) checkbox->SetValue(TRUE); + checkbox->SetToolTip( wxU(p_item->psz_longtext) ); + config_data->control.checkbox = checkbox; + panel_sizer->Add( checkbox, 0, wxALL, 5 ); + if( p_item->b_advanced ) b_has_advanced = VLC_TRUE; + break; - /* Add the config data to our array so we can keep a trace of it */ - config_array.Add( config_data ); + default: + delete panel; panel = NULL; + delete panel_sizer; + delete config_data; + break; + } - config_sizer->Add( panel, 0, wxEXPAND | wxALL, 2 ); - } - while( p_item->i_type != CONFIG_HINT_END && p_item++ ); + /* Don't add items that were not recognized */ + if( panel == NULL ) continue; - /* Display a nice message if no configuration options are available */ - if( !config_array.GetCount() ) - { - config_sizer->Add( new wxStaticText( config_window, -1, - wxU(_("No configuration options available")) ), 1, - wxALIGN_CENTER_VERTICAL | wxALIGN_CENTER, 2 ); - } + panel_sizer->Layout(); + panel->SetSizerAndFit( panel_sizer ); - config_sizer->Layout(); - config_window->SetSizer( config_sizer ); - sizer->Add( config_window, 1, wxEXPAND | wxALL, 5 ); + /* Add the config data to our array so we can keep a trace of it */ + config_array.Add( config_data ); - /* Intercept all menu events in our custom event handler */ - config_window->PushEventHandler( - new ConfigEvtHandler( p_intf, p_prefs_dialog ) ); + config_sizer->Add( panel, 0, wxEXPAND | wxALL, 2 ); + } + while( p_item->i_type != CONFIG_HINT_END && p_item++ ); - /* Update panel */ - wxCommandEvent dummy_event; - b_advanced = !config_GetInt( p_intf, "advanced" ); - OnAdvanced( dummy_event ); + config_sizer->Layout(); + config_window->SetSizer( config_sizer ); + sizer->Add( config_window, 1, wxEXPAND | wxALL, 5 ); - /* Create advanced button */ - if( config_array.GetCount() ) - { - wxButton *advanced_button = new wxButton( this, Advanced_Event, - wxU(_("Advanced...")) ); - sizer->Add( advanced_button, 0, wxALL, 5 ); - } + /* And at last put a useful help string if available */ + if( psz_help && *psz_help ) + { + sizer->Add( new wxStaticLine( this, 0 ), 0, + wxEXPAND | wxLEFT | wxRIGHT, 2 ); + help = new wxStaticText( this, -1, wxU(_(psz_help)), + wxDefaultPosition, wxDefaultSize, + wxALIGN_LEFT, + wxT("") ); + sizer->Add( help ,0 ,wxEXPAND | wxALL, 5 ); + } + + /* Intercept all menu events in our custom event handler */ + config_window->PushEventHandler( + new ConfigEvtHandler( p_intf, p_prefs_dialog ) ); + } sizer->Layout(); SetSizer( sizer ); } @@ -905,29 +1121,41 @@ void PrefsPanel::ApplyChanges() config_data->control.spinctrl->GetValue() ); break; case CONFIG_ITEM_FLOAT: - config_PutFloat( p_intf, config_data->option_name.mb_str(), - config_data->control.spinctrl->GetValue() ); + { + float f_value; + if( (wxSscanf(config_data->control.textctrl->GetValue(), + wxT("%f"), &f_value) == 1) ) + config_PutFloat( p_intf, config_data->option_name.mb_str(), + f_value ); + } break; } } } -void PrefsPanel::OnAdvanced( wxCommandEvent& WXUNUSED(event) ) +void PrefsPanel::SwitchAdvanced( vlc_bool_t b_new_advanced ) { - b_advanced = !b_advanced; + if( b_advanced == b_new_advanced ) return; - for( size_t i = 0; i < config_array.GetCount(); i++ ) + if( config_sizer && config_window ) { - ConfigData *config_data = config_array.Item(i); - if( config_data->b_advanced ) + b_advanced = b_new_advanced; + + for( size_t i = 0; i < config_array.GetCount(); i++ ) { - config_data->panel->Show( b_advanced ); - config_sizer->Show( config_data->panel, b_advanced ); + ConfigData *config_data = config_array.Item(i); + if( config_data->b_advanced ) + { + config_data->panel->Show( b_advanced ); + config_sizer->Show( config_data->panel, b_advanced ); + } } - } - config_sizer->Layout(); - config_window->FitInside(); + config_sizer->Layout(); + config_window->FitInside(); + config_window->Refresh(); + } + return; } /***************************************************************************** @@ -965,7 +1193,12 @@ void ConfigEvtHandler::OnCommandEvent( wxCommandEvent& event ) if( config_data->i_config_type == CONFIG_ITEM_FILE ) { wxFileDialog dialog( p_prefs_dialog, wxU(_("Open file")), - wxT(""), wxT(""), wxT("*.*"), wxOPEN | wxSAVE ); + wxT(""), wxT(""), wxT("*.*"), +#if defined( __WXMSW__ ) + wxOPEN ); +#else + wxOPEN | wxSAVE ); +#endif if( dialog.ShowModal() == wxID_OK ) {