]> git.sesse.net Git - vlc/commitdiff
* modules/gui/wxwindows/*: misc improvements to the main interface, implementation of
authorGildas Bazin <gbazin@videolan.org>
Sat, 23 Nov 2002 14:28:51 +0000 (14:28 +0000)
committerGildas Bazin <gbazin@videolan.org>
Sat, 23 Nov 2002 14:28:51 +0000 (14:28 +0000)
drag and drop, proper initialisation of the i18n routines.

modules/gui/wxwindows/interface.cpp
modules/gui/wxwindows/playlist.cpp
modules/gui/wxwindows/timer.cpp
modules/gui/wxwindows/wxwindows.cpp
modules/gui/wxwindows/wxwindows.h

index fe223047072db72350ae5b21a22392f9cf579ad5..bf0b7bebf83562cec4aab2e3c62d1cb987c1a1d3 100644 (file)
@@ -2,7 +2,7 @@
  * interface.cpp : wxWindows plugin for vlc
  *****************************************************************************
  * Copyright (C) 2000-2001 VideoLAN
- * $Id: interface.cpp,v 1.6 2002/11/23 01:32:40 ipkiss Exp $
+ * $Id: interface.cpp,v 1.7 2002/11/23 14:28:51 gbazin Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
 #include <string.h>                                            /* strerror() */
 #include <stdio.h>
 
-#include <vlc/vlc.h>
-#include <vlc/intf.h>
+#include <wx/wxprec.h>
+#include <wx/wx.h>
 
-/* Let wxWindows take care of the i18n stuff */
+/* Let vlc take care of the i18n stuff */
 #undef _
 
 #ifdef WIN32                                                 /* mingw32 hack */
@@ -40,8 +40,8 @@
 #undef CreateDialog
 #endif
 
-#include <wx/wxprec.h>
-#include <wx/wx.h>
+#include <vlc/vlc.h>
+#include <vlc/intf.h>
 
 #include "wxwindows.h"
 
 #include "bitmaps/next.xpm"
 #include "bitmaps/playlist.xpm"
 
+/* include the icon graphic */
+#include "share/vlc32x32.xpm"
+
+/*****************************************************************************
+ * Local class declarations.
+ *****************************************************************************/
+
 /*****************************************************************************
  * Event Table.
  *****************************************************************************/
@@ -118,20 +125,69 @@ Interface::Interface( intf_thread_t *_p_intf ):
     wxFrame( NULL, -1, "title", wxDefaultPosition, wxDefaultSize,
              wxDEFAULT_FRAME_STYLE )
 {
-
     /* Initializations */
     p_intf = _p_intf;
 
-    /* Give our interface a nice icon */
-    //SetIcon( wxICON(vlcicon) );
+    /* Give our interface a nice little icon */
+    SetIcon( *new wxIcon( vlc_xpm ) );
+
+    /* Create a sizer for the main frame */
+    frame_sizer = new wxBoxSizer( wxHORIZONTAL );
+    SetSizer( frame_sizer );
+
+    /* Creation of the menu bar */
+    CreateOurMenuBar();
+
+    /* Creation of the tool bar */
+    CreateOurToolBar();
+
+    /* Creation of the slider sub-window */
+    CreateOurSlider();
+
+    /* Creation of the status bar 
+     * Helptext for menu items and toolbar tools will automatically get
+     * displayed here. */
+    int i_status_width[2] = {-2,-3};
+    statusbar = CreateStatusBar( 2 );                            /* 2 fields */
+    statusbar->SetStatusWidths( 2, i_status_width );
+
+    SetTitle( COPYRIGHT_MESSAGE );
+
+    /* Layout everything */
+    SetAutoLayout( TRUE );
+    frame_sizer->Layout();
+    frame_sizer->SetSizeHints(this);
+
+    /* Associate drop targets with the main interface */
+    SetDropTarget( new DragAndDrop( p_intf ) );
+}
+
+Interface::~Interface()
+{
+}
 
-    /* Create our "File" menu */
+/*****************************************************************************
+ * Private methods.
+ *****************************************************************************/
+void Interface::CreateOurMenuBar()
+{
 #define HELP_FILE  N_("Open a file")
 #define HELP_DISC  N_("Open a DVD or (S)VCD")
 #define HELP_NET   N_("Open a network stream")
 #define HELP_SAT   N_("Open a satellite stream")
 #define HELP_EJECT N_("Eject the DVD/CD")
 #define HELP_EXIT  N_("Exit this program")
+
+#define HELP_PLAYLIST   N_("Open the playlist")
+#define HELP_LOGS       N_("Show the program logs")
+
+#define HELP_AUDIO N_("Change the current audio track")
+#define HELP_SUBS  N_("Change the current subtitles stream")
+#define HELP_PREFS N_("Go to the preferences menu")
+
+#define HELP_ABOUT N_("About this program")
+
+    /* Create the "File" menu */
     wxMenu *file_menu = new wxMenu;
     file_menu->Append( OpenFile_Event, _("&Open File..."), HELP_FILE );
     file_menu->Append( OpenDisc_Event, _("Open &Disc..."), HELP_DISC );
@@ -144,25 +200,19 @@ Interface::Interface( intf_thread_t *_p_intf ):
     file_menu->AppendSeparator();
     file_menu->Append( Exit_Event, _("E&xit"), HELP_EXIT );
 
-    /* Create our "View" menu */
-#define HELP_PLAYLIST   N_("Open the playlist")
-#define HELP_LOGS       N_("Show the program logs")
+    /* Create the "View" menu */
     wxMenu *view_menu = new wxMenu;
     view_menu->Append( Playlist_Event, _("&Playlist..."), HELP_PLAYLIST );
     view_menu->Append( Logs_Event, _("&Logs..."), HELP_LOGS );
 
-    /* Create our "Settings" menu */
-#define HELP_AUDIO N_("Change the current audio track")
-#define HELP_SUBS  N_("Change the current subtitles stream")
-#define HELP_PREFS N_("Go to the preferences menu")
+    /* Create the "Settings" menu */
     wxMenu *settings_menu = new wxMenu;
     settings_menu->Append( Audio_Event, _("&Audio"), HELP_AUDIO );
     settings_menu->Append( Subtitles_Event, _("&Subtitles"), HELP_SUBS );
     settings_menu->AppendSeparator();
     settings_menu->Append( Prefs_Event, _("&Preferences..."), HELP_PREFS );
 
-    /* Create our "Help" menu */
-#define HELP_ABOUT N_("About this program")
+    /* Create the "Help" menu */
     wxMenu *help_menu = new wxMenu;
     help_menu->Append( About_Event, _("&About..."), HELP_ABOUT );
 
@@ -176,13 +226,19 @@ Interface::Interface( intf_thread_t *_p_intf ):
     /* Attach the menu bar to the frame */
     SetMenuBar( menubar );
 
-    /* Create toolbar */
+    /* Associate drop targets with the menubar */
+    menubar->SetDropTarget( new DragAndDrop( p_intf ) );
+}
+
+void Interface::CreateOurToolBar()
+{
 #define HELP_STOP N_("Stop current playlist item")
 #define HELP_PLAY N_("Play current playlist item")
 #define HELP_PAUSE N_("Pause current playlist item")
 #define HELP_PLO N_("Open playlist")
 #define HELP_PLP N_("Previous playlist item")
 #define HELP_PLN N_("Next playlist item")
+
     wxBitmap *p_bmp_file     = new wxBitmap( file_xpm );
     wxBitmap *p_bmp_disc     = new wxBitmap( disc_xpm );
     wxBitmap *p_bmp_net      = new wxBitmap( net_xpm );
@@ -214,44 +270,41 @@ Interface::Interface( intf_thread_t *_p_intf ):
 
     toolbar->Realize();
 
-    /* Place the toolbar in a sizer, so that the window will stretch
-     * to get its size */
-    wxBoxSizer *toolbar_sizer = new wxBoxSizer( wxVERTICAL );
-    toolbar_sizer->Add( toolbar, 0 );
-    toolbar_sizer->SetSizeHints( this );
+    /* Place the toolbar in a sizer, so we can calculate the width of the
+     * toolbar and set this as the minimum for the main frame size. */
+    wxBoxSizer *toolbar_sizer = new wxBoxSizer( wxHORIZONTAL );
+    toolbar_sizer->Add( toolbar, 0, 0, 0 );
+    toolbar_sizer->Layout();
+    frame_sizer->SetMinSize( toolbar_sizer->GetMinSize().GetWidth(), -1 );
 
-    /* Create slider */
-    wxBoxSizer *slider_sizer = new wxBoxSizer( wxVERTICAL );
-    slider = new wxSlider( this, SliderScroll_Event, 0, 0, 100,
-                           wxDefaultPosition, wxSize( 450, 50 ),
-                           wxSL_HORIZONTAL | wxSL_TOP );
-    slider_sizer->Add( slider, 0, wxGROW | wxALL | wxALIGN_CENTER, 5 );
-
-    /* use the sizer for layout */
-    slider->Hide();
-    slider_sizer->Layout();
-    SetSizerAndFit( slider_sizer );
-
-    /* Give the frame an optional statusbar. The '1' just means one field.
-     * A gripsizer will automatically get put on into the corner, if that
-     * is the normal OS behaviour for frames on that platform. Helptext
-     * for menu items and toolbar tools will automatically get displayed
-     * here. */
-    statusbar = CreateStatusBar(2);
-    int i_status_width[2] = {-2,-3};
-    statusbar->SetStatusWidths( 2, i_status_width );
-
-    SetTitle( COPYRIGHT_MESSAGE );
-    SetAutoLayout( TRUE );
-    Layout();
+    /* Associate drop targets with the toolbar */
+    toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
 }
 
-Interface::~Interface()
+void Interface::CreateOurSlider()
 {
+    /* Create a new frame containing the slider */
+    slider_frame = new wxPanel( this, -1, wxDefaultPosition, wxSize(-1,50) );
+    slider_frame->SetAutoLayout( TRUE );
+    slider_frame->Hide();
+
+    /* Create static box to surround the slider */
+    slider_box = new wxStaticBox( slider_frame, -1, "" );
+
+    /* Create sizer for slider frame */
+    wxStaticBoxSizer *slider_sizer =
+        new wxStaticBoxSizer( slider_box, wxHORIZONTAL );
+    slider_frame->SetSizer( slider_sizer );
+
+    /* Create slider */
+    slider = new wxSlider( slider_frame, SliderScroll_Event, 0, 0,
+                           SLIDER_MAX_POS, wxDefaultPosition, wxDefaultSize );
+    slider_sizer->Add( slider, 1, wxGROW | wxALL, 5 );
+    slider_sizer->Layout();
 }
 
 /*****************************************************************************
- * Private methods.
+ * Event Handlers.
  *****************************************************************************/
 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
 {
@@ -387,3 +440,38 @@ void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
     playlist_Next( p_playlist );
     vlc_object_release( p_playlist );
 }
+
+/*****************************************************************************
+ * Definition of DragAndDrop class.
+ *****************************************************************************/
+DragAndDrop::DragAndDrop( intf_thread_t *_p_intf )
+{
+    p_intf = _p_intf;
+}
+
+bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
+                               const wxArrayString& filenames )
+{
+    unsigned int i;
+
+    /* Add dropped files to the playlist */
+
+    playlist_t *p_playlist =
+        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
+                                       FIND_ANYWHERE );
+    if( p_playlist == NULL )
+    {
+        return FALSE;
+    }
+
+    for( i = 0; i < filenames.GetCount(); i++ )
+        playlist_Add( p_playlist, (char *)filenames[i].c_str(),
+                      PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
+
+    /* Rebuild the playlist */
+    p_intf->p_sys->p_playlist_window->Rebuild();
+
+    vlc_object_release( p_playlist );
+
+    return TRUE;
+}
index c68a3efb2448c120a766d3ed39e8ce317db177a7..b5943beb0bf2107ba7edea86cff78d63d9728917 100644 (file)
 #include <string.h>                                            /* strerror() */
 #include <stdio.h>
 
-#include <vlc/vlc.h>
-#include <vlc/intf.h>
+#include <wx/wxprec.h>
+#include <wx/wx.h>
+#include <wx/listctrl.h>
 
-/* Let wxWindows take care of the i18n stuff */
+/* Let vlc take care of the i18n stuff */
 #undef _
 
 #ifdef WIN32                                                 /* mingw32 hack */
-#undef Yield()
-#undef CreateDialog()
+#undef Yield
+#undef CreateDialog
 #endif
 
-#include <wx/wxprec.h>
-#include <wx/wx.h>
-#include <wx/listctrl.h>
+#include <vlc/vlc.h>
+#include <vlc/intf.h>
 
 #include "wxwindows.h"
 
@@ -143,6 +143,13 @@ Playlist::Playlist( intf_thread_t *_p_intf, Interface *_p_main_interface ):
     main_sizer->Add( ok_button_sizer, 0, wxALIGN_CENTRE );
 
     SetSizerAndFit( main_sizer );
+
+    /* Associate drop targets with the playlist */
+    SetDropTarget( new DragAndDrop( p_intf ) );
+
+    /* Update the playlist */
+    Rebuild();
+
 }
 
 Playlist::~Playlist()
index 75f8cdc1cb380bd2724da7dbb406e8c8d2544a1e..c6ea022b941b0ad728868db52468781b18a186cf 100644 (file)
@@ -2,7 +2,7 @@
  * timer.cpp : wxWindows plugin for vlc
  *****************************************************************************
  * Copyright (C) 2000-2001 VideoLAN
- * $Id: timer.cpp,v 1.3 2002/11/23 01:32:40 ipkiss Exp $
+ * $Id: timer.cpp,v 1.4 2002/11/23 14:28:51 gbazin Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
 #include <string.h>                                            /* strerror() */
 #include <stdio.h>
 
-#include <vlc/vlc.h>
-#include <vlc/intf.h>
+#include <wx/wxprec.h>
+#include <wx/wx.h>
+#include <wx/timer.h>
 
-/* Let wxWindows take care of the i18n stuff */
+/* Let vlc take care of the i18n stuff */
 #undef _
 
 #ifdef WIN32                                                 /* mingw32 hack */
 #undef CreateDialog
 #endif
 
-#include <wx/wxprec.h>
-#include <wx/wx.h>
-#include <wx/timer.h>
+#include <vlc/vlc.h>
+#include <vlc/intf.h>
 
 #include "wxwindows.h"
 
+void DisplayStreamDate( wxControl *, intf_thread_t *, int );
+
 /*****************************************************************************
  * Constructor.
  *****************************************************************************/
@@ -94,7 +96,7 @@ static int wxSetupMenus( intf_thread_t * p_intf )
  *****************************************************************************/
 void Timer::Notify()
 {
-    int i_start, i_stop;
+    int i_stop;
 
     vlc_mutex_lock( &p_intf->change_lock );
 
@@ -111,6 +113,7 @@ void Timer::Notify()
 
     if( p_intf->p_sys->p_sub->i_start != i_stop )
     {
+        /* Append all messages to log window */
     }
 
     /* Update the playlist */
@@ -125,7 +128,11 @@ void Timer::Notify()
         /* Show slider */
         if(p_intf->p_sys->p_input)
         {
-            p_main_interface->slider->Show();
+            p_main_interface->frame_sizer->Add(
+                p_main_interface->slider_frame, 1, wxGROW, 0 );
+            p_main_interface->slider_frame->Show();
+            p_main_interface->frame_sizer->Layout();
+            p_main_interface->frame_sizer->Fit( p_main_interface );
             p_main_interface->statusbar->SetStatusText(
                 p_intf->p_sys->p_input->psz_source, 1 );
         }
@@ -134,7 +141,13 @@ void Timer::Notify()
     {
         /* Hide slider */
         if(p_intf->p_sys->p_input)
-            p_main_interface->slider->Hide();
+        {
+            p_main_interface->slider_frame->Hide();
+            p_main_interface->frame_sizer->Remove(
+                p_main_interface->slider_frame );
+            p_main_interface->frame_sizer->Layout();
+            p_main_interface->frame_sizer->Fit( p_main_interface );
+        }
 
         p_main_interface->statusbar->SetStatusText( "", 1 );
 
@@ -174,7 +187,7 @@ void Timer::Notify()
                     input_Tell( p_input, &position );
                     vlc_mutex_lock( &p_input->stream.stream_lock );
                     p_intf->p_sys->i_slider_oldpos =
-                        ( 100 * position.i_tell ) / position.i_size;
+                        ( SLIDER_MAX_POS * position.i_tell ) / position.i_size;
 
                     if( p_intf->p_sys->i_slider_pos !=
                         p_intf->p_sys->i_slider_oldpos )
@@ -184,6 +197,10 @@ void Timer::Notify()
 
                         p_main_interface->slider->SetValue(
                             p_intf->p_sys->i_slider_pos );
+
+                        DisplayStreamDate( p_main_interface->slider_box,
+                                           p_intf,
+                                           p_intf->p_sys->i_slider_pos );
                     }
                 }
 
@@ -193,7 +210,8 @@ void Timer::Notify()
                 {
                     /* release the lock to be able to seek */
                     vlc_mutex_unlock( &p_input->stream.stream_lock );
-                    input_Seek( p_input, p_intf->p_sys->i_slider_pos,
+                    input_Seek( p_input, p_intf->p_sys->i_slider_pos *
+                                100 / SLIDER_MAX_POS,
                                 INPUT_SEEK_PERCENT | INPUT_SEEK_SET );
                     vlc_mutex_lock( &p_input->stream.stream_lock );
 
@@ -230,3 +248,26 @@ void Timer::Notify()
 
     vlc_mutex_unlock( &p_intf->change_lock );
 }
+
+/*****************************************************************************
+ * DisplayStreamDate: display stream date
+ *****************************************************************************
+ * This function displays the current date related to the position in
+ * the stream. It is called whenever the slider changes its value.
+ * The lock has to be taken before you call the function.
+ *****************************************************************************/
+void DisplayStreamDate( wxControl *p_slider_frame, intf_thread_t * p_intf ,
+                        int i_pos )
+{
+    if( p_intf->p_sys->p_input )
+    {
+#define p_area p_intf->p_sys->p_input->stream.p_selected_area
+        char psz_time[ OFFSETTOTIME_MAX_SIZE ];
+
+        p_slider_frame->SetLabel(
+            input_OffsetToTime( p_intf->p_sys->p_input,
+                                psz_time,
+                                p_area->i_size * i_pos / SLIDER_MAX_POS ) );
+#undef p_area
+     }
+}
index ab8bc6fdc8caba3635a5c036a7cf3fc632f8e432..bfab686d797274cf116a393fe60a4eadf658aefe 100644 (file)
@@ -2,7 +2,7 @@
  * wxwindows.cpp : wxWindows plugin for vlc
  *****************************************************************************
  * Copyright (C) 2000-2001 VideoLAN
- * $Id: wxwindows.cpp,v 1.4 2002/11/23 01:32:40 ipkiss Exp $
+ * $Id: wxwindows.cpp,v 1.5 2002/11/23 14:28:51 gbazin Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
 #include <string.h>                                            /* strerror() */
 #include <stdio.h>
 
-#include <vlc/vlc.h>
-#include <vlc/intf.h>
+#include <wx/wxprec.h>
+#include <wx/wx.h>
 
-/* Let wxWindows take care of the i18n stuff */
+/* Let vlc take care of the i18n stuff */
 #undef _
 
 #ifdef WIN32                                                 /* mingw32 hack */
@@ -40,9 +40,8 @@
 #undef CreateDialog
 #endif
 
-#include <wx/wxprec.h>
-#include <wx/wx.h>
-#include <wx/imagpng.h>
+#include <vlc/vlc.h>
+#include <vlc/intf.h>
 
 #include "wxwindows.h"
 
@@ -67,6 +66,7 @@ public:
 
 private:
     intf_thread_t *p_intf;
+    wxLocale locale;                                /* locale we'll be using */
 };
 
 /*****************************************************************************
@@ -175,6 +175,11 @@ IMPLEMENT_APP_NO_MAIN(Instance)
  *****************************************************************************/
 bool Instance::OnInit()
 {
+    /* Initialization of i18n stuff.
+     * Usefull for things we don't have any control over, like wxWindows
+     * provided facilities (eg. open file dialog) */
+    locale.Init( wxLANGUAGE_DEFAULT );
+
     /* Make an instance of your derived frame. Passing NULL (the default value
      * of Frame's constructor is NULL) as the frame doesn't have a frame
      * since it is the first window */
index 7f4ae6a1d76ba17f24c8a7d3e05e3570a6cec8fc..a2f619b53aae2ec0c6b57cd2a80ed41d6dd0755c 100644 (file)
@@ -2,7 +2,7 @@
  * wxwindows.h: private wxWindows interface description
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: wxwindows.h,v 1.2 2002/11/23 01:32:40 ipkiss Exp $
+ * $Id: wxwindows.h,v 1.3 2002/11/23 14:28:51 gbazin Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
  *****************************************************************************/
 
 #include <wx/listctrl.h>
+#include <wx/dnd.h>
 
 class Playlist;
 
+#define SLIDER_MAX_POS 10000
+
 /*****************************************************************************
  * intf_sys_t: description and status of Gtk+ interface
  *****************************************************************************/
@@ -102,10 +105,19 @@ public:
     /* Constructor */
     Interface( intf_thread_t *p_intf );
     virtual ~Interface();
-    wxSlider *slider;
+
+    wxBoxSizer  *frame_sizer;
     wxStatusBar *statusbar;
 
+    wxSlider    *slider;
+    wxWindow    *slider_frame;
+    wxStaticBox *slider_box;
+
 private:
+    void CreateOurMenuBar();
+    void CreateOurToolBar();
+    void CreateOurSlider();
+
     /* Event handlers (these functions should _not_ be virtual) */
     void OnExit( wxCommandEvent& event );
     void OnAbout( wxCommandEvent& event );
@@ -153,3 +165,16 @@ private:
     wxListView *listview;
     wxButton *ok_button;
 };
+
+/* Drag and Drop class */
+class DragAndDrop: public wxFileDropTarget
+{
+public:
+    DragAndDrop( intf_thread_t *_p_intf );
+
+    virtual bool OnDropFiles( wxCoord x, wxCoord y,
+                              const wxArrayString& filenames );
+
+private:
+    intf_thread_t *p_intf;
+};