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