1 /*****************************************************************************
2 * interface.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: interface.cpp,v 1.22 2003/05/04 22:42:16 gbazin Exp $
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <errno.h> /* ENOMEM */
29 #include <string.h> /* strerror() */
34 #ifdef WIN32 /* mingw32 hack */
39 /* Let vlc take care of the i18n stuff */
40 #define WXINTL_NO_GETTEXT_MACRO
42 #include <wx/wxprec.h>
46 #include "stream_control.h"
48 #include "wxwindows.h"
50 /* include the toolbar graphics */
51 #include "bitmaps/file.xpm"
52 #include "bitmaps/disc.xpm"
53 #include "bitmaps/net.xpm"
55 #include "bitmaps/sat.xpm"
57 #include "bitmaps/play.xpm"
58 #include "bitmaps/pause.xpm"
59 #include "bitmaps/stop.xpm"
60 #include "bitmaps/previous.xpm"
61 #include "bitmaps/next.xpm"
62 #include "bitmaps/playlist.xpm"
63 #define TOOLBAR_BMP_WIDTH 24
64 #define TOOLBAR_BMP_HEIGHT 24
66 /* include the icon graphic */
67 #include "share/vlc32x32.xpm"
69 /*****************************************************************************
70 * Local class declarations.
71 *****************************************************************************/
72 class wxMenuExt: public wxMenu
76 wxMenuExt( wxMenu* parentMenu, int id, const wxString& text,
77 const wxString& helpString, wxItemKind kind,
78 char *_psz_var, int _i_object_id, vlc_value_t _val,
81 virtual ~wxMenuExt() {};
92 /*****************************************************************************
94 *****************************************************************************/
96 /* IDs for the controls and the menu commands */
100 Exit_Event = wxID_HIGHEST,
121 /* it is important for the id corresponding to the "About" command to have
122 * this standard value as otherwise it won't be handled properly under Mac
123 * (where it is special and put into the "Apple" menu) */
124 About_Event = wxID_ABOUT
127 BEGIN_EVENT_TABLE(Interface, wxFrame)
129 EVT_MENU(Exit_Event, Interface::OnExit)
130 EVT_MENU(About_Event, Interface::OnAbout)
131 EVT_MENU(Playlist_Event, Interface::OnPlaylist)
132 EVT_MENU(Logs_Event, Interface::OnLogs)
133 EVT_MENU(FileInfo_Event, Interface::OnFileInfo)
134 EVT_MENU(Prefs_Event, Interface::OnPreferences)
136 EVT_MENU_OPEN(Interface::OnMenuOpen)
137 EVT_MENU_CLOSE(Interface::OnMenuClose)
141 EVT_MENU(OpenFile_Event, Interface::OnOpenFile)
142 EVT_MENU(OpenDisc_Event, Interface::OnOpenDisc)
143 EVT_MENU(OpenNet_Event, Interface::OnOpenNet)
144 EVT_MENU(OpenSat_Event, Interface::OnOpenSat)
145 EVT_MENU(StopStream_Event, Interface::OnStopStream)
146 EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
147 EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
148 EVT_MENU(NextStream_Event, Interface::OnNextStream)
151 EVT_COMMAND_SCROLL(SliderScroll_Event, Interface::OnSliderUpdate)
154 /*****************************************************************************
156 *****************************************************************************/
157 Interface::Interface( intf_thread_t *_p_intf ):
158 wxFrame( NULL, -1, VOUT_TITLE,
159 wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE )
161 /* Initializations */
163 p_prefs_dialog = NULL;
164 i_old_playing_status = PAUSE_S;
166 /* Give our interface a nice little icon */
167 p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );
168 SetIcon( *p_intf->p_sys->p_icon );
170 /* Create a sizer for the main frame */
171 frame_sizer = new wxBoxSizer( wxHORIZONTAL );
172 SetSizer( frame_sizer );
174 /* Creation of the menu bar */
177 /* Creation of the tool bar */
180 /* Creation of the slider sub-window */
182 frame_sizer->Add( slider_frame, 1, wxGROW, 0 );
183 frame_sizer->Hide( slider_frame );
185 /* Creation of the status bar
186 * Helptext for menu items and toolbar tools will automatically get
188 int i_status_width[2] = {-2,-3};
189 statusbar = CreateStatusBar( 2 ); /* 2 fields */
190 statusbar->SetStatusWidths( 2, i_status_width );
192 /* Make sure we've got the right background colour */
193 SetBackgroundColour( slider_frame->GetBackgroundColour() );
195 /* Layout everything */
196 SetAutoLayout( TRUE );
197 frame_sizer->Layout();
198 frame_sizer->Fit(this);
200 #if !defined(__WXX11__)
201 /* Associate drop targets with the main interface */
202 SetDropTarget( new DragAndDrop( p_intf ) );
206 Interface::~Interface()
208 if( p_prefs_dialog ) p_prefs_dialog->Destroy();
211 /*****************************************************************************
213 *****************************************************************************/
214 void Interface::CreateOurMenuBar()
216 #define HELP_FILE N_("Open a file")
217 #define HELP_DISC N_("Open a DVD or (S)VCD")
218 #define HELP_NET N_("Open a network stream")
219 #define HELP_SAT N_("Open a satellite stream")
220 #define HELP_EJECT N_("Eject the DVD/CD")
221 #define HELP_EXIT N_("Exit this program")
223 #define HELP_PLAYLIST N_("Open the playlist")
224 #define HELP_LOGS N_("Show the program logs")
225 #define HELP_FILEINFO N_("Show information about the file being played")
227 #define HELP_AUDIO N_("Change the current audio track")
228 #define HELP_SUBS N_("Change the current subtitles stream")
229 #define HELP_PREFS N_("Go to the preferences menu")
231 #define HELP_ABOUT N_("About this program")
233 /* Create the "File" menu */
234 wxMenu *file_menu = new wxMenu;
235 file_menu->Append( OpenFile_Event, _("&Open File..."), HELP_FILE );
236 file_menu->Append( OpenDisc_Event, _("Open &Disc..."), HELP_DISC );
237 file_menu->Append( OpenNet_Event, _("&Network Stream..."), HELP_NET );
239 file_menu->Append( OpenSat_Event, _("&Satellite Stream..."), HELP_NET );
241 file_menu->AppendSeparator();
242 file_menu->Append( EjectDisc_Event, _("&Eject Disc"), HELP_EJECT );
243 file_menu->AppendSeparator();
244 file_menu->Append( Exit_Event, _("E&xit"), HELP_EXIT );
246 /* Create the "View" menu */
247 wxMenu *view_menu = new wxMenu;
248 view_menu->Append( Playlist_Event, _("&Playlist..."), HELP_PLAYLIST );
249 view_menu->Append( Logs_Event, _("&Logs..."), HELP_LOGS );
250 view_menu->Append( FileInfo_Event, _("&File info..."), HELP_FILEINFO );
252 /* Create the "Settings" menu */
253 wxMenu *settings_menu = new wxMenu;
254 settings_menu->Append( Subtitles_Event, _("&Subtitles"), HELP_SUBS );
255 settings_menu->AppendSeparator();
256 settings_menu->Append( Prefs_Event, _("&Preferences..."), HELP_PREFS );
258 /* Create the "Audio" menu */
259 p_audio_menu = new wxMenu;
262 /* Create the "Video" menu */
263 p_video_menu = new wxMenu;
266 /* Create the "Help" menu */
267 wxMenu *help_menu = new wxMenu;
268 help_menu->Append( About_Event, _("&About..."), HELP_ABOUT );
270 /* Append the freshly created menus to the menu bar... */
271 wxMenuBar *menubar = new wxMenuBar( wxMB_DOCKABLE );
272 menubar->Append( file_menu, _("&File") );
273 menubar->Append( view_menu, _("&View") );
274 menubar->Append( settings_menu, _("&Settings") );
275 menubar->Append( p_audio_menu, _("&Audio") );
276 menubar->Append( p_video_menu, _("&Video") );
277 menubar->Append( help_menu, _("&Help") );
279 /* Attach the menu bar to the frame */
280 SetMenuBar( menubar );
282 /* Intercept all menu events in our custom event handler */
283 PushEventHandler( new MenuEvtHandler( p_intf, this ) );
285 #if !defined(__WXX11__)
286 /* Associate drop targets with the menubar */
287 menubar->SetDropTarget( new DragAndDrop( p_intf ) );
291 void Interface::CreateOurToolBar()
293 #define HELP_STOP N_("Stop current playlist item")
294 #define HELP_PLAY N_("Play current playlist item")
295 #define HELP_PAUSE N_("Pause current playlist item")
296 #define HELP_PLO N_("Open playlist")
297 #define HELP_PLP N_("Previous playlist item")
298 #define HELP_PLN N_("Next playlist item")
300 wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
301 * version because we don't include wx.rc */
303 wxToolBar *toolbar = CreateToolBar(
304 wxTB_HORIZONTAL | wxTB_TEXT | wxTB_FLAT | wxTB_DOCKABLE );
306 toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
308 toolbar->AddTool( OpenFile_Event, _("File"), wxBitmap( file_xpm ),
310 toolbar->AddTool( OpenDisc_Event, _("Disc"), wxBitmap( disc_xpm ),
312 toolbar->AddTool( OpenNet_Event, _("Net"), wxBitmap( net_xpm ),
315 toolbar->AddTool( OpenSat_Event, _("Sat"), wxBitmap( sat_xpm ),
318 toolbar->AddSeparator();
319 toolbar->AddTool( StopStream_Event, _("Stop"), wxBitmap( stop_xpm ),
321 toolbar->AddTool( PlayStream_Event, _("Play"), wxBitmap( play_xpm ),
323 toolbar->AddSeparator();
324 toolbar->AddTool( Playlist_Event, _("Playlist"), wxBitmap( playlist_xpm ),
326 toolbar->AddTool( PrevStream_Event, _("Prev"), wxBitmap( previous_xpm ),
328 toolbar->AddTool( NextStream_Event, _("Next"), wxBitmap( next_xpm ),
333 /* Place the toolbar in a sizer, so we can calculate the width of the
334 * toolbar and set this as the minimum for the main frame size. */
335 wxBoxSizer *toolbar_sizer = new wxBoxSizer( wxHORIZONTAL );
336 toolbar_sizer->Add( toolbar, 0, 0, 0 );
337 toolbar_sizer->Layout();
340 frame_sizer->SetMinSize( toolbar_sizer->GetMinSize().GetWidth(), -1 );
342 frame_sizer->SetMinSize( toolbar->GetToolSize().GetWidth() *
343 toolbar->GetToolsCount(), -1 );
346 #if !defined(__WXX11__)
347 /* Associate drop targets with the toolbar */
348 toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
352 void Interface::CreateOurSlider()
354 /* Create a new frame containing the slider */
355 slider_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
356 slider_frame->SetAutoLayout( TRUE );
358 /* Create static box to surround the slider */
359 slider_box = new wxStaticBox( slider_frame, -1, "" );
361 /* Create sizer for slider frame */
362 wxStaticBoxSizer *slider_sizer =
363 new wxStaticBoxSizer( slider_box, wxHORIZONTAL );
364 slider_frame->SetSizer( slider_sizer );
365 slider_sizer->SetMinSize( -1, 50 );
368 slider = new wxSlider( slider_frame, SliderScroll_Event, 0, 0,
369 SLIDER_MAX_POS, wxDefaultPosition, wxDefaultSize );
370 slider_sizer->Add( slider, 1, wxGROW | wxALL, 5 );
371 slider_sizer->Layout();
372 slider_sizer->SetSizeHints(slider_frame);
374 /* Hide the slider by default */
375 slider_frame->Hide();
378 void Interface::Open( int i_access_method )
380 /* Show/hide the open dialog */
381 OpenDialog dialog( p_intf, this, i_access_method );
383 if( dialog.ShowModal() == wxID_OK )
385 /* Update the playlist */
386 playlist_t *p_playlist =
387 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
389 if( p_playlist == NULL )
394 playlist_Add( p_playlist, (char *)dialog.mrl.c_str(),
395 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
397 TogglePlayButton( PLAYING_S );
399 /* Rebuild the playlist */
400 p_intf->p_sys->p_playlist_window->Rebuild();
402 vlc_object_release( p_playlist );
406 /*****************************************************************************
408 *****************************************************************************/
409 void Interface::OnMenuOpen(wxMenuEvent& event)
411 if( event.GetEventObject() == p_audio_menu )
415 p_audio_menu = AudioMenu( p_intf, this );
417 GetMenuBar()->Replace( 3, p_audio_menu, _("&Audio") );
418 if( menu ) delete menu;
422 else b_audio_menu = 1;
424 else if( event.GetEventObject() == p_video_menu )
428 p_video_menu = VideoMenu( p_intf, this );
430 GetMenuBar()->Replace( 4, p_video_menu, _("&Video") );
431 if( menu ) delete menu;
435 else b_video_menu = 1;
439 void Interface::OnMenuClose(wxMenuEvent& event)
443 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
445 /* TRUE is to force the frame to close. */
449 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
452 msg.Printf( VOUT_TITLE + wxString(_(" (wxWindows interface)\n\n")) +
453 wxString(_("(C) 1996-2003 - the VideoLAN Team\n\n")) +
454 wxString(_("The VideoLAN team <videolan@videolan.org>\n"
455 "http://www.videolan.org/\n\n")) +
456 wxString(_("This is the VideoLAN Client, a DVD, MPEG and DivX player."
457 "\nIt can play MPEG and MPEG2 files from a file or from a "
458 "network source.")) );
460 wxMessageBox( msg, wxString::Format(_("About %s"), VOUT_TITLE),
461 wxOK | wxICON_INFORMATION, this );
464 void Interface::OnPlaylist( wxCommandEvent& WXUNUSED(event) )
466 /* Show/hide the playlist window */
467 wxFrame *p_playlist_window = p_intf->p_sys->p_playlist_window;
468 if( p_playlist_window )
470 p_playlist_window->Show( ! p_playlist_window->IsShown() );
474 void Interface::OnLogs( wxCommandEvent& WXUNUSED(event) )
476 /* Show/hide the log window */
477 wxFrame *p_messages_window = p_intf->p_sys->p_messages_window;
478 if( p_messages_window )
480 p_messages_window->Show( ! p_messages_window->IsShown() );
484 void Interface::OnFileInfo( wxCommandEvent& WXUNUSED(event) )
486 /* Show/hide the file info window */
487 wxFrame *p_fileinfo_window = p_intf->p_sys->p_fileinfo_window;
488 if( p_fileinfo_window )
490 p_fileinfo_window->Show( ! p_fileinfo_window->IsShown() );
494 void Interface::OnPreferences( wxCommandEvent& WXUNUSED(event) )
496 /* Show/hide the open dialog */
497 if( p_prefs_dialog == NULL )
499 p_prefs_dialog = new PrefsDialog( p_intf, this );
504 p_prefs_dialog->Show( true );
508 void Interface::OnOpenFile( wxCommandEvent& WXUNUSED(event) )
513 void Interface::OnOpenDisc( wxCommandEvent& WXUNUSED(event) )
518 void Interface::OnOpenNet( wxCommandEvent& WXUNUSED(event) )
523 void Interface::OnOpenSat( wxCommandEvent& WXUNUSED(event) )
528 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
530 wxCommandEvent dummy;
531 playlist_t *p_playlist =
532 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
534 if( p_playlist == NULL )
536 /* If the playlist is empty, open a file requester instead */
541 vlc_mutex_lock( &p_playlist->object_lock );
542 if( p_playlist->i_size )
544 vlc_mutex_unlock( &p_playlist->object_lock );
546 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
549 if( p_input == NULL )
551 /* No stream was playing, start one */
552 playlist_Play( p_playlist );
553 TogglePlayButton( PLAYING_S );
554 vlc_object_release( p_playlist );
558 if( p_input->stream.control.i_status != PAUSE_S )
560 /* A stream is being played, pause it */
561 input_SetStatus( p_input, INPUT_STATUS_PAUSE );
562 TogglePlayButton( PAUSE_S );
563 vlc_object_release( p_playlist );
564 vlc_object_release( p_input );
568 /* Stream is paused, resume it */
569 playlist_Play( p_playlist );
570 TogglePlayButton( PLAYING_S );
571 vlc_object_release( p_input );
572 vlc_object_release( p_playlist );
576 vlc_mutex_unlock( &p_playlist->object_lock );
577 vlc_object_release( p_playlist );
582 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
584 playlist_t * p_playlist =
585 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
587 if( p_playlist == NULL )
592 playlist_Stop( p_playlist );
593 TogglePlayButton( PAUSE_S );
594 vlc_object_release( p_playlist );
597 void Interface::OnSliderUpdate( wxScrollEvent& event )
599 vlc_mutex_lock( &p_intf->change_lock );
602 if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
603 || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
606 if( p_intf->p_sys->i_slider_pos != event.GetPosition()
607 && p_intf->p_sys->p_input )
609 p_intf->p_sys->i_slider_pos = event.GetPosition();
610 input_Seek( p_intf->p_sys->p_input, p_intf->p_sys->i_slider_pos *
611 100 / SLIDER_MAX_POS,
612 INPUT_SEEK_PERCENT | INPUT_SEEK_SET );
616 p_intf->p_sys->b_slider_free = VLC_TRUE;
620 p_intf->p_sys->b_slider_free = VLC_FALSE;
622 if( p_intf->p_sys->p_input )
624 /* Update stream date */
625 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
626 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
628 slider_box->SetLabel(
629 input_OffsetToTime( p_intf->p_sys->p_input,
631 p_area->i_size * event.GetPosition()
632 / SLIDER_MAX_POS ) );
638 vlc_mutex_unlock( &p_intf->change_lock );
641 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
643 playlist_t * p_playlist =
644 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
646 if( p_playlist == NULL )
651 playlist_Prev( p_playlist );
652 vlc_object_release( p_playlist );
655 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
657 playlist_t * p_playlist =
658 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
660 if( p_playlist == NULL )
665 playlist_Next( p_playlist );
666 vlc_object_release( p_playlist );
669 void Interface::TogglePlayButton( int i_playing_status )
671 if( i_playing_status == i_old_playing_status )
674 GetToolBar()->DeleteTool( PlayStream_Event );
676 if( i_playing_status == PLAYING_S )
678 GetToolBar()->InsertTool( 5, PlayStream_Event, _("Pause"),
679 wxBitmap( pause_xpm ) );
683 GetToolBar()->InsertTool( 5, PlayStream_Event, _("Play"),
684 wxBitmap( play_xpm ) );
687 GetToolBar()->Realize();
689 i_old_playing_status = i_playing_status;
692 #if !defined(__WXX11__)
693 /*****************************************************************************
694 * Definition of DragAndDrop class.
695 *****************************************************************************/
696 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf )
701 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
702 const wxArrayString& filenames )
706 /* Add dropped files to the playlist */
708 playlist_t *p_playlist =
709 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
711 if( p_playlist == NULL )
716 for( i = 0; i < filenames.GetCount(); i++ )
717 playlist_Add( p_playlist, (char *)filenames[i].c_str(),
718 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
720 /* Rebuild the playlist */
721 p_intf->p_sys->p_playlist_window->Rebuild();
723 vlc_object_release( p_playlist );