83fa426fd4345634df82317e9d8b470e06684ab8
[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.34 2003/05/26 16:06:13 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
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(_("&Messages...")), 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 &&
416         p_open_dialog->ShowModal( i_access_method ) == wxID_OK )
417     {
418         /* Update the playlist */
419         playlist_t *p_playlist =
420             (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
421                                            FIND_ANYWHERE );
422         if( p_playlist == NULL )
423         {
424             return;
425         }
426
427         for( size_t i = 0; i < p_open_dialog->mrl.GetCount(); i++ )
428         {
429             playlist_Add( p_playlist,
430                 (const char *)p_open_dialog->mrl[i].mb_str(),
431                 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );
432         }
433
434         TogglePlayButton( PLAYING_S );
435
436         vlc_object_release( p_playlist );
437     }
438 }
439
440 /*****************************************************************************
441  * Event Handlers.
442  *****************************************************************************/
443 /* Work-around helper for buggy wxGTK */
444 void RecursiveDestroy( wxMenu *menu )
445 {
446     wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
447     for( ; node; )
448     {
449         wxMenuItem *item = node->GetData();
450         node = node->GetNext();
451
452         /* Delete the submenus */
453         wxMenu *submenu = item->GetSubMenu();
454         if( submenu )
455         {
456             RecursiveDestroy( submenu );
457         }
458         menu->Delete( item );
459     }
460 }
461
462 void Interface::OnMenuOpen(wxMenuEvent& event)
463 {
464 #if !defined( __WXMSW__ )
465     if( event.GetEventObject() == p_audio_menu )
466     {
467         if( b_audio_menu )
468         {
469             p_audio_menu = AudioMenu( p_intf, this );
470
471             /* Work-around for buggy wxGTK */
472             wxMenu *menu = GetMenuBar()->GetMenu( 3 );
473             RecursiveDestroy( menu );
474             /* End work-around */
475
476             menu =
477                 GetMenuBar()->Replace( 3, p_audio_menu, wxU(_("&Audio")) );
478             if( menu ) delete menu;
479
480             b_audio_menu = 0;
481         }
482         else b_audio_menu = 1;
483     }
484     else if( event.GetEventObject() == p_video_menu )
485     {
486         if( b_video_menu )
487         {
488             p_video_menu = VideoMenu( p_intf, this );
489
490             /* Work-around for buggy wxGTK */
491             wxMenu *menu = GetMenuBar()->GetMenu( 4 );
492             RecursiveDestroy( menu );
493             /* End work-around */
494
495             menu =
496                 GetMenuBar()->Replace( 4, p_video_menu, wxU(_("&Video")) );
497             if( menu ) delete menu;
498
499             b_video_menu = 0;
500         }
501         else b_video_menu = 1;
502     }
503     else if( event.GetEventObject() == p_navig_menu )
504     {
505         if( b_navig_menu )
506         {
507             p_navig_menu = NavigMenu( p_intf, this );
508
509             /* Work-around for buggy wxGTK */
510             wxMenu *menu = GetMenuBar()->GetMenu( 5 );
511             RecursiveDestroy( menu );
512             /* End work-around */
513
514             menu =
515                 GetMenuBar()->Replace( 5, p_navig_menu, wxU(_("&Navigation")));
516             if( menu ) delete menu;
517
518             b_navig_menu = 0;
519         }
520         else b_navig_menu = 1;
521     }
522
523 #else
524     p_audio_menu = AudioMenu( p_intf, this );
525     wxMenu *menu = GetMenuBar()->Replace( 3, p_audio_menu, wxU(_("&Audio")) );
526     if( menu ) delete menu;
527
528     p_video_menu = VideoMenu( p_intf, this );
529     menu = GetMenuBar()->Replace( 4, p_video_menu, wxU(_("&Video")) );
530     if( menu ) delete menu;
531
532     p_navig_menu = NavigMenu( p_intf, this );
533     menu = GetMenuBar()->Replace( 5, p_navig_menu, wxU(_("&Navigation")) );
534     if( menu ) delete menu;
535
536 #endif
537 }
538
539 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
540 void Interface::OnContextMenu(wxContextMenuEvent& event)
541 {
542     ::PopupMenu( p_intf, this, ScreenToClient(event.GetPosition()) );
543 }
544 #else
545 void Interface::OnContextMenu(wxMouseEvent& event)
546 {
547     ::PopupMenu( p_intf, this, event.GetPosition() );
548 }
549 #endif
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