]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/interface.cpp
1f960b6d3856e3d41ea101cf905f91ddc860ca98
[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
47 #define TOOLBAR_BMP_WIDTH 16
48 #define TOOLBAR_BMP_HEIGHT 16
49
50 /* include the icon graphic */
51 #include "../../../share/vlc32x32.xpm"
52
53 /*****************************************************************************
54  * Local class declarations.
55  *****************************************************************************/
56 class wxMenuExt: public wxMenu
57 {
58 public:
59     /* Constructor */
60     wxMenuExt( wxMenu* parentMenu, int id, const wxString& text,
61                    const wxString& helpString, wxItemKind kind,
62                    char *_psz_var, int _i_object_id, vlc_value_t _val,
63                    int _i_val_type );
64
65     virtual ~wxMenuExt() {};
66
67     char *psz_var;
68     int  i_val_type;
69     int  i_object_id;
70     vlc_value_t val;
71
72 private:
73
74 };
75
76 class wxVolCtrl: public wxGauge
77 {
78 public:
79     /* Constructor */
80     wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
81                wxPoint = wxDefaultPosition, wxSize = wxSize( 20, -1 ) );
82     virtual ~wxVolCtrl() {};
83
84     void UpdateVolume();
85
86     void OnChange( wxMouseEvent& event );
87
88 private:
89     intf_thread_t *p_intf;
90
91     DECLARE_EVENT_TABLE();
92 };
93
94 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
95     /* Mouse events */
96     EVT_LEFT_DOWN(wxVolCtrl::OnChange)
97     EVT_MOTION(wxVolCtrl::OnChange)
98 END_EVENT_TABLE()
99
100 /*****************************************************************************
101  * Event Table.
102  *****************************************************************************/
103
104 DEFINE_LOCAL_EVENT_TYPE( wxEVT_INTF );
105
106 /* IDs for the controls and the menu commands */
107 enum
108 {
109     /* menu items */
110     MenuDummy_Event = wxID_HIGHEST + 1000,
111     Exit_Event = wxID_HIGHEST,
112     OpenFileSimple_Event,
113     OpenAdv_Event,
114     OpenFile_Event,
115     OpenDisc_Event,
116     OpenNet_Event,
117     OpenCapture_Event,
118     OpenSat_Event,
119     OpenOther_Event,
120     EjectDisc_Event,
121
122     Wizard_Event,
123
124     Playlist_Event,
125     Logs_Event,
126     FileInfo_Event,
127
128     Prefs_Event,
129     Extended_Event,
130 //    Undock_Event,
131     Bookmarks_Event,
132     Skins_Event,
133
134     SliderScroll_Event,
135     StopStream_Event,
136     PlayStream_Event,
137     PrevStream_Event,
138     NextStream_Event,
139     SlowStream_Event,
140     FastStream_Event,
141
142     DiscMenu_Event,
143     DiscPrev_Event,
144     DiscNext_Event,
145
146     /* it is important for the id corresponding to the "About" command to have
147      * this standard value as otherwise it won't be handled properly under Mac
148      * (where it is special and put into the "Apple" menu) */
149     About_Event = wxID_ABOUT
150 };
151
152 BEGIN_EVENT_TABLE(Interface, wxFrame)
153     /* Menu events */
154     EVT_MENU(Exit_Event, Interface::OnExit)
155     EVT_MENU(About_Event, Interface::OnAbout)
156
157     EVT_MENU(Playlist_Event, Interface::OnShowDialog)
158     EVT_MENU(Logs_Event, Interface::OnShowDialog)
159     EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
160     EVT_MENU(Prefs_Event, Interface::OnShowDialog)
161
162     EVT_MENU_OPEN(Interface::OnMenuOpen)
163
164     EVT_MENU( Extended_Event, Interface::OnExtended )
165 //    EVT_MENU( Undock_Event, Interface::OnUndock )
166
167     EVT_MENU( Bookmarks_Event, Interface::OnShowDialog)
168
169 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
170     EVT_CONTEXT_MENU(Interface::OnContextMenu2)
171 #endif
172     EVT_RIGHT_UP(Interface::OnContextMenu)
173
174     /* Toolbar events */
175     EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
176     EVT_MENU(OpenAdv_Event, Interface::OnShowDialog)
177     EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
178     EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
179     EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
180     EVT_MENU(OpenCapture_Event, Interface::OnShowDialog)
181     EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
182     EVT_MENU(Wizard_Event, Interface::OnShowDialog)
183     EVT_MENU(StopStream_Event, Interface::OnStopStream)
184     EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
185     EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
186     EVT_MENU(NextStream_Event, Interface::OnNextStream)
187     EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
188     EVT_MENU(FastStream_Event, Interface::OnFastStream)
189
190     /* Disc Buttons events */
191     EVT_BUTTON(DiscMenu_Event, Interface::OnDiscMenu)
192     EVT_BUTTON(DiscPrev_Event, Interface::OnDiscPrev)
193     EVT_BUTTON(DiscNext_Event, Interface::OnDiscNext)
194
195     /* Slider events */
196     EVT_COMMAND_SCROLL(SliderScroll_Event, Interface::OnSliderUpdate)
197
198     /* Custom events */
199     EVT_COMMAND(0, wxEVT_INTF, Interface::OnControlEvent)
200     EVT_COMMAND(1, wxEVT_INTF, Interface::OnControlEvent)
201
202 END_EVENT_TABLE()
203
204 /*****************************************************************************
205  * Constructor.
206  *****************************************************************************/
207 Interface::Interface( intf_thread_t *_p_intf ):
208     wxFrame( NULL, -1, wxT("VLC media player"),
209              wxDefaultPosition, wxSize(700,100), wxDEFAULT_FRAME_STYLE )
210 {
211     /* Initializations */
212     p_intf = _p_intf;
213     i_old_playing_status = PAUSE_S;
214     b_extra = VLC_FALSE;
215 //    b_undock = VLC_FALSE;
216
217     extra_window = NULL;
218
219     /* Give our interface a nice little icon */
220     SetIcon( wxIcon( vlc_xpm ) );
221
222     /* Create a sizer for the main frame */
223     frame_sizer = new wxBoxSizer( wxVERTICAL );
224     SetSizer( frame_sizer );
225
226     /* Create a dummy widget that can get the keyboard focus */
227     wxWindow *p_dummy = new wxWindow( this, 0, wxDefaultPosition,
228                                       wxSize(0,0) );
229     p_dummy->SetFocus();
230     frame_sizer->Add( p_dummy, 0, 0 );
231
232     /* Creation of the menu bar */
233     CreateOurMenuBar();
234
235     /* Creation of the tool bar */
236     CreateOurToolBar();
237
238     /* Create the extra panel */
239     extra_frame = new ExtraPanel( p_intf, this );
240     frame_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
241     frame_sizer->Hide( extra_frame );
242
243     /* Creation of the status bar
244      * Helptext for menu items and toolbar tools will automatically get
245      * displayed here. */
246     int i_status_width[3] = {-6, -2, -9};
247     statusbar = CreateStatusBar( 3 );                            /* 2 fields */
248     statusbar->SetStatusWidths( 3, i_status_width );
249     statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
250
251     /* Video window */
252     if( config_GetInt( p_intf, "wxwin-embed" ) )
253     {
254         CreateVideoWindow( p_intf, this );
255         frame_sizer->Add( p_intf->p_sys->p_video_sizer, 1, wxEXPAND , 0 );
256     }
257
258     /* Creation of the slider sub-window */
259     CreateOurSlider();
260     frame_sizer->Add( slider_frame, 0, wxEXPAND , 0 );
261     frame_sizer->Hide( slider_frame );
262
263     /* Make sure we've got the right background colour */
264     SetBackgroundColour( slider_frame->GetBackgroundColour() );
265
266     /* Layout everything */
267     frame_sizer->Layout();
268     frame_sizer->Fit(this);
269
270 #if wxUSE_DRAG_AND_DROP
271     /* Associate drop targets with the main interface */
272     SetDropTarget( new DragAndDrop( p_intf ) );
273 #endif
274
275     SetupHotkeys();
276
277     /* Start timer */
278     timer = new Timer( p_intf, this );
279 }
280
281 Interface::~Interface()
282 {
283     if( p_intf->p_sys->p_wxwindow )
284     {
285         delete p_intf->p_sys->p_wxwindow;
286     }
287
288     /* Clean up */
289     delete timer;
290 }
291
292 void Interface::Init()
293 {
294     /* Misc init */
295     SetupHotkeys();
296 }
297
298 void Interface::Update()
299 {
300     /* Misc updates */
301     ((wxVolCtrl *)volctrl)->UpdateVolume();
302 }
303
304 void Interface::OnControlEvent( wxCommandEvent& event )
305 {
306     switch( event.GetId() )
307     {
308     case 0:
309         frame_sizer->Layout();
310         frame_sizer->Fit(this);
311         break;
312
313     case 1:
314         long i_style = GetWindowStyle();
315         if( event.GetInt() ) i_style |= wxSTAY_ON_TOP;
316         else i_style &= ~wxSTAY_ON_TOP;
317         SetWindowStyle( i_style );
318         break;
319     }
320 }
321
322 /*****************************************************************************
323  * Private methods.
324  *****************************************************************************/
325 void Interface::CreateOurMenuBar()
326 {
327     /* Create the "File" menu */
328     wxMenu *file_menu = new wxMenu;
329     file_menu->Append( OpenFileSimple_Event,
330                        wxU(_("Quick &Open File...\tCtrl-O")) );
331
332     file_menu->AppendSeparator();
333     file_menu->Append( OpenFile_Event, wxU(_("Open &File...\tCtrl-F")) );
334     file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...\tCtrl-D")) );
335     file_menu->Append( OpenNet_Event,
336                        wxU(_("Open &Network Stream...\tCtrl-N")) );
337     file_menu->Append( OpenCapture_Event,
338                        wxU(_("Open &Capture Device...\tCtrl-C")) );
339
340     file_menu->AppendSeparator();
341     file_menu->Append( Wizard_Event, wxU(_("&Wizard...\tCtrl-W")) );
342     file_menu->AppendSeparator();
343     file_menu->Append( Exit_Event, wxU(_("E&xit\tCtrl-X")) );
344
345     /* Create the "View" menu */
346     wxMenu *view_menu = new wxMenu;
347     view_menu->Append( Playlist_Event, wxU(_("&Playlist...\tCtrl-P")) );
348     view_menu->Append( Logs_Event, wxU(_("&Messages...\tCtrl-M")) );
349     view_menu->Append( FileInfo_Event,
350                        wxU(_("Stream and Media &info...\tCtrl-I")) );
351
352     /* Create the "Auto-generated" menus */
353     p_settings_menu = SettingsMenu( p_intf, this );
354     p_audio_menu = AudioMenu( p_intf, this );
355     p_video_menu = VideoMenu( p_intf, this );
356     p_navig_menu = NavigMenu( p_intf, this );
357
358     /* Create the "Help" menu */
359     wxMenu *help_menu = new wxMenu;
360     help_menu->Append( About_Event, wxU(_("About VLC media player")) );
361
362     /* Append the freshly created menus to the menu bar... */
363     wxMenuBar *menubar = new wxMenuBar();
364     menubar->Append( file_menu, wxU(_("&File")) );
365     menubar->Append( view_menu, wxU(_("&View")) );
366     menubar->Append( p_settings_menu, wxU(_("&Settings")) );
367     menubar->Append( p_audio_menu, wxU(_("&Audio")) );
368     menubar->Append( p_video_menu, wxU(_("&Video")) );
369     menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
370     menubar->Append( help_menu, wxU(_("&Help")) );
371
372     /* Attach the menu bar to the frame */
373     SetMenuBar( menubar );
374
375     /* Find out size of menu bar */
376     int i_size = 0;
377     for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
378     {
379         int i_width, i_height;
380         menubar->GetTextExtent( menubar->GetLabelTop(i), &i_width, &i_height );
381         i_size += i_width +
382 #if defined(__WXGTK__)
383             22 /* approximate margin */;
384 #else
385 #if (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 5) && (wxRELEASE_NUMBER < 3)
386             4 /* approximate margin */;
387 #else
388             18 /* approximate margin */;
389 #endif
390 #endif
391     }
392     frame_sizer->SetMinSize( i_size, -1 );
393
394     /* Intercept all menu events in our custom event handler */
395     PushEventHandler( new MenuEvtHandler( p_intf, this ) );
396
397 #if wxUSE_DRAG_AND_DROP
398     /* Associate drop targets with the menubar */
399     menubar->SetDropTarget( new DragAndDrop( p_intf ) );
400 #endif
401 }
402
403 class VLCVolCtrl : public wxControl
404 {
405 public:
406     VLCVolCtrl( intf_thread_t *p_intf, wxWindow *p_parent, wxGauge ** );
407     virtual ~VLCVolCtrl() {};
408
409     virtual void OnPaint( wxPaintEvent &event );
410
411   private:
412     DECLARE_EVENT_TABLE()
413     int i_y_offset;
414 };
415
416 BEGIN_EVENT_TABLE(VLCVolCtrl, wxControl)
417    EVT_PAINT(VLCVolCtrl::OnPaint)
418 END_EVENT_TABLE()
419
420 #if defined(__WXGTK__)
421 #define VLCVOL_HEIGHT p_parent->GetSize().GetHeight()
422 #else
423 #define VLCVOL_HEIGHT TOOLBAR_BMP_HEIGHT
424 #endif
425 VLCVolCtrl::VLCVolCtrl( intf_thread_t *p_intf, wxWindow *p_parent,
426                         wxGauge **pp_volctrl )
427   :wxControl( p_parent, -1, wxDefaultPosition, wxSize(64, VLCVOL_HEIGHT ),
428               wxBORDER_NONE ),
429    i_y_offset((VLCVOL_HEIGHT - TOOLBAR_BMP_HEIGHT) / 2)
430 {
431     *pp_volctrl = new wxVolCtrl( p_intf, this, -1, wxPoint( 18, i_y_offset ),
432                                  wxSize( 44, TOOLBAR_BMP_HEIGHT ) );
433 }
434
435 void VLCVolCtrl::OnPaint( wxPaintEvent &evt )
436 {
437     wxPaintDC dc( this );
438     wxBitmap mPlayBitmap( speaker_xpm );
439     dc.DrawBitmap( mPlayBitmap, 0, i_y_offset, TRUE );
440 }
441
442 void Interface::CreateOurToolBar()
443 {
444 #define HELP_OPEN N_("Open")
445 #define HELP_STOP N_("Stop")
446 #define HELP_PLAY N_("Play")
447 #define HELP_PAUSE N_("Pause")
448 #define HELP_PLO N_("Playlist")
449 #define HELP_PLP N_("Previous playlist item")
450 #define HELP_PLN N_("Next playlist item")
451 #define HELP_SLOW N_("Play slower")
452 #define HELP_FAST N_("Play faster")
453
454     wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
455                          * version because we don't include wx.rc */
456
457     wxToolBar *toolbar =
458         CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
459
460     toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
461
462     toolbar->AddTool( OpenFile_Event, wxT(""),
463                       wxBitmap( eject_xpm ), wxU(_(HELP_OPEN)) );
464     toolbar->AddSeparator();
465
466     wxToolBarToolBase *p_tool = toolbar->AddTool( PlayStream_Event, wxT(""),
467                       wxBitmap( play_xpm ), wxU(_(HELP_PLAY)) );
468     p_tool->SetClientData( p_tool );
469
470     toolbar->AddTool( StopStream_Event, wxT(""), wxBitmap( stop_xpm ),
471                       wxU(_(HELP_STOP)) );
472     toolbar->AddSeparator();
473     toolbar->AddTool( PrevStream_Event, wxT(""),
474                       wxBitmap( prev_xpm ), wxU(_(HELP_PLP)) );
475     toolbar->AddTool( SlowStream_Event, wxT(""),
476                       wxBitmap( slow_xpm ), wxU(_(HELP_SLOW)) );
477     toolbar->AddTool( FastStream_Event, wxT(""),
478                       wxBitmap( fast_xpm ), wxU(_(HELP_FAST)) );
479     toolbar->AddTool( NextStream_Event, wxT(""), wxBitmap( next_xpm ),
480                       wxU(_(HELP_PLN)) );
481     toolbar->AddSeparator();
482     toolbar->AddTool( Playlist_Event, wxT(""), wxBitmap( playlist_xpm ),
483                       wxU(_(HELP_PLO)) );
484
485     wxControl *p_dummy_ctrl =
486         new wxControl( toolbar, -1, wxDefaultPosition,
487                        wxSize(35, 16 ), wxBORDER_NONE );
488
489     toolbar->AddControl( p_dummy_ctrl );
490
491     VLCVolCtrl *sound_control = new VLCVolCtrl( p_intf, toolbar, &volctrl );
492     toolbar->AddControl( sound_control );
493
494     toolbar->Realize();
495
496 #if wxUSE_DRAG_AND_DROP
497     /* Associate drop targets with the toolbar */
498     toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
499 #endif
500 }
501
502 void Interface::CreateOurSlider()
503 {
504     /* Create a new frame and sizer containing the slider */
505     slider_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
506     slider_frame->SetAutoLayout( TRUE );
507     slider_sizer = new wxBoxSizer( wxHORIZONTAL );
508     //slider_sizer->SetMinSize( -1, 50 );
509
510     /* Create slider */
511     slider = new wxSlider( slider_frame, SliderScroll_Event, 0, 0,
512                            SLIDER_MAX_POS, wxDefaultPosition, wxDefaultSize );
513
514     /* Add Disc Buttons */
515     disc_frame = new wxPanel( slider_frame, -1, wxDefaultPosition,
516                               wxDefaultSize );
517     disc_frame->SetAutoLayout( TRUE );
518     disc_sizer = new wxBoxSizer( wxHORIZONTAL );
519
520     disc_menu_button = new wxBitmapButton( disc_frame, DiscMenu_Event,
521                                            wxBitmap( playlist_xpm ) );
522     disc_prev_button = new wxBitmapButton( disc_frame, DiscPrev_Event,
523                                            wxBitmap( prev_xpm ) );
524     disc_next_button = new wxBitmapButton( disc_frame, DiscNext_Event,
525                                            wxBitmap( next_xpm ) );
526
527     disc_sizer->Add( disc_menu_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
528     disc_sizer->Add( disc_prev_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
529     disc_sizer->Add( disc_next_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
530
531     disc_frame->SetSizer( disc_sizer );
532     disc_sizer->Layout();
533
534     /* Add everything to the frame */
535     slider_sizer->Add( slider, 1, wxEXPAND | wxALL, 5 );
536     slider_sizer->Add( disc_frame, 0, wxALL, 2 );
537     slider_frame->SetSizer( slider_sizer );
538
539     disc_frame->Hide();
540     slider_sizer->Hide( disc_frame );
541
542     slider_sizer->Layout();
543     slider_sizer->Fit( slider_frame );
544
545     /* Hide the slider by default */
546     slider_frame->Hide();
547 }
548
549 static int ConvertHotkeyModifiers( int i_hotkey )
550 {
551     int i_accel_flags = 0;
552     if( i_hotkey & KEY_MODIFIER_ALT ) i_accel_flags |= wxACCEL_ALT;
553     if( i_hotkey & KEY_MODIFIER_CTRL ) i_accel_flags |= wxACCEL_CTRL;
554     if( i_hotkey & KEY_MODIFIER_SHIFT ) i_accel_flags |= wxACCEL_SHIFT;
555     if( !i_accel_flags ) i_accel_flags = wxACCEL_NORMAL;
556     return i_accel_flags;
557 }
558
559 static int ConvertHotkey( int i_hotkey )
560 {
561     int i_key = i_hotkey & ~KEY_MODIFIER;
562     if( i_key & KEY_ASCII ) return i_key & KEY_ASCII;
563     else if( i_key & KEY_SPECIAL )
564     {
565         switch ( i_key )
566         {
567         case KEY_LEFT: return WXK_LEFT;
568         case KEY_RIGHT: return WXK_RIGHT;
569         case KEY_UP: return WXK_UP;
570         case KEY_DOWN: return WXK_DOWN;
571         case KEY_SPACE: return WXK_SPACE;
572         case KEY_ENTER: return WXK_RETURN;
573         case KEY_F1: return WXK_F1;
574         case KEY_F2: return WXK_F2;
575         case KEY_F3: return WXK_F3;
576         case KEY_F4: return WXK_F4;
577         case KEY_F5: return WXK_F5;
578         case KEY_F6: return WXK_F6;
579         case KEY_F7: return WXK_F7;
580         case KEY_F8: return WXK_F8;
581         case KEY_F9: return WXK_F9;
582         case KEY_F10: return WXK_F10;
583         case KEY_F11: return WXK_F11;
584         case KEY_F12: return WXK_F12;
585         case KEY_HOME: return WXK_HOME;
586         case KEY_END: return WXK_HOME;
587         case KEY_MENU: return WXK_MENU;
588         case KEY_ESC: return WXK_ESCAPE;
589         case KEY_PAGEUP: return WXK_PRIOR;
590         case KEY_PAGEDOWN: return WXK_NEXT;
591         case KEY_TAB: return WXK_TAB;
592         case KEY_BACKSPACE: return WXK_BACK;
593         }
594     }
595     return WXK_F24;
596 }
597
598 void Interface::SetupHotkeys()
599 {
600     struct vlc_t::hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
601     int i_hotkeys;
602
603     /* Count number of hoteys */
604     for( i_hotkeys = 0; p_hotkeys[i_hotkeys].psz_action != NULL; i_hotkeys++ );
605
606     p_intf->p_sys->i_first_hotkey_event = wxID_HIGHEST + 7000;
607     p_intf->p_sys->i_hotkeys = i_hotkeys;
608
609     wxAcceleratorEntry *p_entries = new wxAcceleratorEntry[i_hotkeys];
610
611     /* Setup the hotkeys as accelerators */
612     for( int i = 0; i < i_hotkeys; i++ )
613     {
614         int i_mod = ConvertHotkeyModifiers( p_hotkeys[i].i_key );
615         int i_key = ConvertHotkey( p_hotkeys[i].i_key );
616
617 #ifdef WIN32
618         if( i_mod ) i_key = toupper(i_key);
619 #endif
620
621         p_entries[i].Set( i_mod, i_key,
622                           p_intf->p_sys->i_first_hotkey_event + i );
623     }
624
625     wxAcceleratorTable accel( i_hotkeys, p_entries );
626
627     if( !accel.Ok() )
628     {
629         msg_Err( p_intf, "invalid accelerator table" );
630     }
631     else
632     {
633         SetAcceleratorTable( accel );
634         msg_Dbg( p_intf, "accelerator table loaded" );
635     }
636
637     delete [] p_entries;
638 }
639
640 /*****************************************************************************
641  * Event Handlers.
642  *****************************************************************************/
643
644 void Interface::OnMenuOpen(wxMenuEvent& event)
645 {
646 #if defined( __WXMSW__ )
647 #   define GetEventObject GetMenu
648 #endif
649
650     if( event.GetEventObject() == p_settings_menu )
651     {
652         p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );
653
654         /* Add static items */
655         p_settings_menu->AppendCheckItem( Extended_Event,
656             wxU(_("&Extended GUI") ) );
657         if( b_extra ) p_settings_menu->Check( Extended_Event, TRUE );
658 #if 0
659         p_settings_menu->AppendCheckItem( Undock_Event,
660             wxU(_("&Undock Ext. GUI") ) );
661         if( b_undock ) p_settings_menu->Check( Undock_Event, TRUE );
662 #endif
663         p_settings_menu->Append( Bookmarks_Event, wxU(_("&Bookmarks...") ) );
664         p_settings_menu->Append( Prefs_Event, wxU(_("&Preferences...")) );
665     }
666
667     else if( event.GetEventObject() == p_audio_menu )
668     {
669         p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
670     }
671
672     else if( event.GetEventObject() == p_video_menu )
673     {
674         p_video_menu = VideoMenu( p_intf, this, p_video_menu );
675     }
676
677     else if( event.GetEventObject() == p_navig_menu )
678     {
679         p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
680     }
681
682 #if defined( __WXMSW__ )
683 #   undef GetEventObject
684 #endif
685 }
686
687 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
688 void Interface::OnContextMenu2(wxContextMenuEvent& event)
689 {
690     /* Only show the context menu for the main interface */
691     if( GetId() != event.GetId() )
692     {
693         event.Skip();
694         return;
695     }
696
697     if( p_intf->p_sys->pf_show_dialog )
698         p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
699 }
700 #endif
701 void Interface::OnContextMenu(wxMouseEvent& event)
702 {
703     if( p_intf->p_sys->pf_show_dialog )
704         p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
705 }
706
707 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
708 {
709     /* TRUE is to force the frame to close. */
710     Close(TRUE);
711 }
712
713 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
714 {
715     wxString msg;
716     msg.Printf( wxString(wxT("VLC media player " PACKAGE_VERSION)) +
717         wxU(_(" (wxWindows interface)\n\n")) +
718         wxU(_("(c) 1996-2005 - the VideoLAN Team\n\n")) +
719         wxU( vlc_wraptext(INTF_ABOUT_MSG,WRAPCOUNT,ISUTF8) ) + wxT("\n\n") +
720         wxU(_("The VideoLAN team <videolan@videolan.org>\n"
721               "http://www.videolan.org/\n\n")) );
722
723     wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
724                   wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
725 }
726
727 void Interface::OnShowDialog( wxCommandEvent& event )
728 {
729     if( p_intf->p_sys->pf_show_dialog )
730     {
731         int i_id;
732
733         switch( event.GetId() )
734         {
735         case OpenFileSimple_Event:
736             i_id = INTF_DIALOG_FILE_SIMPLE;
737             break;
738         case OpenAdv_Event:
739             i_id = INTF_DIALOG_FILE;
740         case OpenFile_Event:
741             i_id = INTF_DIALOG_FILE;
742             break;
743         case OpenDisc_Event:
744             i_id = INTF_DIALOG_DISC;
745             break;
746         case OpenNet_Event:
747             i_id = INTF_DIALOG_NET;
748             break;
749         case OpenCapture_Event:
750             i_id = INTF_DIALOG_CAPTURE;
751             break;
752         case OpenSat_Event:
753             i_id = INTF_DIALOG_SAT;
754             break;
755         case Playlist_Event:
756             i_id = INTF_DIALOG_PLAYLIST;
757             break;
758         case Logs_Event:
759             i_id = INTF_DIALOG_MESSAGES;
760             break;
761         case FileInfo_Event:
762             i_id = INTF_DIALOG_FILEINFO;
763             break;
764         case Prefs_Event:
765             i_id = INTF_DIALOG_PREFS;
766             break;
767         case Wizard_Event:
768             i_id = INTF_DIALOG_WIZARD;
769             break;
770         case Bookmarks_Event:
771             i_id = INTF_DIALOG_BOOKMARKS;
772             break;
773         default:
774             i_id = INTF_DIALOG_FILE;
775             break;
776         }
777
778         p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
779     }
780 }
781
782 void Interface::OnExtended(wxCommandEvent& event)
783 {
784     b_extra = (b_extra == VLC_TRUE ? VLC_FALSE : VLC_TRUE );
785
786     if( b_extra == VLC_FALSE )
787     {
788         extra_frame->Hide();
789         frame_sizer->Hide( extra_frame );
790     }
791     else
792     {
793         extra_frame->Show();
794         frame_sizer->Show( extra_frame );
795     }
796     frame_sizer->Layout();
797     frame_sizer->Fit(this);
798 }
799
800 #if 0
801         if( b_undock == VLC_TRUE )
802         {
803                 fprintf(stderr,"Deleting window\n");
804             if( extra_window )
805             {
806                 delete extra_window;
807                 extra_window = NULL;
808             }
809         }
810         else
811         {
812             extra_frame->Hide();
813             frame_sizer->Hide( extra_frame );
814             frame_sizer->Layout();
815             frame_sizer->Fit(this);
816         }
817     }
818     else
819     {
820         if( b_undock == VLC_TRUE )
821         {
822                 fprintf(stderr,"Creating window\n");
823             extra_frame->Hide();
824             frame_sizer->Hide( extra_frame );
825             frame_sizer->Detach( extra_frame );
826             frame_sizer->Layout();
827             frame_sizer->Fit(this);
828             extra_window = new ExtraWindow( p_intf, this, extra_frame );
829         }
830         else
831         {
832                 fprintf(stderr,"Deleting window\n");
833             if( extra_window )
834             {
835                 delete extra_window;
836             }
837             extra_frame->Show();
838             frame_sizer->Show( extra_frame );
839             frame_sizer->Layout();
840             frame_sizer->Fit(this);
841         }
842     }
843 }
844
845 void Interface::OnUndock(wxCommandEvent& event)
846 {
847     b_undock = (b_undock == VLC_TRUE ? VLC_FALSE : VLC_TRUE );
848
849     if( b_extra == VLC_TRUE )
850     {
851         if( b_undock == VLC_FALSE )
852         {
853                 fprintf(stderr,"Deleting window\n");
854             if( extra_window )
855             {
856                 delete extra_window;
857                 extra_window = NULL;
858             }
859             extra_frame->Show();
860             frame_sizer->Show( extra_frame );
861             frame_sizer->Layout();
862             frame_sizer->Fit(this);
863         }
864         else
865         {
866                 fprintf(stderr,"Creating window\n");
867             extra_frame->Hide();
868             frame_sizer->Hide( extra_frame );
869             frame_sizer->Detach( extra_frame );
870             frame_sizer->Layout();
871             frame_sizer->Fit(this);
872             extra_window = new ExtraWindow( p_intf, this, extra_frame );
873         }
874     }
875 }
876 #endif
877
878 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
879 {
880     wxCommandEvent dummy;
881     playlist_t *p_playlist =
882         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
883                                        FIND_ANYWHERE );
884     if( p_playlist == NULL ) return;
885
886     if( p_playlist->i_size && p_playlist->i_enabled )
887     {
888         vlc_value_t state;
889
890         input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
891                                                        VLC_OBJECT_INPUT,
892                                                        FIND_ANYWHERE );
893         if( p_input == NULL )
894         {
895             /* No stream was playing, start one */
896             playlist_Play( p_playlist );
897             TogglePlayButton( PLAYING_S );
898             vlc_object_release( p_playlist );
899             return;
900         }
901
902         var_Get( p_input, "state", &state );
903
904         if( state.i_int != PAUSE_S )
905         {
906             /* A stream is being played, pause it */
907             state.i_int = PAUSE_S;
908         }
909         else
910         {
911             /* Stream is paused, resume it */
912             state.i_int = PLAYING_S;
913         }
914         var_Set( p_input, "state", state );
915
916         TogglePlayButton( state.i_int );
917         vlc_object_release( p_input );
918         vlc_object_release( p_playlist );
919     }
920     else
921     {
922         /* If the playlist is empty, open a file requester instead */
923         vlc_object_release( p_playlist );
924         OnShowDialog( dummy );
925     }
926 }
927
928 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
929 {
930     playlist_t * p_playlist =
931         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
932                                        FIND_ANYWHERE );
933     if( p_playlist == NULL )
934     {
935         return;
936     }
937
938     playlist_Stop( p_playlist );
939     TogglePlayButton( PAUSE_S );
940     vlc_object_release( p_playlist );
941 }
942
943 void Interface::OnSliderUpdate( wxScrollEvent& event )
944 {
945     vlc_mutex_lock( &p_intf->change_lock );
946
947 #ifdef WIN32
948     if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
949         || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
950     {
951 #endif
952         if( p_intf->p_sys->i_slider_pos != event.GetPosition()
953             && p_intf->p_sys->p_input )
954         {
955             vlc_value_t pos;
956             pos.f_float = (float)event.GetPosition() / (float)SLIDER_MAX_POS;
957
958             var_Set( p_intf->p_sys->p_input, "position", pos );
959         }
960
961 #ifdef WIN32
962         p_intf->p_sys->b_slider_free = VLC_TRUE;
963     }
964     else
965     {
966         p_intf->p_sys->b_slider_free = VLC_FALSE;
967
968         if( p_intf->p_sys->p_input )
969         {
970             /* Update stream date */
971             char psz_time[ MSTRTIME_MAX_SIZE ], psz_total[ MSTRTIME_MAX_SIZE ];
972             mtime_t i_seconds;
973
974             i_seconds = var_GetTime( p_intf->p_sys->p_input, "length" ) /
975                         I64C(1000000 );
976             secstotimestr( psz_total, i_seconds );
977
978             i_seconds = var_GetTime( p_intf->p_sys->p_input, "time" ) /
979                         I64C(1000000 );
980             secstotimestr( psz_time, i_seconds );
981
982             statusbar->SetStatusText( wxU(psz_time) + wxString(wxT(" / ") ) +
983                                       wxU(psz_total), 0 );
984         }
985     }
986 #endif
987
988 #undef WIN32
989     vlc_mutex_unlock( &p_intf->change_lock );
990 }
991
992 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
993 {
994     playlist_t * p_playlist =
995         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
996                                        FIND_ANYWHERE );
997     if( p_playlist == NULL )
998     {
999         return;
1000     }
1001
1002     /* FIXME --fenrir */
1003 #if 0
1004     if( p_playlist->p_input != NULL )
1005     {
1006         vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1007         if( p_playlist->p_input->stream.p_selected_area->i_id > 1 )
1008         {
1009             vlc_value_t val; val.b_bool = VLC_TRUE;
1010             vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1011             var_Set( p_playlist->p_input, "prev-title", val );
1012         } else
1013             vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1014     }
1015     vlc_mutex_unlock( &p_playlist->object_lock );
1016 #endif
1017
1018     playlist_Prev( p_playlist );
1019     vlc_object_release( p_playlist );
1020 }
1021
1022 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1023 {
1024     playlist_t * p_playlist =
1025         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1026                                        FIND_ANYWHERE );
1027     if( p_playlist == NULL )
1028     {
1029         return;
1030     }
1031
1032     /* FIXME --fenrir */
1033 #if 0
1034     var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
1035     vlc_mutex_lock( &p_playlist->object_lock );
1036     if( p_playlist->p_input != NULL )
1037     {
1038         vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1039         if( p_playlist->p_input->stream.i_area_nb > 1 &&
1040             p_playlist->p_input->stream.p_selected_area->i_id <
1041               p_playlist->p_input->stream.i_area_nb - 1 )
1042         {
1043             vlc_value_t val; val.b_bool = VLC_TRUE;
1044             vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1045             var_Set( p_playlist->p_input, "next-title", val );
1046         } else
1047             vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1048     }
1049     vlc_mutex_unlock( &p_playlist->object_lock );
1050 #endif
1051     playlist_Next( p_playlist );
1052     vlc_object_release( p_playlist );
1053 }
1054
1055 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1056 {
1057     input_thread_t *p_input =
1058         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1059                                            FIND_ANYWHERE );
1060     if( p_input )
1061     {
1062         vlc_value_t val; val.b_bool = VLC_TRUE;
1063
1064         var_Set( p_input, "rate-slower", val );
1065         vlc_object_release( p_input );
1066     }
1067 }
1068
1069 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1070 {
1071     input_thread_t *p_input =
1072         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1073                                            FIND_ANYWHERE );
1074     if( p_input )
1075     {
1076         vlc_value_t val; val.b_bool = VLC_TRUE;
1077
1078         var_Set( p_input, "rate-faster", val );
1079         vlc_object_release( p_input );
1080     }
1081 }
1082
1083 void Interface::TogglePlayButton( int i_playing_status )
1084 {
1085     if( i_playing_status == i_old_playing_status )
1086         return;
1087
1088     wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
1089         GetToolBar()->GetToolClientData( PlayStream_Event );
1090     if( !p_tool ) return;
1091
1092     if( i_playing_status == PLAYING_S )
1093     {
1094         p_tool->SetNormalBitmap( wxBitmap( pause_xpm ) );
1095         p_tool->SetLabel( wxU(_("Pause")) );
1096         p_tool->SetShortHelp( wxU(_(HELP_PAUSE)) );
1097     }
1098     else
1099     {
1100         p_tool->SetNormalBitmap( wxBitmap( play_xpm ) );
1101         p_tool->SetLabel( wxU(_("Play")) );
1102         p_tool->SetShortHelp( wxU(_(HELP_PLAY)) );
1103     }
1104
1105     GetToolBar()->Realize();
1106
1107     i_old_playing_status = i_playing_status;
1108 }
1109
1110 void Interface::OnDiscMenu( wxCommandEvent& WXUNUSED(event) )
1111 {
1112     input_thread_t *p_input =
1113         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1114                                            FIND_ANYWHERE );
1115     if( p_input )
1116     {
1117         vlc_value_t val; val.i_int = 2;
1118
1119         var_Set( p_input, "title  0", val);
1120         vlc_object_release( p_input );
1121     }
1122 }
1123
1124 void Interface::OnDiscPrev( wxCommandEvent& WXUNUSED(event) )
1125 {
1126     input_thread_t *p_input =
1127         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1128                                            FIND_ANYWHERE );
1129     if( p_input )
1130     {
1131         int i_type = var_Type( p_input, "prev-chapter" );
1132         vlc_value_t val; val.b_bool = VLC_TRUE;
1133
1134         var_Set( p_input, ( i_type & VLC_VAR_TYPE ) != 0 ?
1135                  "prev-chapter" : "prev-title", val );
1136
1137         vlc_object_release( p_input );
1138     }
1139 }
1140
1141 void Interface::OnDiscNext( wxCommandEvent& WXUNUSED(event) )
1142 {
1143     input_thread_t *p_input =
1144         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1145                                            FIND_ANYWHERE );
1146     if( p_input )
1147     {
1148         int i_type = var_Type( p_input, "next-chapter" );
1149         vlc_value_t val; val.b_bool = VLC_TRUE;
1150
1151         var_Set( p_input, ( i_type & VLC_VAR_TYPE ) != 0 ?
1152                  "next-chapter" : "next-title", val );
1153
1154         vlc_object_release( p_input );
1155     }
1156 }
1157
1158 #if wxUSE_DRAG_AND_DROP
1159 /*****************************************************************************
1160  * Definition of DragAndDrop class.
1161  *****************************************************************************/
1162 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
1163 {
1164     p_intf = _p_intf;
1165     b_enqueue = _b_enqueue;
1166 }
1167
1168 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1169                                const wxArrayString& filenames )
1170 {
1171     /* Add dropped files to the playlist */
1172
1173     playlist_t *p_playlist =
1174         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1175                                        FIND_ANYWHERE );
1176     if( p_playlist == NULL )
1177     {
1178         return FALSE;
1179     }
1180
1181     for( size_t i = 0; i < filenames.GetCount(); i++ )
1182         playlist_Add( p_playlist, (const char *)filenames[i].mb_str(),
1183                       (const char *)filenames[i].mb_str(),
1184                       PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
1185                       PLAYLIST_END );
1186
1187     vlc_object_release( p_playlist );
1188
1189     return TRUE;
1190 }
1191 #endif
1192
1193 /*****************************************************************************
1194  * Definition of VolCtrl class.
1195  *****************************************************************************/
1196 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1197                       wxPoint point, wxSize size )
1198   : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
1199 {
1200     p_intf = _p_intf;
1201     UpdateVolume();
1202 }
1203
1204 void wxVolCtrl::OnChange( wxMouseEvent& event )
1205 {
1206     if( !event.LeftDown() && !event.LeftIsDown() ) return;
1207
1208     int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
1209     aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1210     UpdateVolume();
1211 }
1212
1213 void wxVolCtrl::UpdateVolume()
1214 {
1215     audio_volume_t i_volume;
1216     aout_VolumeGet( p_intf, &i_volume );
1217
1218     int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
1219     if( i_gauge_volume == GetValue() ) return;
1220
1221     SetValue( i_gauge_volume );
1222     SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
1223                 i_gauge_volume / 2 ) );
1224 }