]> git.sesse.net Git - vlc/blobdiff - modules/gui/wince/menus.cpp
Removes trailing spaces. Removes tabs.
[vlc] / modules / gui / wince / menus.cpp
index dc8e69cb3297758a8674929fc7cbea296488b867..cd8edc7d0c18827b347e6c7fa8ccb013e5636ab6 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * menus.cpp : WinCE gui plugin for VLC
  *****************************************************************************
- * Copyright (C) 2000-2004 VideoLAN
+ * Copyright (C) 2000-2004 the VideoLAN team
  * $Id$
  *
  * Authors: Marodon Cedric <cedric_marodon@yahoo.fr>
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
-#include <string.h>                                            /* strerror() */
-#include <stdio.h>
-
-#include <string>
-#include <stdio.h>
-using namespace std; 
-
 #include <vlc/vlc.h>
-#include <vlc/intf.h>
+#include <vlc_interface.h>
 
 #include "wince.h"
 
@@ -59,6 +51,193 @@ enum
     PopupMenu_Events = 6000
 };
 
+HMENU OpenStreamMenu( intf_thread_t *p_intf )
+{
+    HMENU hmenu = CreatePopupMenu();
+    AppendMenu( hmenu, MF_STRING, ID_FILE_QUICKOPEN,
+                _T("Quick &Open File...") );
+    AppendMenu( hmenu, MF_STRING, ID_FILE_OPENFILE,
+                _T("Open &File...") );
+    AppendMenu( hmenu, MF_STRING, ID_FILE_OPENNET,
+                _T("Open &Network Stream...") );
+    return hmenu;
+}
+
+HMENU MiscMenu( intf_thread_t *p_intf )
+{
+    HMENU hmenu = CreatePopupMenu();
+    AppendMenu( hmenu, MF_STRING, ID_VIEW_STREAMINFO, _T("Media &Info...") );
+    AppendMenu( hmenu, MF_STRING, ID_VIEW_MESSAGES, _T("&Messages...") );
+    AppendMenu( hmenu, MF_STRING, ID_PREFERENCES, _T("&Preferences...") );
+    return hmenu;
+}
+
+void PopupMenu( intf_thread_t *p_intf, HWND p_parent, POINT point )
+{
+#define MAX_POPUP_ITEMS 45
+
+    vlc_object_t *p_object, *p_input;
+    char *ppsz_varnames[MAX_POPUP_ITEMS];
+    int pi_objects[MAX_POPUP_ITEMS];
+    int i = 0, i_last_separator = 0;
+
+    /* Initializations */
+    memset( pi_objects, 0, MAX_POPUP_ITEMS * sizeof(int) );
+
+    ppsz_varnames[i] = "VLC media player";
+    pi_objects[i++] = 0;
+    ppsz_varnames[i++] = NULL; /* Separator */
+    i_last_separator = i;
+
+    /* Input menu */
+    p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
+                                                FIND_ANYWHERE );
+    if( p_object != NULL )
+    {
+        ppsz_varnames[i] = "bookmark";
+        pi_objects[i++] = p_object->i_object_id;
+        ppsz_varnames[i] = "title";
+        pi_objects[i++] = p_object->i_object_id;
+        ppsz_varnames[i] = "chapter";
+        pi_objects[i++] = p_object->i_object_id;
+        ppsz_varnames[i] = "program";
+        pi_objects[i++] = p_object->i_object_id;
+        ppsz_varnames[i] = "navigation";
+        pi_objects[i++] = p_object->i_object_id;
+        ppsz_varnames[i] = "dvd_menus";
+        pi_objects[i++] = p_object->i_object_id;
+
+        ppsz_varnames[i] = "video-es";
+        pi_objects[i++] = p_object->i_object_id;
+        ppsz_varnames[i] = "audio-es";
+        pi_objects[i++] = p_object->i_object_id;
+        ppsz_varnames[i] = "spu-es";
+        pi_objects[i++] = p_object->i_object_id;
+    }
+    p_input = p_object;
+    if( !p_input ) goto interfacemenu;
+
+    /* Video menu */
+    if( i != i_last_separator ) ppsz_varnames[i++] = NULL; /* Separator */
+    i_last_separator = i;
+
+    p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
+                                                FIND_ANYWHERE );
+    if( p_object != NULL )
+    {
+        vlc_object_t *p_dec_obj;
+
+        ppsz_varnames[i] = "fullscreen";
+        pi_objects[i++] = p_object->i_object_id;
+        ppsz_varnames[i] = "zoom";
+        pi_objects[i++] = p_object->i_object_id;
+        ppsz_varnames[i] = "deinterlace";
+        pi_objects[i++] = p_object->i_object_id;
+        ppsz_varnames[i] = "aspect-ratio";
+        pi_objects[i++] = p_object->i_object_id;
+        ppsz_varnames[i] = "crop";
+        pi_objects[i++] = p_object->i_object_id;
+        ppsz_varnames[i] = "video-on-top";
+        pi_objects[i++] = p_object->i_object_id;
+        ppsz_varnames[i] = "directx-wallpaper";
+        pi_objects[i++] = p_object->i_object_id;
+        ppsz_varnames[i] = "video-snapshot";
+        pi_objects[i++] = p_object->i_object_id;
+
+        p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
+                                                     VLC_OBJECT_DECODER,
+                                                     FIND_PARENT );
+        if( p_dec_obj != NULL )
+        {
+            ppsz_varnames[i] = "ffmpeg-pp-q";
+            pi_objects[i++] = p_dec_obj->i_object_id;
+            vlc_object_release( p_dec_obj );
+        }
+
+        vlc_object_release( p_object );
+    }
+
+    /* Audio menu */
+    if( i != i_last_separator ) ppsz_varnames[i++] = NULL; /* Separator */
+    i_last_separator  = i;
+
+    p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
+                                                FIND_ANYWHERE );
+    if( p_object != NULL )
+    {
+        ppsz_varnames[i] = "audio-device";
+        pi_objects[i++] = p_object->i_object_id;
+        ppsz_varnames[i] = "audio-channels";
+        pi_objects[i++] = p_object->i_object_id;
+        ppsz_varnames[i] = "visual";
+        pi_objects[i++] = p_object->i_object_id;
+        ppsz_varnames[i] = "equalizer";
+        pi_objects[i++] = p_object->i_object_id;
+        vlc_object_release( p_object );
+    }
+
+ interfacemenu:
+    /* Interface menu */
+    if( i != i_last_separator ) ppsz_varnames[i++] = NULL; /* Separator */
+    i_last_separator = i;
+
+    /* vlc_object_find is needed because of the dialogs provider case */
+    p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INTF,
+                                                FIND_PARENT );
+    if( p_object != NULL )
+    {
+        /* Nothing for now */
+        vlc_object_release( p_object );
+    }
+
+    /* Build menu */
+    vector<MenuItemExt*> popup_menu;
+    HMENU hmenu = CreatePopupMenu();
+    RefreshMenu( p_intf, &popup_menu, hmenu, i,
+                 ppsz_varnames, pi_objects, PopupMenu_Events );
+    MenuItemExt::ClearList( &popup_menu );
+
+
+    /* Add static entries */
+    if( p_input != NULL )
+    {
+        vlc_value_t val;
+        AppendMenu( hmenu, MF_SEPARATOR, 0, _T("") );
+        AppendMenu( hmenu, MF_STRING, StopStream_Event, _T("Stop") );
+        AppendMenu( hmenu, MF_STRING, PrevStream_Event, _T("Previous") );
+        AppendMenu( hmenu, MF_STRING, NextStream_Event, _T("Next") );
+
+        var_Get( p_input, "state", &val );
+        if( val.i_int == PAUSE_S )
+            AppendMenu( hmenu, MF_STRING, PlayStream_Event, _T("Play") );
+        else
+            AppendMenu( hmenu, MF_STRING, PlayStream_Event, _T("Pause") );
+
+        vlc_object_release( p_input );
+    }
+    else
+    {
+        playlist_t * p_playlist =
+            (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
+                                           FIND_ANYWHERE );
+        if( p_playlist && p_playlist->i_size )
+        {
+            AppendMenu( hmenu, MF_SEPARATOR, 0, _T("") );
+            AppendMenu( hmenu, MF_STRING, PlayStream_Event, _T("Play") );
+        }
+        if( p_playlist ) vlc_object_release( p_playlist );
+    }
+
+    AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)MiscMenu( p_intf ),
+                _T("Miscellaneous") );
+    AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)OpenStreamMenu( p_intf ),
+                _T("Open") );
+
+    TrackPopupMenu( hmenu, 0, point.x, point.y, 0, p_parent, 0 );
+    PostMessage( p_parent, WM_NULL, 0, 0 );
+    DestroyMenu( hmenu );
+}
+
 void RefreshAudioMenu( intf_thread_t *p_intf, HMENU hMenu )
 {
 #define MAX_AUDIO_ITEMS 10
@@ -66,22 +245,17 @@ void RefreshAudioMenu( intf_thread_t *p_intf, HMENU hMenu )
     vlc_object_t *p_object;
     char *ppsz_varnames[MAX_AUDIO_ITEMS];
     int pi_objects[MAX_AUDIO_ITEMS];
-    vector<MenuItemExt*>::iterator iter;
     int i;
 
     /* Delete old menu */
     int count = wce_GetMenuItemCount( hMenu );
     for( i = 0; i <= count; i++ ) RemoveMenu( hMenu, 0, MF_BYPOSITION );
-        
+
     if( p_intf->p_sys->p_audio_menu )
-    {
-        for( iter = p_intf->p_sys->p_audio_menu->begin();
-             iter != p_intf->p_sys->p_audio_menu->end(); iter++ )
-            delete *iter;
-        p_intf->p_sys->p_audio_menu->clear();
-    }
+        MenuItemExt::ClearList( p_intf->p_sys->p_audio_menu );
     else p_intf->p_sys->p_audio_menu = new vector<MenuItemExt*>;
 
+
     /* Initializations */
     memset( pi_objects, 0, MAX_AUDIO_ITEMS * sizeof(int) );
     i = 0;
@@ -120,22 +294,16 @@ void RefreshVideoMenu( intf_thread_t *p_intf, HMENU hMenu )
     vlc_object_t *p_object;
     char *ppsz_varnames[MAX_VIDEO_ITEMS];
     int pi_objects[MAX_VIDEO_ITEMS];
-    vector<MenuItemExt*>::iterator iter;
     int i;
 
     /* Delete old menu */
     int count = wce_GetMenuItemCount( hMenu );
     for( i = 0; i <= count; i++ ) RemoveMenu( hMenu, 0, MF_BYPOSITION );
-        
+
     if( p_intf->p_sys->p_video_menu )
-    {
-        for( iter = p_intf->p_sys->p_video_menu->begin();
-             iter != p_intf->p_sys->p_video_menu->end(); iter++ )
-            delete *iter;
-        p_intf->p_sys->p_video_menu->clear();
-    }
+        MenuItemExt::ClearList( p_intf->p_sys->p_video_menu );
     else p_intf->p_sys->p_video_menu = new vector<MenuItemExt*>;
-        
+
     /* Initializations */
     memset( pi_objects, 0, MAX_VIDEO_ITEMS * sizeof(int) );
     i = 0;
@@ -198,20 +366,14 @@ void RefreshNavigMenu( intf_thread_t *p_intf, HMENU hMenu )
     vlc_object_t *p_object;
     char *ppsz_varnames[MAX_NAVIG_ITEMS];
     int pi_objects[MAX_NAVIG_ITEMS];
-    vector<MenuItemExt*>::iterator iter;
     int i;
 
     /* Delete old menu */
     int count = wce_GetMenuItemCount( hMenu );
     for( i = 0; i <= count; i++ ) RemoveMenu( hMenu, 0, MF_BYPOSITION );
-        
     if( p_intf->p_sys->p_navig_menu )
-    {
-        for( iter = p_intf->p_sys->p_navig_menu->begin();
-             iter != p_intf->p_sys->p_navig_menu->end(); iter++ )
-            delete *iter;
-        p_intf->p_sys->p_navig_menu->clear();
-    }
+        MenuItemExt::ClearList( p_intf->p_sys->p_navig_menu );
     else p_intf->p_sys->p_navig_menu = new vector<MenuItemExt*>;
 
     /* Initializations */
@@ -257,7 +419,6 @@ void RefreshSettingsMenu( intf_thread_t *p_intf, HMENU hMenu )
     vlc_object_t *p_object;
     char *ppsz_varnames[MAX_SETTINGS_ITEMS];
     int pi_objects[MAX_SETTINGS_ITEMS];
-    vector<MenuItemExt*>::iterator iter;
     int i;
 
     /* Delete old menu */
@@ -265,20 +426,14 @@ void RefreshSettingsMenu( intf_thread_t *p_intf, HMENU hMenu )
     for( i = 0; i <= count; i++ ) RemoveMenu( hMenu, 0, MF_BYPOSITION );
 
     if( p_intf->p_sys->p_settings_menu )
-    {
-        for( iter = p_intf->p_sys->p_settings_menu->begin();
-             iter != p_intf->p_sys->p_settings_menu->end(); iter++ )
-            delete(*iter);
-        p_intf->p_sys->p_settings_menu->clear();
-    }
+        MenuItemExt::ClearList( p_intf->p_sys->p_settings_menu );
     else p_intf->p_sys->p_settings_menu = new vector<MenuItemExt*>;
 
     /* Initializations */
     memset( pi_objects, 0, MAX_SETTINGS_ITEMS * sizeof(int) );
     i = 0;
 
-    AppendMenu( hMenu, MF_STRING, ID_SETTINGS_EXTEND, _T("&Extended GUI") );
-    AppendMenu( hMenu, MF_STRING, ID_SETTINGS_PREF, _T("&Preferences...") );
+    AppendMenu( hMenu, MF_STRING, ID_PREFERENCES, _T("&Preferences...") );
 
     p_object = (vlc_object_t *)
         vlc_object_find( p_intf, VLC_OBJECT_INTF, FIND_PARENT );
@@ -299,8 +454,8 @@ void RefreshSettingsMenu( intf_thread_t *p_intf, HMENU hMenu )
 /*****************************************************************************
  * Refresh the menu.
  *****************************************************************************/
-void RefreshMenu( intf_thread_t *p_intf, vector<MenuItemExt*> *_p_menuList,
-                  HMENU hMenu , int i_count, char **ppsz_varnames, 
+void RefreshMenu( intf_thread_t *p_intf, vector<MenuItemExt*> *p_menu_list,
+                  HMENU hMenu , int i_count, char **ppsz_varnames,
                   int *pi_objects, int i_start_id )
 {
     vlc_object_t *p_object;
@@ -338,7 +493,7 @@ void RefreshMenu( intf_thread_t *p_intf, vector<MenuItemExt*> *_p_menuList,
         if( p_object == NULL ) continue;
 
         b_section_empty = VLC_FALSE;
-        CreateMenuItem( p_intf, _p_menuList, hMenu, ppsz_varnames[i],
+        CreateMenuItem( p_intf, p_menu_list, hMenu, ppsz_varnames[i],
                         p_object, &i_item_id );
         vlc_object_release( p_object );
     }
@@ -354,7 +509,7 @@ void RefreshMenu( intf_thread_t *p_intf, vector<MenuItemExt*> *_p_menuList,
 /*****************************************************************************
  * Private methods.
  *****************************************************************************/
-void CreateMenuItem( intf_thread_t *p_intf, vector<MenuItemExt*> *_p_menuList,
+void CreateMenuItem( intf_thread_t *p_intf, vector<MenuItemExt*> *p_menu_list,
                      HMENU hMenu, char *psz_var, vlc_object_t *p_object,
                      int *pi_item_id )
 {
@@ -396,10 +551,11 @@ void CreateMenuItem( intf_thread_t *p_intf, vector<MenuItemExt*> *_p_menuList,
 
     if( i_type & VLC_VAR_HASCHOICE )
     {
-        hMenuItem = CreateChoicesMenu( p_intf, _p_menuList, psz_var,
+        hMenuItem = CreateChoicesMenu( p_intf, p_menu_list, psz_var,
                                        p_object, pi_item_id );
         AppendMenu( hMenu, MF_STRING | MF_POPUP, (UINT)hMenuItem,
                     _FROMMB(text.psz_string ? text.psz_string : psz_var) );
+        if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
         if( text.psz_string ) free( text.psz_string );
         return;
     }
@@ -411,7 +567,7 @@ void CreateMenuItem( intf_thread_t *p_intf, vector<MenuItemExt*> *_p_menuList,
                     _FROMMB(text.psz_string ? text.psz_string : psz_var) );
         pMenuItemExt = new MenuItemExt( p_intf, *pi_item_id, psz_var,
                                         p_object->i_object_id, val, i_type );
-        _p_menuList->push_back( pMenuItemExt );
+        p_menu_list->push_back( pMenuItemExt );
         break;
 
     case VLC_VAR_BOOL:
@@ -420,10 +576,10 @@ void CreateMenuItem( intf_thread_t *p_intf, vector<MenuItemExt*> *_p_menuList,
                     _FROMMB(text.psz_string ? text.psz_string : psz_var) );
         pMenuItemExt = new MenuItemExt( p_intf, *pi_item_id, psz_var,
                                         p_object->i_object_id, val, i_type );
-        _p_menuList->push_back( pMenuItemExt );
+        p_menu_list->push_back( pMenuItemExt );
         CheckMenuItem( hMenu, *pi_item_id ,
                        ( val.b_bool ? MF_UNCHECKED : MF_CHECKED ) |
-                       MF_BYCOMMAND ); 
+                       MF_BYCOMMAND );
         break;
 
     default:
@@ -436,7 +592,7 @@ void CreateMenuItem( intf_thread_t *p_intf, vector<MenuItemExt*> *_p_menuList,
 }
 
 HMENU CreateChoicesMenu( intf_thread_t *p_intf,
-                         vector<MenuItemExt*> *_p_menuList, char *psz_var, 
+                         vector<MenuItemExt*> *p_menu_list, char *psz_var,
                          vlc_object_t *p_object, int *pi_item_id )
 {
     MenuItemExt *pMenuItemExt;
@@ -491,7 +647,7 @@ HMENU CreateChoicesMenu( intf_thread_t *p_intf,
         switch( i_type & VLC_VAR_TYPE )
         {
         case VLC_VAR_VARIABLE:
-            hMenuItem = CreateChoicesMenu( p_intf, _p_menuList,
+            hMenuItem = CreateChoicesMenu( p_intf, p_menu_list,
               val_list.p_list->p_values[i].psz_string, p_object, pi_item_id );
             AppendMenu( hSubMenu, MF_STRING | MF_POPUP, (UINT)hMenuItem,
                         _FROMMB(text_list.p_list->p_values[i].psz_string ?
@@ -508,7 +664,7 @@ HMENU CreateChoicesMenu( intf_thread_t *p_intf,
                           val_list.p_list->p_values[i].psz_string) );
             pMenuItemExt = new MenuItemExt( p_intf, *pi_item_id, psz_var,
                           p_object->i_object_id, another_val, i_type );
-            _p_menuList->push_back( pMenuItemExt );
+            p_menu_list->push_back( pMenuItemExt );
 
             if( !(i_type & VLC_VAR_ISCOMMAND) && val.psz_string &&
                 !strcmp( val.psz_string,
@@ -523,7 +679,7 @@ HMENU CreateChoicesMenu( intf_thread_t *p_intf,
                           text_list.p_list->p_values[i].psz_string : psz_tmp));
             pMenuItemExt = new MenuItemExt( p_intf, *pi_item_id, psz_var,
                 p_object->i_object_id, val_list.p_list->p_values[i], i_type );
-            _p_menuList->push_back( pMenuItemExt );
+            p_menu_list->push_back( pMenuItemExt );
 
             if( val_list.p_list->p_values[i].i_int == val.i_int )
               CheckMenuItem( hSubMenu, *pi_item_id, MF_CHECKED | MF_BYCOMMAND);
@@ -565,6 +721,7 @@ void OnMenuEvent( intf_thread_t *p_intf, int id )
     MenuItemExt *p_menuitemext = NULL;
     vector<MenuItemExt*>::iterator iter;
 
+    if( p_intf->p_sys->p_settings_menu )
     for( iter = p_intf->p_sys->p_settings_menu->begin();
          iter != p_intf->p_sys->p_settings_menu->end(); iter++ )
         if( (*iter)->id == id )
@@ -572,13 +729,17 @@ void OnMenuEvent( intf_thread_t *p_intf, int id )
             p_menuitemext = *iter;
             break;
         }
+
+    if( p_intf->p_sys->p_audio_menu && !p_menuitemext )
     for( iter = p_intf->p_sys->p_audio_menu->begin();
-         iter != p_intf->p_sys->p_audio_menu->end(); iter++ ) 
+         iter != p_intf->p_sys->p_audio_menu->end(); iter++ )
         if( (*iter)->id == id )
         {
             p_menuitemext = *iter;
             break;
         }
+
+    if( p_intf->p_sys->p_video_menu && !p_menuitemext )
     for( iter = p_intf->p_sys->p_video_menu->begin();
          iter != p_intf->p_sys->p_video_menu->end(); iter++ )
         if( (*iter)->id == id )
@@ -586,6 +747,8 @@ void OnMenuEvent( intf_thread_t *p_intf, int id )
             p_menuitemext = *iter;
             break;
         }
+
+    if( p_intf->p_sys->p_navig_menu && !p_menuitemext )
     for( iter = p_intf->p_sys->p_navig_menu->begin();
          iter != p_intf->p_sys->p_navig_menu->end(); iter++ )
         if( (*iter)->id == id )
@@ -641,3 +804,15 @@ MenuItemExt::~MenuItemExt()
     if( ((i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
         && val.psz_string ) free( val.psz_string );
 };
+
+void MenuItemExt::ClearList( vector<MenuItemExt*> *p_menu_list )
+{
+    vector<MenuItemExt*>::iterator iter;
+
+    if( !p_menu_list ) return;
+    for( iter = p_menu_list->begin(); iter != p_menu_list->end(); iter++ )
+    {
+        delete *iter;
+    }
+    p_menu_list->clear();
+}