]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/interface.cpp
* include/vlc_config.h: removed unused config stuff.
[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.59 2003/08/30 13:59:15 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 #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         input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
673                                                        VLC_OBJECT_INPUT,
674                                                        FIND_ANYWHERE );
675         if( p_input == NULL )
676         {
677             /* No stream was playing, start one */
678             playlist_Play( p_playlist );
679             TogglePlayButton( PLAYING_S );
680             vlc_object_release( p_playlist );
681             return;
682         }
683
684         if( p_input->stream.control.i_status != PAUSE_S )
685         {
686             /* A stream is being played, pause it */
687             input_SetStatus( p_input, INPUT_STATUS_PAUSE );
688             TogglePlayButton( PAUSE_S );
689             vlc_object_release( p_playlist );
690             vlc_object_release( p_input );
691             return;
692         }
693
694         /* Stream is paused, resume it */
695         input_SetStatus( p_input, INPUT_STATUS_PLAY );
696         TogglePlayButton( PLAYING_S );
697         vlc_object_release( p_input );
698         vlc_object_release( p_playlist );
699     }
700     else
701     {
702         /* If the playlist is empty, open a file requester instead */
703         vlc_object_release( p_playlist );
704         OnShowDialog( dummy );
705     }
706 }
707
708 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
709 {
710     playlist_t * p_playlist =
711         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
712                                        FIND_ANYWHERE );
713     if( p_playlist == NULL )
714     {
715         return;
716     }
717
718     playlist_Stop( p_playlist );
719     TogglePlayButton( PAUSE_S );
720     vlc_object_release( p_playlist );
721 }
722
723 void Interface::OnSliderUpdate( wxScrollEvent& event )
724 {
725     vlc_mutex_lock( &p_intf->change_lock );
726
727 #ifdef WIN32
728     if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
729         || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
730     {
731 #endif
732         if( p_intf->p_sys->i_slider_pos != event.GetPosition()
733             && p_intf->p_sys->p_input )
734         {
735             p_intf->p_sys->i_slider_pos = event.GetPosition();
736             input_Seek( p_intf->p_sys->p_input, p_intf->p_sys->i_slider_pos *
737                         100 / SLIDER_MAX_POS,
738                         INPUT_SEEK_PERCENT | INPUT_SEEK_SET );
739         }
740
741 #ifdef WIN32
742         p_intf->p_sys->b_slider_free = VLC_TRUE;
743     }
744     else
745     {
746         p_intf->p_sys->b_slider_free = VLC_FALSE;
747
748         if( p_intf->p_sys->p_input )
749         {
750             /* Update stream date */
751 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
752             char psz_time[ OFFSETTOTIME_MAX_SIZE ];
753
754             slider_box->SetLabel(
755                 wxU(input_OffsetToTime( p_intf->p_sys->p_input,
756                                         psz_time,
757                                         p_area->i_size * event.GetPosition()
758                                         / SLIDER_MAX_POS )) );
759 #undef p_area
760         }
761     }
762 #endif
763
764     vlc_mutex_unlock( &p_intf->change_lock );
765 }
766
767 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
768 {
769     playlist_t * p_playlist =
770         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
771                                        FIND_ANYWHERE );
772     if( p_playlist == NULL )
773     {
774         return;
775     }
776
777     vlc_mutex_lock( &p_playlist->object_lock );
778     if( p_playlist->p_input != NULL )
779     {
780         vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
781         if( p_playlist->p_input->stream.p_selected_area->i_id > 1 )
782         {
783             vlc_value_t val; val.b_bool = VLC_TRUE;
784             vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
785             var_Set( p_playlist->p_input, "prev-title", val );
786             vlc_mutex_unlock( &p_playlist->object_lock );
787             vlc_object_release( p_playlist );  
788             return;
789         }
790         vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
791     }
792     vlc_mutex_unlock( &p_playlist->object_lock );
793
794     playlist_Prev( p_playlist );
795     vlc_object_release( p_playlist );
796 }
797
798 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
799 {
800     playlist_t * p_playlist =
801         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
802                                        FIND_ANYWHERE );
803     if( p_playlist == NULL )
804     {
805         return;
806     }
807
808     vlc_mutex_lock( &p_playlist->object_lock );
809     if( p_playlist->p_input != NULL )
810     {
811         vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
812         if( p_playlist->p_input->stream.i_area_nb > 1 &&
813             p_playlist->p_input->stream.p_selected_area->i_id <
814               p_playlist->p_input->stream.i_area_nb - 1 )
815         {
816             vlc_value_t val; val.b_bool = VLC_TRUE;
817             vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
818             var_Set( p_playlist->p_input, "next-title", val );
819             vlc_mutex_unlock( &p_playlist->object_lock );
820             vlc_object_release( p_playlist );  
821             return;
822         }
823         vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
824     }
825     vlc_mutex_unlock( &p_playlist->object_lock );
826
827     playlist_Next( p_playlist );
828     vlc_object_release( p_playlist );
829 }
830
831 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
832 {
833     input_thread_t *p_input =
834         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
835                                            FIND_ANYWHERE );
836     if( p_input )
837     {
838         input_SetStatus( p_input, INPUT_STATUS_SLOWER );
839         vlc_object_release( p_input );
840     }
841 }
842
843 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
844 {
845     input_thread_t *p_input =
846         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
847                                            FIND_ANYWHERE );
848     if( p_input )
849     {
850         input_SetStatus( p_input, INPUT_STATUS_FASTER );
851         vlc_object_release( p_input );
852     }
853 }
854
855 void Interface::TogglePlayButton( int i_playing_status )
856 {
857     if( i_playing_status == i_old_playing_status )
858         return;
859
860     GetToolBar()->DeleteTool( PlayStream_Event );
861
862     if( i_playing_status == PLAYING_S )
863     {
864         GetToolBar()->InsertTool( 5, PlayStream_Event, wxU(_("Pause")),
865                                   wxBitmap( pause_xpm ), wxNullBitmap,
866                                   wxITEM_NORMAL, wxU(_(HELP_PAUSE)) );
867     }
868     else
869     {
870         GetToolBar()->InsertTool( 5, PlayStream_Event, wxU(_("Play")),
871                                   wxBitmap( play_xpm ), wxNullBitmap,
872                                   wxITEM_NORMAL, wxU(_(HELP_PLAY)) );
873     }
874
875     GetToolBar()->Realize();
876
877     i_old_playing_status = i_playing_status;
878 }
879
880 #if !defined(__WXX11__)
881 /*****************************************************************************
882  * Definition of DragAndDrop class.
883  *****************************************************************************/
884 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf )
885 {
886     p_intf = _p_intf;
887 }
888
889 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
890                                const wxArrayString& filenames )
891 {
892     /* Add dropped files to the playlist */
893
894     playlist_t *p_playlist =
895         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
896                                        FIND_ANYWHERE );
897     if( p_playlist == NULL )
898     {
899         return FALSE;
900     }
901
902     for( size_t i = 0; i < filenames.GetCount(); i++ )
903         playlist_Add( p_playlist, (const char *)filenames[i].mb_str(), 0, 0,
904                       PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );
905
906     vlc_object_release( p_playlist );
907
908     return TRUE;
909 }
910 #endif
911
912 /*****************************************************************************
913  * Definition of wxVolCtrl class.
914  *****************************************************************************/
915 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id )
916   : wxGauge( parent, id, 200, wxDefaultPosition, wxDefaultSize,
917              wxGA_VERTICAL | wxGA_SMOOTH )
918 {
919     p_intf = _p_intf;
920 }
921
922 void wxVolCtrl::OnChange( wxMouseEvent& event )
923 {
924     if( !event.LeftDown() && !event.LeftIsDown() ) return;
925
926     int i_volume = (GetClientSize().GetHeight() - event.GetY()) * 200 /
927                     GetClientSize().GetHeight();
928     Change( i_volume );
929 }
930
931 void wxVolCtrl::Change( int i_volume )
932 {
933     aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 );
934     SetValue( i_volume );
935     SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
936                 i_volume ) );
937 }