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