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