]> git.sesse.net Git - vlc/blobdiff - modules/gui/wxwindows/dialogs.cpp
fix images, don't rescale them
[vlc] / modules / gui / wxwindows / dialogs.cpp
index cf41ce71b054d883ff777b3be9357b4467438a5d..c96ed6b10e06c1750851edfb6747215067d7eec2 100644 (file)
@@ -1,10 +1,10 @@
 /*****************************************************************************
  * dialogs.cpp : wxWindows plugin for vlc
  *****************************************************************************
- * Copyright (C) 2000-2001 VideoLAN
- * $Id: dialogs.cpp,v 1.2 2003/07/17 18:58:23 gbazin Exp $
+ * Copyright (C) 2000-2004 VideoLAN
+ * $Id$
  *
- * Authors: Gildas Bazin <gbazin@netcourrier.com>
+ * Authors: Gildas Bazin <gbazin@videolan.org>
  *
  * 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
 
 #include <vlc/vlc.h>
 #include <vlc/aout.h>
-
-#ifdef WIN32                                                 /* mingw32 hack */
-#undef Yield
-#undef CreateDialog
-#endif
-
-/* Let vlc take care of the i18n stuff */
-#define WXINTL_NO_GETTEXT_MACRO
-
-#include <wx/wxprec.h>
-#include <wx/wx.h>
-
 #include <vlc/intf.h>
-#include "stream_control.h"
 
 #include "wxwindows.h"
 
 /* include the icon graphic */
 #include "../../../share/vlc32x32.xpm"
 
+/* Dialogs Provider */
+class DialogsProvider: public wxFrame
+{
+public:
+    /* Constructor */
+    DialogsProvider( intf_thread_t *p_intf, wxWindow *p_parent );
+    virtual ~DialogsProvider();
+
+private:
+    void Open( int i_access_method, int i_arg );
+
+    /* Event handlers (these functions should _not_ be virtual) */
+    void OnExit( wxCommandEvent& event );
+    void OnPlaylist( wxCommandEvent& event );
+    void OnMessages( wxCommandEvent& event );
+    void OnFileInfo( wxCommandEvent& event );
+    void OnPreferences( wxCommandEvent& event );
+    void OnWizardDialog( wxCommandEvent& event );
+    void OnBookmarks( wxCommandEvent& event );
+
+    void OnOpenFileGeneric( wxCommandEvent& event );
+    void OnOpenFileSimple( wxCommandEvent& event );
+    void OnOpenFile( wxCommandEvent& event );
+    void OnOpenDisc( wxCommandEvent& event );
+    void OnOpenNet( wxCommandEvent& event );
+    void OnOpenCapture( wxCommandEvent& event );
+    void OnOpenSat( wxCommandEvent& event );
+
+    void OnPopupMenu( wxCommandEvent& event );
+
+    void OnIdle( wxIdleEvent& event );
+
+    void OnExitThread( wxCommandEvent& event );
+
+    DECLARE_EVENT_TABLE();
+
+    intf_thread_t *p_intf;
+
+public:
+    /* Secondary windows */
+    OpenDialog          *p_open_dialog;
+    wxFileDialog        *p_file_dialog;
+    Playlist            *p_playlist_dialog;
+    Messages            *p_messages_dialog;
+    FileInfo            *p_fileinfo_dialog;
+    WizardDialog        *p_wizard_dialog;
+    wxFrame             *p_prefs_dialog;
+    wxWindow            *p_bookmarks_dialog;
+    wxFileDialog        *p_file_generic_dialog;
+};
+
 DEFINE_LOCAL_EVENT_TYPE( wxEVT_DIALOG );
 
 BEGIN_EVENT_TABLE(DialogsProvider, wxFrame)
@@ -61,8 +99,12 @@ BEGIN_EVENT_TABLE(DialogsProvider, wxFrame)
     EVT_COMMAND(INTF_DIALOG_FILE, wxEVT_DIALOG, DialogsProvider::OnOpenFile)
     EVT_COMMAND(INTF_DIALOG_DISC, wxEVT_DIALOG, DialogsProvider::OnOpenDisc)
     EVT_COMMAND(INTF_DIALOG_NET, wxEVT_DIALOG, DialogsProvider::OnOpenNet)
+    EVT_COMMAND(INTF_DIALOG_CAPTURE, wxEVT_DIALOG,
+                DialogsProvider::OnOpenCapture)
     EVT_COMMAND(INTF_DIALOG_FILE_SIMPLE, wxEVT_DIALOG,
                 DialogsProvider::OnOpenFileSimple)
+    EVT_COMMAND(INTF_DIALOG_FILE_GENERIC, wxEVT_DIALOG,
+                DialogsProvider::OnOpenFileGeneric)
 
     EVT_COMMAND(INTF_DIALOG_PLAYLIST, wxEVT_DIALOG,
                 DialogsProvider::OnPlaylist)
@@ -70,12 +112,23 @@ BEGIN_EVENT_TABLE(DialogsProvider, wxFrame)
                 DialogsProvider::OnMessages)
     EVT_COMMAND(INTF_DIALOG_PREFS, wxEVT_DIALOG,
                 DialogsProvider::OnPreferences)
+    EVT_COMMAND(INTF_DIALOG_WIZARD, wxEVT_DIALOG,
+                DialogsProvider::OnWizardDialog)
     EVT_COMMAND(INTF_DIALOG_FILEINFO, wxEVT_DIALOG,
                 DialogsProvider::OnFileInfo)
+    EVT_COMMAND(INTF_DIALOG_BOOKMARKS, wxEVT_DIALOG,
+                DialogsProvider::OnBookmarks)
     EVT_COMMAND(INTF_DIALOG_POPUPMENU, wxEVT_DIALOG,
                 DialogsProvider::OnPopupMenu)
+    EVT_COMMAND(INTF_DIALOG_EXIT, wxEVT_DIALOG,
+                DialogsProvider::OnExitThread)
 END_EVENT_TABLE()
 
+wxWindow *CreateDialogsProvider( intf_thread_t *p_intf, wxWindow *p_parent )
+{
+    return new DialogsProvider( p_intf, p_parent );
+}
+
 /*****************************************************************************
  * Constructor.
  *****************************************************************************/
@@ -90,6 +143,9 @@ DialogsProvider::DialogsProvider( intf_thread_t *_p_intf, wxWindow *p_parent )
     p_messages_dialog = NULL;
     p_fileinfo_dialog = NULL;
     p_prefs_dialog = NULL;
+    p_file_generic_dialog = NULL;
+    p_wizard_dialog = NULL;
+    p_bookmarks_dialog = NULL;
 
     /* Give our interface a nice little icon */
     p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );
@@ -97,6 +153,11 @@ DialogsProvider::DialogsProvider( intf_thread_t *_p_intf, wxWindow *p_parent )
     /* Create the messages dialog so it can begin storing logs */
     p_messages_dialog = new Messages( p_intf, p_parent ? p_parent : this );
 
+    /* Check if user wants to show the bookmarks dialog by default */
+    wxCommandEvent dummy_event;
+    if( config_GetInt( p_intf, "wxwin-bookmarks" ) )
+        OnBookmarks( dummy_event );
+
     /* Intercept all menu events in our custom event handler */
     PushEventHandler( new MenuEvtHandler( p_intf, NULL ) );
 }
@@ -110,15 +171,25 @@ DialogsProvider::~DialogsProvider()
     if( p_playlist_dialog ) delete p_playlist_dialog;
     if( p_messages_dialog ) delete p_messages_dialog;
     if( p_fileinfo_dialog ) delete p_fileinfo_dialog;
+    if( p_file_generic_dialog ) delete p_file_generic_dialog;
+    if( p_wizard_dialog ) delete p_wizard_dialog;
+    if( p_bookmarks_dialog ) delete p_bookmarks_dialog;
+
 
     if( p_intf->p_sys->p_icon ) delete p_intf->p_sys->p_icon;
+
+    /* We must set this here because on win32 this destructor will be
+     * automatically called so we must not call it again on wxApp->OnExit().
+     * There shouldn't be any race conditions as all this should be done
+     * from the same thread. */
+    p_intf->p_sys->p_wxwindow = NULL;
 }
 
 void DialogsProvider::OnIdle( wxIdleEvent& WXUNUSED(event) )
 {
   /* Update the log window */
   if( p_messages_dialog )
-    p_messages_dialog->UpdateLog();
+//    p_messages_dialog->UpdateLog();
 
   /* Update the playlist */
   if( p_playlist_dialog )
@@ -177,6 +248,88 @@ void DialogsProvider::OnPreferences( wxCommandEvent& WXUNUSED(event) )
     }
 }
 
+void DialogsProvider::OnWizardDialog( wxCommandEvent& WXUNUSED(event) )
+{
+    p_wizard_dialog = new WizardDialog( p_intf, this, NULL, 0, 0 );
+
+    if( p_wizard_dialog )
+    {
+        p_wizard_dialog->Run();
+        delete p_wizard_dialog;
+    }
+
+    p_wizard_dialog = NULL;
+}
+
+void DialogsProvider::OnBookmarks( wxCommandEvent& WXUNUSED(event) )
+{
+    /* Show/hide the open dialog */
+    if( !p_bookmarks_dialog )
+        p_bookmarks_dialog = BookmarksDialog( p_intf, this );
+
+    if( p_bookmarks_dialog )
+    {
+        p_bookmarks_dialog->Show( !p_bookmarks_dialog->IsShown() );
+    }
+}
+
+void DialogsProvider::OnOpenFileGeneric( wxCommandEvent& event )
+{
+    intf_dialog_args_t *p_arg = (intf_dialog_args_t *)event.GetClientData();
+
+    if( p_arg == NULL )
+    {
+        msg_Dbg( p_intf, "OnOpenFileGeneric() called with NULL arg" );
+        return;
+    }
+
+    if( p_file_generic_dialog == NULL )
+        p_file_generic_dialog = new wxFileDialog( NULL );
+
+    if( p_file_generic_dialog )
+    {
+        p_file_generic_dialog->SetMessage( wxU(p_arg->psz_title) );
+        p_file_generic_dialog->SetWildcard( wxU(p_arg->psz_extensions) );
+        p_file_generic_dialog->SetStyle( (p_arg->b_save ? wxSAVE : wxOPEN) |
+                                         (p_arg->b_multiple ? wxMULTIPLE:0) );
+    }
+
+    if( p_file_generic_dialog &&
+        p_file_generic_dialog->ShowModal() == wxID_OK )
+    {
+        wxArrayString paths;
+
+        p_file_generic_dialog->GetPaths( paths );
+
+        p_arg->i_results = paths.GetCount();
+        p_arg->psz_results = (char **)malloc( p_arg->i_results *
+                                              sizeof(char *) );
+        for( size_t i = 0; i < paths.GetCount(); i++ )
+        {
+            p_arg->psz_results[i] = strdup( paths[i].mb_str() );
+        }
+    }
+
+    /* Callback */
+    if( p_arg->pf_callback )
+    {
+        p_arg->pf_callback( p_arg );
+    }
+
+    if( p_arg->psz_results )
+    {
+        for( int i = 0; i < p_arg->i_results; i++ )
+        {
+            free( p_arg->psz_results[i] );
+        }
+        free( p_arg->psz_results );
+    }
+    if( p_arg->psz_title ) free( p_arg->psz_title );
+    if( p_arg->psz_extensions ) free( p_arg->psz_extensions );
+
+    free( p_arg );
+}
+
 void DialogsProvider::OnOpenFileSimple( wxCommandEvent& event )
 {
     playlist_t *p_playlist =
@@ -188,7 +341,7 @@ void DialogsProvider::OnOpenFileSimple( wxCommandEvent& event )
     }
 
     if( p_file_dialog == NULL )
-        p_file_dialog = new wxFileDialog( this, wxU(_("Open file")),
+        p_file_dialog = new wxFileDialog( NULL, wxU(_("Open File")),
             wxT(""), wxT(""), wxT("*"), wxOPEN | wxMULTIPLE );
 
     if( p_file_dialog && p_file_dialog->ShowModal() == wxID_OK )
@@ -200,10 +353,12 @@ void DialogsProvider::OnOpenFileSimple( wxCommandEvent& event )
         for( size_t i = 0; i < paths.GetCount(); i++ )
             if( event.GetInt() )
                 playlist_Add( p_playlist, (const char *)paths[i].mb_str(),
+                              (const char *)paths[i].mb_str(),
                               PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO),
                               PLAYLIST_END );
             else
                 playlist_Add( p_playlist, (const char *)paths[i].mb_str(),
+                              (const char *)paths[i].mb_str(),
                               PLAYLIST_APPEND, PLAYLIST_END );
     }
 
@@ -225,16 +380,17 @@ void DialogsProvider::OnOpenNet( wxCommandEvent& event )
     Open( NET_ACCESS, event.GetInt() );
 }
 
-void DialogsProvider::OnOpenSat( wxCommandEvent& event )
+void DialogsProvider::OnOpenCapture( wxCommandEvent& event )
 {
-    Open( SAT_ACCESS, event.GetInt() );
+    Open( CAPTURE_ACCESS, event.GetInt() );
 }
 
 void DialogsProvider::Open( int i_access_method, int i_arg )
 {
     /* Show/hide the open dialog */
     if( !p_open_dialog )
-        p_open_dialog = new OpenDialog( p_intf, this, i_access_method, i_arg );
+        p_open_dialog = new OpenDialog( p_intf, this, i_access_method, i_arg,
+                                        OPEN_NORMAL );
 
     if( p_open_dialog )
     {
@@ -244,14 +400,11 @@ void DialogsProvider::Open( int i_access_method, int i_arg )
 
 void DialogsProvider::OnPopupMenu( wxCommandEvent& event )
 {
-    wxPoint mousepos = wxGetMousePosition();
-
-#if 0
-    wxMouseEvent event = wxMouseEvent( wxEVT_RIGHT_UP );
-    event.m_x = p_main_interface->ScreenToClient(mousepos).x;
-    event.m_y = p_main_interface->ScreenToClient(mousepos).y;
-#endif
-
+    wxPoint mousepos = ScreenToClient( wxGetMousePosition() );
     ::PopupMenu( p_intf, this, mousepos );
+}
 
+void DialogsProvider::OnExitThread( wxCommandEvent& WXUNUSED(event) )
+{
+    wxTheApp->ExitMainLoop();
 }