]> git.sesse.net Git - vlc/blobdiff - modules/gui/wxwidgets/menus.cpp
Use pl_Release with the right argument.
[vlc] / modules / gui / wxwidgets / menus.cpp
index 28a0a350159993b35078c6fa5c037f8ad6d85339..ff0a99c1804131a7c0337f281c2bb3a2c3577aae 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
-#include <vlc/vlc.h>
-#include <vlc/intf.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_interface.h>
 
 #include "wxwidgets.hpp"
 #include "interface.hpp"
 
-#include <vector>
-#include <string>
-using namespace std;
+#include <wx/dynarray.h>
+WX_DEFINE_ARRAY(int, ArrayOfInts);
+WX_DEFINE_ARRAY_PTR(const char *, ArrayOfStrings);
+
 
 class wxMenuItemExt: public wxMenuItem
 {
@@ -54,13 +59,13 @@ public:
     Menu( intf_thread_t *p_intf, int i_start_id );
     virtual ~Menu();
 
-    void Populate( vector<string> &, vector<int> &);
+    void Populate( ArrayOfStrings &, ArrayOfInts &);
     void Clear();
 
 private:
     wxMenu *CreateDummyMenu();
     void   CreateMenuItem( wxMenu *, const char *, vlc_object_t * );
-    wxMenu *CreateChoicesMenu( char *, vlc_object_t *, bool );
+    wxMenu *CreateChoicesMenu( const char *, vlc_object_t *, bool );
 
     DECLARE_EVENT_TABLE();
 
@@ -143,11 +148,11 @@ wxMenu *MiscMenu( intf_thread_t *p_intf )
 /*****************************************************************************
  * Builders for the dynamic menus
  *****************************************************************************/
-#define PUSH_VAR( var ) rs_varnames.push_back( var ); \
-                        ri_objects.push_back( p_object->i_object_id );
+#define PUSH_VAR( var ) rs_varnames.Add( var ); \
+                        ri_objects.Add( p_object->i_object_id )
 
-int InputAutoMenuBuilder( vlc_object_t *p_object,
-                          vector<int> &ri_objects, vector<string> &rs_varnames )
+int InputAutoMenuBuilder( vlc_object_t *p_object, ArrayOfInts &ri_objects,
+                          ArrayOfStrings &rs_varnames )
 {
     PUSH_VAR( "bookmark");
     PUSH_VAR( "title" );
@@ -158,8 +163,8 @@ int InputAutoMenuBuilder( vlc_object_t *p_object,
     return VLC_SUCCESS;
 }
 
-int VideoAutoMenuBuilder( vlc_object_t *p_object,
-                          vector<int> &ri_objects, vector<string> &rs_varnames )
+int VideoAutoMenuBuilder( vlc_object_t *p_object, ArrayOfInts &ri_objects,
+                          ArrayOfStrings &rs_varnames )
 {
     PUSH_VAR( "fullscreen" );
     PUSH_VAR( "zoom" );
@@ -175,14 +180,15 @@ int VideoAutoMenuBuilder( vlc_object_t *p_object,
                                                  FIND_PARENT );
     if( p_dec_obj != NULL )
     {
+        vlc_object_t *p_object = p_dec_obj;
         PUSH_VAR( "ffmpeg-pp-q" );
         vlc_object_release( p_dec_obj );
     }
     return VLC_SUCCESS;
 }
 
-int AudioAutoMenuBuilder( vlc_object_t *p_object,
-                          vector<int> &ri_objects, vector<string> &rs_varnames )
+int AudioAutoMenuBuilder( vlc_object_t *p_object, ArrayOfInts &ri_objects,
+                          ArrayOfStrings &rs_varnames )
 {
     PUSH_VAR( "audio-device" );
     PUSH_VAR( "audio-channels" );
@@ -191,9 +197,8 @@ int AudioAutoMenuBuilder( vlc_object_t *p_object,
     return VLC_SUCCESS;
 }
 
-int IntfAutoMenuBuilder( intf_thread_t *p_intf,
-                         vector<int> &ri_objects, vector<string> &rs_varnames,
-                         bool is_popup)
+int IntfAutoMenuBuilder( intf_thread_t *p_intf, ArrayOfInts &ri_objects,
+                         ArrayOfStrings &rs_varnames, bool is_popup)
 {
     /* vlc_object_find is needed because of the dialogs provider case */
     vlc_object_t *p_object;
@@ -201,14 +206,6 @@ int IntfAutoMenuBuilder( intf_thread_t *p_intf,
                                                 FIND_PARENT );
     if( p_object != NULL )
     {
-        if( is_popup )
-        {
-#ifndef WIN32
-            PUSH_VAR( "intf-switch" );
-#endif
-        }
-        else
-            PUSH_VAR( "intf-switch" );
         PUSH_VAR( "intf-add" );
         PUSH_VAR( "intf-skins" );
         vlc_object_release( p_object );
@@ -220,22 +217,22 @@ int IntfAutoMenuBuilder( intf_thread_t *p_intf,
 /*****************************************************************************
  * Popup menus
  *****************************************************************************/
-#define PUSH_VAR( var ) as_varnames.push_back( var ); \
-                        ai_objects.push_back( p_object->i_object_id );
-#define PUSH_SEPARATOR if( ai_objects.size() != i_last_separator ) { \
-                            ai_objects.push_back( 0 ); \
-                            as_varnames.push_back( "" ); \
-                            i_last_separator = ai_objects.size(); }
+#define PUSH_VAR( var ) as_varnames.Add( var ); \
+                        ai_objects.Add( p_object->i_object_id )
+
+#define PUSH_SEPARATOR if( ai_objects.GetCount() != i_last_separator ) { \
+                            ai_objects.Add( 0 ); \
+                            as_varnames.Add( "" ); \
+                            i_last_separator = ai_objects.GetCount(); }
 
 #define POPUP_BOILERPLATE \
     unsigned int i_last_separator = 0; \
-    vector<int> ai_objects; \
-    vector<string> as_varnames; \
-    playlist_t *p_playlist = (playlist_t *) vlc_object_find( p_intf, \
-                                          VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );\
+    ArrayOfInts ai_objects; \
+    ArrayOfStrings as_varnames; \
+    playlist_t *p_playlist = pl_Yield( p_intf ); \
     if( !p_playlist ) \
         return; \
-    input_thread_t *p_input = p_playlist->p_input;
+    input_thread_t *p_input = p_playlist->p_input
 
 #define CREATE_POPUP    \
     Menu popupmenu( p_intf, PopupMenu_Events ); \
@@ -243,6 +240,7 @@ int IntfAutoMenuBuilder( intf_thread_t *p_intf,
     p_intf->p_sys->p_popup_menu = &popupmenu; \
     p_parent->PopupMenu( &popupmenu, pos.x, pos.y ); \
     p_intf->p_sys->p_popup_menu = NULL; \
+    i_last_separator = 0 /* stop compiler warning */
 
 #define POPUP_STATIC_ENTRIES \
     if( p_input != NULL ) \
@@ -266,16 +264,16 @@ int IntfAutoMenuBuilder( intf_thread_t *p_intf,
     } \
     else \
     { \
-        if( p_playlist && p_playlist->i_size ) \
+        if( p_playlist && !playlist_IsEmpty( p_playlist ) ) \
         { \
             popupmenu.InsertSeparator( 0 ); \
             popupmenu.Insert( 0, Play_Event, wxU(_("Play")) ); \
         } \
-        if( p_playlist ) vlc_object_release( p_playlist ); \
+        if( p_playlist ) pl_Release( p_intf ); \
     } \
     \
     popupmenu.Append( MenuDummy_Event, wxU(_("Miscellaneous")), \
-                      MiscMenu( p_intf ), wxT("") ); \
+                      MiscMenu( p_intf ), wxT("") )
 
 
 void VideoPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
@@ -285,10 +283,10 @@ void VideoPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
     if( p_input )
     {
         vlc_object_yield( p_input );
-        as_varnames.push_back( "video-es" );
-        ai_objects.push_back( p_input->i_object_id );
-        as_varnames.push_back( "spu-es" );
-        ai_objects.push_back( p_input->i_object_id );
+        as_varnames.Add( "video-es" );
+        ai_objects.Add( p_input->i_object_id );
+        as_varnames.Add( "spu-es" );
+        ai_objects.Add( p_input->i_object_id );
         vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
                                                 VLC_OBJECT_VOUT, FIND_CHILD );
         if( p_vout )
@@ -298,7 +296,7 @@ void VideoPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
         }
         vlc_object_release( p_input );
     }
-    vlc_object_release( p_playlist );
+    pl_Release( p_intf );
     CREATE_POPUP;
 }
 
@@ -309,8 +307,8 @@ void AudioPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
     if( p_input )
     {
         vlc_object_yield( p_input );
-        as_varnames.push_back( "audio-es" );
-        ai_objects.push_back( p_input->i_object_id );
+        as_varnames.Add( "audio-es" );
+        ai_objects.Add( p_input->i_object_id );
         vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
                                              VLC_OBJECT_AOUT, FIND_ANYWHERE );
         if( p_aout )
@@ -320,7 +318,7 @@ void AudioPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
         }
         vlc_object_release( p_input );
     }
-    vlc_object_release( p_playlist );
+    pl_Release( p_intf );
     CREATE_POPUP;
 }
 
@@ -333,7 +331,7 @@ void MiscPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
     if( p_input )
     {
         vlc_object_yield( p_input );
-        as_varnames.push_back( "audio-es" );
+        as_varnames.Add( "audio-es" );
         InputAutoMenuBuilder( VLC_OBJECT(p_input), ai_objects, as_varnames );
         PUSH_SEPARATOR;
     }
@@ -349,7 +347,7 @@ void MiscPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
     p_intf->p_sys->p_popup_menu = &popupmenu;
     p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
     p_intf->p_sys->p_popup_menu = NULL;
-    vlc_object_release( p_playlist );
+    pl_Release( p_intf );
 }
 
 void PopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
@@ -364,10 +362,10 @@ void PopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
 
         /* Video menu */
         PUSH_SEPARATOR;
-        as_varnames.push_back( "video-es" );
-        ai_objects.push_back( p_input->i_object_id );
-        as_varnames.push_back( "spu-es" );
-        ai_objects.push_back( p_input->i_object_id );
+        as_varnames.Add( "video-es" );
+        ai_objects.Add( p_input->i_object_id );
+        as_varnames.Add( "spu-es" );
+        ai_objects.Add( p_input->i_object_id );
         vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
                                                 VLC_OBJECT_VOUT, FIND_CHILD );
         if( p_vout )
@@ -377,8 +375,8 @@ void PopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
         }
         /* Audio menu */
         PUSH_SEPARATOR
-        as_varnames.push_back( "audio-es" );
-        ai_objects.push_back( p_input->i_object_id );
+        as_varnames.Add( "audio-es" );
+        ai_objects.Add( p_input->i_object_id );
         vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
                                              VLC_OBJECT_AOUT, FIND_ANYWHERE );
         if( p_aout )
@@ -405,7 +403,7 @@ void PopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
     p_intf->p_sys->p_popup_menu = &popupmenu;
     p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
     p_intf->p_sys->p_popup_menu = NULL;
-    vlc_object_release( p_playlist );
+    pl_Release( p_intf );
 }
 
 /*****************************************************************************
@@ -414,8 +412,8 @@ void PopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
 wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
 {
     vlc_object_t *p_object;
-    vector<int> ai_objects;
-    vector<string> as_varnames;
+    ArrayOfInts ai_objects;
+    ArrayOfStrings as_varnames;
 
     p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
                                                 FIND_ANYWHERE );
@@ -448,8 +446,8 @@ wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
 wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
 {
     vlc_object_t *p_object;
-    vector<int> ai_objects;
-    vector<string> as_varnames;
+    ArrayOfInts ai_objects;
+    ArrayOfStrings as_varnames;
 
     p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
                                                 FIND_ANYWHERE );
@@ -482,8 +480,8 @@ wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
 wxMenu *NavigMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
 {
     vlc_object_t *p_object;
-    vector<int> ai_objects;
-    vector<string> as_varnames;
+    ArrayOfInts ai_objects;
+    ArrayOfStrings as_varnames;
 
     p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
                                                 FIND_ANYWHERE );
@@ -511,14 +509,13 @@ wxMenu *SettingsMenu( intf_thread_t *_p_intf, wxWindow *p_parent,
                       wxMenu *p_menu )
 {
     vlc_object_t *p_object;
-    vector<int> ai_objects;
-    vector<string> as_varnames;
+    ArrayOfInts ai_objects;
+    ArrayOfStrings as_varnames;
 
     p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INTF,
                                                 FIND_PARENT );
     if( p_object != NULL )
     {
-        PUSH_VAR( "intf-switch" );
         PUSH_VAR( "intf-add" );
         vlc_object_release( p_object );
     }
@@ -552,17 +549,18 @@ Menu::~Menu()
 /*****************************************************************************
  * Public methods.
  *****************************************************************************/
-void Menu::Populate( vector<string> & ras_varnames, vector<int> & rai_objects )
+void Menu::Populate( ArrayOfStrings & ras_varnames,
+                     ArrayOfInts & rai_objects )
 {
     vlc_object_t *p_object;
-    vlc_bool_t b_section_empty = VLC_FALSE;
+    bool b_section_empty = false;
     int i;
 
     i_item_id = i_start_id;
 
-    for( i = 0; i < rai_objects.size() ; i++ )
+    for( i = 0; i < (int)rai_objects.GetCount() ; i++ )
     {
-        if( ras_varnames[i] == ""  )
+        if( !ras_varnames[i] || !*ras_varnames[i] )
         {
             if( b_section_empty )
             {
@@ -570,23 +568,22 @@ void Menu::Populate( vector<string> & ras_varnames, vector<int> & rai_objects )
                 Enable( MenuDummy_Event + i, FALSE );
             }
             AppendSeparator();
-            b_section_empty = VLC_TRUE;
+            b_section_empty = true;
             continue;
         }
 
         if( rai_objects[i] == 0  )
         {
-            Append( MenuDummy_Event, wxU(ras_varnames[i].c_str()) );
-            b_section_empty = VLC_FALSE;
+            Append( MenuDummy_Event, wxU(ras_varnames[i]) );
+            b_section_empty = false;
             continue;
         }
 
-        p_object = (vlc_object_t *)vlc_object_get( p_intf,
-                                                   rai_objects[i] );
+        p_object = (vlc_object_t *)vlc_object_get( rai_objects[i] );
         if( p_object == NULL ) continue;
 
-        b_section_empty = VLC_FALSE;
-        CreateMenuItem( this, ras_varnames[i].c_str(), p_object );
+        b_section_empty = false;
+        CreateMenuItem( this, ras_varnames[i], p_object );
         vlc_object_release( p_object );
     }
 
@@ -625,7 +622,7 @@ void Menu::Clear( )
 /*****************************************************************************
  * Private methods.
  *****************************************************************************/
-static bool IsMenuEmpty( char *psz_var, vlc_object_t *p_object,
+static bool IsMenuEmpty( const char *psz_var, vlc_object_t *p_object,
                          bool b_root = TRUE )
 {
     vlc_value_t val, val_list;
@@ -642,8 +639,6 @@ static bool IsMenuEmpty( char *psz_var, vlc_object_t *p_object,
 
     if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
     {
-        /* Very evil hack ! intf-switch can have only one value */ 
-        if( !strcmp( psz_var, "intf-switch" ) ) return FALSE;
         if( val.i_int == 1 && b_root ) return TRUE;
         else return FALSE;
     }
@@ -707,7 +702,7 @@ void Menu::CreateMenuItem( wxMenu *menu, const char *psz_var,
                       CreateChoicesMenu( psz_var, p_object, TRUE ),
                       wxT("")/* Nothing for now (maybe use a GETLONGTEXT) */ );
 
-        if( text.psz_string ) free( text.psz_string );
+        free( text.psz_string );
         return;
     }
 
@@ -737,10 +732,10 @@ void Menu::CreateMenuItem( wxMenu *menu, const char *psz_var,
         break;
     }
 
-    if( text.psz_string ) free( text.psz_string );
+    free( text.psz_string );
 }
 
-wxMenu *Menu::CreateChoicesMenu( char *psz_var, vlc_object_t *p_object,
+wxMenu *Menu::CreateChoicesMenu( const char *psz_var, vlc_object_t *p_object,
                                  bool b_root )
 {
     vlc_value_t val, val_list, text_list;
@@ -812,7 +807,7 @@ wxMenu *Menu::CreateChoicesMenu( char *psz_var, vlc_object_t *p_object,
                        val_list.p_list->p_values[i].psz_string ) )
               menu->Check( i_item_id, TRUE );
 
-          if( val.psz_string ) free( val.psz_string );
+          free( val.psz_string );
           break;
 
         case VLC_VAR_INTEGER:
@@ -941,9 +936,7 @@ void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
     if( event.GetId() >= Play_Event && event.GetId() <= Stop_Event )
     {
         input_thread_t *p_input;
-        playlist_t * p_playlist =
-            (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
-                                           FIND_ANYWHERE );
+        playlist_t * p_playlist = pl_Yield( p_intf );
         if( !p_playlist ) return;
 
         switch( event.GetId() )
@@ -974,8 +967,7 @@ void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
             playlist_Next( p_playlist );
             break;
         }
-
-        vlc_object_release( p_playlist );
+        pl_Release( p_intf );
         return;
     }
 
@@ -993,10 +985,10 @@ void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
         vlc_value_t val;
 
         val.i_int =
-            p_intf->p_vlc->p_hotkeys[event.GetId() - i_hotkey_event].i_key;
+            p_intf->p_libvlc->p_hotkeys[event.GetId() - i_hotkey_event].i_key;
 
         /* Get the key combination and send it to the hotkey handler */
-        var_Set( p_intf->p_vlc, "key-pressed", val );
+        var_Set( p_intf->p_libvlc, "key-pressed", val );
         return;
     }
 
@@ -1016,8 +1008,7 @@ void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
         wxMenuItemExt *p_menuitemext = (wxMenuItemExt *)p_menuitem;
         vlc_object_t *p_object;
 
-        p_object = (vlc_object_t *)vlc_object_get( p_intf,
-                                       p_menuitemext->i_object_id );
+        p_object = (vlc_object_t *)vlc_object_get( p_menuitemext->i_object_id );
         if( p_object == NULL ) return;
 
         wxMutexGuiLeave(); // We don't want deadlocks
@@ -1048,7 +1039,7 @@ wxMenuItemExt::wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
 
 wxMenuItemExt::~wxMenuItemExt()
 {
-    if( psz_var ) free( psz_var );
-    if( ((i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
-        && val.psz_string ) free( val.psz_string );
+    free( psz_var );
+    if( ( i_val_type & VLC_VAR_TYPE ) == VLC_VAR_STRING )
+        free( val.psz_string );
 };