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