]> git.sesse.net Git - vlc/blobdiff - modules/gui/wxwindows/menus.cpp
* modules/gui/wxwindows/*, include/vlc_interface.h: new generic "open file" dialog.
[vlc] / modules / gui / wxwindows / menus.cpp
index d2865a2a85e3582b0b50c945c41fccfefd4b4e45..d306ca0f1f1b309f85dc92961722517f0af93b18 100644 (file)
@@ -2,7 +2,7 @@
  * menus.cpp : wxWindows plugin for vlc
  *****************************************************************************
  * Copyright (C) 2000-2001 VideoLAN
- * $Id: menus.cpp,v 1.14 2003/05/26 19:06:47 gbazin Exp $
+ * $Id: menus.cpp,v 1.17 2003/07/20 10:38:49 gbazin Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
 
 #include <vlc/intf.h>
 
+#if defined MODULE_NAME_IS_skins
+#   include "../skins/src/skin_common.h"
+#endif
+
 #include "wxwindows.h"
 
 class wxMenuItemExt: public wxMenuItem
@@ -75,24 +79,40 @@ private:
 enum
 {
     /* menu items */
-    FirstAutoGenerated_Event = wxID_HIGHEST + 1000,
-    MenuDummy_Event,
-    AudioMenu_Events,
-    VideoMenu_Events = wxID_HIGHEST + 1100,
-    NavigMenu_Events = wxID_HIGHEST + 1200,
-    PopupMenu_Events = wxID_HIGHEST + 1300,
+    MenuDummy_Event = wxID_HIGHEST + 1000,
+    OpenFileSimple_Event,
+    OpenFile_Event,
+    OpenDisc_Event,
+    OpenNet_Event,
+    FirstAutoGenerated_Event = wxID_HIGHEST + 1999,
+    AudioMenu_Events = wxID_HIGHEST + 2000,
+    VideoMenu_Events = wxID_HIGHEST + 3000,
+    NavigMenu_Events = wxID_HIGHEST + 4000,
+    PopupMenu_Events = wxID_HIGHEST + 5000
 };
 
 BEGIN_EVENT_TABLE(Menu, wxMenu)
-    /* Menu events */
-    EVT_MENU(MenuDummy_Event, Menu::OnEntrySelected)
 END_EVENT_TABLE()
 
 BEGIN_EVENT_TABLE(MenuEvtHandler, wxEvtHandler)
+    EVT_MENU(OpenFileSimple_Event, MenuEvtHandler::OnShowDialog)
+    EVT_MENU(OpenFile_Event, MenuEvtHandler::OnShowDialog)
+    EVT_MENU(OpenDisc_Event, MenuEvtHandler::OnShowDialog)
+    EVT_MENU(OpenNet_Event, MenuEvtHandler::OnShowDialog)
     EVT_MENU(-1, MenuEvtHandler::OnMenuEvent)
 END_EVENT_TABLE()
 
-void PopupMenu( intf_thread_t *_p_intf, Interface *_p_main_interface,
+wxMenu *OpenStreamMenu( intf_thread_t *p_intf )
+{
+    wxMenu *menu = new wxMenu;
+    menu->Append( OpenFileSimple_Event, wxU(_("Simple &Open ...")) );
+    menu->Append( OpenFile_Event, wxU(_("Open &File...")) );
+    menu->Append( OpenDisc_Event, wxU(_("Open &Disc...")) );
+    menu->Append( OpenNet_Event, wxU(_("Open &Network Stream...")) );
+    return menu;
+}
+
+void PopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
                 const wxPoint& pos )
 {
     vlc_object_t *p_object;
@@ -107,7 +127,7 @@ void PopupMenu( intf_thread_t *_p_intf, Interface *_p_main_interface,
     ppsz_varnames[i++] = _("Audio menu");
     ppsz_varnames[i++] = NULL; /* Separator */
 
-    p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_AOUT,
+    p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
                                                 FIND_ANYWHERE );
     if( p_object != NULL )
     {
@@ -123,7 +143,7 @@ void PopupMenu( intf_thread_t *_p_intf, Interface *_p_main_interface,
     ppsz_varnames[i++] = _("Video menu");
     ppsz_varnames[i++] = NULL; /* Separator */
 
-    p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_VOUT,
+    p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
                                                 FIND_ANYWHERE );
     if( p_object != NULL )
     {
@@ -141,7 +161,7 @@ void PopupMenu( intf_thread_t *_p_intf, Interface *_p_main_interface,
     ppsz_varnames[i++] = _("Input menu");
     ppsz_varnames[i++] = NULL; /* Separator */
 
-    p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
+    p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
                                                 FIND_ANYWHERE );
     if( p_object != NULL )
     {
@@ -164,20 +184,25 @@ void PopupMenu( intf_thread_t *_p_intf, Interface *_p_main_interface,
         vlc_object_release( p_object );
     }
 
-    /* Misc stuff */
-    ppsz_varnames[i++] = NULL; /* Separator */
-    ppsz_varnames[i++] = _("Close");
-
     /* Build menu */
-    Menu popupmenu( _p_intf, _p_main_interface, i,
+    Menu popupmenu( p_intf, p_parent, i,
                      ppsz_varnames, pi_objects, PopupMenu_Events );
 
-    _p_main_interface->p_popup_menu = &popupmenu;
-    _p_main_interface->PopupMenu( &popupmenu, pos.x, pos.y );
-    _p_main_interface->p_popup_menu = NULL;
+#if 1
+    /* Add static entries */
+    popupmenu.AppendSeparator();
+    popupmenu.Append( MenuDummy_Event, wxU("Open"),
+                      OpenStreamMenu( p_intf ), wxT("") );
+    popupmenu.AppendSeparator();
+    popupmenu.Append( MenuDummy_Event, wxU(_("Close Menu")) );
+#endif
+
+    p_intf->p_sys->p_popup_menu = &popupmenu;
+    p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
+    p_intf->p_sys->p_popup_menu = NULL;
 }
 
-wxMenu *AudioMenu( intf_thread_t *_p_intf, Interface *_p_main_interface )
+wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent )
 {
     vlc_object_t *p_object;
     char *ppsz_varnames[5];
@@ -208,11 +233,11 @@ wxMenu *AudioMenu( intf_thread_t *_p_intf, Interface *_p_main_interface )
     }
 
     /* Build menu */
-    return new Menu( _p_intf, _p_main_interface, i,
+    return new Menu( _p_intf, p_parent, i,
                      ppsz_varnames, pi_objects, AudioMenu_Events );
 }
 
-wxMenu *VideoMenu( intf_thread_t *_p_intf, Interface *_p_main_interface )
+wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent )
 {
     vlc_object_t *p_object;
     char *ppsz_varnames[6];
@@ -247,11 +272,11 @@ wxMenu *VideoMenu( intf_thread_t *_p_intf, Interface *_p_main_interface )
     }
 
     /* Build menu */
-    return new Menu( _p_intf, _p_main_interface, i,
+    return new Menu( _p_intf, p_parent, i,
                      ppsz_varnames, pi_objects, VideoMenu_Events );
 }
 
-wxMenu *NavigMenu( intf_thread_t *_p_intf, Interface *_p_main_interface )
+wxMenu *NavigMenu( intf_thread_t *_p_intf, wxWindow *p_parent )
 {
     vlc_object_t *p_object;
     char *ppsz_varnames[10];
@@ -287,14 +312,14 @@ wxMenu *NavigMenu( intf_thread_t *_p_intf, Interface *_p_main_interface )
     }
 
     /* Build menu */
-    return new Menu( _p_intf, _p_main_interface, i,
+    return new Menu( _p_intf, p_parent, i,
                      ppsz_varnames, pi_objects, NavigMenu_Events );
 }
 
 /*****************************************************************************
  * Constructor.
  *****************************************************************************/
-Menu::Menu( intf_thread_t *_p_intf, Interface *_p_main_interface,
+Menu::Menu( intf_thread_t *_p_intf, wxWindow *p_parent,
             int i_count, char **ppsz_varnames, int *pi_objects,
             int i_start_id ): wxMenu( )
 {
@@ -303,7 +328,6 @@ Menu::Menu( intf_thread_t *_p_intf, Interface *_p_main_interface,
 
     /* Initializations */
     p_intf = _p_intf;
-    p_main_interface = _p_main_interface;
 
     i_item_id = i_start_id;
 
@@ -343,10 +367,6 @@ Menu::~Menu()
 /*****************************************************************************
  * Private methods.
  *****************************************************************************/
-void Menu::OnEntrySelected( wxCommandEvent& WXUNUSED(event) )
-{
-}
-
 void Menu::CreateMenuItem( wxMenu *menu, char *psz_var,
                            vlc_object_t *p_object )
 {
@@ -513,7 +533,8 @@ wxMenu *Menu::CreateChoicesMenu( char *psz_var, vlc_object_t *p_object )
           menuitem =
               new wxMenuItemExt( menu, ++i_item_id,
                                  text_list.p_list->p_values[i].psz_string ?
-                                 wxU(text_list.p_list->p_values[i].psz_string):
+                                 (wxString)wxU(
+                                   text_list.p_list->p_values[i].psz_string) :
                                  wxString::Format(wxT("%d"),
                                  val_list.p_list->p_values[i].i_int),
                                  wxT(""), wxITEM_RADIO, strdup(psz_var),
@@ -538,6 +559,36 @@ wxMenu *Menu::CreateChoicesMenu( char *psz_var, vlc_object_t *p_object )
     return menu;
 }
 
+void Menu::OnShowDialog( wxCommandEvent& event )
+{
+    if( p_intf->p_sys->pf_show_dialog )
+    {
+        int i_id;
+
+        switch( event.GetId() )
+        {
+        case OpenFileSimple_Event:
+            i_id = INTF_DIALOG_FILE_SIMPLE;
+            break;
+        case OpenFile_Event:
+            i_id = INTF_DIALOG_FILE;
+            break;
+        case OpenDisc_Event:
+            i_id = INTF_DIALOG_DISC;
+            break;
+        case OpenNet_Event:
+            i_id = INTF_DIALOG_NET;
+            break;
+        default:
+            i_id = INTF_DIALOG_FILE;
+            break;
+
+        }
+
+        p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
+    }
+}
+
 /*****************************************************************************
  * A small helper class which intercepts all popup menu events
  *****************************************************************************/
@@ -553,9 +604,39 @@ MenuEvtHandler::~MenuEvtHandler()
 {
 }
 
+void MenuEvtHandler::OnShowDialog( wxCommandEvent& event )
+{
+    if( p_intf->p_sys->pf_show_dialog )
+    {
+        int i_id;
+
+        switch( event.GetId() )
+        {
+        case OpenFileSimple_Event:
+            i_id = INTF_DIALOG_FILE_SIMPLE;
+            break;
+        case OpenFile_Event:
+            i_id = INTF_DIALOG_FILE;
+            break;
+        case OpenDisc_Event:
+            i_id = INTF_DIALOG_DISC;
+            break;
+        case OpenNet_Event:
+            i_id = INTF_DIALOG_NET;
+            break;
+        default:
+            i_id = INTF_DIALOG_FILE;
+            break;
+
+        }
+
+        p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
+    }
+}
+
 void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
 {
-    wxMenuItem *p_menuitem;
+    wxMenuItem *p_menuitem = NULL;
 
     /* Check if this is an auto generated menu item */
     if( event.GetId() < FirstAutoGenerated_Event )
@@ -564,13 +645,14 @@ void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
         return;
     }
 
-    if( (p_menuitem = p_main_interface->GetMenuBar()->FindItem(event.GetId()))
+    if( !p_main_interface ||
+        (p_menuitem = p_main_interface->GetMenuBar()->FindItem(event.GetId()))
         == NULL )
     {
-        if( p_main_interface->p_popup_menu )
+        if( p_intf->p_sys->p_popup_menu )
         {
             p_menuitem = 
-                p_main_interface->p_popup_menu->FindItem( event.GetId() );
+                p_intf->p_sys->p_popup_menu->FindItem( event.GetId() );
         }
     }