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