]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins/src/dialogs.cpp
* modules/gui/wxwindows/*: The wxwindows interface is now a "dialogs provider" module...
[vlc] / modules / gui / skins / src / dialogs.cpp
index 346d98641d99ea549b2697b2a1c2ab963ff9a12e..13bed920a9041b27d810ac28dc1ee5ff36dbf6e0 100644 (file)
-/*****************************************************************************\r
- * dialogs.cpp: Handles all the different dialog boxes we provide.\r
- *****************************************************************************\r
- * Copyright (C) 2003 VideoLAN\r
- * $Id: dialogs.cpp,v 1.9 2003/07/13 14:55:17 gbazin Exp $\r
- *\r
- * Authors: Gildas Bazin <gbazin@netcourrier.com>\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111,\r
- * USA.\r
- *****************************************************************************/\r
-\r
-//--- VLC -------------------------------------------------------------------\r
-#include <vlc/vlc.h>\r
-#include <vlc/intf.h>\r
-\r
-//--- SKIN ------------------------------------------------------------------\r
-#include "../os_api.h"\r
-#include "event.h"\r
-#include "banks.h"\r
-#include "theme.h"\r
-#include "../os_theme.h"\r
-#include "themeloader.h"\r
-#include "window.h"\r
-#include "vlcproc.h"\r
-#include "skin_common.h"\r
-#include "dialogs.h"\r
-\r
-/* Callback prototype */\r
-int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,\r
-                 vlc_value_t old_val, vlc_value_t new_val, void *param );\r
-\r
-#if defined(MODULE_NAME_IS_basic_skins)\r
-\r
-// Constructor\r
-Dialogs::Dialogs( intf_thread_t *_p_intf ){}\r
-// Destructor\r
-Dialogs::~Dialogs(){}\r
-\r
-void Dialogs::ShowOpen( bool b_play ){}\r
-void Dialogs::ShowOpenSkin(){}\r
-void Dialogs::ShowMessages(){}\r
-void Dialogs::ShowPrefs(){}\r
-void Dialogs::ShowFileInfo(){}\r
-void Dialogs::ShowPopup(){}\r
-\r
-#else // !MODULE_NAME_IS_basic_skins\r
-\r
-#include "../../wxwindows/wxwindows.h"\r
-#include "../../../../share/vlc32x32.xpm"       // include the graphic icon\r
-\r
-#define ShowOpen_Event     0\r
-#define ShowOpenSkin_Event 1\r
-#define ShowMessages_Event 2\r
-#define ShowPrefs_Event    3\r
-#define ShowFileInfo_Event 4\r
-#define ShowPopup_Event    5\r
-#define ExitThread_Event   99\r
-\r
-//---------------------------------------------------------------------------\r
-// Local classes declarations.\r
-//---------------------------------------------------------------------------\r
-\r
-DEFINE_EVENT_TYPE(wxEVT_DIALOG)\r
-\r
-class Instance: public wxApp\r
-{\r
-public:\r
-    Instance();\r
-    Instance( intf_thread_t *_p_intf );\r
-\r
-    bool OnInit();\r
-    int  OnExit();\r
-\r
-private:\r
-    intf_thread_t *p_intf;\r
-\r
-    DECLARE_EVENT_TABLE();\r
-};\r
-\r
-BEGIN_EVENT_TABLE(Instance, wxApp)\r
-    EVT_COMMAND(ShowOpen_Event, wxEVT_DIALOG, Dialogs::OnShowOpen)\r
-    EVT_COMMAND(ShowOpenSkin_Event, wxEVT_DIALOG, Dialogs::OnShowOpenSkin)\r
-    EVT_COMMAND(ShowMessages_Event, wxEVT_DIALOG, Dialogs::OnShowMessages)\r
-    EVT_COMMAND(ShowPrefs_Event, wxEVT_DIALOG, Dialogs::OnShowPrefs)\r
-    EVT_COMMAND(ShowFileInfo_Event, wxEVT_DIALOG, Dialogs::OnShowFileInfo)\r
-    EVT_COMMAND(ShowPopup_Event, wxEVT_DIALOG, Dialogs::OnShowPopup)\r
-    EVT_COMMAND(ExitThread_Event, wxEVT_DIALOG, Dialogs::OnExitThread)\r
-END_EVENT_TABLE()\r
-\r
-//---------------------------------------------------------------------------\r
-// Implementation of Instance class\r
-//---------------------------------------------------------------------------\r
-Instance::Instance( )\r
-{\r
-}\r
-\r
-Instance::Instance( intf_thread_t *_p_intf )\r
-{\r
-    // Initialization\r
-    p_intf = _p_intf;\r
-}\r
-\r
-IMPLEMENT_APP_NO_MAIN(Instance)\r
-\r
-bool Instance::OnInit()\r
-{\r
-    p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );\r
-\r
-    // Create all the dialog boxes\r
-    p_intf->p_sys->p_dialogs->OpenDlg =\r
-        new OpenDialog( p_intf, NULL, FILE_ACCESS );\r
-    p_intf->p_sys->p_dialogs->MessagesDlg = new Messages( p_intf, NULL );\r
-    p_intf->p_sys->p_dialogs->PrefsDlg = new PrefsDialog( p_intf, NULL );\r
-    p_intf->p_sys->p_dialogs->FileInfoDlg = new FileInfo( p_intf, NULL );\r
-\r
-    // OK, initialization is over, now the other thread can go on working...\r
-    vlc_thread_ready( p_intf->p_sys->p_dialogs->p_thread );\r
-\r
-    /* Register callback for the intf-popupmenu variable */\r
-    playlist_t *p_playlist =\r
-        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,\r
-                                       FIND_ANYWHERE );\r
-    if( p_playlist != NULL )\r
-    {\r
-        var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB,\r
-                         p_intf->p_sys->p_dialogs );\r
-        vlc_object_release( p_playlist );\r
-    }\r
-\r
-    /* Intercept all menu events in our custom event handler */\r
-    p_intf->p_sys->p_dialogs->OpenDlg->PushEventHandler(\r
-        new MenuEvtHandler( p_intf, NULL ) );\r
-\r
-    return TRUE;\r
-}\r
-\r
-int Instance::OnExit()\r
-{\r
-    // Delete evertything\r
-    delete p_intf->p_sys->p_dialogs->FileInfoDlg;\r
-    delete p_intf->p_sys->p_dialogs->PrefsDlg;\r
-    delete p_intf->p_sys->p_dialogs->MessagesDlg;\r
-    delete p_intf->p_sys->p_dialogs->OpenDlg;\r
-    delete p_intf->p_sys->p_icon;\r
-\r
-    return 0;\r
-}\r
-\r
-//---------------------------------------------------------------------------\r
-#if !defined(__BUILTIN__) && defined( WIN32 )\r
-HINSTANCE hInstance = 0;\r
-extern "C" BOOL WINAPI\r
-DllMain (HANDLE hModule, DWORD fdwReason, LPVOID lpReserved)\r
-{\r
-    hInstance = (HINSTANCE)hModule;\r
-    return TRUE;\r
-}\r
-#endif\r
-\r
-//---------------------------------------------------------------------------\r
-// Thread callback\r
-// We create all wxWindows dialogs in a separate thread because we don't want\r
-// any interaction with our own message loop\r
-//---------------------------------------------------------------------------\r
-void SkinsDialogsThread( dialogs_thread_t *p_thread )\r
-{\r
-#if !defined( WIN32 )\r
-    static char  *p_args[] = { "" };\r
-#endif\r
-    intf_thread_t *p_intf = p_thread->p_intf;\r
-\r
-    /* Hack to pass the p_intf pointer to the new wxWindow Instance object */\r
-    wxTheApp = new Instance( p_intf );\r
-\r
-#if defined( WIN32 )\r
-#if !defined(__BUILTIN__)\r
-    wxEntry( hInstance/*GetModuleHandle(NULL)*/, NULL, NULL, SW_SHOW, TRUE );\r
-#else\r
-    wxEntry( GetModuleHandle( NULL ), NULL, NULL, SW_SHOW, TRUE );\r
-#endif\r
-#else\r
-    wxEntry( 1, p_args );\r
-#endif\r
-\r
-    return;\r
-}\r
-\r
-//---------------------------------------------------------------------------\r
-// Implementation of Dialogs class\r
-//---------------------------------------------------------------------------\r
-Dialogs::Dialogs( intf_thread_t *_p_intf )\r
-{\r
-    p_intf = _p_intf;\r
-    p_intf->p_sys->p_dialogs = this;\r
-    b_popup_change = VLC_FALSE;\r
-\r
-    p_thread = (dialogs_thread_t *)vlc_object_create( p_intf,\r
-                                                sizeof(dialogs_thread_t) );\r
-    p_thread->p_intf = p_intf;\r
-\r
-    // Create a new thread for wxWindows\r
-    if( vlc_thread_create( p_thread, "Skins Dialogs Thread",\r
-                           SkinsDialogsThread, 0, VLC_TRUE ) )\r
-    {\r
-        OpenDlg = NULL;\r
-        msg_Err( p_intf, "cannot create SkinsDialogsThread" );\r
-    }\r
-}\r
-\r
-Dialogs::~Dialogs()\r
-{\r
-    wxCommandEvent event( wxEVT_DIALOG, ExitThread_Event );\r
-    event.SetClientData( this );\r
-\r
-    wxTheApp->AddPendingEvent( event );\r
-\r
-    vlc_thread_join( p_thread );\r
-}\r
-\r
-void Dialogs::ShowOpen( bool b_play )\r
-{\r
-    wxCommandEvent event( wxEVT_DIALOG, ShowOpen_Event );\r
-    event.SetClientData( this );\r
-    event.SetInt( b_play );\r
-\r
-    wxTheApp->AddPendingEvent( event );\r
-}\r
-\r
-void Dialogs::ShowOpenSkin()\r
-{\r
-    wxCommandEvent event( wxEVT_DIALOG, ShowOpenSkin_Event );\r
-    event.SetClientData( this );\r
-\r
-    wxTheApp->AddPendingEvent( event );\r
-}\r
-\r
-void Dialogs::ShowMessages()\r
-{\r
-    wxCommandEvent event( wxEVT_DIALOG, ShowMessages_Event );\r
-    event.SetClientData( this );\r
-\r
-    wxTheApp->AddPendingEvent( event );\r
-}\r
-\r
-void Dialogs::ShowPrefs()\r
-{\r
-    wxCommandEvent event( wxEVT_DIALOG, ShowPrefs_Event );\r
-    event.SetClientData( this );\r
-\r
-    wxTheApp->AddPendingEvent( event );\r
-}\r
-\r
-void Dialogs::ShowFileInfo()\r
-{\r
-    wxCommandEvent event( wxEVT_DIALOG, ShowFileInfo_Event );\r
-    event.SetClientData( this );\r
-\r
-    wxTheApp->AddPendingEvent( event );\r
-}\r
-\r
-void Dialogs::ShowPopup()\r
-{\r
-    wxCommandEvent event( wxEVT_DIALOG, ShowPopup_Event );\r
-    event.SetClientData( this );\r
-\r
-    wxTheApp->AddPendingEvent( event );\r
-}\r
-\r
-void Dialogs::OnShowOpen( wxCommandEvent& event )\r
-{\r
-    Dialogs *p_dialogs = (Dialogs *)event.GetClientData();\r
-    bool b_play = event.GetInt() ? TRUE : FALSE;\r
-\r
-    if( p_dialogs->OpenDlg->IsShown() ) return;\r
\r
-    if( p_dialogs->OpenDlg->ShowModal() != wxID_OK )\r
-    {\r
-        return;\r
-    }\r
-\r
-    // Check if playlist is available\r
-    playlist_t *p_playlist = p_dialogs->p_intf->p_sys->p_playlist;\r
-    if( p_playlist == NULL )\r
-    {\r
-        return;\r
-    }\r
-\r
-    if( b_play )\r
-    {\r
-        // Append and play\r
-        for( size_t i = 0; i < p_dialogs->OpenDlg->mrl.GetCount(); i++ )\r
-        {\r
-            playlist_Add( p_playlist,\r
-                (const char *)p_dialogs->OpenDlg->mrl[i].mb_str(),\r
-                PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );\r
-        }\r
-        p_dialogs->p_intf->p_sys->p_theme->EvtBank->Get( "play" )->SendEvent();\r
-    }\r
-    else\r
-    {\r
-        // Append only\r
-        for( size_t i = 0; i < p_dialogs->OpenDlg->mrl.GetCount(); i++ )\r
-        {\r
-            playlist_Add( p_playlist,\r
-                (const char *)p_dialogs->OpenDlg->mrl[i].mb_str(),\r
-                PLAYLIST_APPEND, PLAYLIST_END );\r
-        }\r
-    }\r
-\r
-    // Refresh interface !\r
-    p_dialogs->p_intf->p_sys->p_theme->EvtBank->Get( "playlist_refresh" )\r
-        ->PostSynchroMessage();\r
-\r
-    return;\r
-}\r
-\r
-void Dialogs::OnShowOpenSkin( wxCommandEvent& event )\r
-{\r
-    Dialogs *p_dialogs = (Dialogs *)event.GetClientData();\r
-    intf_thread_t *p_intf = p_dialogs->p_intf;\r
-\r
-    wxFileDialog dialog( NULL,\r
-        wxU(_("Open a skin file")), wxT(""), wxT(""),\r
-        wxT("Skin files (*.vlt)|*.vlt|Skin files (*.xml)|*.xml|"\r
-            "All files|*.*"), wxOPEN );\r
-\r
-    if( dialog.ShowModal() == wxID_OK )\r
-    {\r
-        p_intf->p_sys->p_new_theme_file =\r
-           new char[strlen(dialog.GetPath().mb_str()) + 1];\r
-\r
-        strcpy( p_intf->p_sys->p_new_theme_file,\r
-                dialog.GetPath().mb_str() );\r
-\r
-        // Tell vlc to change skin after hiding interface\r
-        OSAPI_PostMessage( NULL, VLC_HIDE, VLC_LOAD_SKIN, 0 );\r
-    }\r
-}\r
-\r
-void Dialogs::OnShowMessages( wxCommandEvent& event )\r
-{\r
-    Dialogs *p_dialogs = (Dialogs *)event.GetClientData();\r
-    p_dialogs->MessagesDlg->Show( !p_dialogs->MessagesDlg->IsShown() );\r
-}\r
-\r
-void Dialogs::OnShowPrefs( wxCommandEvent& event )\r
-{\r
-    Dialogs *p_dialogs = (Dialogs *)event.GetClientData();\r
-    p_dialogs->PrefsDlg->Show( !p_dialogs->PrefsDlg->IsShown() );\r
-}\r
-\r
-void Dialogs::OnShowFileInfo( wxCommandEvent& event )\r
-{\r
-    Dialogs *p_dialogs = (Dialogs *)event.GetClientData();\r
-    p_dialogs->FileInfoDlg->Show( !p_dialogs->FileInfoDlg->IsShown() );\r
-}\r
-\r
-void Dialogs::OnShowPopup( wxCommandEvent& event )\r
-{\r
-    Dialogs *p_dialogs = (Dialogs *)event.GetClientData();\r
-\r
-    wxPoint mousepos = wxGetMousePosition();\r
-\r
-    wxMouseEvent mouseevent = wxMouseEvent( wxEVT_RIGHT_UP );\r
-    mouseevent.m_x = p_dialogs->OpenDlg->ScreenToClient(mousepos).x;\r
-    mouseevent.m_y = p_dialogs->OpenDlg->ScreenToClient(mousepos).y;\r
-\r
-    ::PopupMenu( p_dialogs->p_intf,\r
-                 p_dialogs->OpenDlg, mouseevent.GetPosition() );\r
-}\r
-\r
-void Dialogs::OnExitThread( wxCommandEvent& event )\r
-{\r
-    wxTheApp->ExitMainLoop();\r
-}\r
-#endif // MODULE_NAME_IS_basic_skins\r
-\r
-/*****************************************************************************\r
- * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.\r
- *  We don't show the menu directly here because we don't want the\r
- *  caller to block for a too long time.\r
- *****************************************************************************/\r
-int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,\r
-                 vlc_value_t old_val, vlc_value_t new_val, void *param )\r
-{\r
-#if !defined(MODULE_NAME_IS_basic_skins)\r
-    Dialogs *p_dialogs = (Dialogs *)param;\r
-\r
-    p_dialogs->ShowPopup();\r
-#endif\r
-\r
-    return VLC_SUCCESS;\r
-}\r
+/*****************************************************************************
+ * dialogs.cpp: Handles all the different dialog boxes we provide.
+ *****************************************************************************
+ * Copyright (C) 2003 VideoLAN
+ * $Id: dialogs.cpp,v 1.10 2003/07/17 17:30:40 gbazin Exp $
+ *
+ * Authors: Gildas Bazin <gbazin@netcourrier.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * 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.
+ *****************************************************************************/
+
+//--- VLC -------------------------------------------------------------------
+#include <vlc/vlc.h>
+#include <vlc/intf.h>
+
+//--- SKIN ------------------------------------------------------------------
+#include "../os_api.h"
+#include "event.h"
+#include "banks.h"
+#include "theme.h"
+#include "../os_theme.h"
+#include "themeloader.h"
+#include "window.h"
+#include "vlcproc.h"
+#include "skin_common.h"
+#include "dialogs.h"
+
+/* Callback prototype */
+static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
+                       vlc_value_t old_val, vlc_value_t new_val, void *param );
+
+//---------------------------------------------------------------------------
+// Implementation of Dialogs class
+//---------------------------------------------------------------------------
+Dialogs::Dialogs( intf_thread_t *_p_intf )
+{
+    /* Errors while loading the dialogs provider are not fatal.
+     * Dialogs just won't be available. */
+
+    p_intf = _p_intf;
+    p_intf->p_sys->p_dialogs = this;
+    b_popup_change = VLC_FALSE;
+
+    /* Allocate descriptor */
+    p_provider = (intf_thread_t *)vlc_object_create( p_intf, VLC_OBJECT_INTF );
+    if( p_provider == NULL )
+    {
+        msg_Err( p_intf, "out of memory" );
+        return;
+    }
+
+    p_module = module_Need( p_provider, "dialogs provider", NULL );
+    if( p_module == NULL )
+    {
+        msg_Err( p_intf, "no suitable dialogs provider found" );
+        vlc_object_destroy( p_provider );
+        p_provider = NULL;
+        return;
+    }
+
+    /* Initialize dialogs provider
+     * (returns as soon as initialization is done) */
+    if( p_provider->pf_run ) p_provider->pf_run( p_provider );
+}
+
+Dialogs::~Dialogs()
+{
+    if( p_provider && p_module )
+    {
+        module_Unneed( p_provider, p_module );
+        vlc_object_destroy( p_provider );
+    }
+}
+
+void Dialogs::ShowDialog( intf_thread_t *p_intf, int i_dialog_event,
+                          int i_arg )
+{
+}
+
+void Dialogs::ShowOpen( bool b_play )
+{
+    if( p_provider && p_provider->pf_show_dialog )
+        p_provider->pf_show_dialog( p_provider, INTF_DIALOG_FILE, b_play );
+}
+
+void Dialogs::ShowOpenSkin()
+{
+    if( p_provider && p_provider->pf_show_dialog )
+        p_provider->pf_show_dialog( p_provider, INTF_DIALOG_FILE, 0 );
+}
+
+void Dialogs::ShowMessages()
+{
+    if( p_provider && p_provider->pf_show_dialog )
+        p_provider->pf_show_dialog( p_provider, INTF_DIALOG_MESSAGES, 0 );
+}
+
+void Dialogs::ShowPrefs()
+{
+    if( p_provider && p_provider->pf_show_dialog )
+        p_provider->pf_show_dialog( p_provider, INTF_DIALOG_PREFS, 0 );
+}
+
+void Dialogs::ShowFileInfo()
+{
+    if( p_provider && p_provider->pf_show_dialog )
+        p_provider->pf_show_dialog( p_provider, INTF_DIALOG_FILEINFO, 0 );
+}
+
+void Dialogs::ShowPopup()
+{
+}
+
+/*****************************************************************************
+ * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
+ *  We don't show the menu directly here because we don't want the
+ *  caller to block for a too long time.
+ *****************************************************************************/
+static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
+                        vlc_value_t old_val, vlc_value_t new_val, void *param )
+{
+    Dialogs *p_dialogs = (Dialogs *)param;
+    p_dialogs->ShowPopup();
+
+    return VLC_SUCCESS;
+}