]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/interface.cpp
3eeb816a8d0bd6553a1bd936ff791e0e3d8f31d4
[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.58 2003/08/28 15:59:04 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(_("The VideoLAN team <videolan@videolan.org>\n"
610               "http://www.videolan.org/\n\n")) +
611         wxU(_("This is the VideoLAN Client, a DVD, MPEG and DivX player."
612               "\nIt can play MPEG and MPEG2 files from a file or from a "
613               "network source.")) );
614
615     wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
616                   wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
617 }
618
619 void Interface::OnShowDialog( wxCommandEvent& event )
620 {
621     if( p_intf->p_sys->pf_show_dialog )
622     {
623         int i_id;
624
625         switch( event.GetId() )
626         {
627         case OpenFileSimple_Event:
628             i_id = INTF_DIALOG_FILE_SIMPLE;
629             break;
630         case OpenFile_Event:
631             i_id = INTF_DIALOG_FILE;
632             break;
633         case OpenDisc_Event:
634             i_id = INTF_DIALOG_DISC;
635             break;
636         case OpenNet_Event:
637             i_id = INTF_DIALOG_NET;
638             break;
639         case OpenSat_Event:
640             i_id = INTF_DIALOG_SAT;
641             break;
642         case Playlist_Event:
643             i_id = INTF_DIALOG_PLAYLIST;
644             break;
645         case Logs_Event:
646             i_id = INTF_DIALOG_MESSAGES;
647             break;
648         case FileInfo_Event:
649             i_id = INTF_DIALOG_FILEINFO;
650             break;
651         case Prefs_Event:
652             i_id = INTF_DIALOG_PREFS;
653             break;
654         default:
655             i_id = INTF_DIALOG_FILE;
656             break;
657
658         }
659
660         p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
661     }
662 }
663
664 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
665 {
666     wxCommandEvent dummy;
667     playlist_t *p_playlist =
668         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
669                                        FIND_ANYWHERE );
670     if( p_playlist == NULL ) return;
671
672     if( p_playlist->i_size )
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         if( p_input->stream.control.i_status != PAUSE_S )
687         {
688             /* A stream is being played, pause it */
689             input_SetStatus( p_input, INPUT_STATUS_PAUSE );
690             TogglePlayButton( PAUSE_S );
691             vlc_object_release( p_playlist );
692             vlc_object_release( p_input );
693             return;
694         }
695
696         /* Stream is paused, resume it */
697         input_SetStatus( p_input, INPUT_STATUS_PLAY );
698         TogglePlayButton( PLAYING_S );
699         vlc_object_release( p_input );
700         vlc_object_release( p_playlist );
701     }
702     else
703     {
704         /* If the playlist is empty, open a file requester instead */
705         vlc_object_release( p_playlist );
706         OnShowDialog( dummy );
707     }
708 }
709
710 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
711 {
712     playlist_t * p_playlist =
713         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
714                                        FIND_ANYWHERE );
715     if( p_playlist == NULL )
716     {
717         return;
718     }
719
720     playlist_Stop( p_playlist );
721     TogglePlayButton( PAUSE_S );
722     vlc_object_release( p_playlist );
723 }
724
725 void Interface::OnSliderUpdate( wxScrollEvent& event )
726 {
727     vlc_mutex_lock( &p_intf->change_lock );
728
729 #ifdef WIN32
730     if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
731         || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
732     {
733 #endif
734         if( p_intf->p_sys->i_slider_pos != event.GetPosition()
735             && p_intf->p_sys->p_input )
736         {
737             p_intf->p_sys->i_slider_pos = event.GetPosition();
738             input_Seek( p_intf->p_sys->p_input, p_intf->p_sys->i_slider_pos *
739                         100 / SLIDER_MAX_POS,
740                         INPUT_SEEK_PERCENT | INPUT_SEEK_SET );
741         }
742
743 #ifdef WIN32
744         p_intf->p_sys->b_slider_free = VLC_TRUE;
745     }
746     else
747     {
748         p_intf->p_sys->b_slider_free = VLC_FALSE;
749
750         if( p_intf->p_sys->p_input )
751         {
752             /* Update stream date */
753 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
754             char psz_time[ OFFSETTOTIME_MAX_SIZE ];
755
756             slider_box->SetLabel(
757                 wxU(input_OffsetToTime( p_intf->p_sys->p_input,
758                                         psz_time,
759                                         p_area->i_size * event.GetPosition()
760                                         / SLIDER_MAX_POS )) );
761 #undef p_area
762         }
763     }
764 #endif
765
766     vlc_mutex_unlock( &p_intf->change_lock );
767 }
768
769 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
770 {
771     playlist_t * p_playlist =
772         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
773                                        FIND_ANYWHERE );
774     if( p_playlist == NULL )
775     {
776         return;
777     }
778
779     vlc_mutex_lock( &p_playlist->object_lock );
780     if( p_playlist->p_input != NULL )
781     {
782         vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
783         if( p_playlist->p_input->stream.p_selected_area->i_id > 1 )
784         {
785             vlc_value_t val; val.b_bool = VLC_TRUE;
786             vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
787             var_Set( p_playlist->p_input, "prev-title", val );
788             vlc_mutex_unlock( &p_playlist->object_lock );
789             vlc_object_release( p_playlist );  
790             return;
791         }
792         vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
793     }
794     vlc_mutex_unlock( &p_playlist->object_lock );
795
796     playlist_Prev( p_playlist );
797     vlc_object_release( p_playlist );
798 }
799
800 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
801 {
802     playlist_t * p_playlist =
803         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
804                                        FIND_ANYWHERE );
805     if( p_playlist == NULL )
806     {
807         return;
808     }
809
810     vlc_mutex_lock( &p_playlist->object_lock );
811     if( p_playlist->p_input != NULL )
812     {
813         vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
814         if( p_playlist->p_input->stream.i_area_nb > 1 &&
815             p_playlist->p_input->stream.p_selected_area->i_id <
816               p_playlist->p_input->stream.i_area_nb - 1 )
817         {
818             vlc_value_t val; val.b_bool = VLC_TRUE;
819             vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
820             var_Set( p_playlist->p_input, "next-title", val );
821             vlc_mutex_unlock( &p_playlist->object_lock );
822             vlc_object_release( p_playlist );  
823             return;
824         }
825         vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
826     }
827     vlc_mutex_unlock( &p_playlist->object_lock );
828
829     playlist_Next( p_playlist );
830     vlc_object_release( p_playlist );
831 }
832
833 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
834 {
835     input_thread_t *p_input =
836         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
837                                            FIND_ANYWHERE );
838     if( p_input )
839     {
840         input_SetStatus( p_input, INPUT_STATUS_SLOWER );
841         vlc_object_release( p_input );
842     }
843 }
844
845 void Interface::OnFastStream( 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_FASTER );
853         vlc_object_release( p_input );
854     }
855 }
856
857 void Interface::TogglePlayButton( int i_playing_status )
858 {
859     if( i_playing_status == i_old_playing_status )
860         return;
861
862     GetToolBar()->DeleteTool( PlayStream_Event );
863
864     if( i_playing_status == PLAYING_S )
865     {
866         GetToolBar()->InsertTool( 5, PlayStream_Event, wxU(_("Pause")),
867                                   wxBitmap( pause_xpm ), wxNullBitmap,
868                                   wxITEM_NORMAL, wxU(_(HELP_PAUSE)) );
869     }
870     else
871     {
872         GetToolBar()->InsertTool( 5, PlayStream_Event, wxU(_("Play")),
873                                   wxBitmap( play_xpm ), wxNullBitmap,
874                                   wxITEM_NORMAL, wxU(_(HELP_PLAY)) );
875     }
876
877     GetToolBar()->Realize();
878
879     i_old_playing_status = i_playing_status;
880 }
881
882 #if !defined(__WXX11__)
883 /*****************************************************************************
884  * Definition of DragAndDrop class.
885  *****************************************************************************/
886 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf )
887 {
888     p_intf = _p_intf;
889 }
890
891 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
892                                const wxArrayString& filenames )
893 {
894     /* Add dropped files to the playlist */
895
896     playlist_t *p_playlist =
897         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
898                                        FIND_ANYWHERE );
899     if( p_playlist == NULL )
900     {
901         return FALSE;
902     }
903
904     for( size_t i = 0; i < filenames.GetCount(); i++ )
905         playlist_Add( p_playlist, (const char *)filenames[i].mb_str(), 0, 0,
906                       PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );
907
908     vlc_object_release( p_playlist );
909
910     return TRUE;
911 }
912 #endif
913
914 /*****************************************************************************
915  * Definition of wxVolCtrl class.
916  *****************************************************************************/
917 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id )
918   : wxGauge( parent, id, 200, wxDefaultPosition, wxDefaultSize,
919              wxGA_VERTICAL | wxGA_SMOOTH )
920 {
921     p_intf = _p_intf;
922 }
923
924 void wxVolCtrl::OnChange( wxMouseEvent& event )
925 {
926     if( !event.LeftDown() && !event.LeftIsDown() ) return;
927
928     int i_volume = (GetClientSize().GetHeight() - event.GetY()) * 200 /
929                     GetClientSize().GetHeight();
930     Change( i_volume );
931 }
932
933 void wxVolCtrl::Change( int i_volume )
934 {
935     aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 );
936     SetValue( i_volume );
937     SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
938                 i_volume ) );
939 }