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