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