1 /*****************************************************************************
2 * interface.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: interface.cpp,v 1.24 2003/05/11 13:22:23 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,
119 /* it is important for the id corresponding to the "About" command to have
120 * this standard value as otherwise it won't be handled properly under Mac
121 * (where it is special and put into the "Apple" menu) */
122 About_Event = wxID_ABOUT
125 BEGIN_EVENT_TABLE(Interface, wxFrame)
127 EVT_MENU(Exit_Event, Interface::OnExit)
128 EVT_MENU(About_Event, Interface::OnAbout)
129 EVT_MENU(Playlist_Event, Interface::OnPlaylist)
130 EVT_MENU(Logs_Event, Interface::OnLogs)
131 EVT_MENU(FileInfo_Event, Interface::OnFileInfo)
132 EVT_MENU(Prefs_Event, Interface::OnPreferences)
134 EVT_MENU_OPEN(Interface::OnMenuOpen)
136 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
137 EVT_CONTEXT_MENU(Interface::OnContextMenu)
139 EVT_RIGHT_UP(Interface::OnContextMenu)
143 EVT_MENU(OpenFile_Event, Interface::OnOpenFile)
144 EVT_MENU(OpenDisc_Event, Interface::OnOpenDisc)
145 EVT_MENU(OpenNet_Event, Interface::OnOpenNet)
146 EVT_MENU(OpenSat_Event, Interface::OnOpenSat)
147 EVT_MENU(StopStream_Event, Interface::OnStopStream)
148 EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
149 EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
150 EVT_MENU(NextStream_Event, Interface::OnNextStream)
153 EVT_COMMAND_SCROLL(SliderScroll_Event, Interface::OnSliderUpdate)
156 /*****************************************************************************
158 *****************************************************************************/
159 Interface::Interface( intf_thread_t *_p_intf ):
160 wxFrame( NULL, -1, wxT(VOUT_TITLE),
161 wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE )
163 /* Initializations */
165 p_prefs_dialog = NULL;
166 i_old_playing_status = PAUSE_S;
168 /* Give our interface a nice little icon */
169 p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );
170 SetIcon( *p_intf->p_sys->p_icon );
172 /* Create a sizer for the main frame */
173 frame_sizer = new wxBoxSizer( wxHORIZONTAL );
174 SetSizer( frame_sizer );
176 /* Creation of the menu bar */
179 /* Creation of the tool bar */
182 /* Creation of the slider sub-window */
184 frame_sizer->Add( slider_frame, 1, wxGROW, 0 );
185 frame_sizer->Hide( slider_frame );
187 /* Creation of the status bar
188 * Helptext for menu items and toolbar tools will automatically get
190 int i_status_width[2] = {-2,-3};
191 statusbar = CreateStatusBar( 2 ); /* 2 fields */
192 statusbar->SetStatusWidths( 2, i_status_width );
194 /* Make sure we've got the right background colour */
195 SetBackgroundColour( slider_frame->GetBackgroundColour() );
197 /* Layout everything */
198 SetAutoLayout( TRUE );
199 frame_sizer->Layout();
200 frame_sizer->Fit(this);
202 #if !defined(__WXX11__)
203 /* Associate drop targets with the main interface */
204 SetDropTarget( new DragAndDrop( p_intf ) );
208 Interface::~Interface()
210 if( p_prefs_dialog ) p_prefs_dialog->Destroy();
213 /*****************************************************************************
215 *****************************************************************************/
216 void Interface::CreateOurMenuBar()
218 #define HELP_FILE N_("Open a file")
219 #define HELP_DISC N_("Open a DVD or (S)VCD")
220 #define HELP_NET N_("Open a network stream")
221 #define HELP_SAT N_("Open a satellite stream")
222 #define HELP_EJECT N_("Eject the DVD/CD")
223 #define HELP_EXIT N_("Exit this program")
225 #define HELP_PLAYLIST N_("Open the playlist")
226 #define HELP_LOGS N_("Show the program logs")
227 #define HELP_FILEINFO N_("Show information about the file being played")
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, wxU(_("&Open File...")),
237 file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...")),
239 file_menu->Append( OpenNet_Event, wxU(_("&Network Stream...")),
242 file_menu->Append( OpenSat_Event, wxU(_("&Satellite Stream...")),
246 file_menu->AppendSeparator();
247 file_menu->Append( EjectDisc_Event, wxU(_("&Eject Disc")),
248 wxU(_(HELP_EJECT)) );
250 file_menu->AppendSeparator();
251 file_menu->Append( Exit_Event, wxU(_("E&xit")), wxU(_(HELP_EXIT)) );
253 /* Create the "View" menu */
254 wxMenu *view_menu = new wxMenu;
255 view_menu->Append( Playlist_Event, wxU(_("&Playlist...")),
256 wxU(_(HELP_PLAYLIST)) );
257 view_menu->Append( Logs_Event, wxU(_("&Logs...")), wxU(_(HELP_LOGS)) );
258 view_menu->Append( FileInfo_Event, wxU(_("&File info...")),
259 wxU(_(HELP_FILEINFO)) );
261 /* Create the "Settings" menu */
262 wxMenu *settings_menu = new wxMenu;
263 settings_menu->Append( Prefs_Event, wxU(_("&Preferences...")),
264 wxU(_(HELP_PREFS)) );
266 /* Create the "Audio" menu */
267 p_audio_menu = new wxMenu;
270 /* Create the "Video" menu */
271 p_video_menu = new wxMenu;
274 /* Create the "Help" menu */
275 wxMenu *help_menu = new wxMenu;
276 help_menu->Append( About_Event, wxU(_("&About...")), wxU(_(HELP_ABOUT)) );
278 /* Append the freshly created menus to the menu bar... */
279 wxMenuBar *menubar = new wxMenuBar( wxMB_DOCKABLE );
280 menubar->Append( file_menu, wxU(_("&File")) );
281 menubar->Append( view_menu, wxU(_("&View")) );
282 menubar->Append( settings_menu, wxU(_("&Settings")) );
283 menubar->Append( p_audio_menu, wxU(_("&Audio")) );
284 menubar->Append( p_video_menu, wxU(_("&Video")) );
285 menubar->Append( help_menu, wxU(_("&Help")) );
287 /* Attach the menu bar to the frame */
288 SetMenuBar( menubar );
290 /* Intercept all menu events in our custom event handler */
291 PushEventHandler( new MenuEvtHandler( p_intf, this ) );
293 #if !defined(__WXX11__)
294 /* Associate drop targets with the menubar */
295 menubar->SetDropTarget( new DragAndDrop( p_intf ) );
299 void Interface::CreateOurToolBar()
301 #define HELP_STOP N_("Stop current playlist item")
302 #define HELP_PLAY N_("Play current playlist item")
303 #define HELP_PAUSE N_("Pause current playlist item")
304 #define HELP_PLO N_("Open playlist")
305 #define HELP_PLP N_("Previous playlist item")
306 #define HELP_PLN N_("Next playlist item")
308 wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
309 * version because we don't include wx.rc */
311 wxToolBar *toolbar = CreateToolBar(
312 wxTB_HORIZONTAL | wxTB_TEXT | wxTB_FLAT | wxTB_DOCKABLE );
314 toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
316 toolbar->AddTool( OpenFile_Event, wxU(_("File")), wxBitmap( file_xpm ),
318 toolbar->AddTool( OpenDisc_Event, wxU(_("Disc")), wxBitmap( disc_xpm ),
320 toolbar->AddTool( OpenNet_Event, wxU(_("Net")), wxBitmap( net_xpm ),
323 toolbar->AddTool( OpenSat_Event, wxU(_("Sat")), wxBitmap( sat_xpm ),
326 toolbar->AddSeparator();
327 toolbar->AddTool( StopStream_Event, wxU(_("Stop")), wxBitmap( stop_xpm ),
329 toolbar->AddTool( PlayStream_Event, wxU(_("Play")), wxBitmap( play_xpm ),
331 toolbar->AddSeparator();
332 toolbar->AddTool( Playlist_Event, wxU(_("Playlist")),
333 wxBitmap( playlist_xpm ), wxU(_(HELP_PLO)) );
334 toolbar->AddTool( PrevStream_Event, wxU(_("Prev")),
335 wxBitmap( previous_xpm ), wxU(_(HELP_PLP)) );
336 toolbar->AddTool( NextStream_Event, wxU(_("Next")), wxBitmap( next_xpm ),
341 /* Place the toolbar in a sizer, so we can calculate the width of the
342 * toolbar and set this as the minimum for the main frame size. */
343 wxBoxSizer *toolbar_sizer = new wxBoxSizer( wxHORIZONTAL );
344 toolbar_sizer->Add( toolbar, 0, 0, 0 );
345 toolbar_sizer->Layout();
348 frame_sizer->SetMinSize( toolbar_sizer->GetMinSize().GetWidth(), -1 );
350 frame_sizer->SetMinSize( toolbar->GetToolSize().GetWidth() *
351 toolbar->GetToolsCount(), -1 );
354 #if !defined(__WXX11__)
355 /* Associate drop targets with the toolbar */
356 toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
360 void Interface::CreateOurSlider()
362 /* Create a new frame containing the slider */
363 slider_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
364 slider_frame->SetAutoLayout( TRUE );
366 /* Create static box to surround the slider */
367 slider_box = new wxStaticBox( slider_frame, -1, wxT("") );
369 /* Create sizer for slider frame */
370 wxStaticBoxSizer *slider_sizer =
371 new wxStaticBoxSizer( slider_box, wxHORIZONTAL );
372 slider_frame->SetSizer( slider_sizer );
373 slider_sizer->SetMinSize( -1, 50 );
376 slider = new wxSlider( slider_frame, SliderScroll_Event, 0, 0,
377 SLIDER_MAX_POS, wxDefaultPosition, wxDefaultSize );
378 slider_sizer->Add( slider, 1, wxGROW | wxALL, 5 );
379 slider_sizer->Layout();
380 slider_sizer->SetSizeHints(slider_frame);
382 /* Hide the slider by default */
383 slider_frame->Hide();
386 void Interface::Open( int i_access_method )
388 /* Show/hide the open dialog */
389 OpenDialog dialog( p_intf, this, i_access_method );
391 if( dialog.ShowModal() == wxID_OK )
393 /* Update the playlist */
394 playlist_t *p_playlist =
395 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
397 if( p_playlist == NULL )
402 playlist_Add( p_playlist, (const char *)dialog.mrl.mb_str(),
403 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
405 TogglePlayButton( PLAYING_S );
407 /* Rebuild the playlist */
408 p_intf->p_sys->p_playlist_window->Rebuild();
410 vlc_object_release( p_playlist );
414 /*****************************************************************************
416 *****************************************************************************/
417 void Interface::OnMenuOpen(wxMenuEvent& event)
419 #if !defined( __WXMSW__ )
420 if( event.GetEventObject() == p_audio_menu )
424 p_audio_menu = AudioMenu( p_intf, this );
426 GetMenuBar()->Replace( 3, p_audio_menu, wxU(_("&Audio")) );
427 if( menu ) delete menu;
431 else b_audio_menu = 1;
433 else if( event.GetEventObject() == p_video_menu )
437 p_video_menu = VideoMenu( p_intf, this );
439 GetMenuBar()->Replace( 4, p_video_menu, wxU(_("&Video")) );
440 if( menu ) delete menu;
444 else b_video_menu = 1;
448 p_audio_menu = AudioMenu( p_intf, this );
449 wxMenu *menu = GetMenuBar()->Replace( 3, p_audio_menu, wxU(_("&Audio")) );
450 if( menu ) delete menu;
452 p_video_menu = VideoMenu( p_intf, this );
453 menu = GetMenuBar()->Replace( 4, p_video_menu, wxU(_("&Video")) );
454 if( menu ) delete menu;
459 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
460 void Interface::OnContextMenu(wxContextMenuEvent& event)
462 ::PopupMenu( p_intf, this, ScreenToClient(event.GetPosition()) );
465 void Interface::OnContextMenu(wxMouseEvent& event)
467 ::PopupMenu( p_intf, this, event.GetPosition() );
471 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
473 /* TRUE is to force the frame to close. */
477 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
480 msg.Printf( wxT(VOUT_TITLE) + wxU(_(" (wxWindows interface)\n\n")) +
481 wxU(_("(C) 1996-2003 - the VideoLAN Team\n\n")) +
482 wxU(_("The VideoLAN team <videolan@videolan.org>\n"
483 "http://www.videolan.org/\n\n")) +
484 wxU(_("This is the VideoLAN Client, a DVD, MPEG and DivX player."
485 "\nIt can play MPEG and MPEG2 files from a file or from a "
486 "network source.")) );
488 wxMessageBox( msg, wxString::Format(wxU(_("About %s")), wxT(VOUT_TITLE)),
489 wxOK | wxICON_INFORMATION, this );
492 void Interface::OnPlaylist( wxCommandEvent& WXUNUSED(event) )
494 /* Show/hide the playlist window */
495 wxFrame *p_playlist_window = p_intf->p_sys->p_playlist_window;
496 if( p_playlist_window )
498 p_playlist_window->Show( ! p_playlist_window->IsShown() );
502 void Interface::OnLogs( wxCommandEvent& WXUNUSED(event) )
504 /* Show/hide the log window */
505 wxFrame *p_messages_window = p_intf->p_sys->p_messages_window;
506 if( p_messages_window )
508 p_messages_window->Show( ! p_messages_window->IsShown() );
512 void Interface::OnFileInfo( wxCommandEvent& WXUNUSED(event) )
514 /* Show/hide the file info window */
515 wxFrame *p_fileinfo_window = p_intf->p_sys->p_fileinfo_window;
516 if( p_fileinfo_window )
518 p_fileinfo_window->Show( ! p_fileinfo_window->IsShown() );
522 void Interface::OnPreferences( wxCommandEvent& WXUNUSED(event) )
524 /* Show/hide the open dialog */
525 if( p_prefs_dialog == NULL )
527 p_prefs_dialog = new PrefsDialog( p_intf, this );
532 p_prefs_dialog->Show( true );
536 void Interface::OnOpenFile( wxCommandEvent& WXUNUSED(event) )
541 void Interface::OnOpenDisc( wxCommandEvent& WXUNUSED(event) )
546 void Interface::OnOpenNet( wxCommandEvent& WXUNUSED(event) )
551 void Interface::OnOpenSat( wxCommandEvent& WXUNUSED(event) )
556 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
558 wxCommandEvent dummy;
559 playlist_t *p_playlist =
560 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
562 if( p_playlist == NULL )
564 /* If the playlist is empty, open a file requester instead */
569 vlc_mutex_lock( &p_playlist->object_lock );
570 if( p_playlist->i_size )
572 vlc_mutex_unlock( &p_playlist->object_lock );
574 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
577 if( p_input == NULL )
579 /* No stream was playing, start one */
580 playlist_Play( p_playlist );
581 TogglePlayButton( PLAYING_S );
582 vlc_object_release( p_playlist );
586 if( p_input->stream.control.i_status != PAUSE_S )
588 /* A stream is being played, pause it */
589 input_SetStatus( p_input, INPUT_STATUS_PAUSE );
590 TogglePlayButton( PAUSE_S );
591 vlc_object_release( p_playlist );
592 vlc_object_release( p_input );
596 /* Stream is paused, resume it */
597 playlist_Play( p_playlist );
598 TogglePlayButton( PLAYING_S );
599 vlc_object_release( p_input );
600 vlc_object_release( p_playlist );
604 vlc_mutex_unlock( &p_playlist->object_lock );
605 vlc_object_release( p_playlist );
610 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
612 playlist_t * p_playlist =
613 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
615 if( p_playlist == NULL )
620 playlist_Stop( p_playlist );
621 TogglePlayButton( PAUSE_S );
622 vlc_object_release( p_playlist );
625 void Interface::OnSliderUpdate( wxScrollEvent& event )
627 vlc_mutex_lock( &p_intf->change_lock );
630 if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
631 || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
634 if( p_intf->p_sys->i_slider_pos != event.GetPosition()
635 && p_intf->p_sys->p_input )
637 p_intf->p_sys->i_slider_pos = event.GetPosition();
638 input_Seek( p_intf->p_sys->p_input, p_intf->p_sys->i_slider_pos *
639 100 / SLIDER_MAX_POS,
640 INPUT_SEEK_PERCENT | INPUT_SEEK_SET );
644 p_intf->p_sys->b_slider_free = VLC_TRUE;
648 p_intf->p_sys->b_slider_free = VLC_FALSE;
650 if( p_intf->p_sys->p_input )
652 /* Update stream date */
653 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
654 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
656 slider_box->SetLabel(
657 wxU(input_OffsetToTime( p_intf->p_sys->p_input,
659 p_area->i_size * event.GetPosition()
660 / SLIDER_MAX_POS )) );
666 vlc_mutex_unlock( &p_intf->change_lock );
669 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
671 playlist_t * p_playlist =
672 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
674 if( p_playlist == NULL )
679 playlist_Prev( p_playlist );
680 vlc_object_release( p_playlist );
683 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
685 playlist_t * p_playlist =
686 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
688 if( p_playlist == NULL )
693 playlist_Next( p_playlist );
694 vlc_object_release( p_playlist );
697 void Interface::TogglePlayButton( int i_playing_status )
699 if( i_playing_status == i_old_playing_status )
702 GetToolBar()->DeleteTool( PlayStream_Event );
704 if( i_playing_status == PLAYING_S )
706 GetToolBar()->InsertTool( 5, PlayStream_Event, wxU(_("Pause")),
707 wxBitmap( pause_xpm ) );
711 GetToolBar()->InsertTool( 5, PlayStream_Event, wxU(_("Play")),
712 wxBitmap( play_xpm ) );
715 GetToolBar()->Realize();
717 i_old_playing_status = i_playing_status;
720 #if !defined(__WXX11__)
721 /*****************************************************************************
722 * Definition of DragAndDrop class.
723 *****************************************************************************/
724 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf )
729 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
730 const wxArrayString& filenames )
734 /* Add dropped files to the playlist */
736 playlist_t *p_playlist =
737 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
739 if( p_playlist == NULL )
744 for( i = 0; i < filenames.GetCount(); i++ )
745 playlist_Add( p_playlist, (const char *)filenames[i].mb_str(),
746 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
748 /* Rebuild the playlist */
749 p_intf->p_sys->p_playlist_window->Rebuild();
751 vlc_object_release( p_playlist );