]> git.sesse.net Git - vlc/blobdiff - modules/gui/wxwindows/preferences.cpp
* modules/gui/wxwindows/preferences.cpp: fixed the preferences to also show the confi...
[vlc] / modules / gui / wxwindows / preferences.cpp
index 82240ac28dec85ea60536931f7a663d1c4cf0e43..66cabba037b925d42680f1af031f13695378d577 100644 (file)
@@ -2,7 +2,7 @@
  * preferences.cpp : wxWindows plugin for vlc
  *****************************************************************************
  * Copyright (C) 2000-2001 VideoLAN
- * $Id: preferences.cpp,v 1.13 2003/05/12 17:33:19 gbazin Exp $
+ * $Id: preferences.cpp,v 1.20 2003/06/16 21:55:58 gbazin Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
@@ -76,6 +76,7 @@ public:
     virtual ~PrefsTreeCtrl();
 
     void ApplyChanges();
+    void CleanChanges();
 
 private:
     /* Event handlers (these functions should _not_ be virtual) */
@@ -125,8 +126,7 @@ public:
 
     PrefsPanel() { }
     PrefsPanel( wxWindow *parent, intf_thread_t *_p_intf,
-                PrefsDialog *_p_prefs_dialog,
-                module_t *p_module, char * );
+                PrefsDialog *_p_prefs_dialog, int i_object_id, char * );
     virtual ~PrefsPanel() {}
 
     void ApplyChanges();
@@ -150,11 +150,13 @@ class ConfigTreeData : public wxTreeItemData
 {
 public:
 
-    ConfigTreeData() { panel == NULL; }
+    ConfigTreeData() { panel = NULL; psz_section = NULL; }
     virtual ~ConfigTreeData() { if( panel ) delete panel; }
 
     PrefsPanel *panel;
     wxBoxSizer *sizer;
+    int i_object_id;
+    char *psz_section;
 };
 
 class ConfigEvtHandler : public wxEvtHandler
@@ -209,7 +211,7 @@ END_EVENT_TABLE()
 
 BEGIN_EVENT_TABLE(PrefsPanel, wxPanel)
     /* Button events */
-    EVT_BUTTON(Advanced_Event, PrefsPanel::OnAdvanced)
+    EVT_CHECKBOX(Advanced_Event, PrefsPanel::OnAdvanced)
 
 END_EVENT_TABLE()
 
@@ -223,13 +225,12 @@ END_EVENT_TABLE()
 /*****************************************************************************
  * Constructor.
  *****************************************************************************/
-PrefsDialog::PrefsDialog( intf_thread_t *_p_intf, Interface *_p_main_interface)
-  :  wxFrame( _p_main_interface, -1, wxU(_("Preferences")), wxDefaultPosition,
+PrefsDialog::PrefsDialog( intf_thread_t *_p_intf, wxWindow *p_parent)
+  :  wxFrame( p_parent, -1, wxU(_("Preferences")), wxDefaultPosition,
               wxSize(650,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 */
@@ -289,19 +290,19 @@ PrefsDialog::~PrefsDialog()
 void PrefsDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
 {
     prefs_tree->ApplyChanges();
-
     this->Hide();
+    prefs_tree->CleanChanges();
 }
 
 void PrefsDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
 {
     this->Hide();
+    prefs_tree->CleanChanges();
 }
 
 void PrefsDialog::OnSave( wxCommandEvent& WXUNUSED(event) )
 {
     prefs_tree->ApplyChanges();
-
     config_SaveConfigFile( p_intf, NULL );
 }
 
@@ -316,6 +317,7 @@ void PrefsDialog::OnResetAll( wxCommandEvent& WXUNUSED(event) )
     {
         /* TODO: need to reset all the controls */
         config_ResetAll( p_intf );
+        prefs_tree->CleanChanges();
         config_SaveConfigFile( p_intf, NULL );
     }
 }
@@ -361,7 +363,8 @@ PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf,
     {
         /* 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;
 
         if( p_item ) do
@@ -370,10 +373,8 @@ PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf,
             {
             case CONFIG_HINT_CATEGORY:
                 ConfigTreeData *config_data = new ConfigTreeData;
-                config_data->panel =
-                    new PrefsPanel( p_parent, p_intf, p_prefs_dialog,
-                                    p_module, p_item->psz_text );
-                config_data->panel->Hide();
+                config_data->psz_section = strdup(p_item->psz_text);
+                config_data->i_object_id = p_module->i_object_id;
 
                 /* Add the category to the tree */
                 AppendItem( root_item, wxU(p_item->psz_text),
@@ -400,8 +401,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
         {
@@ -436,9 +442,7 @@ PrefsTreeCtrl::PrefsTreeCtrl( wxWindow *_p_parent, intf_thread_t *_p_intf,
 
         /* Add the plugin to the tree */
         ConfigTreeData *config_data = new ConfigTreeData;
-        config_data->panel =
-            new PrefsPanel( p_parent, p_intf, p_prefs_dialog, p_module, NULL );
-        config_data->panel->Hide();
+        config_data->i_object_id = p_module->i_object_id;
         AppendItem( capability_item, wxU(p_module->psz_object_name), -1, -1,
                     config_data );
     }
@@ -483,7 +487,7 @@ void PrefsTreeCtrl::ApplyChanges()
          i_child_index++ )
     {
         config_data = (ConfigTreeData *)GetItemData( item );
-        if( config_data )
+        if( config_data && config_data->panel )
         {
             config_data->panel->ApplyChanges();
         }
@@ -503,7 +507,7 @@ void PrefsTreeCtrl::ApplyChanges()
              i_child_index++ )
         {
             config_data = (ConfigTreeData *)GetItemData( item2 );
-            if( config_data )
+            if( config_data && config_data->panel )
             {
                 config_data->panel->ApplyChanges();
             }
@@ -515,6 +519,77 @@ 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;
+                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;
+                    OnSelectTreeItem( event );
+                }
+            }
+
+            item2 = GetNextChild( item, cookie2 );
+        }
+
+        item = GetNextChild( plugins_item, cookie );
+    }
+}
+
 void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event )
 {
     ConfigTreeData *config_data;
@@ -526,10 +601,23 @@ void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event )
         p_sizer->Remove( config_data->panel );
     }
 
-    config_data = (ConfigTreeData *)GetItemData( event.GetItem() );
-    if( config_data && config_data->panel )
+    /* Don't use event.GetItem() because we also send fake events */
+    config_data = (ConfigTreeData *)GetItemData( GetSelection() );
+    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->Layout();
     }
@@ -540,7 +628,7 @@ void PrefsTreeCtrl::OnSelectTreeItem( wxTreeEvent& event )
  *****************************************************************************/
 PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
                         PrefsDialog *_p_prefs_dialog,
-                        module_t *p_module, char *psz_section )
+                        int i_object_id, char *psz_section )
   :  wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize )
 {
     module_config_t *p_item;
@@ -564,8 +652,21 @@ PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
 
     wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
 
-    /* Enumerate config options and add corresponding config boxes */
-    p_item = p_module->p_config;
+    /* 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
+     * (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;
 
     /* Find the category if it has been specified */
     if( psz_section && p_item->i_type == CONFIG_HINT_CATEGORY )
@@ -593,7 +694,7 @@ PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
     /* Now put all the config options into a scrolled window */
     config_sizer = new wxBoxSizer( wxVERTICAL );
     config_window = new wxScrolledWindow( this, -1, wxDefaultPosition,
-                                          wxDefaultSize );
+        wxDefaultSize, wxSTATIC_BORDER | wxHSCROLL | wxVSCROLL );
     config_window->SetAutoLayout( TRUE );
     config_window->SetScrollRate( 5, 5 );
 
@@ -639,6 +740,7 @@ PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
                         combo->SetValue( wxU(p_parser->psz_longname) );
                 }
             }
+            vlc_list_release( p_list );
 
             combo->SetToolTip( wxU(p_item->psz_longtext) );
             config_data->control.combobox = combo;
@@ -673,7 +775,7 @@ PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
                     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->SetToolTip( wxU(p_item->psz_longtext) );
                 config_data->control.combobox = combo;
@@ -695,7 +797,7 @@ PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
                                    wxString::Format(wxT("%d"),p_item->i_value),
                                    wxDefaultPosition, wxDefaultSize,
                                    wxSP_ARROW_KEYS,
-                                   0, 16000, p_item->i_value);
+                                   -16000, 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 );
@@ -710,7 +812,7 @@ PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
                                    wxString::Format(wxT("%f"),p_item->f_value),
                                    wxDefaultPosition, wxDefaultSize,
                                    wxSP_ARROW_KEYS,
-                                   0, 16000, (int)p_item->f_value);
+                                   -16000, 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 );
@@ -766,12 +868,14 @@ PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf,
     b_advanced = !config_GetInt( p_intf, "advanced" );
     OnAdvanced( dummy_event );
 
-    /* Create advanced button */
+    /* Create advanced checkbox */
     if( config_array.GetCount() )
     {
-        wxButton *advanced_button = new wxButton( this, Advanced_Event,
-                                                  wxU(_("Advanced...")) );
-        sizer->Add( advanced_button, 0, wxALL, 5 );
+        wxCheckBox *advanced_checkbox =
+           new wxCheckBox( this, Advanced_Event, wxU(_("Advanced options")) );
+
+        if( b_advanced ) advanced_checkbox->SetValue(TRUE);
+        sizer->Add( advanced_checkbox, 0, wxALL|wxALIGN_RIGHT, 0 );
     }
 
     sizer->Layout();
@@ -833,6 +937,7 @@ void PrefsPanel::OnAdvanced( wxCommandEvent& WXUNUSED(event) )
 
     config_sizer->Layout();
     config_window->FitInside();
+    config_window->Refresh();
 }
 
 /*****************************************************************************