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