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