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