Commit 86e2b37d authored by Gildas Bazin's avatar Gildas Bazin

* modules/gui/wxwindows/preferences.cpp: the config panels are now generated on demand instead of generating everything at the beginning. ResetAll now also takes care of resetting the values shown in the config panels.
* modules/gui/wxwindows/open.cpp: small cosmetic changes.
parent a476938b
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* open.cpp : wxWindows plugin for vlc * open.cpp : wxWindows plugin for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2000-2001 VideoLAN * Copyright (C) 2000-2001 VideoLAN
* $Id: open.cpp,v 1.19 2003/05/12 17:33:19 gbazin Exp $ * $Id: open.cpp,v 1.20 2003/05/12 21:55:01 gbazin Exp $
* *
* Authors: Gildas Bazin <gbazin@netcourrier.com> * Authors: Gildas Bazin <gbazin@netcourrier.com>
* *
...@@ -165,7 +165,7 @@ OpenDialog::OpenDialog( intf_thread_t *_p_intf, wxWindow *_p_parent, ...@@ -165,7 +165,7 @@ OpenDialog::OpenDialog( intf_thread_t *_p_intf, wxWindow *_p_parent,
0, NULL ); 0, NULL );
mrl_combo->SetToolTip( wxU(_("You can use this field directly by typing " mrl_combo->SetToolTip( wxU(_("You can use this field directly by typing "
"the full MRL you want to open.\n""Alternatively, the field will be " "the full MRL you want to open.\n""Alternatively, the field will be "
"filled automatically when you use the controls below")) ); "filled automatically when you use the controls below.")) );
mrl_sizer->Add( mrl_label, 0, wxALL | wxALIGN_CENTER, 5 ); mrl_sizer->Add( mrl_label, 0, wxALL | wxALIGN_CENTER, 5 );
mrl_sizer->Add( mrl_combo, 1, wxALL | wxALIGN_CENTER, 5 ); mrl_sizer->Add( mrl_combo, 1, wxALL | wxALIGN_CENTER, 5 );
...@@ -433,9 +433,10 @@ wxPanel *OpenDialog::NetPanel( wxWindow* parent ) ...@@ -433,9 +433,10 @@ wxPanel *OpenDialog::NetPanel( wxWindow* parent )
/* Stuff everything into the main panel */ /* Stuff everything into the main panel */
for( i=0; i<3; i++ ) for( i=0; i<3; i++ )
{ {
sizer->Add( net_radios[i], 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL ); sizer->Add( net_radios[i], 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
sizer->Add( net_subpanels[i], 1, wxALL, 5 );
wxEXPAND | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL ); sizer->Add( net_subpanels[i], 1, wxEXPAND | wxALIGN_LEFT |
wxALIGN_CENTER_VERTICAL | wxALL, 5 );
} }
sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 ); sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* preferences.cpp : wxWindows plugin for vlc * preferences.cpp : wxWindows plugin for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2000-2001 VideoLAN * Copyright (C) 2000-2001 VideoLAN
* $Id: preferences.cpp,v 1.13 2003/05/12 17:33:19 gbazin Exp $ * $Id: preferences.cpp,v 1.14 2003/05/12 21:55:01 gbazin Exp $
* *
* Authors: Gildas Bazin <gbazin@netcourrier.com> * Authors: Gildas Bazin <gbazin@netcourrier.com>
* *
...@@ -76,6 +76,7 @@ public: ...@@ -76,6 +76,7 @@ public:
virtual ~PrefsTreeCtrl(); virtual ~PrefsTreeCtrl();
void ApplyChanges(); void ApplyChanges();
void CleanChanges();
private: private:
/* Event handlers (these functions should _not_ be virtual) */ /* Event handlers (these functions should _not_ be virtual) */
...@@ -125,8 +126,7 @@ public: ...@@ -125,8 +126,7 @@ public:
PrefsPanel() { } PrefsPanel() { }
PrefsPanel( wxWindow *parent, intf_thread_t *_p_intf, PrefsPanel( wxWindow *parent, intf_thread_t *_p_intf,
PrefsDialog *_p_prefs_dialog, PrefsDialog *_p_prefs_dialog, int i_object_id, char * );
module_t *p_module, char * );
virtual ~PrefsPanel() {} virtual ~PrefsPanel() {}
void ApplyChanges(); void ApplyChanges();
...@@ -150,11 +150,13 @@ class ConfigTreeData : public wxTreeItemData ...@@ -150,11 +150,13 @@ class ConfigTreeData : public wxTreeItemData
{ {
public: public:
ConfigTreeData() { panel == NULL; } ConfigTreeData() { panel = NULL; psz_section = NULL; }
virtual ~ConfigTreeData() { if( panel ) delete panel; } virtual ~ConfigTreeData() { if( panel ) delete panel; }
PrefsPanel *panel; PrefsPanel *panel;
wxBoxSizer *sizer; wxBoxSizer *sizer;
int i_object_id;
char *psz_section;
}; };
class ConfigEvtHandler : public wxEvtHandler class ConfigEvtHandler : public wxEvtHandler
...@@ -289,19 +291,19 @@ PrefsDialog::~PrefsDialog() ...@@ -289,19 +291,19 @@ PrefsDialog::~PrefsDialog()
void PrefsDialog::OnOk( wxCommandEvent& WXUNUSED(event) ) void PrefsDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
{ {
prefs_tree->ApplyChanges(); prefs_tree->ApplyChanges();
this->Hide(); this->Hide();
prefs_tree->CleanChanges();
} }
void PrefsDialog::OnCancel( wxCommandEvent& WXUNUSED(event) ) void PrefsDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
{ {
this->Hide(); this->Hide();
prefs_tree->CleanChanges();
} }
void PrefsDialog::OnSave( wxCommandEvent& WXUNUSED(event) ) void PrefsDialog::OnSave( wxCommandEvent& WXUNUSED(event) )
{ {
prefs_tree->ApplyChanges(); prefs_tree->ApplyChanges();
config_SaveConfigFile( p_intf, NULL ); config_SaveConfigFile( p_intf, NULL );
} }
...@@ -316,6 +318,7 @@ void PrefsDialog::OnResetAll( wxCommandEvent& WXUNUSED(event) ) ...@@ -316,6 +318,7 @@ void PrefsDialog::OnResetAll( wxCommandEvent& WXUNUSED(event) )
{ {
/* TODO: need to reset all the controls */ /* TODO: need to reset all the controls */
config_ResetAll( p_intf ); config_ResetAll( p_intf );
prefs_tree->CleanChanges();
config_SaveConfigFile( p_intf, NULL ); config_SaveConfigFile( p_intf, NULL );
} }
} }
...@@ -361,7 +364,8 @@ PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf, ...@@ -361,7 +364,8 @@ PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf,
{ {
/* We found the main module */ /* We found the main module */
/* Enumerate config options and add corresponding config boxes */ /* Enumerate config categories and store a reference so we can
* generate their config panel them when it is asked by the user. */
p_item = p_module->p_config; p_item = p_module->p_config;
if( p_item ) do if( p_item ) do
...@@ -370,10 +374,8 @@ PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf, ...@@ -370,10 +374,8 @@ PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf,
{ {
case CONFIG_HINT_CATEGORY: case CONFIG_HINT_CATEGORY:
ConfigTreeData *config_data = new ConfigTreeData; ConfigTreeData *config_data = new ConfigTreeData;
config_data->panel = config_data->psz_section = strdup(p_item->psz_text);
new PrefsPanel( p_parent, p_intf, p_prefs_dialog, config_data->i_object_id = p_module->i_object_id;
p_module, p_item->psz_text );
config_data->panel->Hide();
/* Add the category to the tree */ /* Add the category to the tree */
AppendItem( root_item, wxU(p_item->psz_text), AppendItem( root_item, wxU(p_item->psz_text),
...@@ -436,9 +438,7 @@ PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf, ...@@ -436,9 +438,7 @@ PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf,
/* Add the plugin to the tree */ /* Add the plugin to the tree */
ConfigTreeData *config_data = new ConfigTreeData; ConfigTreeData *config_data = new ConfigTreeData;
config_data->panel = config_data->i_object_id = p_module->i_object_id;
new PrefsPanel( p_parent, p_intf, p_prefs_dialog, p_module, NULL );
config_data->panel->Hide();
AppendItem( capability_item, wxU(p_module->psz_object_name), -1, -1, AppendItem( capability_item, wxU(p_module->psz_object_name), -1, -1,
config_data ); config_data );
} }
...@@ -483,7 +483,7 @@ void PrefsTreeCtrl::ApplyChanges() ...@@ -483,7 +483,7 @@ void PrefsTreeCtrl::ApplyChanges()
i_child_index++ ) i_child_index++ )
{ {
config_data = (ConfigTreeData *)GetItemData( item ); config_data = (ConfigTreeData *)GetItemData( item );
if( config_data ) if( config_data && config_data->panel )
{ {
config_data->panel->ApplyChanges(); config_data->panel->ApplyChanges();
} }
...@@ -503,7 +503,7 @@ void PrefsTreeCtrl::ApplyChanges() ...@@ -503,7 +503,7 @@ void PrefsTreeCtrl::ApplyChanges()
i_child_index++ ) i_child_index++ )
{ {
config_data = (ConfigTreeData *)GetItemData( item2 ); config_data = (ConfigTreeData *)GetItemData( item2 );
if( config_data ) if( config_data && config_data->panel )
{ {
config_data->panel->ApplyChanges(); config_data->panel->ApplyChanges();
} }
...@@ -515,6 +515,81 @@ void PrefsTreeCtrl::ApplyChanges() ...@@ -515,6 +515,81 @@ void PrefsTreeCtrl::ApplyChanges()
} }
} }
void PrefsTreeCtrl::CleanChanges()
{
long cookie, cookie2;
ConfigTreeData *config_data;
/* Clean changes for the main module */
wxTreeItemId item = GetFirstChild( root_item, cookie );
for( size_t i_child_index = 0;
i_child_index < GetChildrenCount( root_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 );
}
/* Clean changes for the plugins */
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_data = (ConfigTreeData *)GetItemData( item2 );
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);
OnSelectTreeItem( event );
}
}
item2 = GetNextChild( item, cookie2 );
}
item = GetNextChild( plugins_item, cookie );
}
}
void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event ) void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event )
{ {
ConfigTreeData *config_data; ConfigTreeData *config_data;
...@@ -527,9 +602,21 @@ void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event ) ...@@ -527,9 +602,21 @@ void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event )
} }
config_data = (ConfigTreeData *)GetItemData( event.GetItem() ); config_data = (ConfigTreeData *)GetItemData( event.GetItem() );
if( config_data && config_data->panel ) if( config_data )
{ {
config_data->panel->Show(); if( !config_data->panel )
{
/* The panel hasn't been created yet. Let's do it. */
config_data->panel =
new PrefsPanel( p_parent, p_intf, p_prefs_dialog,
config_data->i_object_id,
config_data->psz_section );
}
else
{
config_data->panel->Show();
}
p_sizer->Add( config_data->panel, 2, wxEXPAND | wxALL, 0 ); p_sizer->Add( config_data->panel, 2, wxEXPAND | wxALL, 0 );
p_sizer->Layout(); p_sizer->Layout();
} }
...@@ -540,7 +627,7 @@ void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event ) ...@@ -540,7 +627,7 @@ void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event )
*****************************************************************************/ *****************************************************************************/
PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf, PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
PrefsDialog *_p_prefs_dialog, PrefsDialog *_p_prefs_dialog,
module_t *p_module, char *psz_section ) int i_object_id, char *psz_section )
: wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize ) : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize )
{ {
module_config_t *p_item; module_config_t *p_item;
...@@ -564,6 +651,14 @@ PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf, ...@@ -564,6 +651,14 @@ PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL ); 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 )
{
/* 0OOoo something went really bad */
return;
}
/* Enumerate config options and add corresponding config boxes */ /* Enumerate config options and add corresponding config boxes */
p_item = p_module->p_config; p_item = p_module->p_config;
...@@ -673,7 +768,7 @@ PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf, ...@@ -673,7 +768,7 @@ PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
combo->Append( wxU(p_item->ppsz_list[i_index]) ); combo->Append( wxU(p_item->ppsz_list[i_index]) );
} }
if( p_item->psz_value ) if( p_item->psz_value )
combo->SetValue( wxU(p_item->psz_value) ); combo->SetValue( wxU(p_item->psz_value) );
combo->SetToolTip( wxU(p_item->psz_longtext) ); combo->SetToolTip( wxU(p_item->psz_longtext) );
config_data->control.combobox = combo; config_data->control.combobox = combo;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment