1 /*****************************************************************************
2 * interface.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: interface.cpp,v 1.26 2003/05/11 15:55:51 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 /* Work-around helper for buggy wxGTK */
418 void RecursiveDestroy( wxMenu *menu )
420 wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
423 wxMenuItem *item = node->GetData();
424 node = node->GetNext();
426 /* Delete the submenus */
427 wxMenu *submenu = item->GetSubMenu();
430 RecursiveDestroy( submenu );
432 menu->Delete( item );
436 void Interface::OnMenuOpen(wxMenuEvent& event)
438 #if !defined( __WXMSW__ )
439 if( event.GetEventObject() == p_audio_menu )
443 p_audio_menu = AudioMenu( p_intf, this );
445 /* Work-around for buggy wxGTK */
446 wxMenu *menu = GetMenuBar()->GetMenu( 3 );
447 RecursiveDestroy( menu );
448 /* End work-around */
451 GetMenuBar()->Replace( 3, p_audio_menu, wxU(_("&Audio")) );
452 if( menu ) delete menu;
456 else b_audio_menu = 1;
458 else if( event.GetEventObject() == p_video_menu )
462 p_video_menu = VideoMenu( p_intf, this );
464 /* Work-around for buggy wxGTK */
465 wxMenu *menu = GetMenuBar()->GetMenu( 4 );
466 RecursiveDestroy( menu );
467 /* End work-around */
470 GetMenuBar()->Replace( 4, p_video_menu, wxU(_("&Video")) );
471 if( menu ) delete menu;
475 else b_video_menu = 1;
479 p_audio_menu = AudioMenu( p_intf, this );
480 wxMenu *menu = GetMenuBar()->Replace( 3, p_audio_menu, wxU(_("&Audio")) );
481 if( menu ) delete menu;
483 p_video_menu = VideoMenu( p_intf, this );
484 menu = GetMenuBar()->Replace( 4, p_video_menu, wxU(_("&Video")) );
485 if( menu ) delete menu;
490 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
491 void Interface::OnContextMenu(wxContextMenuEvent& event)
493 ::PopupMenu( p_intf, this, ScreenToClient(event.GetPosition()) );
496 void Interface::OnContextMenu(wxMouseEvent& event)
498 ::PopupMenu( p_intf, this, event.GetPosition() );
502 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
504 /* TRUE is to force the frame to close. */
508 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
511 msg.Printf( wxString(wxT(VOUT_TITLE)) +
512 wxU(_(" (wxWindows interface)\n\n")) +
513 wxU(_("(C) 1996-2003 - the VideoLAN Team\n\n")) +
514 wxU(_("The VideoLAN team <videolan@videolan.org>\n"
515 "http://www.videolan.org/\n\n")) +
516 wxU(_("This is the VideoLAN Client, a DVD, MPEG and DivX player."
517 "\nIt can play MPEG and MPEG2 files from a file or from a "
518 "network source.")) );
520 wxMessageBox( msg, wxString::Format(wxU(_("About %s")), wxT(VOUT_TITLE)),
521 wxOK | wxICON_INFORMATION, this );
524 void Interface::OnPlaylist( wxCommandEvent& WXUNUSED(event) )
526 /* Show/hide the playlist window */
527 wxFrame *p_playlist_window = p_intf->p_sys->p_playlist_window;
528 if( p_playlist_window )
530 p_playlist_window->Show( ! p_playlist_window->IsShown() );
534 void Interface::OnLogs( wxCommandEvent& WXUNUSED(event) )
536 /* Show/hide the log window */
537 wxFrame *p_messages_window = p_intf->p_sys->p_messages_window;
538 if( p_messages_window )
540 p_messages_window->Show( ! p_messages_window->IsShown() );
544 void Interface::OnFileInfo( wxCommandEvent& WXUNUSED(event) )
546 /* Show/hide the file info window */
547 wxFrame *p_fileinfo_window = p_intf->p_sys->p_fileinfo_window;
548 if( p_fileinfo_window )
550 p_fileinfo_window->Show( ! p_fileinfo_window->IsShown() );
554 void Interface::OnPreferences( wxCommandEvent& WXUNUSED(event) )
556 /* Show/hide the open dialog */
557 if( p_prefs_dialog == NULL )
559 p_prefs_dialog = new PrefsDialog( p_intf, this );
564 p_prefs_dialog->Show( true );
568 void Interface::OnOpenFile( wxCommandEvent& WXUNUSED(event) )
573 void Interface::OnOpenDisc( wxCommandEvent& WXUNUSED(event) )
578 void Interface::OnOpenNet( wxCommandEvent& WXUNUSED(event) )
583 void Interface::OnOpenSat( wxCommandEvent& WXUNUSED(event) )
588 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
590 wxCommandEvent dummy;
591 playlist_t *p_playlist =
592 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
594 if( p_playlist == NULL )
596 /* If the playlist is empty, open a file requester instead */
601 vlc_mutex_lock( &p_playlist->object_lock );
602 if( p_playlist->i_size )
604 vlc_mutex_unlock( &p_playlist->object_lock );
606 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
609 if( p_input == NULL )
611 /* No stream was playing, start one */
612 playlist_Play( p_playlist );
613 TogglePlayButton( PLAYING_S );
614 vlc_object_release( p_playlist );
618 if( p_input->stream.control.i_status != PAUSE_S )
620 /* A stream is being played, pause it */
621 input_SetStatus( p_input, INPUT_STATUS_PAUSE );
622 TogglePlayButton( PAUSE_S );
623 vlc_object_release( p_playlist );
624 vlc_object_release( p_input );
628 /* Stream is paused, resume it */
629 playlist_Play( p_playlist );
630 TogglePlayButton( PLAYING_S );
631 vlc_object_release( p_input );
632 vlc_object_release( p_playlist );
636 vlc_mutex_unlock( &p_playlist->object_lock );
637 vlc_object_release( p_playlist );
642 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
644 playlist_t * p_playlist =
645 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
647 if( p_playlist == NULL )
652 playlist_Stop( p_playlist );
653 TogglePlayButton( PAUSE_S );
654 vlc_object_release( p_playlist );
657 void Interface::OnSliderUpdate( wxScrollEvent& event )
659 vlc_mutex_lock( &p_intf->change_lock );
662 if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
663 || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
666 if( p_intf->p_sys->i_slider_pos != event.GetPosition()
667 && p_intf->p_sys->p_input )
669 p_intf->p_sys->i_slider_pos = event.GetPosition();
670 input_Seek( p_intf->p_sys->p_input, p_intf->p_sys->i_slider_pos *
671 100 / SLIDER_MAX_POS,
672 INPUT_SEEK_PERCENT | INPUT_SEEK_SET );
676 p_intf->p_sys->b_slider_free = VLC_TRUE;
680 p_intf->p_sys->b_slider_free = VLC_FALSE;
682 if( p_intf->p_sys->p_input )
684 /* Update stream date */
685 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
686 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
688 slider_box->SetLabel(
689 wxU(input_OffsetToTime( p_intf->p_sys->p_input,
691 p_area->i_size * event.GetPosition()
692 / SLIDER_MAX_POS )) );
698 vlc_mutex_unlock( &p_intf->change_lock );
701 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
703 playlist_t * p_playlist =
704 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
706 if( p_playlist == NULL )
711 playlist_Prev( p_playlist );
712 vlc_object_release( p_playlist );
715 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
717 playlist_t * p_playlist =
718 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
720 if( p_playlist == NULL )
725 playlist_Next( p_playlist );
726 vlc_object_release( p_playlist );
729 void Interface::TogglePlayButton( int i_playing_status )
731 if( i_playing_status == i_old_playing_status )
734 GetToolBar()->DeleteTool( PlayStream_Event );
736 if( i_playing_status == PLAYING_S )
738 GetToolBar()->InsertTool( 5, PlayStream_Event, wxU(_("Pause")),
739 wxBitmap( pause_xpm ) );
743 GetToolBar()->InsertTool( 5, PlayStream_Event, wxU(_("Play")),
744 wxBitmap( play_xpm ) );
747 GetToolBar()->Realize();
749 i_old_playing_status = i_playing_status;
752 #if !defined(__WXX11__)
753 /*****************************************************************************
754 * Definition of DragAndDrop class.
755 *****************************************************************************/
756 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf )
761 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
762 const wxArrayString& filenames )
766 /* Add dropped files to the playlist */
768 playlist_t *p_playlist =
769 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
771 if( p_playlist == NULL )
776 for( i = 0; i < filenames.GetCount(); i++ )
777 playlist_Add( p_playlist, (const char *)filenames[i].mb_str(),
778 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
780 /* Rebuild the playlist */
781 p_intf->p_sys->p_playlist_window->Rebuild();
783 vlc_object_release( p_playlist );