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