]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/interface.cpp
Update copyright dates used in interfaces and binaries (2005 -> 2006)
[vlc] / modules / gui / wxwidgets / interface.cpp
1 /*****************************************************************************
2  * interface.cpp : wxWidgets plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include "interface.hpp"
28 #include "playlist_manager.hpp"
29 #include "extrapanel.hpp"
30 #include "timer.hpp"
31 #include "video.hpp"
32 #include <vlc_keys.h>
33
34 #include "charset.h"
35
36 #include <vlc/aout.h>
37 #include "charset.h"
38
39 #include <vlc_interaction.h>
40
41 #include <wx/splitter.h>
42
43 /* include the toolbar graphics */
44 #include "bitmaps/play.xpm"
45 #include "bitmaps/pause.xpm"
46 #include "bitmaps/stop.xpm"
47 #include "bitmaps/prev.xpm"
48 #include "bitmaps/next.xpm"
49 #include "bitmaps/eject.xpm"
50 #include "bitmaps/slow.xpm"
51 #include "bitmaps/fast.xpm"
52 #include "bitmaps/playlist.xpm"
53 #include "bitmaps/playlist_small.xpm"
54 #include "bitmaps/speaker.xpm"
55 #include "bitmaps/speaker_mute.xpm"
56
57 #define TOOLBAR_BMP_WIDTH 16
58 #define TOOLBAR_BMP_HEIGHT 16
59
60 /* include the icon graphic */
61 #include "../../../share/vlc32x32.xpm"
62 /* include a small icon graphic for the systray icon */
63 #ifdef wxHAS_TASK_BAR_ICON
64 #include "../../../share/vlc16x16.xpm"
65 #endif
66
67 /*****************************************************************************
68  * Local prototypes
69  *****************************************************************************/
70 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
71                              vlc_value_t, void *);
72
73 /*****************************************************************************
74  * Local class declarations.
75  *****************************************************************************/
76 class wxMenuExt: public wxMenu
77 {
78 public:
79     /* Constructor */
80     wxMenuExt( wxMenu* parentMenu, int id, const wxString& text,
81                    const wxString& helpString, wxItemKind kind,
82                    char *_psz_var, int _i_object_id, vlc_value_t _val,
83                    int _i_val_type );
84
85     virtual ~wxMenuExt() {};
86
87     char *psz_var;
88     int  i_val_type;
89     int  i_object_id;
90     vlc_value_t val;
91
92 private:
93
94 };
95
96 class wxVolCtrl;
97 class VLCVolCtrl : public wxControl
98 {
99 public:
100     VLCVolCtrl( intf_thread_t *p_intf, wxWindow *p_parent );
101     virtual ~VLCVolCtrl() {};
102
103     virtual void OnPaint( wxPaintEvent &event );
104     void OnChange( wxMouseEvent& event );
105     void UpdateVolume();
106
107   private:
108     DECLARE_EVENT_TABLE()
109
110     wxVolCtrl *gauge;
111     int i_y_offset;
112     vlc_bool_t b_mute;
113     intf_thread_t *p_intf;
114 };
115
116 BEGIN_EVENT_TABLE(VLCVolCtrl, wxControl)
117     EVT_PAINT(VLCVolCtrl::OnPaint)
118
119     /* Mouse events */
120     EVT_LEFT_UP(VLCVolCtrl::OnChange)
121 END_EVENT_TABLE()
122
123 class Splitter : public wxSplitterWindow
124 {
125 public:
126     Splitter( wxWindow *p_parent, intf_thread_t *_p_intf )
127       : wxSplitterWindow( p_parent, -1, wxDefaultPosition, wxSize(0,0),
128 #if defined( __WXMSW__ )
129                           wxCLIP_CHILDREN ),
130 #else
131                           wxCLIP_CHILDREN | wxSP_3DSASH ),
132 #endif
133         p_intf(_p_intf), b_video(0), i_delay(0)
134     {
135         SetSashSize( 0 );
136
137         wxSize size = wxSize(-1, 150);
138         wxPoint p = wxPoint(0,0);
139         bool b_dummy;
140         WindowSettings *ws = p_intf->p_sys->p_window_settings;
141         ws->GetSettings( WindowSettings::ID_SMALL_PLAYLIST, b_dummy, p, size );
142
143         i_width = size.GetWidth();
144         i_sash_position = size.GetHeight();
145         b_show_on_start = !!p.x;
146     }
147
148     virtual ~Splitter()
149     {
150         WindowSettings *ws = p_intf->p_sys->p_window_settings;
151         ws->SetSettings( WindowSettings::ID_SMALL_PLAYLIST, true,
152                          wxPoint(!!GetWindow2(),0),
153                          wxSize(i_width, i_sash_position) );
154     };
155
156     virtual bool Split( wxWindow* window1, wxWindow* window2 )
157     {
158         SetSashSize( 0 );
159         wxSize size = wxSize( i_width, i_sash_position );
160         if( window2->GetSizer() ) window2->GetSizer()->SetMinSize( size );
161
162         return wxSplitterWindow::SplitHorizontally( window1, window2,
163                                                     -i_sash_position );
164     }
165
166     virtual bool Unsplit( wxWindow* window )
167     {
168         SetSashSize( 0 );
169         return wxSplitterWindow::Unsplit( window );
170     }
171
172     bool ShowOnStart() { return b_show_on_start; }
173
174 private:
175     DECLARE_EVENT_TABLE()
176
177     void OnSize( wxSizeEvent &event )
178     {
179         /* If we display video, then resize the video window */
180         if( GetWindow2() &&
181             p_intf->p_sys->p_video_window && p_intf->p_sys->p_video_sizer &&
182             p_intf->p_sys->p_video_sizer->GetMinSize() != wxSize(0,0) )
183         {
184             if( !b_video ) i_delay = mdate() + 1000000;
185             b_video = VLC_TRUE;
186
187             SetSashSize( -1 );
188
189 #if defined( __WXMSW__ )
190             SetSashPosition( event.GetSize().GetHeight() - i_sash_position );
191 #else
192             SetSashPosition( event.GetSize().GetHeight() -
193                              i_sash_position - GetSashSize() );
194 #endif
195         }
196         else if( GetWindow2() && GetWindow1() && GetWindow1()->GetSizer() )
197         {
198             wxSize size = GetWindow1()->GetSizer()->GetMinSize();
199
200             if( b_video ) i_delay = mdate() + 1000000;
201             b_video = VLC_FALSE;
202
203             if( event.GetSize().GetHeight() - size.GetHeight() )
204             {
205                 SetSashSize( 0 );
206
207                 SetSashPosition( size.GetHeight() ? size.GetHeight() : 1 );
208
209                 if( i_delay < mdate() )
210                 {
211                     i_sash_position = event.GetSize().GetHeight() -
212                         size.GetHeight();
213                     i_width = event.GetSize().GetWidth();
214
215                     size = wxSize( i_width, i_sash_position );
216                     if( GetWindow2()->GetSizer() )
217                         GetWindow2()->GetSizer()->SetMinSize( size );
218                 }
219             }
220         }
221
222         event.Skip();
223     }
224
225     void OnSashPosChanged( wxSplitterEvent &event )
226     {
227         if( !GetSize().GetHeight() ){ event.Skip(); return; }
228
229         if( i_delay < mdate() )
230         {
231             i_sash_position = GetSize().GetHeight() - event.GetSashPosition();
232
233             wxSize size = wxSize( i_width, i_sash_position );
234             if( GetWindow2()->GetSizer() )
235                 GetWindow2()->GetSizer()->SetMinSize( size );
236         }
237         event.Skip();
238     }
239
240     intf_thread_t *p_intf;
241     int i_sash_position;
242     int i_width;
243     vlc_bool_t b_video;
244     mtime_t i_delay;
245     vlc_bool_t b_show_on_start;
246 };
247
248 BEGIN_EVENT_TABLE(Splitter, wxSplitterWindow)
249     EVT_SIZE( Splitter::OnSize )
250     EVT_SPLITTER_SASH_POS_CHANGED(-1, Splitter::OnSashPosChanged)
251 END_EVENT_TABLE()
252
253 /*****************************************************************************
254  * Event Table.
255  *****************************************************************************/
256
257 DEFINE_LOCAL_EVENT_TYPE( wxEVT_INTF );
258
259 /* IDs for the controls and the menu commands */
260 enum
261 {
262     /* menu items */
263     MenuDummy_Event = wxID_HIGHEST + 1000,
264     Exit_Event = wxID_HIGHEST,
265     OpenFileSimple_Event,
266     OpenAdv_Event,
267     OpenFile_Event,
268     OpenDir_Event,
269     OpenDisc_Event,
270     OpenNet_Event,
271     OpenCapture_Event,
272     OpenSat_Event,
273     OpenOther_Event,
274     EjectDisc_Event,
275
276     Wizard_Event,
277
278     Playlist_Event,
279     PlaylistSmall_Event,
280     Logs_Event,
281     FileInfo_Event,
282
283     Prefs_Event,
284     Extended_Event,
285     Bookmarks_Event,
286     Skins_Event,
287
288     StopStream_Event,
289     PlayStream_Event,
290     PrevStream_Event,
291     NextStream_Event,
292     SlowStream_Event,
293     FastStream_Event,
294
295     /* it is important for the id corresponding to the "About" command to have
296      * this standard value as otherwise it won't be handled properly under Mac
297      * (where it is special and put into the "Apple" menu) */
298     About_Event = wxID_ABOUT,
299     UpdateVLC_Event,
300     VLM_Event,
301
302     Iconize_Event,
303 };
304
305 DEFINE_LOCAL_EVENT_TYPE( wxEVT_INTERACTION );
306
307 BEGIN_EVENT_TABLE(Interface, wxFrame)
308     /* Menu events */
309     EVT_MENU(Exit_Event, Interface::OnExit)
310     EVT_MENU(About_Event, Interface::OnAbout)
311     EVT_MENU(UpdateVLC_Event, Interface::OnShowDialog)
312     EVT_MENU(VLM_Event, Interface::OnShowDialog)
313
314     EVT_MENU(Playlist_Event, Interface::OnShowDialog)
315     EVT_MENU(PlaylistSmall_Event, Interface::OnSmallPlaylist)
316     EVT_MENU(Logs_Event, Interface::OnShowDialog)
317     EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
318     EVT_MENU(Prefs_Event, Interface::OnShowDialog)
319
320     EVT_MENU_OPEN(Interface::OnMenuOpen)
321
322     EVT_MENU( Extended_Event, Interface::OnExtended )
323
324     EVT_MENU( Bookmarks_Event, Interface::OnShowDialog)
325
326 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
327     EVT_CONTEXT_MENU(Interface::OnContextMenu2)
328 #endif
329     EVT_RIGHT_UP(Interface::OnContextMenu)
330
331     /* Toolbar events */
332     EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
333     EVT_MENU(OpenAdv_Event, Interface::OnShowDialog)
334     EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
335     EVT_MENU(OpenDir_Event, Interface::OnShowDialog)
336     EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
337     EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
338     EVT_MENU(OpenCapture_Event, Interface::OnShowDialog)
339     EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
340     EVT_MENU(Wizard_Event, Interface::OnShowDialog)
341     EVT_MENU(StopStream_Event, Interface::OnStopStream)
342     EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
343     EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
344     EVT_MENU(NextStream_Event, Interface::OnNextStream)
345     EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
346     EVT_MENU(FastStream_Event, Interface::OnFastStream)
347
348     /* Custom events */
349     EVT_COMMAND(0, wxEVT_INTF, Interface::OnControlEvent)
350     EVT_COMMAND(1, wxEVT_INTF, Interface::OnControlEvent)
351
352     EVT_COMMAND( -1, wxEVT_INTERACTION, Interface::OnInteraction )
353 END_EVENT_TABLE()
354
355 /*****************************************************************************
356  * Constructor.
357  *****************************************************************************/
358 Interface::Interface( intf_thread_t *_p_intf, long style ):
359     wxFrame( NULL, -1, wxT("VLC media player"),
360              wxDefaultPosition, wxSize(700,100), style )
361 {
362     /* Initializations */
363     p_intf = _p_intf;
364     b_extra = VLC_FALSE;
365     extra_frame = 0;
366     playlist_manager = 0;
367
368
369     /* Give our interface a nice little icon */
370     SetIcon( wxIcon( vlc_xpm ) );
371
372     /* Create a splitter window that will fill in the interface window.
373      * We need a splitter bar in order to make the embedded playlist
374      * resizable. */
375     splitter = new Splitter( this, p_intf );
376     main_sizer = new wxBoxSizer( wxVERTICAL );
377     main_sizer->Add( splitter, 1, wxEXPAND );
378     SetSizer( main_sizer );
379
380     /* Create a main panel that will fill in the interface window */
381     main_panel = new wxPanel( splitter, -1, wxPoint(0,0), wxSize(0,0),
382                               wxCLIP_CHILDREN );
383     main_panel->SetFocus();
384
385 #if defined(__WXGTK20__) && wxCHECK_VERSION(2,5,6)
386     /* As ugly as your butt! Please remove when wxWidgets 2.6 fixed their
387      * Accelerators bug. */
388     main_panel->m_imData = 0;
389     m_imData = 0;
390 #endif
391
392     /* Create a sizer for the main frame */
393     panel_sizer = new wxBoxSizer( wxVERTICAL );
394     main_panel->SetSizer( panel_sizer );
395
396     /* Put this in the splitter */
397     splitter->Initialize( main_panel );
398
399 #ifdef wxHAS_TASK_BAR_ICON
400     /* Systray integration */
401     p_systray = NULL;
402     if( config_GetInt( p_intf, "wx-systray" ) )
403     {
404         p_systray = new Systray( this, p_intf );
405     }
406 #endif
407
408     /* Creation of the menu bar */
409     CreateOurMenuBar();
410
411     /* Creation of the tool bar */
412     CreateOurToolBar();
413
414     /* Creation of the status bar
415      * Helptext for menu items and toolbar tools will automatically get
416      * displayed here. */
417     int i_status_width[3] = {100, 40, -1};
418     statusbar = CreateStatusBar( 3 );                            /* 2 fields */
419     statusbar->SetStatusWidths( 3, i_status_width );
420     statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
421
422     /* Get minimum window size to prevent user from glitching it */
423     splitter->SetSizeHints( -1, 0 );
424     panel_sizer->Layout(); panel_sizer->Fit( main_panel );
425     main_sizer->Layout(); main_sizer->Fit( this );
426     main_min_size = GetSize();
427     splitter->SetSizeHints( -1, -1 );
428
429     /* Video window */
430     video_window = 0;
431     if( config_GetInt( p_intf, "wx-embed" ) )
432     {
433         video_window = CreateVideoWindow( p_intf, main_panel );
434         panel_sizer->Add( p_intf->p_sys->p_video_sizer, 1, wxEXPAND, 0 );
435     }
436
437     /* Creation of the input manager panel */
438     input_manager = new InputManager( p_intf, this, main_panel );
439     panel_sizer->Add( input_manager, 0, wxEXPAND , 0 );
440
441     /* Layout everything */
442     splitter->SetSizeHints( -1, 0 );
443     panel_sizer->Layout(); panel_sizer->Fit( main_panel );
444     main_sizer->Layout(); main_sizer->Fit( this );
445     splitter->SetSizeHints( -1, -1 );
446
447 #if wxUSE_DRAG_AND_DROP
448     /* Associate drop targets with the main interface */
449     SetDropTarget( new DragAndDrop( p_intf ) );
450 #endif
451
452     SetupHotkeys();
453
454     /* Start timer */
455     timer = new Timer( p_intf, this );
456
457     /* Restore previous position / settings */
458     WindowSettings *ws = p_intf->p_sys->p_window_settings;
459     wxPoint p;
460     wxSize s;
461     bool b_shown;
462
463     ws->SetScreen( wxSystemSettings::GetMetric( wxSYS_SCREEN_X ),
464                    wxSystemSettings::GetMetric( wxSYS_SCREEN_Y ) );
465
466     if( ws->GetSettings( WindowSettings::ID_MAIN, b_shown, p, s ) ) Move( p );
467
468     /* Show extended GUI if requested */
469     wxCommandEvent dummy;
470     if( config_GetInt( p_intf, "wx-extended" ) ) OnExtended( dummy );
471
472     SetIntfMinSize();
473
474     var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
475     var_AddCallback( p_intf, "interaction", InteractCallback, this );
476     p_intf->b_interaction = VLC_TRUE;
477
478     /* Show embedded playlist if requested */
479     if( splitter->ShowOnStart() ) OnSmallPlaylist( dummy );
480 }
481
482 Interface::~Interface()
483 {
484     WindowSettings *ws = p_intf->p_sys->p_window_settings;
485
486     if( !IsIconized() )
487     {
488         ws->SetSettings( WindowSettings::ID_MAIN, true,
489                          GetPosition(), GetSize() );
490     }
491
492     PopEventHandler(true);
493
494     if( video_window ) delete video_window;
495
496 #ifdef wxHAS_TASK_BAR_ICON
497     if( p_systray ) delete p_systray;
498 #endif
499
500     p_intf->b_interaction = VLC_FALSE;
501     var_DelCallback( p_intf, "interaction", InteractCallback, this );
502
503     if( p_intf->p_sys->p_wxwindow ) delete p_intf->p_sys->p_wxwindow;
504
505
506     /* Clean up */
507     delete timer;
508 }
509
510 void Interface::Init()
511 {
512     /* Misc init */
513     SetupHotkeys();
514 }
515
516 void Interface::Update()
517 {
518     /* Misc updates */
519     ((VLCVolCtrl *)volctrl)->UpdateVolume();
520
521     if( playlist_manager ) playlist_manager->Update();
522 }
523
524 void Interface::OnControlEvent( wxCommandEvent& event )
525 {
526     switch( event.GetId() )
527     {
528     case 0:
529         main_sizer->Layout();
530         main_sizer->Fit( this );
531         break;
532
533     case 1:
534         long i_style = GetWindowStyle();
535         if( event.GetInt() ) i_style |= wxSTAY_ON_TOP;
536         else i_style &= ~wxSTAY_ON_TOP;
537         SetWindowStyle( i_style );
538         break;
539     }
540 }
541
542 /*****************************************************************************
543  * Private methods.
544  *****************************************************************************/
545 void Interface::CreateOurMenuBar()
546 {
547     int minimal = config_GetInt( p_intf, "wx-minimal" );
548
549     /* Create the "File" menu */
550     wxMenu *file_menu = new wxMenu;
551
552     if (!minimal)
553     {
554     file_menu->Append( OpenFileSimple_Event,
555                        wxU(_("Quick &Open File...\tCtrl-O")) );
556
557     file_menu->AppendSeparator();
558     file_menu->Append( OpenFile_Event, wxU(_("Open &File...\tCtrl-F")) );
559     file_menu->Append( OpenDir_Event, wxU(_("Open Dir&ectory...\tCtrl-E")) );
560     file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...\tCtrl-D")) );
561     file_menu->Append( OpenNet_Event,
562                        wxU(_("Open &Network Stream...\tCtrl-N")) );
563     file_menu->Append( OpenCapture_Event,
564                        wxU(_("Open C&apture Device...\tCtrl-A")) );
565
566     file_menu->AppendSeparator();
567     file_menu->Append( Wizard_Event, wxU(_("&Wizard...\tCtrl-W")) );
568     file_menu->AppendSeparator();
569     }
570     file_menu->Append( Exit_Event, wxU(_("E&xit\tCtrl-X")) );
571
572     /* Create the "View" menu */
573     wxMenu *view_menu = new wxMenu;
574     if (!minimal)
575     {
576     view_menu->Append( Playlist_Event, wxU(_("&Playlist...\tCtrl-P")) );
577     }
578     view_menu->Append( Logs_Event, wxU(_("&Messages...\tCtrl-M")) );
579     view_menu->Append( FileInfo_Event,
580                        wxU(_("Stream and Media &info...\tCtrl-I")) );
581     view_menu->Append( VLM_Event,
582                        wxU(_("VLM Control...\tCtrl-V")) );
583
584     /* Create the "Auto-generated" menus */
585     p_settings_menu = SettingsMenu( p_intf, this );
586     p_audio_menu = AudioMenu( p_intf, this );
587     p_video_menu = VideoMenu( p_intf, this );
588     p_navig_menu = NavigMenu( p_intf, this );
589
590     /* Create the "Help" menu */
591     wxMenu *help_menu = new wxMenu;
592     help_menu->Append( About_Event, wxU(_("About VLC media player")) );
593     help_menu->AppendSeparator();
594     help_menu->Append( UpdateVLC_Event, wxU(_("Check for updates ...")) );
595
596     /* Append the freshly created menus to the menu bar... */
597     wxMenuBar *menubar = new wxMenuBar();
598     menubar->Append( file_menu, wxU(_("&File")) );
599     menubar->Append( view_menu, wxU(_("&View")) );
600     menubar->Append( p_settings_menu, wxU(_("&Settings")) );
601     menubar->Append( p_audio_menu, wxU(_("&Audio")) );
602     menubar->Append( p_video_menu, wxU(_("&Video")) );
603     menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
604     menubar->Append( help_menu, wxU(_("&Help")) );
605
606     /* Attach the menu bar to the frame */
607     SetMenuBar( menubar );
608
609     /* Find out size of menu bar */
610     int i_size = 0;
611     for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
612     {
613         int i_width, i_height;
614         menubar->GetTextExtent( menubar->GetLabelTop(i), &i_width, &i_height );
615         i_size += i_width +
616 #if defined(__WXGTK__)
617             22 /* approximate margin */;
618 #else
619 #if (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 5) && (wxRELEASE_NUMBER < 3)
620             4 /* approximate margin */;
621 #else
622             18 /* approximate margin */;
623 #endif
624 #endif
625     }
626
627 /* Patch by zcot for menu wrapping */
628 #if defined(WIN32)
629     /* Find out size of msw menu bar */
630     i_size = 0;
631     SIZE sizing;
632     HDC hdc = GetDC( NULL );
633     for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
634     {
635         GetTextExtentPoint32( hdc, menubar->GetLabelTop(i).c_str(),
636                                 menubar->GetLabelTop(i).Length(), &sizing );
637
638         // [ SM_CXDLGFRAME + pixels + textextent + pixels + SM_CXDLGFRAME ]
639         i_size += sizing.cx + 2 + GetSystemMetrics( SM_CXDLGFRAME ) * 2;
640     }
641     ReleaseDC( NULL, hdc );
642     i_size += GetSystemMetrics( SM_CXSIZEFRAME ) * 2 + 4;
643 #endif
644 /* End patch by zcot */
645
646     panel_sizer->SetMinSize( i_size, -1 );
647
648     /* Intercept all menu events in our custom event handler */
649     PushEventHandler( new MenuEvtHandler( p_intf, this ) );
650
651 #if wxUSE_DRAG_AND_DROP
652     /* Associate drop targets with the menubar */
653     menubar->SetDropTarget( new DragAndDrop( p_intf ) );
654 #endif
655 }
656
657 void Interface::CreateOurToolBar()
658 {
659 #define HELP_OPEN N_("Open")
660 #define HELP_STOP N_("Stop")
661 #define HELP_PLAY N_("Play")
662 #define HELP_PAUSE N_("Pause")
663 #define HELP_PLO N_("Playlist")
664 #define HELP_SPLO N_("Small playlist")
665 #define HELP_PLP N_("Previous playlist item")
666 #define HELP_PLN N_("Next playlist item")
667 #define HELP_SLOW N_("Play slower")
668 #define HELP_FAST N_("Play faster")
669
670     int minimal = config_GetInt( p_intf, "wx-minimal" );
671
672     wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
673                          * version because we don't include wx.rc */
674
675     wxToolBar *toolbar =
676         CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
677
678     toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
679
680     if (!minimal)
681     {
682     toolbar->AddTool( OpenFile_Event, wxT(""),
683                       wxBitmap( eject_xpm ), wxU(_(HELP_OPEN)) );
684     toolbar->AddSeparator();
685     }
686
687     wxToolBarToolBase *p_tool = toolbar->AddTool( PlayStream_Event, wxT(""),
688                       wxBitmap( play_xpm ), wxU(_(HELP_PLAY)), wxITEM_CHECK );
689     p_tool->SetClientData( p_tool );
690
691     if (!minimal)
692     {
693     toolbar->AddTool( StopStream_Event, wxT(""), wxBitmap( stop_xpm ),
694                       wxU(_(HELP_STOP)) );
695     toolbar->AddSeparator();
696
697     toolbar->AddTool( PrevStream_Event, wxT(""),
698                       wxBitmap( prev_xpm ), wxU(_(HELP_PLP)) );
699     toolbar->AddTool( SlowStream_Event, wxT(""),
700                       wxBitmap( slow_xpm ), wxU(_(HELP_SLOW)) );
701     toolbar->AddTool( FastStream_Event, wxT(""),
702                       wxBitmap( fast_xpm ), wxU(_(HELP_FAST)) );
703     toolbar->AddTool( NextStream_Event, wxT(""), wxBitmap( next_xpm ),
704                       wxU(_(HELP_PLN)) );
705     toolbar->AddSeparator();
706     toolbar->AddTool( Playlist_Event, wxT(""), wxBitmap( playlist_xpm ),
707                       wxU(_(HELP_PLO)) );
708     toolbar->AddTool( PlaylistSmall_Event, wxT(""),
709                       wxBitmap( playlist_small_xpm ), wxU(_(HELP_SPLO)) );
710     }
711
712     wxControl *p_dummy_ctrl =
713         new wxControl( toolbar, -1, wxDefaultPosition,
714                        wxSize(16, 16 ), wxBORDER_NONE );
715
716     toolbar->AddControl( p_dummy_ctrl );
717
718     volctrl = new VLCVolCtrl( p_intf, toolbar );
719     toolbar->AddControl( volctrl );
720
721     toolbar->Realize();
722
723 #if wxUSE_DRAG_AND_DROP
724     /* Associate drop targets with the toolbar */
725     toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
726 #endif
727 }
728
729 static int ConvertHotkeyModifiers( int i_hotkey )
730 {
731     int i_accel_flags = 0;
732     if( i_hotkey & KEY_MODIFIER_ALT ) i_accel_flags |= wxACCEL_ALT;
733     if( i_hotkey & KEY_MODIFIER_CTRL ) i_accel_flags |= wxACCEL_CTRL;
734     if( i_hotkey & KEY_MODIFIER_SHIFT ) i_accel_flags |= wxACCEL_SHIFT;
735     if( !i_accel_flags ) i_accel_flags = wxACCEL_NORMAL;
736     return i_accel_flags;
737 }
738
739 static int ConvertHotkey( int i_hotkey )
740 {
741     int i_key = i_hotkey & ~KEY_MODIFIER;
742     if( i_key & KEY_ASCII ) return i_key & KEY_ASCII;
743     else if( i_key & KEY_SPECIAL )
744     {
745         switch ( i_key )
746         {
747         case KEY_LEFT: return WXK_LEFT;
748         case KEY_RIGHT: return WXK_RIGHT;
749         case KEY_UP: return WXK_UP;
750         case KEY_DOWN: return WXK_DOWN;
751         case KEY_SPACE: return WXK_SPACE;
752         case KEY_ENTER: return WXK_RETURN;
753         case KEY_F1: return WXK_F1;
754         case KEY_F2: return WXK_F2;
755         case KEY_F3: return WXK_F3;
756         case KEY_F4: return WXK_F4;
757         case KEY_F5: return WXK_F5;
758         case KEY_F6: return WXK_F6;
759         case KEY_F7: return WXK_F7;
760         case KEY_F8: return WXK_F8;
761         case KEY_F9: return WXK_F9;
762         case KEY_F10: return WXK_F10;
763         case KEY_F11: return WXK_F11;
764         case KEY_F12: return WXK_F12;
765         case KEY_HOME: return WXK_HOME;
766         case KEY_END: return WXK_END;
767         case KEY_INSERT: return WXK_INSERT;
768         case KEY_DELETE: return WXK_DELETE;
769         case KEY_MENU: return WXK_MENU;
770         case KEY_ESC: return WXK_ESCAPE;
771         case KEY_PAGEUP: return WXK_PRIOR;
772         case KEY_PAGEDOWN: return WXK_NEXT;
773         case KEY_TAB: return WXK_TAB;
774         case KEY_BACKSPACE: return WXK_BACK;
775         }
776     }
777     return WXK_F24;
778 }
779
780 void Interface::SetupHotkeys()
781 {
782     struct vlc_t::hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
783     int i_hotkeys;
784
785     /* Count number of hoteys */
786     for( i_hotkeys = 0; p_hotkeys[i_hotkeys].psz_action != NULL; i_hotkeys++ );
787
788     p_intf->p_sys->i_first_hotkey_event = wxID_HIGHEST + 7000;
789     p_intf->p_sys->i_hotkeys = i_hotkeys;
790
791     wxAcceleratorEntry *p_entries = new wxAcceleratorEntry[i_hotkeys];
792
793     /* Setup the hotkeys as accelerators */
794     for( int i = 0; i < i_hotkeys; i++ )
795     {
796         int i_mod = ConvertHotkeyModifiers( p_hotkeys[i].i_key );
797         int i_key = ConvertHotkey( p_hotkeys[i].i_key );
798
799 #ifdef WIN32
800         if( !(p_hotkeys[i].i_key & KEY_SPECIAL) && i_mod )
801             i_key = toupper(i_key);
802 #endif
803
804         p_entries[i].Set( i_mod, i_key,
805                           p_intf->p_sys->i_first_hotkey_event + i );
806     }
807
808     wxAcceleratorTable accel( i_hotkeys, p_entries );
809
810     if( !accel.Ok() )
811     {
812         msg_Err( p_intf, "invalid accelerator table" );
813     }
814     else
815     {
816         SetAcceleratorTable( accel );
817     }
818
819     delete [] p_entries;
820 }
821
822 void Interface::SetIntfMinSize()
823 {
824     wxSize ms = main_min_size;
825
826     if( extra_frame && extra_frame->IsShown() )
827     {
828         ms.SetHeight( ms.GetHeight() + ext_min_size.GetHeight() );
829         if( ext_min_size.GetWidth() > ms.GetWidth() )
830             ms.SetWidth( ext_min_size.GetWidth() );
831     }
832
833     SetSizeHints( ms.GetWidth(), ms.GetHeight() );
834 }
835
836 /*****************************************************************************
837  * Event Handlers.
838  *****************************************************************************/
839 void Interface::OnMenuOpen( wxMenuEvent& event )
840 {
841 #if defined( __WXMSW__ )
842 #   define GetEventObject GetMenu
843 #endif
844
845     if( event.GetEventObject() == p_settings_menu )
846     {
847         p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );
848
849         /* Add static items */
850         p_settings_menu->AppendCheckItem( Extended_Event,
851             wxU(_("Extended &GUI\tCtrl-G") ) );
852         if( b_extra ) p_settings_menu->Check( Extended_Event, TRUE );
853         p_settings_menu->Append( Bookmarks_Event,
854                                  wxU(_("&Bookmarks...\tCtrl-B") ) );
855         p_settings_menu->Append( Prefs_Event,
856                                  wxU(_("Preference&s...\tCtrl-S")) );
857     }
858
859     else if( event.GetEventObject() == p_audio_menu )
860     {
861         p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
862     }
863
864     else if( event.GetEventObject() == p_video_menu )
865     {
866         p_video_menu = VideoMenu( p_intf, this, p_video_menu );
867     }
868
869     else if( event.GetEventObject() == p_navig_menu )
870     {
871         p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
872     }
873
874 #if defined( __WXMSW__ )
875 #   undef GetEventObject
876 #endif
877 }
878
879 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
880 void Interface::OnContextMenu2(wxContextMenuEvent& event)
881 {
882     /* Only show the context menu for the main interface */
883     if( GetId() != event.GetId() )
884     {
885         event.Skip();
886         return;
887     }
888
889     if( p_intf->p_sys->pf_show_dialog )
890         p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
891 }
892 #endif
893 void Interface::OnContextMenu(wxMouseEvent& event)
894 {
895     if( p_intf->p_sys->pf_show_dialog )
896         p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
897 }
898
899 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
900 {
901     /* TRUE is to force the frame to close. */
902     Close(TRUE);
903 }
904
905 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
906 {
907     wxString msg;
908     msg.Printf( wxString(wxT("VLC media player " PACKAGE_VERSION)) +
909         wxU(_(" (wxWidgets interface)\n\n")) +
910         wxU(_("(c) 1996-2006 - the VideoLAN Team\n\n")) +
911        wxU(_("Compiled by "))+ wxU(VLC_CompileBy())+ wxU("@") +
912        wxU(VLC_CompileHost())+ wxT(".")+ wxU(VLC_CompileDomain())+ wxT(".\n") +
913        wxU(_("Compiler: "))+ wxU(VLC_Compiler())+wxT( ".\n") +
914        wxU(_("Based on SVN revision: "))+wxU(VLC_Changeset())+wxT(".\n\n") +
915 #ifdef __WXMSW__
916         wxU( vlc_wraptext(LICENSE_MSG,WRAPCOUNT,VLC_TRUE) ) + wxT("\n\n") +
917 #else
918         wxU( LICENSE_MSG ) + wxT("\n\n") +
919 #endif
920         wxU(_("The VideoLAN team <videolan@videolan.org>\n"
921               "http://www.videolan.org/\n\n")) );
922
923     wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
924                   wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
925 }
926
927 void Interface::OnShowDialog( wxCommandEvent& event )
928 {
929     if( p_intf->p_sys->pf_show_dialog )
930     {
931         int i_id;
932
933         switch( event.GetId() )
934         {
935         case OpenFileSimple_Event:
936             i_id = INTF_DIALOG_FILE_SIMPLE;
937             break;
938         case OpenAdv_Event:
939             i_id = INTF_DIALOG_FILE;
940             break;
941         case OpenFile_Event:
942             i_id = INTF_DIALOG_FILE;
943             break;
944         case OpenDir_Event:
945             i_id = INTF_DIALOG_DIRECTORY;
946             break;
947         case OpenDisc_Event:
948             i_id = INTF_DIALOG_DISC;
949             break;
950         case OpenNet_Event:
951             i_id = INTF_DIALOG_NET;
952             break;
953         case OpenCapture_Event:
954             i_id = INTF_DIALOG_CAPTURE;
955             break;
956         case OpenSat_Event:
957             i_id = INTF_DIALOG_SAT;
958             break;
959         case Playlist_Event:
960             i_id = INTF_DIALOG_PLAYLIST;
961             break;
962         case Logs_Event:
963             i_id = INTF_DIALOG_MESSAGES;
964             break;
965         case FileInfo_Event:
966             i_id = INTF_DIALOG_FILEINFO;
967             break;
968         case Prefs_Event:
969             i_id = INTF_DIALOG_PREFS;
970             break;
971         case Wizard_Event:
972             i_id = INTF_DIALOG_WIZARD;
973             break;
974         case Bookmarks_Event:
975             i_id = INTF_DIALOG_BOOKMARKS;
976             break;
977         case UpdateVLC_Event:
978             i_id = INTF_DIALOG_UPDATEVLC;
979             break;
980         case VLM_Event:
981             i_id = INTF_DIALOG_VLM;
982             break;
983         default:
984             i_id = INTF_DIALOG_FILE;
985             break;
986         }
987
988         p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
989     }
990 }
991
992 void Interface::OnExtended( wxCommandEvent& WXUNUSED(event) )
993 {
994     UpdateVideoWindow( p_intf, video_window );
995
996     if( !extra_frame )
997     {
998         /* Create the extra panel */
999         extra_frame = new ExtraPanel( p_intf, main_panel );
1000         panel_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
1001         ext_min_size = extra_frame->GetBestSize();
1002     }
1003
1004     b_extra = !b_extra;
1005     panel_sizer->Show( extra_frame, b_extra );
1006
1007     SetIntfMinSize();
1008     main_sizer->Layout();
1009     main_sizer->Fit( this );
1010 }
1011
1012 void Interface::OnSmallPlaylist( wxCommandEvent& WXUNUSED(event) )
1013 {
1014     UpdateVideoWindow( p_intf, video_window );
1015
1016     if( !playlist_manager )
1017     {
1018         /* Create the extra panel */
1019         playlist_manager = new PlaylistManager( p_intf, splitter );
1020     }
1021
1022     if( !splitter->IsSplit() ) splitter->Split( main_panel, playlist_manager );
1023     else splitter->Unsplit( playlist_manager );
1024
1025     SetIntfMinSize();
1026     main_sizer->Layout();
1027     main_sizer->Fit( this );
1028 }
1029
1030 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
1031 {
1032     PlayStream();
1033 }
1034
1035 void Interface::PlayStream()
1036 {
1037     wxCommandEvent dummy;
1038     playlist_t *p_playlist =
1039         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1040                                        FIND_ANYWHERE );
1041     if( p_playlist == NULL ) return;
1042
1043     if( p_playlist->i_size && p_playlist->i_enabled )
1044     {
1045         vlc_value_t state;
1046
1047         input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
1048                                                        VLC_OBJECT_INPUT,
1049                                                        FIND_ANYWHERE );
1050         if( p_input == NULL )
1051         {
1052             /* No stream was playing, start one */
1053             playlist_Play( p_playlist );
1054             vlc_object_release( p_playlist );
1055             input_manager->Update();
1056             return;
1057         }
1058
1059         var_Get( p_input, "state", &state );
1060         if( state.i_int != PAUSE_S )
1061         {
1062             /* A stream is being played, pause it */
1063             state.i_int = PAUSE_S;
1064         }
1065         else
1066         {
1067             /* Stream is paused, resume it */
1068             state.i_int = PLAYING_S;
1069         }
1070         var_Set( p_input, "state", state );
1071
1072         vlc_object_release( p_input );
1073         vlc_object_release( p_playlist );
1074         input_manager->Update();
1075     }
1076     else
1077     {
1078         /* If the playlist is empty, open a file requester instead */
1079         vlc_object_release( p_playlist );
1080         OnShowDialog( dummy );
1081     }
1082 }
1083
1084 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
1085 {
1086     StopStream();
1087 }
1088 void Interface::StopStream()
1089 {
1090     playlist_t * p_playlist =
1091         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1092                                        FIND_ANYWHERE );
1093     if( p_playlist == NULL )
1094     {
1095         return;
1096     }
1097
1098     playlist_Stop( p_playlist );
1099     vlc_object_release( p_playlist );
1100     input_manager->Update();
1101 }
1102
1103 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
1104 {
1105     PrevStream();
1106 }
1107
1108 void Interface::PrevStream()
1109 {
1110     playlist_t * p_playlist =
1111         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1112                                        FIND_ANYWHERE );
1113     if( p_playlist == NULL )
1114     {
1115         return;
1116     }
1117
1118     playlist_Prev( p_playlist );
1119     vlc_object_release( p_playlist );
1120 }
1121
1122 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1123 {
1124     NextStream();
1125 }
1126
1127 void Interface::NextStream()
1128 {
1129     playlist_t * p_playlist =
1130         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1131                                        FIND_ANYWHERE );
1132     if( p_playlist == NULL )
1133     {
1134         return;
1135     }
1136     playlist_Next( p_playlist );
1137     vlc_object_release( p_playlist );
1138 }
1139
1140 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1141 {
1142     input_thread_t *p_input =
1143         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1144                                            FIND_ANYWHERE );
1145     if( p_input )
1146     {
1147         vlc_value_t val; val.b_bool = VLC_TRUE;
1148
1149         var_Set( p_input, "rate-slower", val );
1150         vlc_object_release( p_input );
1151     }
1152 }
1153
1154 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1155 {
1156     input_thread_t *p_input =
1157         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1158                                            FIND_ANYWHERE );
1159     if( p_input )
1160     {
1161         vlc_value_t val; val.b_bool = VLC_TRUE;
1162
1163         var_Set( p_input, "rate-faster", val );
1164         vlc_object_release( p_input );
1165     }
1166 }
1167
1168 void Interface::TogglePlayButton( int i_playing_status )
1169 {
1170     wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
1171         GetToolBar()->GetToolClientData( PlayStream_Event );
1172     if( !p_tool ) return;
1173
1174     if( i_playing_status == PLAYING_S )
1175     {
1176         p_tool->SetNormalBitmap( wxBitmap( pause_xpm ) );
1177         p_tool->SetLabel( wxU(_("Pause")) );
1178         p_tool->SetShortHelp( wxU(_(HELP_PAUSE)) );
1179     }
1180     else
1181     {
1182         p_tool->SetNormalBitmap( wxBitmap( play_xpm ) );
1183         p_tool->SetLabel( wxU(_("Play")) );
1184         p_tool->SetShortHelp( wxU(_(HELP_PLAY)) );
1185     }
1186
1187     GetToolBar()->Realize();
1188
1189 #if defined( __WXMSW__ )
1190     /* Needed to work around a bug in wxToolBar::Realize() */
1191     GetToolBar()->SetSize( GetSize().GetWidth(),
1192                            GetToolBar()->GetSize().GetHeight() );
1193     GetToolBar()->Update();
1194 #endif
1195
1196     GetToolBar()->ToggleTool( PlayStream_Event, true );
1197     GetToolBar()->ToggleTool( PlayStream_Event, false );
1198 }
1199
1200 void Interface::OnInteraction( wxCommandEvent& event )
1201 {
1202     interaction_dialog_t *p_dialog = (interaction_dialog_t *)
1203                                         event.GetClientData();
1204
1205     intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1206     p_arg->p_dialog = p_dialog;
1207     p_arg->p_intf = p_intf;
1208
1209     if( p_dialog->i_type == INTERACT_PROGRESS )
1210     {
1211         /// \todo Handle progress in the interface
1212     }
1213     else
1214     {
1215         p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_INTERACTION,
1216                                        0, p_arg );
1217     }
1218 }
1219
1220 static int InteractCallback( vlc_object_t *p_this,
1221                              const char *psz_var, vlc_value_t old_val,
1222                              vlc_value_t new_val, void *param )
1223 {
1224     Interface *p_interface = (Interface*)param;
1225     /*interaction_dialog_t *p_dialog = (interaction_dialog_t*)(new_val.p_address);*/
1226
1227     wxCommandEvent event( wxEVT_INTERACTION, -1 );
1228     event.SetClientData( new_val.p_address );
1229     p_interface->AddPendingEvent( event );
1230     return VLC_SUCCESS;
1231 }
1232
1233 #if wxUSE_DRAG_AND_DROP
1234 /*****************************************************************************
1235  * Definition of DragAndDrop class.
1236  *****************************************************************************/
1237 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
1238 {
1239     p_intf = _p_intf;
1240     b_enqueue = _b_enqueue;
1241 }
1242
1243 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1244                                const wxArrayString& filenames )
1245 {
1246     /* Add dropped files to the playlist */
1247
1248     playlist_t *p_playlist =
1249         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1250                                        FIND_ANYWHERE );
1251     if( p_playlist == NULL )
1252     {
1253         return FALSE;
1254     }
1255
1256     for( size_t i = 0; i < filenames.GetCount(); i++ )
1257     {
1258 #ifdef wxUSE_UNICODE
1259         /*
1260          * FIXME: this is yet another awful and ugly bug-to-bug work-around
1261          * for the painfully broken and brain-dead wxWidgets character
1262          * encoding internals. Maybe, one day the wxWidgets team will find out
1263          * and we will have to remove (phew) this kludge or autodetect whether
1264          * to trigger it (damn).
1265          *
1266          * In Unicode mode, wxWidgets will encode file names in the locale
1267          * encoding with each **bytes** (rather than characters) represented
1268          * by a 32 bits unsigned integer. If you are lucky enough to be using
1269          * ISO-8859-1 as your local character encoding, that lame encoding
1270          * scheme happens to be identical to UTF-32 with your arch native
1271          * byte-endianess. If you are using anything else, including not only
1272          * UTF-8 but also Windows-1252(!) and ISO-8859-15(!) or any
1273          * non-western encoding, it obviously fails.
1274          */
1275         unsigned len = 1;
1276         const wxChar *stupid = filenames[i];
1277
1278         for (const wxChar *braindead = stupid; *braindead; braindead++)
1279             len++;
1280         char *psz_local = (char *)malloc (len);
1281         do
1282             psz_local[len] = (char)stupid[len];
1283         while (len--);
1284
1285         fprintf (stderr, "local = \"%s\"\n", psz_local);
1286         char *psz_utf8 = FromLocale( psz_local );
1287         fprintf (stderr, "utf8 = \"%s\"\n", psz_utf8);
1288 #else
1289         char *psz_utf8 = wxFromLocale( filenames[i] );
1290 #endif
1291
1292         playlist_Add( p_playlist, psz_utf8, psz_utf8,
1293                       PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
1294                       PLAYLIST_END );
1295 #ifdef wxUSE_UNICODE
1296         LocaleFree( psz_utf8 );
1297         free( psz_local );
1298 #else
1299         wxLocaleFree( psz_utf8 );
1300 #endif
1301     }
1302
1303     vlc_object_release( p_playlist );
1304
1305     return TRUE;
1306 }
1307 #endif
1308
1309 /*****************************************************************************
1310  * Definition of VolCtrl class.
1311  *****************************************************************************/
1312 class wxVolCtrl: public wxGauge
1313 {
1314 public:
1315     /* Constructor */
1316     wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1317                wxPoint = wxDefaultPosition, wxSize = wxSize( 20, -1 ) );
1318     virtual ~wxVolCtrl() {};
1319
1320     void UpdateVolume();
1321     int GetVolume();
1322
1323     void OnChange( wxMouseEvent& event );
1324
1325 private:
1326     intf_thread_t *p_intf;
1327
1328     DECLARE_EVENT_TABLE();
1329 };
1330
1331 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
1332     /* Mouse events */
1333     EVT_LEFT_DOWN(wxVolCtrl::OnChange)
1334     EVT_MOTION(wxVolCtrl::OnChange)
1335 END_EVENT_TABLE()
1336
1337 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1338                       wxPoint point, wxSize size )
1339   : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
1340 {
1341     p_intf = _p_intf;
1342     UpdateVolume();
1343 }
1344
1345 void wxVolCtrl::OnChange( wxMouseEvent& event )
1346 {
1347     if( !event.LeftDown() && !event.LeftIsDown() ) return;
1348
1349     int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
1350     aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1351     UpdateVolume();
1352 }
1353
1354 void wxVolCtrl::UpdateVolume()
1355 {
1356     audio_volume_t i_volume;
1357     aout_VolumeGet( p_intf, &i_volume );
1358
1359     int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
1360     if( i_gauge_volume == GetValue() ) return;
1361
1362     SetValue( i_gauge_volume );
1363     SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
1364                 i_gauge_volume / 2 ) );
1365 }
1366
1367 #if defined(__WXGTK__)
1368 #define VLCVOL_HEIGHT p_parent->GetSize().GetHeight()
1369 #else
1370 #define VLCVOL_HEIGHT TOOLBAR_BMP_HEIGHT
1371 #endif
1372 VLCVolCtrl::VLCVolCtrl( intf_thread_t *_p_intf, wxWindow *p_parent )
1373   :wxControl( p_parent, -1, wxDefaultPosition, wxSize(64, VLCVOL_HEIGHT ),
1374               wxBORDER_NONE ),
1375    i_y_offset((VLCVOL_HEIGHT - TOOLBAR_BMP_HEIGHT) / 2),
1376    b_mute(0), p_intf(_p_intf)
1377 {
1378     gauge = new wxVolCtrl( p_intf, this, -1, wxPoint( 18, i_y_offset ),
1379                            wxSize( 44, TOOLBAR_BMP_HEIGHT ) );
1380 }
1381
1382 void VLCVolCtrl::OnPaint( wxPaintEvent &evt )
1383 {
1384     wxPaintDC dc( this );
1385     wxBitmap mPlayBitmap( b_mute ? speaker_mute_xpm : speaker_xpm );
1386     dc.DrawBitmap( mPlayBitmap, 0, i_y_offset, TRUE );
1387 }
1388
1389 void VLCVolCtrl::OnChange( wxMouseEvent& event )
1390 {
1391     if( event.GetX() < TOOLBAR_BMP_WIDTH )
1392     {
1393         int i_volume;
1394         aout_VolumeMute( p_intf, (audio_volume_t *)&i_volume );
1395
1396         b_mute = !b_mute;
1397         Refresh();
1398     }
1399 }
1400
1401 void VLCVolCtrl::UpdateVolume()
1402 {
1403     gauge->UpdateVolume();
1404
1405     int i_volume = gauge->GetValue();
1406     if( !!i_volume == !b_mute ) return;
1407     b_mute = !b_mute;
1408     Refresh();
1409 }
1410
1411 /*****************************************************************************
1412  * Systray class.
1413  *****************************************************************************/
1414
1415 #ifdef wxHAS_TASK_BAR_ICON
1416
1417 BEGIN_EVENT_TABLE(Systray, wxTaskBarIcon)
1418     /* Mouse events */
1419 #ifdef WIN32
1420     EVT_TASKBAR_LEFT_DCLICK(Systray::OnLeftClick)
1421 #else
1422     EVT_TASKBAR_LEFT_DOWN(Systray::OnLeftClick)
1423 #endif
1424     /* Menu events */
1425     EVT_MENU(Iconize_Event, Systray::OnMenuIconize)
1426     EVT_MENU(Exit_Event, Systray::OnExit)
1427     EVT_MENU(PlayStream_Event, Systray::OnPlayStream)
1428     EVT_MENU(NextStream_Event, Systray::OnNextStream)
1429     EVT_MENU(PrevStream_Event, Systray::OnPrevStream)
1430     EVT_MENU(StopStream_Event, Systray::OnStopStream)
1431 END_EVENT_TABLE()
1432
1433 Systray::Systray( Interface *_p_main_interface, intf_thread_t *_p_intf )
1434 {
1435     p_main_interface = _p_main_interface;
1436     p_intf = _p_intf;
1437
1438     SetIcon( wxIcon( vlc16x16_xpm ), wxT("VLC media player") );
1439     if( !IsOk() || !IsIconInstalled() )
1440     {
1441         msg_Warn(p_intf, "cannot set systray icon, weird things may happen");
1442     }
1443 }
1444
1445 /* Event handlers */
1446 void Systray::OnMenuIconize( wxCommandEvent& event )
1447 {
1448     p_main_interface->Show( ! p_main_interface->IsShown() );
1449     if ( p_main_interface->IsShown() ) p_main_interface->Raise();
1450 }
1451
1452 void Systray::OnLeftClick( wxTaskBarIconEvent& event )
1453 {
1454     wxCommandEvent cevent;
1455     OnMenuIconize(cevent);
1456 }
1457
1458 void Systray::OnExit( wxCommandEvent& event )
1459 {
1460     p_main_interface->Close(TRUE);
1461 }
1462
1463 void Systray::OnPrevStream( wxCommandEvent& event )
1464 {
1465     p_main_interface->PrevStream();
1466 }
1467
1468 void Systray::OnNextStream( wxCommandEvent& event )
1469 {
1470     p_main_interface->NextStream();
1471 }
1472
1473 void Systray::OnPlayStream( wxCommandEvent& event )
1474 {
1475     p_main_interface->PlayStream();
1476 }
1477
1478 void Systray::OnStopStream( wxCommandEvent& event )
1479 {
1480     p_main_interface->StopStream();
1481 }
1482
1483 /* Systray popup menu */
1484 wxMenu* Systray::CreatePopupMenu()
1485 {
1486     int minimal = config_GetInt( p_intf, "wx-minimal" );
1487
1488     wxMenu* systray_menu = new wxMenu;
1489     systray_menu->Append( Exit_Event, wxU(_("Quit VLC")) );
1490     systray_menu->AppendSeparator();
1491     systray_menu->Append( PlayStream_Event, wxU(_("Play/Pause")) );
1492
1493     if (!minimal)
1494     {
1495     systray_menu->Append( PrevStream_Event, wxU(_("Previous")) );
1496     systray_menu->Append( NextStream_Event, wxU(_("Next")) );
1497     systray_menu->Append( StopStream_Event, wxU(_("Stop")) );
1498     }
1499     systray_menu->AppendSeparator();
1500     systray_menu->Append( Iconize_Event, wxU(_("Show/Hide interface")) );
1501     return systray_menu;
1502 }
1503
1504 void Systray::UpdateTooltip( const wxChar* tooltip )
1505 {
1506     SetIcon( wxIcon( vlc16x16_xpm ), tooltip );
1507 }
1508 #endif