]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/interface.cpp
a3361d3479f5aa4d3d4b2460ff13620b70f19ebd
[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.55 2003/08/14 19:25:56 sigmunau Exp $
6  *
7  * Authors: Gildas Bazin <gbazin@netcourrier.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <string.h>                                            /* strerror() */
30 #include <stdio.h>
31
32 #include <vlc/vlc.h>
33 #include <vlc/aout.h>
34
35 #ifdef WIN32                                                 /* mingw32 hack */
36 #undef Yield
37 #undef CreateDialog
38 #endif
39
40 /* Let vlc take care of the i18n stuff */
41 #define WXINTL_NO_GETTEXT_MACRO
42
43 #include <wx/wxprec.h>
44 #include <wx/wx.h>
45
46 #include <vlc/intf.h>
47 #include "stream_control.h"
48
49 #include "wxwindows.h"
50
51 /* include the toolbar graphics */
52 #include "bitmaps/file.xpm"
53 #include "bitmaps/disc.xpm"
54 #include "bitmaps/net.xpm"
55 #if 0
56 #include "bitmaps/sat.xpm"
57 #endif
58 #include "bitmaps/play.xpm"
59 #include "bitmaps/pause.xpm"
60 #include "bitmaps/stop.xpm"
61 #include "bitmaps/previous.xpm"
62 #include "bitmaps/next.xpm"
63 #include "bitmaps/playlist.xpm"
64 #include "bitmaps/fast.xpm"
65 #include "bitmaps/slow.xpm"
66
67 #define TOOLBAR_BMP_WIDTH 36
68 #define TOOLBAR_BMP_HEIGHT 36
69
70 /* include the icon graphic */
71 #include "../../../share/vlc32x32.xpm"
72
73 /*****************************************************************************
74  * Local class declarations.
75  *****************************************************************************/
76 class wxMenuExt: public wxMenu
77 {
78 public:
79     /* Constructor */
80     wxMenuExt( wxMenu* parentMenu, int id, const wxString& text,
81                    const wxString& helpString, wxItemKind kind,
82                    char *_psz_var, int _i_object_id, vlc_value_t _val,
83                    int _i_val_type );
84
85     virtual ~wxMenuExt() {};
86
87     char *psz_var;
88     int  i_val_type;
89     int  i_object_id;
90     vlc_value_t val;
91
92 private:
93
94 };
95
96 class wxVolCtrl: public wxGauge
97 {
98 public:
99     /* Constructor */
100     wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id );
101     virtual ~wxVolCtrl() {};
102
103     void Change( int i_volume );
104
105     void OnChange( wxMouseEvent& event );
106
107 private:
108     intf_thread_t *p_intf;
109
110     DECLARE_EVENT_TABLE();
111 };
112
113 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
114     /* Mouse events */
115     EVT_LEFT_DOWN(wxVolCtrl::OnChange)
116     EVT_MOTION(wxVolCtrl::OnChange)
117 END_EVENT_TABLE()
118
119 /*****************************************************************************
120  * Event Table.
121  *****************************************************************************/
122
123 /* IDs for the controls and the menu commands */
124 enum
125 {
126     /* menu items */
127     Exit_Event = wxID_HIGHEST,
128     OpenFileSimple_Event,
129     OpenFile_Event,
130     OpenDisc_Event,
131     OpenNet_Event,
132     OpenSat_Event,
133     EjectDisc_Event,
134
135     Playlist_Event,
136     Logs_Event,
137     FileInfo_Event,
138
139     Prefs_Event,
140
141     SliderScroll_Event,
142     StopStream_Event,
143     PlayStream_Event,
144     PrevStream_Event,
145     NextStream_Event,
146     SlowStream_Event,
147     FastStream_Event,
148
149     /* it is important for the id corresponding to the "About" command to have
150      * this standard value as otherwise it won't be handled properly under Mac
151      * (where it is special and put into the "Apple" menu) */
152     About_Event = wxID_ABOUT
153 };
154
155 BEGIN_EVENT_TABLE(Interface, wxFrame)
156     /* Menu events */
157     EVT_MENU(Exit_Event, Interface::OnExit)
158     EVT_MENU(About_Event, Interface::OnAbout)
159
160     EVT_MENU(Playlist_Event, Interface::OnShowDialog)
161     EVT_MENU(Logs_Event, Interface::OnShowDialog)
162     EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
163     EVT_MENU(Prefs_Event, Interface::OnShowDialog)
164
165     EVT_MENU_OPEN(Interface::OnMenuOpen)
166
167 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
168     EVT_CONTEXT_MENU(Interface::OnContextMenu2)
169 #endif
170     EVT_RIGHT_UP(Interface::OnContextMenu)
171
172     /* Toolbar events */
173     EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
174     EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
175     EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
176     EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
177     EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
178     EVT_MENU(StopStream_Event, Interface::OnStopStream)
179     EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
180     EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
181     EVT_MENU(NextStream_Event, Interface::OnNextStream)
182     EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
183     EVT_MENU(FastStream_Event, Interface::OnFastStream)
184
185     /* Slider events */
186     EVT_COMMAND_SCROLL(SliderScroll_Event, Interface::OnSliderUpdate)
187
188 END_EVENT_TABLE()
189
190 /*****************************************************************************
191  * Constructor.
192  *****************************************************************************/
193 Interface::Interface( intf_thread_t *_p_intf ):
194     wxFrame( NULL, -1, wxT("VLC media player"),
195              wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE )
196 {
197     /* Initializations */
198     p_intf = _p_intf;
199     i_old_playing_status = PAUSE_S;
200
201     /* Give our interface a nice little icon */
202     SetIcon( wxIcon( vlc_xpm ) );
203
204     /* Create a sizer for the main frame */
205     frame_sizer = new wxBoxSizer( wxHORIZONTAL );
206     SetSizer( frame_sizer );
207
208     /* Create a dummy widget that can get the keyboard focus */
209     wxWindow *p_dummy = new wxWindow( this, 0, wxDefaultPosition,
210                                       wxSize(0,0) );
211     p_dummy->SetFocus();
212     frame_sizer->Add( p_dummy );
213                 
214     /* Creation of the menu bar */
215     CreateOurMenuBar();
216
217     /* Creation of the tool bar */
218     CreateOurToolBar();
219
220     /* Creation of the slider sub-window */
221     CreateOurSlider();
222     frame_sizer->Add( slider_frame, 1, wxGROW, 0 );
223     frame_sizer->Hide( slider_frame );
224
225     /* Creation of the status bar
226      * Helptext for menu items and toolbar tools will automatically get
227      * displayed here. */
228     int i_status_width[3] = {-6, -2, -9};
229     statusbar = CreateStatusBar( 3 );                            /* 2 fields */
230     statusbar->SetStatusWidths( 3, i_status_width );
231     statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
232
233     /* Make sure we've got the right background colour */
234     SetBackgroundColour( slider_frame->GetBackgroundColour() );
235
236     /* Layout everything */
237     SetAutoLayout( TRUE );
238     frame_sizer->Layout();
239     frame_sizer->Fit(this);
240
241 #if !defined(__WXX11__)
242     /* Associate drop targets with the main interface */
243     SetDropTarget( new DragAndDrop( p_intf ) );
244 #endif
245
246     UpdateAcceleratorTable();
247 }
248
249 Interface::~Interface()
250 {
251     if( p_intf->p_sys->p_wxwindow )
252     {
253         delete p_intf->p_sys->p_wxwindow;
254     }
255     /* Clean up */
256 }
257
258 /*****************************************************************************
259  * Private methods.
260  *****************************************************************************/
261 void Interface::CreateOurMenuBar()
262 {
263 #define HELP_FILE  N_("Open a file")
264 #define HELP_DISC  N_("Open a DVD or (S)VCD")
265 #define HELP_NET   N_("Open a network stream")
266 #define HELP_SAT   N_("Open a satellite stream")
267 #define HELP_EJECT N_("Eject the DVD/CD")
268 #define HELP_EXIT  N_("Exit this program")
269
270 #define HELP_PLAYLIST   N_("Open the playlist")
271 #define HELP_LOGS       N_("Show the program logs")
272 #define HELP_FILEINFO       N_("Show information about the file being played")
273
274 #define HELP_PREFS N_("Go to the preferences menu")
275
276 #define HELP_ABOUT N_("About this program")
277
278     /* Create the "File" menu */
279     wxMenu *file_menu = new wxMenu;
280     file_menu->Append( OpenFileSimple_Event, wxU(_("Simple &Open ...")),
281                        wxU(_(HELP_FILE)) );
282     file_menu->Append( OpenFile_Event, wxU(_("Open &File...")),
283                        wxU(_(HELP_FILE)) );
284     file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...")),
285                        wxU(_(HELP_DISC)) );
286     file_menu->Append( OpenNet_Event, wxU(_("Open &Network Stream...")),
287                        wxU(_(HELP_NET)) );
288 #if 0
289     file_menu->Append( OpenSat_Event, wxU(_("Open &Satellite Stream...")),
290                        wxU(_(HELP_NET)) );
291 #endif
292 #if 0
293     file_menu->AppendSeparator();
294     file_menu->Append( EjectDisc_Event, wxU(_("&Eject Disc")),
295                        wxU(_(HELP_EJECT)) );
296 #endif
297     file_menu->AppendSeparator();
298     file_menu->Append( Exit_Event, wxU(_("E&xit")), wxU(_(HELP_EXIT)) );
299
300     /* Create the "View" menu */
301     wxMenu *view_menu = new wxMenu;
302     view_menu->Append( Playlist_Event, wxU(_("&Playlist...")),
303                        wxU(_(HELP_PLAYLIST)) );
304     view_menu->Append( Logs_Event, wxU(_("&Messages...")), wxU(_(HELP_LOGS)) );
305     view_menu->Append( FileInfo_Event, wxU(_("&File info...")),
306                        wxU(_(HELP_FILEINFO)) );
307
308     /* Create the "Settings" menu */
309     wxMenu *settings_menu = new wxMenu;
310     settings_menu->Append( Prefs_Event, wxU(_("&Preferences...")),
311                            wxU(_(HELP_PREFS)) );
312
313     /* Create the "Audio" menu */
314     p_audio_menu = new wxMenu;
315     b_audio_menu = 1;
316
317     /* Create the "Video" menu */
318     p_video_menu = new wxMenu;
319     b_video_menu = 1;
320
321     /* Create the "Navigation" menu */
322     p_navig_menu = new wxMenu;
323     b_navig_menu = 1;
324
325     /* Create the "Help" menu */
326     wxMenu *help_menu = new wxMenu;
327     help_menu->Append( About_Event, wxU(_("&About...")), wxU(_(HELP_ABOUT)) );
328
329     /* Append the freshly created menus to the menu bar... */
330     wxMenuBar *menubar = new wxMenuBar( wxMB_DOCKABLE );
331     menubar->Append( file_menu, wxU(_("&File")) );
332     menubar->Append( view_menu, wxU(_("&View")) );
333     menubar->Append( settings_menu, wxU(_("&Settings")) );
334     menubar->Append( p_audio_menu, wxU(_("&Audio")) );
335     menubar->Append( p_video_menu, wxU(_("&Video")) );
336     menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
337     menubar->Append( help_menu, wxU(_("&Help")) );
338
339     /* Attach the menu bar to the frame */
340     SetMenuBar( menubar );
341
342     /* Intercept all menu events in our custom event handler */
343     PushEventHandler( new MenuEvtHandler( p_intf, this ) );
344
345 #if !defined(__WXX11__)
346     /* Associate drop targets with the menubar */
347     menubar->SetDropTarget( new DragAndDrop( p_intf ) );
348 #endif
349 }
350
351 void Interface::CreateOurToolBar()
352 {
353 #define HELP_STOP N_("Stop current playlist item")
354 #define HELP_PLAY N_("Play current playlist item")
355 #define HELP_PAUSE N_("Pause current playlist item")
356 #define HELP_PLO N_("Open playlist")
357 #define HELP_PLP N_("Previous playlist item")
358 #define HELP_PLN N_("Next playlist item")
359 #define HELP_SLOW N_("Play slower")
360 #define HELP_FAST N_("Play faster")
361
362     wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
363                          * version because we don't include wx.rc */
364
365     wxToolBar *toolbar = CreateToolBar(
366         wxTB_HORIZONTAL | wxTB_FLAT | wxTB_DOCKABLE );
367
368     toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
369
370     toolbar->AddTool( OpenFile_Event, wxU(_("File")), wxBitmap( file_xpm ),
371                       wxU(_(HELP_FILE)) );
372     toolbar->AddTool( OpenDisc_Event, wxU(_("Disc")), wxBitmap( disc_xpm ),
373                       wxU(_(HELP_DISC)) );
374     toolbar->AddTool( OpenNet_Event, wxU(_("Net")), wxBitmap( net_xpm ),
375                       wxU(_(HELP_NET)) );
376 #if 0
377     toolbar->AddTool( OpenSat_Event, wxU(_("Sat")), wxBitmap( sat_xpm ),
378                       wxU(_(HELP_SAT)) );
379 #endif
380     toolbar->AddSeparator();
381     toolbar->AddTool( StopStream_Event, wxU(_("Stop")), wxBitmap( stop_xpm ),
382                       wxU(_(HELP_STOP)) );
383     toolbar->AddTool( PlayStream_Event, wxU(_("Play")), wxBitmap( play_xpm ),
384                       wxU(_(HELP_PLAY)) );
385     toolbar->AddSeparator();
386     toolbar->AddTool( Playlist_Event, wxU(_("Playlist")),
387                       wxBitmap( playlist_xpm ), wxU(_(HELP_PLO)) );
388     toolbar->AddTool( PrevStream_Event, wxU(_("Prev")),
389                       wxBitmap( previous_xpm ), wxU(_(HELP_PLP)) );
390     toolbar->AddTool( NextStream_Event, wxU(_("Next")), wxBitmap( next_xpm ),
391                       wxU(_(HELP_PLN)) );
392     toolbar->AddTool( SlowStream_Event, wxU(_("Slower")), wxBitmap( slow_xpm ),
393                       wxU(_(HELP_SLOW)) );
394     toolbar->AddTool( FastStream_Event, wxU(_("Faster")), wxBitmap( fast_xpm ),
395                       wxU(_(HELP_FAST)) );
396
397     toolbar->Realize();
398
399     /* Place the toolbar in a sizer, so we can calculate the width of the
400      * toolbar and set this as the minimum for the main frame size. */
401     wxBoxSizer *toolbar_sizer = new wxBoxSizer( wxHORIZONTAL );
402     toolbar_sizer->Add( toolbar, 0, 0, 0 );
403     toolbar_sizer->Layout();
404
405 #ifndef WIN32
406     frame_sizer->SetMinSize( toolbar_sizer->GetMinSize().GetWidth(), -1 );
407 #else
408     frame_sizer->SetMinSize( toolbar->GetToolSize().GetWidth() *
409                              toolbar->GetToolsCount(), -1 );
410 #endif
411
412 #if !defined(__WXX11__)
413     /* Associate drop targets with the toolbar */
414     toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
415 #endif
416 }
417
418 void Interface::CreateOurSlider()
419 {
420     /* Create a new frame and sizer containing the slider */
421     slider_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
422     slider_frame->SetAutoLayout( TRUE );
423     wxBoxSizer *frame_sizer =
424         new wxBoxSizer( wxHORIZONTAL );
425
426     /* Create static box to surround the slider */
427     slider_box = new wxStaticBox( slider_frame, -1, wxT("") );
428
429     /* Create sizer for slider frame */
430     wxStaticBoxSizer *slider_sizer =
431         new wxStaticBoxSizer( slider_box, wxHORIZONTAL );
432     slider_sizer->SetMinSize( -1, 50 );
433
434     /* Create slider */
435     slider = new wxSlider( slider_frame, SliderScroll_Event, 0, 0,
436                            SLIDER_MAX_POS, wxDefaultPosition, wxDefaultSize );
437     slider_sizer->Add( slider, 1, wxEXPAND | wxALL, 5 );
438
439
440     volctrl = new wxVolCtrl( p_intf, slider_frame, -1 );
441
442     /* Add everything to the frame */
443     frame_sizer->Add( slider_sizer, 1, wxEXPAND | wxBOTTOM, 5 );
444     frame_sizer->Add( volctrl, 0, wxEXPAND | wxALL, 5 );
445     slider_frame->SetSizer( frame_sizer );
446     frame_sizer->Layout();
447     frame_sizer->SetSizeHints(slider_frame);
448
449     /* Hide the slider by default */
450     slider_frame->Hide();
451 }
452
453 void Interface::UpdateAcceleratorTable()
454 {
455     /* Set some hotkeys */
456     wxAcceleratorEntry entries[6];
457     int i_key = config_GetInt( p_intf, "quit-key" );
458     int i = 0;
459     entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
460                     Exit_Event );
461     i_key = config_GetInt( p_intf, "stop-key" );
462     entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
463                     StopStream_Event );
464     i_key = config_GetInt( p_intf, "play-pause-key" );
465     entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
466                     PlayStream_Event );
467     i_key = config_GetInt( p_intf, "next-key" );
468     entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
469                     NextStream_Event );
470     i_key = config_GetInt( p_intf, "prev-key" );
471     entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
472                     PrevStream_Event );
473     i_key = config_GetInt( p_intf, "faster-key" );
474     entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
475                     FastStream_Event );
476     i_key = config_GetInt( p_intf, "slower-key" );
477     entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
478                     SlowStream_Event );
479
480     wxAcceleratorTable accel( 6, entries );
481
482     if( !accel.Ok() )
483         msg_Err( p_intf, "invalid accelerator table" );
484     
485     SetAcceleratorTable( accel );
486     msg_Dbg( p_intf, "accelerator table loaded" );
487     
488 }
489
490 /*****************************************************************************
491  * Event Handlers.
492  *****************************************************************************/
493 /* Work-around helper for buggy wxGTK */
494 void RecursiveDestroy( wxMenu *menu )
495 {
496     wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
497     for( ; node; )
498     {
499         wxMenuItem *item = node->GetData();
500         node = node->GetNext();
501
502         /* Delete the submenus */
503         wxMenu *submenu = item->GetSubMenu();
504         if( submenu )
505         {
506             RecursiveDestroy( submenu );
507         }
508         menu->Delete( item );
509     }
510 }
511
512 void Interface::OnMenuOpen(wxMenuEvent& event)
513 {
514 #if !defined( __WXMSW__ )
515     if( event.GetEventObject() == p_audio_menu )
516     {
517         if( b_audio_menu )
518         {
519             p_audio_menu = AudioMenu( p_intf, this );
520
521             /* Work-around for buggy wxGTK */
522             wxMenu *menu = GetMenuBar()->GetMenu( 3 );
523             RecursiveDestroy( menu );
524             /* End work-around */
525
526             menu =
527                 GetMenuBar()->Replace( 3, p_audio_menu, wxU(_("&Audio")) );
528             if( menu ) delete menu;
529
530             b_audio_menu = 0;
531         }
532         else b_audio_menu = 1;
533     }
534     else if( event.GetEventObject() == p_video_menu )
535     {
536         if( b_video_menu )
537         {
538             p_video_menu = VideoMenu( p_intf, this );
539
540             /* Work-around for buggy wxGTK */
541             wxMenu *menu = GetMenuBar()->GetMenu( 4 );
542             RecursiveDestroy( menu );
543             /* End work-around */
544
545             menu =
546                 GetMenuBar()->Replace( 4, p_video_menu, wxU(_("&Video")) );
547             if( menu ) delete menu;
548
549             b_video_menu = 0;
550         }
551         else b_video_menu = 1;
552     }
553     else if( event.GetEventObject() == p_navig_menu )
554     {
555         if( b_navig_menu )
556         {
557             p_navig_menu = NavigMenu( p_intf, this );
558
559             /* Work-around for buggy wxGTK */
560             wxMenu *menu = GetMenuBar()->GetMenu( 5 );
561             RecursiveDestroy( menu );
562             /* End work-around */
563
564             menu =
565                 GetMenuBar()->Replace( 5, p_navig_menu, wxU(_("&Navigation")));
566             if( menu ) delete menu;
567
568             b_navig_menu = 0;
569         }
570         else b_navig_menu = 1;
571     }
572
573 #else
574     p_audio_menu = AudioMenu( p_intf, this );
575     wxMenu *menu = GetMenuBar()->Replace( 3, p_audio_menu, wxU(_("&Audio")) );
576     if( menu ) delete menu;
577
578     p_video_menu = VideoMenu( p_intf, this );
579     menu = GetMenuBar()->Replace( 4, p_video_menu, wxU(_("&Video")) );
580     if( menu ) delete menu;
581
582     p_navig_menu = NavigMenu( p_intf, this );
583     menu = GetMenuBar()->Replace( 5, p_navig_menu, wxU(_("&Navigation")) );
584     if( menu ) delete menu;
585
586 #endif
587 }
588
589 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
590 void Interface::OnContextMenu2(wxContextMenuEvent& event)
591 {
592     /* Only show the context menu for the main interface */
593     if( GetId() != event.GetId() )
594     {
595         event.Skip();
596         return;
597     }
598
599     if( p_intf->p_sys->pf_show_dialog )
600         p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 0, 0 );
601 }
602 #endif
603 void Interface::OnContextMenu(wxMouseEvent& event)
604 {
605     if( p_intf->p_sys->pf_show_dialog )
606         p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 0, 0 );
607 }
608
609 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
610 {
611     /* TRUE is to force the frame to close. */
612     Close(TRUE);
613 }
614
615 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
616 {
617     wxString msg;
618     msg.Printf( wxString(wxT("VLC media player " VERSION)) +
619         wxU(_(" (wxWindows interface)\n\n")) +
620         wxU(_("(C) 1996-2003 - the VideoLAN Team\n\n")) +
621         wxU(_("The VideoLAN team <videolan@videolan.org>\n"
622               "http://www.videolan.org/\n\n")) +
623         wxU(_("This is the VideoLAN Client, a DVD, MPEG and DivX player."
624               "\nIt can play MPEG and MPEG2 files from a file or from a "
625               "network source.")) );
626
627     wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
628                   wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
629 }
630
631 void Interface::OnShowDialog( wxCommandEvent& event )
632 {
633     if( p_intf->p_sys->pf_show_dialog )
634     {
635         int i_id;
636
637         switch( event.GetId() )
638         {
639         case OpenFileSimple_Event:
640             i_id = INTF_DIALOG_FILE_SIMPLE;
641             break;
642         case OpenFile_Event:
643             i_id = INTF_DIALOG_FILE;
644             break;
645         case OpenDisc_Event:
646             i_id = INTF_DIALOG_DISC;
647             break;
648         case OpenNet_Event:
649             i_id = INTF_DIALOG_NET;
650             break;
651         case OpenSat_Event:
652             i_id = INTF_DIALOG_SAT;
653             break;
654         case Playlist_Event:
655             i_id = INTF_DIALOG_PLAYLIST;
656             break;
657         case Logs_Event:
658             i_id = INTF_DIALOG_MESSAGES;
659             break;
660         case FileInfo_Event:
661             i_id = INTF_DIALOG_FILEINFO;
662             break;
663         case Prefs_Event:
664             i_id = INTF_DIALOG_PREFS;
665             break;
666         default:
667             i_id = INTF_DIALOG_FILE;
668             break;
669
670         }
671
672         p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
673     }
674 }
675
676 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
677 {
678     wxCommandEvent dummy;
679     playlist_t *p_playlist =
680         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
681                                        FIND_ANYWHERE );
682     if( p_playlist == NULL ) return;
683
684     if( p_playlist->i_size )
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         input_SetStatus( p_input, INPUT_STATUS_PLAY );
710         TogglePlayButton( PLAYING_S );
711         vlc_object_release( p_input );
712         vlc_object_release( p_playlist );
713     }
714     else
715     {
716         /* If the playlist is empty, open a file requester instead */
717         vlc_object_release( p_playlist );
718         OnShowDialog( 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     vlc_mutex_lock( &p_playlist->object_lock );
792     if( p_playlist->p_input != NULL )
793     {
794         vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
795         if( p_playlist->p_input->stream.p_selected_area->i_id > 1 )
796         {
797             vlc_value_t val; val.b_bool = VLC_TRUE;
798             vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
799             var_Set( p_playlist->p_input, "prev-title", val );
800             vlc_mutex_unlock( &p_playlist->object_lock );
801             vlc_object_release( p_playlist );  
802             return;
803         }
804         vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
805     }
806     vlc_mutex_unlock( &p_playlist->object_lock );
807
808     playlist_Prev( p_playlist );
809     vlc_object_release( p_playlist );
810 }
811
812 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
813 {
814     playlist_t * p_playlist =
815         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
816                                        FIND_ANYWHERE );
817     if( p_playlist == NULL )
818     {
819         return;
820     }
821
822     vlc_mutex_lock( &p_playlist->object_lock );
823     if( p_playlist->p_input != NULL )
824     {
825         vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
826         if( p_playlist->p_input->stream.i_area_nb > 1 &&
827             p_playlist->p_input->stream.p_selected_area->i_id <
828               p_playlist->p_input->stream.i_area_nb - 1 )
829         {
830             vlc_value_t val; val.b_bool = VLC_TRUE;
831             vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
832             var_Set( p_playlist->p_input, "next-title", val );
833             vlc_mutex_unlock( &p_playlist->object_lock );
834             vlc_object_release( p_playlist );  
835             return;
836         }
837         vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
838     }
839     vlc_mutex_unlock( &p_playlist->object_lock );
840
841     playlist_Next( p_playlist );
842     vlc_object_release( p_playlist );
843 }
844
845 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
846 {
847     input_thread_t *p_input =
848         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
849                                            FIND_ANYWHERE );
850     if( p_input )
851     {
852         input_SetStatus( p_input, INPUT_STATUS_SLOWER );
853         vlc_object_release( p_input );
854     }
855 }
856
857 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
858 {
859     input_thread_t *p_input =
860         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
861                                            FIND_ANYWHERE );
862     if( p_input )
863     {
864         input_SetStatus( p_input, INPUT_STATUS_FASTER );
865         vlc_object_release( p_input );
866     }
867 }
868
869 void Interface::TogglePlayButton( int i_playing_status )
870 {
871     if( i_playing_status == i_old_playing_status )
872         return;
873
874     GetToolBar()->DeleteTool( PlayStream_Event );
875
876     if( i_playing_status == PLAYING_S )
877     {
878         GetToolBar()->InsertTool( 5, PlayStream_Event, wxU(_("Pause")),
879                                   wxBitmap( pause_xpm ), wxNullBitmap,
880                                   wxITEM_NORMAL, wxU(_(HELP_PAUSE)) );
881     }
882     else
883     {
884         GetToolBar()->InsertTool( 5, PlayStream_Event, wxU(_("Play")),
885                                   wxBitmap( play_xpm ), wxNullBitmap,
886                                   wxITEM_NORMAL, wxU(_(HELP_PLAY)) );
887     }
888
889     GetToolBar()->Realize();
890
891     i_old_playing_status = i_playing_status;
892 }
893
894 #if !defined(__WXX11__)
895 /*****************************************************************************
896  * Definition of DragAndDrop class.
897  *****************************************************************************/
898 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf )
899 {
900     p_intf = _p_intf;
901 }
902
903 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
904                                const wxArrayString& filenames )
905 {
906     /* Add dropped files to the playlist */
907
908     playlist_t *p_playlist =
909         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
910                                        FIND_ANYWHERE );
911     if( p_playlist == NULL )
912     {
913         return FALSE;
914     }
915
916     for( size_t i = 0; i < filenames.GetCount(); i++ )
917         playlist_Add( p_playlist, (const char *)filenames[i].mb_str(), 0, 0,
918                       PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );
919
920     vlc_object_release( p_playlist );
921
922     return TRUE;
923 }
924 #endif
925
926 /*****************************************************************************
927  * Definition of wxVolCtrl class.
928  *****************************************************************************/
929 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id )
930   : wxGauge( parent, id, 200, wxDefaultPosition, wxDefaultSize,
931              wxGA_VERTICAL | wxGA_SMOOTH )
932 {
933     p_intf = _p_intf;
934 }
935
936 void wxVolCtrl::OnChange( wxMouseEvent& event )
937 {
938     if( !event.LeftDown() && !event.LeftIsDown() ) return;
939
940     int i_volume = (GetClientSize().GetHeight() - event.GetY()) * 200 /
941                     GetClientSize().GetHeight();
942     Change( i_volume );
943 }
944
945 void wxVolCtrl::Change( int i_volume )
946 {
947     aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 );
948     SetValue( i_volume );
949     SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
950                 i_volume ) );
951 }