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