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