]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/interface.cpp
* INSTALL.win32: added a small note about running vlc under the msvc debugger.
[vlc] / modules / gui / wxwindows / interface.cpp
1 /*****************************************************************************
2  * interface.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2001 VideoLAN
5  * $Id: interface.cpp,v 1.32 2003/05/22 12:00:56 gbazin Exp $
6  *
7  * Authors: Gildas Bazin <gbazin@netcourrier.com>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <string.h>                                            /* strerror() */
30 #include <stdio.h>
31
32 #include <vlc/vlc.h>
33
34 #ifdef WIN32                                                 /* mingw32 hack */
35 #undef Yield
36 #undef CreateDialog
37 #endif
38
39 /* Let vlc take care of the i18n stuff */
40 #define WXINTL_NO_GETTEXT_MACRO
41
42 #include <wx/wxprec.h>
43 #include <wx/wx.h>
44
45 #include <vlc/intf.h>
46 #include "stream_control.h"
47
48 #include "wxwindows.h"
49
50 /* include the toolbar graphics */
51 #include "bitmaps/file.xpm"
52 #include "bitmaps/disc.xpm"
53 #include "bitmaps/net.xpm"
54 #if 0
55 #include "bitmaps/sat.xpm"
56 #endif
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 #include "bitmaps/fast.xpm"
64 #include "bitmaps/slow.xpm"
65
66 #define TOOLBAR_BMP_WIDTH 36
67 #define TOOLBAR_BMP_HEIGHT 36
68
69 /* include the icon graphic */
70 #include "share/vlc32x32.xpm"
71
72 /*****************************************************************************
73  * Local class declarations.
74  *****************************************************************************/
75 class wxMenuExt: public wxMenu
76 {
77 public:
78     /* Constructor */
79     wxMenuExt( wxMenu* parentMenu, int id, const wxString& text,
80                    const wxString& helpString, wxItemKind kind,
81                    char *_psz_var, int _i_object_id, vlc_value_t _val,
82                    int _i_val_type );
83
84     virtual ~wxMenuExt() {};
85
86     char *psz_var;
87     int  i_val_type;
88     int  i_object_id;
89     vlc_value_t val;
90
91 private:
92
93 };
94
95 /*****************************************************************************
96  * Event Table.
97  *****************************************************************************/
98
99 /* IDs for the controls and the menu commands */
100 enum
101 {
102     /* menu items */
103     Exit_Event = wxID_HIGHEST,
104     OpenFile_Event,
105     OpenDisc_Event,
106     OpenNet_Event,
107     OpenSat_Event,
108     EjectDisc_Event,
109
110     Playlist_Event,
111     Logs_Event,
112     FileInfo_Event,
113
114     Prefs_Event,
115
116     SliderScroll_Event,
117     StopStream_Event,
118     PlayStream_Event,
119     PrevStream_Event,
120     NextStream_Event,
121     SlowStream_Event,
122     FastStream_Event,
123
124     /* it is important for the id corresponding to the "About" command to have
125      * this standard value as otherwise it won't be handled properly under Mac
126      * (where it is special and put into the "Apple" menu) */
127     About_Event = wxID_ABOUT
128 };
129
130 BEGIN_EVENT_TABLE(Interface, wxFrame)
131     /* Menu events */
132     EVT_MENU(Exit_Event, Interface::OnExit)
133     EVT_MENU(About_Event, Interface::OnAbout)
134     EVT_MENU(Playlist_Event, Interface::OnPlaylist)
135     EVT_MENU(Logs_Event, Interface::OnLogs)
136     EVT_MENU(FileInfo_Event, Interface::OnFileInfo)
137     EVT_MENU(Prefs_Event, Interface::OnPreferences)
138
139     EVT_MENU_OPEN(Interface::OnMenuOpen)
140
141 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
142     EVT_CONTEXT_MENU(Interface::OnContextMenu)
143 #else
144     EVT_RIGHT_UP(Interface::OnContextMenu)
145 #endif
146
147     /* Toolbar events */
148     EVT_MENU(OpenFile_Event, Interface::OnOpenFile)
149     EVT_MENU(OpenDisc_Event, Interface::OnOpenDisc)
150     EVT_MENU(OpenNet_Event, Interface::OnOpenNet)
151     EVT_MENU(OpenSat_Event, Interface::OnOpenSat)
152     EVT_MENU(StopStream_Event, Interface::OnStopStream)
153     EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
154     EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
155     EVT_MENU(NextStream_Event, Interface::OnNextStream)
156     EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
157     EVT_MENU(FastStream_Event, Interface::OnFastStream)
158
159     /* Slider events */
160     EVT_COMMAND_SCROLL(SliderScroll_Event, Interface::OnSliderUpdate)
161 END_EVENT_TABLE()
162
163 /*****************************************************************************
164  * Constructor.
165  *****************************************************************************/
166 Interface::Interface( intf_thread_t *_p_intf ):
167     wxFrame( NULL, -1, wxT(VOUT_TITLE),
168              wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE )
169 {
170     /* Initializations */
171     p_intf = _p_intf;
172     p_prefs_dialog = NULL;
173     i_old_playing_status = PAUSE_S;
174     p_open_dialog = NULL;
175
176     /* Give our interface a nice little icon */
177     p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );
178     SetIcon( *p_intf->p_sys->p_icon );
179
180     /* Create a sizer for the main frame */
181     frame_sizer = new wxBoxSizer( wxHORIZONTAL );
182     SetSizer( frame_sizer );
183
184     /* Creation of the menu bar */
185     CreateOurMenuBar();
186
187     /* Creation of the tool bar */
188     CreateOurToolBar();
189
190     /* Creation of the slider sub-window */
191     CreateOurSlider();
192     frame_sizer->Add( slider_frame, 1, wxGROW, 0 );
193     frame_sizer->Hide( slider_frame );
194
195     /* Creation of the status bar
196      * Helptext for menu items and toolbar tools will automatically get
197      * displayed here. */
198     int i_status_width[3] = {-6, -2, -9};
199     statusbar = CreateStatusBar( 3 );                            /* 2 fields */
200     statusbar->SetStatusWidths( 3, i_status_width );
201     statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
202
203
204     /* Make sure we've got the right background colour */
205     SetBackgroundColour( slider_frame->GetBackgroundColour() );
206
207     /* Layout everything */
208     SetAutoLayout( TRUE );
209     frame_sizer->Layout();
210     frame_sizer->Fit(this);
211
212 #if !defined(__WXX11__)
213     /* Associate drop targets with the main interface */
214     SetDropTarget( new DragAndDrop( p_intf ) );
215 #endif
216 }
217
218 Interface::~Interface()
219 {
220     /* Clean up */
221     if( p_open_dialog ) delete p_open_dialog;
222     if( p_prefs_dialog ) p_prefs_dialog->Destroy();
223 }
224
225 /*****************************************************************************
226  * Private methods.
227  *****************************************************************************/
228 void Interface::CreateOurMenuBar()
229 {
230 #define HELP_FILE  N_("Open a file")
231 #define HELP_DISC  N_("Open a DVD or (S)VCD")
232 #define HELP_NET   N_("Open a network stream")
233 #define HELP_SAT   N_("Open a satellite stream")
234 #define HELP_EJECT N_("Eject the DVD/CD")
235 #define HELP_EXIT  N_("Exit this program")
236
237 #define HELP_PLAYLIST   N_("Open the playlist")
238 #define HELP_LOGS       N_("Show the program logs")
239 #define HELP_FILEINFO       N_("Show information about the file being played")
240
241 #define HELP_PREFS N_("Go to the preferences menu")
242
243 #define HELP_ABOUT N_("About this program")
244
245     /* Create the "File" menu */
246     wxMenu *file_menu = new wxMenu;
247     file_menu->Append( OpenFile_Event, wxU(_("&Open File...")),
248                        wxU(_(HELP_FILE)) );
249     file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...")),
250                        wxU(_(HELP_DISC)) );
251     file_menu->Append( OpenNet_Event, wxU(_("&Network Stream...")),
252                        wxU(_(HELP_NET)) );
253 #if 0
254     file_menu->Append( OpenSat_Event, wxU(_("&Satellite Stream...")),
255                        wxU(_(HELP_NET)) );
256 #endif
257 #if 0
258     file_menu->AppendSeparator();
259     file_menu->Append( EjectDisc_Event, wxU(_("&Eject Disc")),
260                        wxU(_(HELP_EJECT)) );
261 #endif
262     file_menu->AppendSeparator();
263     file_menu->Append( Exit_Event, wxU(_("E&xit")), wxU(_(HELP_EXIT)) );
264
265     /* Create the "View" menu */
266     wxMenu *view_menu = new wxMenu;
267     view_menu->Append( Playlist_Event, wxU(_("&Playlist...")),
268                        wxU(_(HELP_PLAYLIST)) );
269     view_menu->Append( Logs_Event, wxU(_("&Logs...")), wxU(_(HELP_LOGS)) );
270     view_menu->Append( FileInfo_Event, wxU(_("&File info...")),
271                        wxU(_(HELP_FILEINFO)) );
272
273     /* Create the "Settings" menu */
274     wxMenu *settings_menu = new wxMenu;
275     settings_menu->Append( Prefs_Event, wxU(_("&Preferences...")),
276                            wxU(_(HELP_PREFS)) );
277
278     /* Create the "Audio" menu */
279     p_audio_menu = new wxMenu;
280     b_audio_menu = 1;
281
282     /* Create the "Video" menu */
283     p_video_menu = new wxMenu;
284     b_video_menu = 1;
285
286     /* Create the "Navigation" menu */
287     p_navig_menu = new wxMenu;
288     b_navig_menu = 1;
289
290     /* Create the "Help" menu */
291     wxMenu *help_menu = new wxMenu;
292     help_menu->Append( About_Event, wxU(_("&About...")), wxU(_(HELP_ABOUT)) );
293
294     /* Append the freshly created menus to the menu bar... */
295     wxMenuBar *menubar = new wxMenuBar( wxMB_DOCKABLE );
296     menubar->Append( file_menu, wxU(_("&File")) );
297     menubar->Append( view_menu, wxU(_("&View")) );
298     menubar->Append( settings_menu, wxU(_("&Settings")) );
299     menubar->Append( p_audio_menu, wxU(_("&Audio")) );
300     menubar->Append( p_video_menu, wxU(_("&Video")) );
301     menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
302     menubar->Append( help_menu, wxU(_("&Help")) );
303
304     /* Attach the menu bar to the frame */
305     SetMenuBar( menubar );
306
307     /* Intercept all menu events in our custom event handler */
308     PushEventHandler( new MenuEvtHandler( p_intf, this ) );
309
310 #if !defined(__WXX11__)
311     /* Associate drop targets with the menubar */
312     menubar->SetDropTarget( new DragAndDrop( p_intf ) );
313 #endif
314 }
315
316 void Interface::CreateOurToolBar()
317 {
318 #define HELP_STOP N_("Stop current playlist item")
319 #define HELP_PLAY N_("Play current playlist item")
320 #define HELP_PAUSE N_("Pause current playlist item")
321 #define HELP_PLO N_("Open playlist")
322 #define HELP_PLP N_("Previous playlist item")
323 #define HELP_PLN N_("Next playlist item")
324 #define HELP_SLOW N_("Play slower")
325 #define HELP_FAST N_("Play faster")
326
327     wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
328                          * version because we don't include wx.rc */
329
330     wxToolBar *toolbar = CreateToolBar(
331         wxTB_HORIZONTAL | wxTB_FLAT | wxTB_DOCKABLE );
332
333     toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
334
335     toolbar->AddTool( OpenFile_Event, wxU(_("File")), wxBitmap( file_xpm ),
336                       wxU(_(HELP_FILE)) );
337     toolbar->AddTool( OpenDisc_Event, wxU(_("Disc")), wxBitmap( disc_xpm ),
338                       wxU(_(HELP_DISC)) );
339     toolbar->AddTool( OpenNet_Event, wxU(_("Net")), wxBitmap( net_xpm ),
340                       wxU(_(HELP_NET)) );
341 #if 0
342     toolbar->AddTool( OpenSat_Event, wxU(_("Sat")), wxBitmap( sat_xpm ),
343                       wxU(_(HELP_SAT)) );
344 #endif
345     toolbar->AddSeparator();
346     toolbar->AddTool( StopStream_Event, wxU(_("Stop")), wxBitmap( stop_xpm ),
347                       wxU(_(HELP_STOP)) );
348     toolbar->AddTool( PlayStream_Event, wxU(_("Play")), wxBitmap( play_xpm ),
349                       wxU(_(HELP_PLAY)) );
350     toolbar->AddSeparator();
351     toolbar->AddTool( Playlist_Event, wxU(_("Playlist")),
352                       wxBitmap( playlist_xpm ), wxU(_(HELP_PLO)) );
353     toolbar->AddTool( PrevStream_Event, wxU(_("Prev")),
354                       wxBitmap( previous_xpm ), wxU(_(HELP_PLP)) );
355     toolbar->AddTool( NextStream_Event, wxU(_("Next")), wxBitmap( next_xpm ),
356                       wxU(_(HELP_PLN)) );
357     toolbar->AddTool( SlowStream_Event, wxU(_("Slower")), wxBitmap( slow_xpm ),
358                       wxU(_(HELP_SLOW)) );
359     toolbar->AddTool( FastStream_Event, wxU(_("Faster")), wxBitmap( fast_xpm ),
360                       wxU(_(HELP_FAST)) );
361
362     toolbar->Realize();
363
364     /* Place the toolbar in a sizer, so we can calculate the width of the
365      * toolbar and set this as the minimum for the main frame size. */
366     wxBoxSizer *toolbar_sizer = new wxBoxSizer( wxHORIZONTAL );
367     toolbar_sizer->Add( toolbar, 0, 0, 0 );
368     toolbar_sizer->Layout();
369
370 #ifndef WIN32
371     frame_sizer->SetMinSize( toolbar_sizer->GetMinSize().GetWidth(), -1 );
372 #else
373     frame_sizer->SetMinSize( toolbar->GetToolSize().GetWidth() *
374                              toolbar->GetToolsCount(), -1 );
375 #endif
376
377 #if !defined(__WXX11__)
378     /* Associate drop targets with the toolbar */
379     toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
380 #endif
381 }
382
383 void Interface::CreateOurSlider()
384 {
385     /* Create a new frame containing the slider */
386     slider_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
387     slider_frame->SetAutoLayout( TRUE );
388
389     /* Create static box to surround the slider */
390     slider_box = new wxStaticBox( slider_frame, -1, wxT("") );
391
392     /* Create sizer for slider frame */
393     wxStaticBoxSizer *slider_sizer =
394         new wxStaticBoxSizer( slider_box, wxHORIZONTAL );
395     slider_frame->SetSizer( slider_sizer );
396     slider_sizer->SetMinSize( -1, 50 );
397
398     /* Create slider */
399     slider = new wxSlider( slider_frame, SliderScroll_Event, 0, 0,
400                            SLIDER_MAX_POS, wxDefaultPosition, wxDefaultSize );
401     slider_sizer->Add( slider, 1, wxGROW | wxALL, 5 );
402     slider_sizer->Layout();
403     slider_sizer->SetSizeHints(slider_frame);
404
405     /* Hide the slider by default */
406     slider_frame->Hide();
407 }
408
409 void Interface::Open( int i_access_method )
410 {
411     /* Show/hide the open dialog */
412     if( p_open_dialog == NULL )
413         p_open_dialog = new OpenDialog( p_intf, this, i_access_method );
414
415     if( p_open_dialog && p_open_dialog->ShowModal() == wxID_OK )
416     {
417         /* Update the playlist */
418         playlist_t *p_playlist =
419             (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
420                                            FIND_ANYWHERE );
421         if( p_playlist == NULL )
422         {
423             return;
424         }
425
426         for( size_t i = 0; i < p_open_dialog->mrl.GetCount(); i++ )
427         {
428             playlist_Add( p_playlist,
429                 (const char *)p_open_dialog->mrl[i].mb_str(),
430                 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );
431         }
432
433         TogglePlayButton( PLAYING_S );
434
435         vlc_object_release( p_playlist );
436     }
437 }
438
439 /*****************************************************************************
440  * Event Handlers.
441  *****************************************************************************/
442 /* Work-around helper for buggy wxGTK */
443 void RecursiveDestroy( wxMenu *menu )
444 {
445     wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
446     for( ; node; )
447     {
448         wxMenuItem *item = node->GetData();
449         node = node->GetNext();
450
451         /* Delete the submenus */
452         wxMenu *submenu = item->GetSubMenu();
453         if( submenu )
454         {
455             RecursiveDestroy( submenu );
456         }
457         menu->Delete( item );
458     }
459 }
460
461 void Interface::OnMenuOpen(wxMenuEvent& event)
462 {
463 #if !defined( __WXMSW__ )
464     if( event.GetEventObject() == p_audio_menu )
465     {
466         if( b_audio_menu )
467         {
468             p_audio_menu = AudioMenu( p_intf, this );
469
470             /* Work-around for buggy wxGTK */
471             wxMenu *menu = GetMenuBar()->GetMenu( 3 );
472             RecursiveDestroy( menu );
473             /* End work-around */
474
475             menu =
476                 GetMenuBar()->Replace( 3, p_audio_menu, wxU(_("&Audio")) );
477             if( menu ) delete menu;
478
479             b_audio_menu = 0;
480         }
481         else b_audio_menu = 1;
482     }
483     else if( event.GetEventObject() == p_video_menu )
484     {
485         if( b_video_menu )
486         {
487             p_video_menu = VideoMenu( p_intf, this );
488
489             /* Work-around for buggy wxGTK */
490             wxMenu *menu = GetMenuBar()->GetMenu( 4 );
491             RecursiveDestroy( menu );
492             /* End work-around */
493
494             menu =
495                 GetMenuBar()->Replace( 4, p_video_menu, wxU(_("&Video")) );
496             if( menu ) delete menu;
497
498             b_video_menu = 0;
499         }
500         else b_video_menu = 1;
501     }
502     else if( event.GetEventObject() == p_navig_menu )
503     {
504         if( b_navig_menu )
505         {
506             p_navig_menu = NavigMenu( p_intf, this );
507
508             /* Work-around for buggy wxGTK */
509             wxMenu *menu = GetMenuBar()->GetMenu( 5 );
510             RecursiveDestroy( menu );
511             /* End work-around */
512
513             menu =
514                 GetMenuBar()->Replace( 5, p_navig_menu, wxU(_("&Navigation")));
515             if( menu ) delete menu;
516
517             b_navig_menu = 0;
518         }
519         else b_navig_menu = 1;
520     }
521
522 #else
523     p_audio_menu = AudioMenu( p_intf, this );
524     wxMenu *menu = GetMenuBar()->Replace( 3, p_audio_menu, wxU(_("&Audio")) );
525     if( menu ) delete menu;
526
527     p_video_menu = VideoMenu( p_intf, this );
528     menu = GetMenuBar()->Replace( 4, p_video_menu, wxU(_("&Video")) );
529     if( menu ) delete menu;
530
531     p_navig_menu = NavigMenu( p_intf, this );
532     menu = GetMenuBar()->Replace( 5, p_navig_menu, wxU(_("&Navigation")) );
533     if( menu ) delete menu;
534
535 #endif
536 }
537
538 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
539 void Interface::OnContextMenu(wxContextMenuEvent& event)
540 {
541     ::PopupMenu( p_intf, this, ScreenToClient(event.GetPosition()) );
542 }
543 #else
544 void Interface::OnContextMenu(wxMouseEvent& event)
545 {
546     ::PopupMenu( p_intf, this, event.GetPosition() );
547 }
548 #endif
549
550 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
551 {
552     /* TRUE is to force the frame to close. */
553     Close(TRUE);
554 }
555
556 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
557 {
558     wxString msg;
559     msg.Printf( wxString(wxT(VOUT_TITLE)) +
560         wxU(_(" (wxWindows interface)\n\n")) +
561         wxU(_("(C) 1996-2003 - the VideoLAN Team\n\n")) +
562         wxU(_("The VideoLAN team <videolan@videolan.org>\n"
563               "http://www.videolan.org/\n\n")) +
564         wxU(_("This is the VideoLAN Client, a DVD, MPEG and DivX player."
565               "\nIt can play MPEG and MPEG2 files from a file or from a "
566               "network source.")) );
567
568     wxMessageBox( msg, wxString::Format(wxU(_("About %s")), wxT(VOUT_TITLE)),
569                   wxOK | wxICON_INFORMATION, this );
570 }
571
572 void Interface::OnPlaylist( wxCommandEvent& WXUNUSED(event) )
573 {
574     /* Show/hide the playlist window */
575     Playlist *p_playlist_window = p_intf->p_sys->p_playlist_window;
576     if( p_playlist_window )
577     {
578         p_playlist_window->ShowPlaylist( ! p_playlist_window->IsShown() );
579     }
580 }
581
582 void Interface::OnLogs( wxCommandEvent& WXUNUSED(event) )
583 {
584     /* Show/hide the log window */
585     wxFrame *p_messages_window = p_intf->p_sys->p_messages_window;
586     if( p_messages_window )
587     {
588         p_messages_window->Show( ! p_messages_window->IsShown() );
589     }
590 }
591
592 void Interface::OnFileInfo( wxCommandEvent& WXUNUSED(event) )
593 {
594     /* Show/hide the file info window */
595     wxFrame *p_fileinfo_window = p_intf->p_sys->p_fileinfo_window;
596     if( p_fileinfo_window )
597     {
598         p_fileinfo_window->Show( ! p_fileinfo_window->IsShown() );
599     }
600 }
601
602 void Interface::OnPreferences( wxCommandEvent& WXUNUSED(event) )
603 {
604     /* Show/hide the open dialog */
605     if( p_prefs_dialog == NULL )
606     {
607         p_prefs_dialog = new PrefsDialog( p_intf, this );
608     }
609
610     if( p_prefs_dialog )
611     {
612         p_prefs_dialog->Show( true );
613     }
614 }
615
616 void Interface::OnOpenFile( wxCommandEvent& WXUNUSED(event) )
617 {
618     Open( FILE_ACCESS );
619 }
620
621 void Interface::OnOpenDisc( wxCommandEvent& WXUNUSED(event) )
622 {
623     Open( DISC_ACCESS );
624 }
625
626 void Interface::OnOpenNet( wxCommandEvent& WXUNUSED(event) )
627 {
628     Open( NET_ACCESS );
629 }
630
631 void Interface::OnOpenSat( wxCommandEvent& WXUNUSED(event) )
632 {
633     Open( SAT_ACCESS );
634 }
635
636 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
637 {
638     wxCommandEvent dummy;
639     playlist_t *p_playlist =
640         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
641                                        FIND_ANYWHERE );
642     if( p_playlist == NULL )
643     {
644         /* If the playlist is empty, open a file requester instead */
645         OnOpenFile( dummy );
646         return;
647     }
648
649     vlc_mutex_lock( &p_playlist->object_lock );
650     if( p_playlist->i_size )
651     {
652         vlc_mutex_unlock( &p_playlist->object_lock );
653
654         input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
655                                                        VLC_OBJECT_INPUT,
656                                                        FIND_ANYWHERE );
657         if( p_input == NULL )
658         {
659             /* No stream was playing, start one */
660             playlist_Play( p_playlist );
661             TogglePlayButton( PLAYING_S );
662             vlc_object_release( p_playlist );
663             return;
664         }
665
666         if( p_input->stream.control.i_status != PAUSE_S )
667         {
668             /* A stream is being played, pause it */
669             input_SetStatus( p_input, INPUT_STATUS_PAUSE );
670             TogglePlayButton( PAUSE_S );
671             vlc_object_release( p_playlist );
672             vlc_object_release( p_input );
673             return;
674         }
675
676         /* Stream is paused, resume it */
677         playlist_Play( p_playlist );
678         TogglePlayButton( PLAYING_S );
679         vlc_object_release( p_input );
680         vlc_object_release( p_playlist );
681     }
682     else
683     {
684         vlc_mutex_unlock( &p_playlist->object_lock );
685         vlc_object_release( p_playlist );
686         OnOpenFile( dummy );
687     }
688 }
689
690 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
691 {
692     playlist_t * p_playlist =
693         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
694                                        FIND_ANYWHERE );
695     if( p_playlist == NULL )
696     {
697         return;
698     }
699
700     playlist_Stop( p_playlist );
701     TogglePlayButton( PAUSE_S );
702     vlc_object_release( p_playlist );
703 }
704
705 void Interface::OnSliderUpdate( wxScrollEvent& event )
706 {
707     vlc_mutex_lock( &p_intf->change_lock );
708
709 #ifdef WIN32
710     if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
711         || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
712     {
713 #endif
714         if( p_intf->p_sys->i_slider_pos != event.GetPosition()
715             && p_intf->p_sys->p_input )
716         {
717             p_intf->p_sys->i_slider_pos = event.GetPosition();
718             input_Seek( p_intf->p_sys->p_input, p_intf->p_sys->i_slider_pos *
719                         100 / SLIDER_MAX_POS,
720                         INPUT_SEEK_PERCENT | INPUT_SEEK_SET );
721         }
722
723 #ifdef WIN32
724         p_intf->p_sys->b_slider_free = VLC_TRUE;
725     }
726     else
727     {
728         p_intf->p_sys->b_slider_free = VLC_FALSE;
729
730         if( p_intf->p_sys->p_input )
731         {
732             /* Update stream date */
733 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
734             char psz_time[ OFFSETTOTIME_MAX_SIZE ];
735
736             slider_box->SetLabel(
737                 wxU(input_OffsetToTime( p_intf->p_sys->p_input,
738                                         psz_time,
739                                         p_area->i_size * event.GetPosition()
740                                         / SLIDER_MAX_POS )) );
741 #undef p_area
742         }
743     }
744 #endif
745
746     vlc_mutex_unlock( &p_intf->change_lock );
747 }
748
749 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
750 {
751     playlist_t * p_playlist =
752         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
753                                        FIND_ANYWHERE );
754     if( p_playlist == NULL )
755     {
756         return;
757     }
758
759     playlist_Prev( p_playlist );
760     vlc_object_release( p_playlist );
761 }
762
763 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
764 {
765     playlist_t * p_playlist =
766         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
767                                        FIND_ANYWHERE );
768     if( p_playlist == NULL )
769     {
770         return;
771     }
772
773     playlist_Next( p_playlist );
774     vlc_object_release( p_playlist );
775 }
776
777 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
778 {
779     input_thread_t *p_input =
780         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
781                                            FIND_ANYWHERE );
782     if( p_input )
783     {
784         input_SetStatus( p_input, INPUT_STATUS_SLOWER );
785         vlc_object_release( p_input );
786     }
787 }
788
789 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
790 {
791     input_thread_t *p_input =
792         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
793                                            FIND_ANYWHERE );
794     if( p_input )
795     {
796         input_SetStatus( p_input, INPUT_STATUS_FASTER );
797         vlc_object_release( p_input );
798     }
799 }
800
801 void Interface::TogglePlayButton( int i_playing_status )
802 {
803     if( i_playing_status == i_old_playing_status )
804         return;
805
806     GetToolBar()->DeleteTool( PlayStream_Event );
807
808     if( i_playing_status == PLAYING_S )
809     {
810         GetToolBar()->InsertTool( 5, PlayStream_Event, wxU(_("Pause")),
811                                   wxBitmap( pause_xpm ) );
812     }
813     else
814     {
815         GetToolBar()->InsertTool( 5, PlayStream_Event, wxU(_("Play")),
816                                   wxBitmap( play_xpm ) );
817     }
818
819     GetToolBar()->Realize();
820
821     i_old_playing_status = i_playing_status;
822 }
823
824 #if !defined(__WXX11__)
825 /*****************************************************************************
826  * Definition of DragAndDrop class.
827  *****************************************************************************/
828 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf )
829 {
830     p_intf = _p_intf;
831 }
832
833 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
834                                const wxArrayString& filenames )
835 {
836     /* Add dropped files to the playlist */
837
838     playlist_t *p_playlist =
839         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
840                                        FIND_ANYWHERE );
841     if( p_playlist == NULL )
842     {
843         return FALSE;
844     }
845
846     for( size_t i = 0; i < filenames.GetCount(); i++ )
847         playlist_Add( p_playlist, (const char *)filenames[i].mb_str(),
848                       PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );
849
850     vlc_object_release( p_playlist );
851
852     return TRUE;
853 }
854 #endif