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