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