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