* control: use new variables and 'title*', 'chapter*' ones.
[vlc.git] / 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.60 2003/09/07 22:53:09 fenrir 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 #include <vlc/intf.h>
35 #include "stream_control.h"
36
37 #include "wxwindows.h"
38
39 /* include the toolbar graphics */
40 #include "bitmaps/file.xpm"
41 #include "bitmaps/disc.xpm"
42 #include "bitmaps/net.xpm"
43 #if 0
44 #include "bitmaps/sat.xpm"
45 #endif
46 #include "bitmaps/play.xpm"
47 #include "bitmaps/pause.xpm"
48 #include "bitmaps/stop.xpm"
49 #include "bitmaps/previous.xpm"
50 #include "bitmaps/next.xpm"
51 #include "bitmaps/playlist.xpm"
52 #include "bitmaps/fast.xpm"
53 #include "bitmaps/slow.xpm"
54
55 #define TOOLBAR_BMP_WIDTH 36
56 #define TOOLBAR_BMP_HEIGHT 36
57
58 /* include the icon graphic */
59 #include "../../../share/vlc32x32.xpm"
60
61 /*****************************************************************************
62  * Local class declarations.
63  *****************************************************************************/
64 class wxMenuExt: public wxMenu
65 {
66 public:
67     /* Constructor */
68     wxMenuExt( wxMenu* parentMenu, int id, const wxString& text,
69                    const wxString& helpString, wxItemKind kind,
70                    char *_psz_var, int _i_object_id, vlc_value_t _val,
71                    int _i_val_type );
72
73     virtual ~wxMenuExt() {};
74
75     char *psz_var;
76     int  i_val_type;
77     int  i_object_id;
78     vlc_value_t val;
79
80 private:
81
82 };
83
84 class wxVolCtrl: public wxGauge
85 {
86 public:
87     /* Constructor */
88     wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id );
89     virtual ~wxVolCtrl() {};
90
91     void Change( int i_volume );
92
93     void OnChange( wxMouseEvent& event );
94
95 private:
96     intf_thread_t *p_intf;
97
98     DECLARE_EVENT_TABLE();
99 };
100
101 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
102     /* Mouse events */
103     EVT_LEFT_DOWN(wxVolCtrl::OnChange)
104     EVT_MOTION(wxVolCtrl::OnChange)
105 END_EVENT_TABLE()
106
107 /*****************************************************************************
108  * Event Table.
109  *****************************************************************************/
110
111 /* IDs for the controls and the menu commands */
112 enum
113 {
114     /* menu items */
115     Exit_Event = wxID_HIGHEST,
116     OpenFileSimple_Event,
117     OpenFile_Event,
118     OpenDisc_Event,
119     OpenNet_Event,
120     OpenSat_Event,
121     EjectDisc_Event,
122
123     Playlist_Event,
124     Logs_Event,
125     FileInfo_Event,
126
127     Prefs_Event,
128
129     SliderScroll_Event,
130     StopStream_Event,
131     PlayStream_Event,
132     PrevStream_Event,
133     NextStream_Event,
134     SlowStream_Event,
135     FastStream_Event,
136
137     /* it is important for the id corresponding to the "About" command to have
138      * this standard value as otherwise it won't be handled properly under Mac
139      * (where it is special and put into the "Apple" menu) */
140     About_Event = wxID_ABOUT
141 };
142
143 BEGIN_EVENT_TABLE(Interface, wxFrame)
144     /* Menu events */
145     EVT_MENU(Exit_Event, Interface::OnExit)
146     EVT_MENU(About_Event, Interface::OnAbout)
147
148     EVT_MENU(Playlist_Event, Interface::OnShowDialog)
149     EVT_MENU(Logs_Event, Interface::OnShowDialog)
150     EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
151     EVT_MENU(Prefs_Event, Interface::OnShowDialog)
152
153     EVT_MENU_OPEN(Interface::OnMenuOpen)
154
155 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
156     EVT_CONTEXT_MENU(Interface::OnContextMenu2)
157 #endif
158     EVT_RIGHT_UP(Interface::OnContextMenu)
159
160     /* Toolbar events */
161     EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
162     EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
163     EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
164     EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
165     EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
166     EVT_MENU(StopStream_Event, Interface::OnStopStream)
167     EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
168     EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
169     EVT_MENU(NextStream_Event, Interface::OnNextStream)
170     EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
171     EVT_MENU(FastStream_Event, Interface::OnFastStream)
172
173     /* Slider events */
174     EVT_COMMAND_SCROLL(SliderScroll_Event, Interface::OnSliderUpdate)
175
176 END_EVENT_TABLE()
177
178 /*****************************************************************************
179  * Constructor.
180  *****************************************************************************/
181 Interface::Interface( intf_thread_t *_p_intf ):
182     wxFrame( NULL, -1, wxT("VLC media player"),
183              wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE )
184 {
185     /* Initializations */
186     p_intf = _p_intf;
187     i_old_playing_status = PAUSE_S;
188
189     /* Give our interface a nice little icon */
190     SetIcon( wxIcon( vlc_xpm ) );
191
192     /* Create a sizer for the main frame */
193     frame_sizer = new wxBoxSizer( wxHORIZONTAL );
194     SetSizer( frame_sizer );
195
196     /* Create a dummy widget that can get the keyboard focus */
197     wxWindow *p_dummy = new wxWindow( this, 0, wxDefaultPosition,
198                                       wxSize(0,0) );
199     p_dummy->SetFocus();
200     frame_sizer->Add( p_dummy );
201                 
202     /* Creation of the menu bar */
203     CreateOurMenuBar();
204
205     /* Creation of the tool bar */
206     CreateOurToolBar();
207
208     /* Creation of the slider sub-window */
209     CreateOurSlider();
210     frame_sizer->Add( slider_frame, 1, wxGROW, 0 );
211     frame_sizer->Hide( slider_frame );
212
213     /* Creation of the status bar
214      * Helptext for menu items and toolbar tools will automatically get
215      * displayed here. */
216     int i_status_width[3] = {-6, -2, -9};
217     statusbar = CreateStatusBar( 3 );                            /* 2 fields */
218     statusbar->SetStatusWidths( 3, i_status_width );
219     statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
220
221     /* Make sure we've got the right background colour */
222     SetBackgroundColour( slider_frame->GetBackgroundColour() );
223
224     /* Layout everything */
225     SetAutoLayout( TRUE );
226     frame_sizer->Layout();
227     frame_sizer->Fit(this);
228
229 #if !defined(__WXX11__)
230     /* Associate drop targets with the main interface */
231     SetDropTarget( new DragAndDrop( p_intf ) );
232 #endif
233
234     UpdateAcceleratorTable();
235 }
236
237 Interface::~Interface()
238 {
239     if( p_intf->p_sys->p_wxwindow )
240     {
241         delete p_intf->p_sys->p_wxwindow;
242     }
243     /* Clean up */
244 }
245
246 /*****************************************************************************
247  * Private methods.
248  *****************************************************************************/
249 void Interface::CreateOurMenuBar()
250 {
251 #define HELP_FILE  N_("Open a file")
252 #define HELP_DISC  N_("Open a DVD or (S)VCD")
253 #define HELP_NET   N_("Open a network stream")
254 #define HELP_SAT   N_("Open a satellite stream")
255 #define HELP_EJECT N_("Eject the DVD/CD")
256 #define HELP_EXIT  N_("Exit this program")
257
258 #define HELP_PLAYLIST   N_("Open the playlist")
259 #define HELP_LOGS       N_("Show the program logs")
260 #define HELP_FILEINFO       N_("Show information about the file being played")
261
262 #define HELP_PREFS N_("Go to the preferences menu")
263
264 #define HELP_ABOUT N_("About this program")
265
266     /* Create the "File" menu */
267     wxMenu *file_menu = new wxMenu;
268     file_menu->Append( OpenFileSimple_Event, wxU(_("Simple &Open ...")),
269                        wxU(_(HELP_FILE)) );
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(_("Open &Network Stream...")),
275                        wxU(_(HELP_NET)) );
276 #if 0
277     file_menu->Append( OpenSat_Event, wxU(_("Open &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::UpdateAcceleratorTable()
442 {
443     /* Set some hotkeys */
444     wxAcceleratorEntry entries[7];
445     int i_key = config_GetInt( p_intf, "quit-key" );
446     int i = 0;
447     entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
448                     Exit_Event );
449     i_key = config_GetInt( p_intf, "stop-key" );
450     entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
451                     StopStream_Event );
452     i_key = config_GetInt( p_intf, "play-pause-key" );
453     entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
454                     PlayStream_Event );
455     i_key = config_GetInt( p_intf, "next-key" );
456     entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
457                     NextStream_Event );
458     i_key = config_GetInt( p_intf, "prev-key" );
459     entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
460                     PrevStream_Event );
461     i_key = config_GetInt( p_intf, "faster-key" );
462     entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
463                     FastStream_Event );
464     i_key = config_GetInt( p_intf, "slower-key" );
465     entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
466                     SlowStream_Event );
467
468     wxAcceleratorTable accel( 7, entries );
469
470     if( !accel.Ok() )
471         msg_Err( p_intf, "invalid accelerator table" );
472     
473     SetAcceleratorTable( accel );
474     msg_Dbg( p_intf, "accelerator table loaded" );
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     /* Only show the context menu for the main interface */
581     if( GetId() != event.GetId() )
582     {
583         event.Skip();
584         return;
585     }
586
587     if( p_intf->p_sys->pf_show_dialog )
588         p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
589 }
590 #endif
591 void Interface::OnContextMenu(wxMouseEvent& event)
592 {
593     if( p_intf->p_sys->pf_show_dialog )
594         p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
595 }
596
597 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
598 {
599     /* TRUE is to force the frame to close. */
600     Close(TRUE);
601 }
602
603 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
604 {
605     wxString msg;
606     msg.Printf( wxString(wxT("VLC media player " VERSION)) +
607         wxU(_(" (wxWindows interface)\n\n")) +
608         wxU(_("(C) 1996-2003 - the VideoLAN Team\n\n")) +
609         wxU( INTF_ABOUT_MSG ) + wxT("\n\n") +
610         wxU(_("The VideoLAN team <videolan@videolan.org>\n"
611               "http://www.videolan.org/\n\n")) );
612
613     wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
614                   wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
615 }
616
617 void Interface::OnShowDialog( wxCommandEvent& event )
618 {
619     if( p_intf->p_sys->pf_show_dialog )
620     {
621         int i_id;
622
623         switch( event.GetId() )
624         {
625         case OpenFileSimple_Event:
626             i_id = INTF_DIALOG_FILE_SIMPLE;
627             break;
628         case OpenFile_Event:
629             i_id = INTF_DIALOG_FILE;
630             break;
631         case OpenDisc_Event:
632             i_id = INTF_DIALOG_DISC;
633             break;
634         case OpenNet_Event:
635             i_id = INTF_DIALOG_NET;
636             break;
637         case OpenSat_Event:
638             i_id = INTF_DIALOG_SAT;
639             break;
640         case Playlist_Event:
641             i_id = INTF_DIALOG_PLAYLIST;
642             break;
643         case Logs_Event:
644             i_id = INTF_DIALOG_MESSAGES;
645             break;
646         case FileInfo_Event:
647             i_id = INTF_DIALOG_FILEINFO;
648             break;
649         case Prefs_Event:
650             i_id = INTF_DIALOG_PREFS;
651             break;
652         default:
653             i_id = INTF_DIALOG_FILE;
654             break;
655
656         }
657
658         p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
659     }
660 }
661
662 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
663 {
664     wxCommandEvent dummy;
665     playlist_t *p_playlist =
666         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
667                                        FIND_ANYWHERE );
668     if( p_playlist == NULL ) return;
669
670     if( p_playlist->i_size )
671     {
672         vlc_value_t state;
673
674         input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
675                                                        VLC_OBJECT_INPUT,
676                                                        FIND_ANYWHERE );
677         if( p_input == NULL )
678         {
679             /* No stream was playing, start one */
680             playlist_Play( p_playlist );
681             TogglePlayButton( PLAYING_S );
682             vlc_object_release( p_playlist );
683             return;
684         }
685
686         var_Get( p_input, "state", &state );
687
688         if( state.i_int != PAUSE_S )
689         {
690             /* A stream is being played, pause it */
691             state.i_int = PAUSE_S;
692         }
693         else
694         {
695             /* Stream is paused, resume it */
696             state.i_int = PLAYING_S;
697         }
698         var_Set( p_input, "state", state );
699
700         TogglePlayButton( state.i_int );
701         vlc_object_release( p_input );
702         vlc_object_release( p_playlist );
703     }
704     else
705     {
706         /* If the playlist is empty, open a file requester instead */
707         vlc_object_release( p_playlist );
708         OnShowDialog( dummy );
709     }
710 }
711
712 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
713 {
714     playlist_t * p_playlist =
715         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
716                                        FIND_ANYWHERE );
717     if( p_playlist == NULL )
718     {
719         return;
720     }
721
722     playlist_Stop( p_playlist );
723     TogglePlayButton( PAUSE_S );
724     vlc_object_release( p_playlist );
725 }
726
727 void Interface::OnSliderUpdate( wxScrollEvent& event )
728 {
729     vlc_mutex_lock( &p_intf->change_lock );
730
731 #ifdef WIN32
732     if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
733         || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
734     {
735 #endif
736         if( p_intf->p_sys->i_slider_pos != event.GetPosition()
737             && p_intf->p_sys->p_input )
738         {
739             vlc_value_t pos;
740             pos.f_float = (float)event.GetPosition() / (float)SLIDER_MAX_POS;
741
742             var_Set( p_intf->p_sys->p_input, "position", pos );
743         }
744
745 #ifdef WIN32
746         p_intf->p_sys->b_slider_free = VLC_TRUE;
747     }
748     else
749     {
750         p_intf->p_sys->b_slider_free = VLC_FALSE;
751
752         if( p_intf->p_sys->p_input )
753         {
754             /* Update stream date */
755 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
756             char psz_time[ OFFSETTOTIME_MAX_SIZE ];
757
758             slider_box->SetLabel(
759                 wxU(input_OffsetToTime( p_intf->p_sys->p_input,
760                                         psz_time,
761                                         p_area->i_size * event.GetPosition()
762                                         / SLIDER_MAX_POS )) );
763 #undef p_area
764         }
765     }
766 #endif
767
768     vlc_mutex_unlock( &p_intf->change_lock );
769 }
770
771 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
772 {
773     playlist_t * p_playlist =
774         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
775                                        FIND_ANYWHERE );
776     if( p_playlist == NULL )
777     {
778         return;
779     }
780
781     vlc_mutex_lock( &p_playlist->object_lock );
782     if( p_playlist->p_input != NULL )
783     {
784         vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
785         if( p_playlist->p_input->stream.p_selected_area->i_id > 1 )
786         {
787             vlc_value_t val; val.b_bool = VLC_TRUE;
788             vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
789             var_Set( p_playlist->p_input, "prev-title", val );
790             vlc_mutex_unlock( &p_playlist->object_lock );
791             vlc_object_release( p_playlist );  
792             return;
793         }
794         vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
795     }
796     vlc_mutex_unlock( &p_playlist->object_lock );
797
798     playlist_Prev( p_playlist );
799     vlc_object_release( p_playlist );
800 }
801
802 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
803 {
804     playlist_t * p_playlist =
805         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
806                                        FIND_ANYWHERE );
807     if( p_playlist == NULL )
808     {
809         return;
810     }
811
812     vlc_mutex_lock( &p_playlist->object_lock );
813     if( p_playlist->p_input != NULL )
814     {
815         vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
816         if( p_playlist->p_input->stream.i_area_nb > 1 &&
817             p_playlist->p_input->stream.p_selected_area->i_id <
818               p_playlist->p_input->stream.i_area_nb - 1 )
819         {
820             vlc_value_t val; val.b_bool = VLC_TRUE;
821             vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
822             var_Set( p_playlist->p_input, "next-title", val );
823             vlc_mutex_unlock( &p_playlist->object_lock );
824             vlc_object_release( p_playlist );  
825             return;
826         }
827         vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
828     }
829     vlc_mutex_unlock( &p_playlist->object_lock );
830
831     playlist_Next( p_playlist );
832     vlc_object_release( p_playlist );
833 }
834
835 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
836 {
837     input_thread_t *p_input =
838         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
839                                            FIND_ANYWHERE );
840     if( p_input )
841     {
842         vlc_value_t val; val.b_bool = VLC_TRUE;
843
844         var_Set( p_input, "rate-slower", val );
845         vlc_object_release( p_input );
846     }
847 }
848
849 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
850 {
851     input_thread_t *p_input =
852         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
853                                            FIND_ANYWHERE );
854     if( p_input )
855     {
856         vlc_value_t val; val.b_bool = VLC_TRUE;
857
858         var_Set( p_input, "rate-faster", val );
859         vlc_object_release( p_input );
860     }
861 }
862
863 void Interface::TogglePlayButton( int i_playing_status )
864 {
865     if( i_playing_status == i_old_playing_status )
866         return;
867
868     GetToolBar()->DeleteTool( PlayStream_Event );
869
870     if( i_playing_status == PLAYING_S )
871     {
872         GetToolBar()->InsertTool( 5, PlayStream_Event, wxU(_("Pause")),
873                                   wxBitmap( pause_xpm ), wxNullBitmap,
874                                   wxITEM_NORMAL, wxU(_(HELP_PAUSE)) );
875     }
876     else
877     {
878         GetToolBar()->InsertTool( 5, PlayStream_Event, wxU(_("Play")),
879                                   wxBitmap( play_xpm ), wxNullBitmap,
880                                   wxITEM_NORMAL, wxU(_(HELP_PLAY)) );
881     }
882
883     GetToolBar()->Realize();
884
885     i_old_playing_status = i_playing_status;
886 }
887
888 #if !defined(__WXX11__)
889 /*****************************************************************************
890  * Definition of DragAndDrop class.
891  *****************************************************************************/
892 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf )
893 {
894     p_intf = _p_intf;
895 }
896
897 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
898                                const wxArrayString& filenames )
899 {
900     /* Add dropped files to the playlist */
901
902     playlist_t *p_playlist =
903         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
904                                        FIND_ANYWHERE );
905     if( p_playlist == NULL )
906     {
907         return FALSE;
908     }
909
910     for( size_t i = 0; i < filenames.GetCount(); i++ )
911         playlist_Add( p_playlist, (const char *)filenames[i].mb_str(), 0, 0,
912                       PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );
913
914     vlc_object_release( p_playlist );
915
916     return TRUE;
917 }
918 #endif
919
920 /*****************************************************************************
921  * Definition of wxVolCtrl class.
922  *****************************************************************************/
923 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id )
924   : wxGauge( parent, id, 200, wxDefaultPosition, wxDefaultSize,
925              wxGA_VERTICAL | wxGA_SMOOTH )
926 {
927     p_intf = _p_intf;
928 }
929
930 void wxVolCtrl::OnChange( wxMouseEvent& event )
931 {
932     if( !event.LeftDown() && !event.LeftIsDown() ) return;
933
934     int i_volume = (GetClientSize().GetHeight() - event.GetY()) * 200 /
935                     GetClientSize().GetHeight();
936     Change( i_volume );
937 }
938
939 void wxVolCtrl::Change( int i_volume )
940 {
941     aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 );
942     SetValue( i_volume );
943     SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
944                 i_volume ) );
945 }