]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/interface.cpp
Reduce the global verbosity
[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     }
635
636     delete [] p_entries;
637 }
638
639 /*****************************************************************************
640  * Event Handlers.
641  *****************************************************************************/
642
643 void Interface::OnMenuOpen(wxMenuEvent& event)
644 {
645 #if defined( __WXMSW__ )
646 #   define GetEventObject GetMenu
647 #endif
648
649     if( event.GetEventObject() == p_settings_menu )
650     {
651         p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );
652
653         /* Add static items */
654         p_settings_menu->AppendCheckItem( Extended_Event,
655             wxU(_("&Extended GUI") ) );
656         if( b_extra ) p_settings_menu->Check( Extended_Event, TRUE );
657 #if 0
658         p_settings_menu->AppendCheckItem( Undock_Event,
659             wxU(_("&Undock Ext. GUI") ) );
660         if( b_undock ) p_settings_menu->Check( Undock_Event, TRUE );
661 #endif
662         p_settings_menu->Append( Bookmarks_Event, wxU(_("&Bookmarks...") ) );
663         p_settings_menu->Append( Prefs_Event, wxU(_("&Preferences...")) );
664     }
665
666     else if( event.GetEventObject() == p_audio_menu )
667     {
668         p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
669     }
670
671     else if( event.GetEventObject() == p_video_menu )
672     {
673         p_video_menu = VideoMenu( p_intf, this, p_video_menu );
674     }
675
676     else if( event.GetEventObject() == p_navig_menu )
677     {
678         p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
679     }
680
681 #if defined( __WXMSW__ )
682 #   undef GetEventObject
683 #endif
684 }
685
686 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
687 void Interface::OnContextMenu2(wxContextMenuEvent& event)
688 {
689     /* Only show the context menu for the main interface */
690     if( GetId() != event.GetId() )
691     {
692         event.Skip();
693         return;
694     }
695
696     if( p_intf->p_sys->pf_show_dialog )
697         p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
698 }
699 #endif
700 void Interface::OnContextMenu(wxMouseEvent& event)
701 {
702     if( p_intf->p_sys->pf_show_dialog )
703         p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
704 }
705
706 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
707 {
708     /* TRUE is to force the frame to close. */
709     Close(TRUE);
710 }
711
712 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
713 {
714     wxString msg;
715     msg.Printf( wxString(wxT("VLC media player " PACKAGE_VERSION)) +
716         wxU(_(" (wxWindows interface)\n\n")) +
717         wxU(_("(c) 1996-2005 - the VideoLAN Team\n\n")) +
718         wxU( vlc_wraptext(INTF_ABOUT_MSG,WRAPCOUNT,ISUTF8) ) + wxT("\n\n") +
719         wxU(_("The VideoLAN team <videolan@videolan.org>\n"
720               "http://www.videolan.org/\n\n")) );
721
722     wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
723                   wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
724 }
725
726 void Interface::OnShowDialog( wxCommandEvent& event )
727 {
728     if( p_intf->p_sys->pf_show_dialog )
729     {
730         int i_id;
731
732         switch( event.GetId() )
733         {
734         case OpenFileSimple_Event:
735             i_id = INTF_DIALOG_FILE_SIMPLE;
736             break;
737         case OpenAdv_Event:
738             i_id = INTF_DIALOG_FILE;
739         case OpenFile_Event:
740             i_id = INTF_DIALOG_FILE;
741             break;
742         case OpenDisc_Event:
743             i_id = INTF_DIALOG_DISC;
744             break;
745         case OpenNet_Event:
746             i_id = INTF_DIALOG_NET;
747             break;
748         case OpenCapture_Event:
749             i_id = INTF_DIALOG_CAPTURE;
750             break;
751         case OpenSat_Event:
752             i_id = INTF_DIALOG_SAT;
753             break;
754         case Playlist_Event:
755             i_id = INTF_DIALOG_PLAYLIST;
756             break;
757         case Logs_Event:
758             i_id = INTF_DIALOG_MESSAGES;
759             break;
760         case FileInfo_Event:
761             i_id = INTF_DIALOG_FILEINFO;
762             break;
763         case Prefs_Event:
764             i_id = INTF_DIALOG_PREFS;
765             break;
766         case Wizard_Event:
767             i_id = INTF_DIALOG_WIZARD;
768             break;
769         case Bookmarks_Event:
770             i_id = INTF_DIALOG_BOOKMARKS;
771             break;
772         default:
773             i_id = INTF_DIALOG_FILE;
774             break;
775         }
776
777         p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
778     }
779 }
780
781 void Interface::OnExtended(wxCommandEvent& event)
782 {
783     b_extra = (b_extra == VLC_TRUE ? VLC_FALSE : VLC_TRUE );
784
785     if( b_extra == VLC_FALSE )
786     {
787         extra_frame->Hide();
788         frame_sizer->Hide( extra_frame );
789     }
790     else
791     {
792         extra_frame->Show();
793         frame_sizer->Show( extra_frame );
794     }
795     frame_sizer->Layout();
796     frame_sizer->Fit(this);
797 }
798
799 #if 0
800         if( b_undock == VLC_TRUE )
801         {
802                 fprintf(stderr,"Deleting window\n");
803             if( extra_window )
804             {
805                 delete extra_window;
806                 extra_window = NULL;
807             }
808         }
809         else
810         {
811             extra_frame->Hide();
812             frame_sizer->Hide( extra_frame );
813             frame_sizer->Layout();
814             frame_sizer->Fit(this);
815         }
816     }
817     else
818     {
819         if( b_undock == VLC_TRUE )
820         {
821                 fprintf(stderr,"Creating window\n");
822             extra_frame->Hide();
823             frame_sizer->Hide( extra_frame );
824             frame_sizer->Detach( extra_frame );
825             frame_sizer->Layout();
826             frame_sizer->Fit(this);
827             extra_window = new ExtraWindow( p_intf, this, extra_frame );
828         }
829         else
830         {
831                 fprintf(stderr,"Deleting window\n");
832             if( extra_window )
833             {
834                 delete extra_window;
835             }
836             extra_frame->Show();
837             frame_sizer->Show( extra_frame );
838             frame_sizer->Layout();
839             frame_sizer->Fit(this);
840         }
841     }
842 }
843
844 void Interface::OnUndock(wxCommandEvent& event)
845 {
846     b_undock = (b_undock == VLC_TRUE ? VLC_FALSE : VLC_TRUE );
847
848     if( b_extra == VLC_TRUE )
849     {
850         if( b_undock == VLC_FALSE )
851         {
852                 fprintf(stderr,"Deleting window\n");
853             if( extra_window )
854             {
855                 delete extra_window;
856                 extra_window = NULL;
857             }
858             extra_frame->Show();
859             frame_sizer->Show( extra_frame );
860             frame_sizer->Layout();
861             frame_sizer->Fit(this);
862         }
863         else
864         {
865                 fprintf(stderr,"Creating window\n");
866             extra_frame->Hide();
867             frame_sizer->Hide( extra_frame );
868             frame_sizer->Detach( extra_frame );
869             frame_sizer->Layout();
870             frame_sizer->Fit(this);
871             extra_window = new ExtraWindow( p_intf, this, extra_frame );
872         }
873     }
874 }
875 #endif
876
877 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
878 {
879     wxCommandEvent dummy;
880     playlist_t *p_playlist =
881         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
882                                        FIND_ANYWHERE );
883     if( p_playlist == NULL ) return;
884
885     if( p_playlist->i_size && p_playlist->i_enabled )
886     {
887         vlc_value_t state;
888
889         input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
890                                                        VLC_OBJECT_INPUT,
891                                                        FIND_ANYWHERE );
892         if( p_input == NULL )
893         {
894             /* No stream was playing, start one */
895             playlist_Play( p_playlist );
896             TogglePlayButton( PLAYING_S );
897             vlc_object_release( p_playlist );
898             return;
899         }
900
901         var_Get( p_input, "state", &state );
902
903         if( state.i_int != PAUSE_S )
904         {
905             /* A stream is being played, pause it */
906             state.i_int = PAUSE_S;
907         }
908         else
909         {
910             /* Stream is paused, resume it */
911             state.i_int = PLAYING_S;
912         }
913         var_Set( p_input, "state", state );
914
915         TogglePlayButton( state.i_int );
916         vlc_object_release( p_input );
917         vlc_object_release( p_playlist );
918     }
919     else
920     {
921         /* If the playlist is empty, open a file requester instead */
922         vlc_object_release( p_playlist );
923         OnShowDialog( dummy );
924     }
925 }
926
927 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
928 {
929     playlist_t * p_playlist =
930         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
931                                        FIND_ANYWHERE );
932     if( p_playlist == NULL )
933     {
934         return;
935     }
936
937     playlist_Stop( p_playlist );
938     TogglePlayButton( PAUSE_S );
939     vlc_object_release( p_playlist );
940 }
941
942 void Interface::OnSliderUpdate( wxScrollEvent& event )
943 {
944     vlc_mutex_lock( &p_intf->change_lock );
945
946 #ifdef WIN32
947     if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
948         || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
949     {
950 #endif
951         if( p_intf->p_sys->i_slider_pos != event.GetPosition()
952             && p_intf->p_sys->p_input )
953         {
954             vlc_value_t pos;
955             pos.f_float = (float)event.GetPosition() / (float)SLIDER_MAX_POS;
956
957             var_Set( p_intf->p_sys->p_input, "position", pos );
958         }
959
960 #ifdef WIN32
961         p_intf->p_sys->b_slider_free = VLC_TRUE;
962     }
963     else
964     {
965         p_intf->p_sys->b_slider_free = VLC_FALSE;
966
967         if( p_intf->p_sys->p_input )
968         {
969             /* Update stream date */
970             char psz_time[ MSTRTIME_MAX_SIZE ], psz_total[ MSTRTIME_MAX_SIZE ];
971             mtime_t i_seconds;
972
973             i_seconds = var_GetTime( p_intf->p_sys->p_input, "length" ) /
974                         I64C(1000000 );
975             secstotimestr( psz_total, i_seconds );
976
977             i_seconds = var_GetTime( p_intf->p_sys->p_input, "time" ) /
978                         I64C(1000000 );
979             secstotimestr( psz_time, i_seconds );
980
981             statusbar->SetStatusText( wxU(psz_time) + wxString(wxT(" / ") ) +
982                                       wxU(psz_total), 0 );
983         }
984     }
985 #endif
986
987 #undef WIN32
988     vlc_mutex_unlock( &p_intf->change_lock );
989 }
990
991 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
992 {
993     playlist_t * p_playlist =
994         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
995                                        FIND_ANYWHERE );
996     if( p_playlist == NULL )
997     {
998         return;
999     }
1000
1001     /* FIXME --fenrir */
1002 #if 0
1003     if( p_playlist->p_input != NULL )
1004     {
1005         vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1006         if( p_playlist->p_input->stream.p_selected_area->i_id > 1 )
1007         {
1008             vlc_value_t val; val.b_bool = VLC_TRUE;
1009             vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1010             var_Set( p_playlist->p_input, "prev-title", val );
1011         } else
1012             vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1013     }
1014     vlc_mutex_unlock( &p_playlist->object_lock );
1015 #endif
1016
1017     playlist_Prev( p_playlist );
1018     vlc_object_release( p_playlist );
1019 }
1020
1021 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1022 {
1023     playlist_t * p_playlist =
1024         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1025                                        FIND_ANYWHERE );
1026     if( p_playlist == NULL )
1027     {
1028         return;
1029     }
1030
1031     /* FIXME --fenrir */
1032 #if 0
1033     var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
1034     vlc_mutex_lock( &p_playlist->object_lock );
1035     if( p_playlist->p_input != NULL )
1036     {
1037         vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1038         if( p_playlist->p_input->stream.i_area_nb > 1 &&
1039             p_playlist->p_input->stream.p_selected_area->i_id <
1040               p_playlist->p_input->stream.i_area_nb - 1 )
1041         {
1042             vlc_value_t val; val.b_bool = VLC_TRUE;
1043             vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1044             var_Set( p_playlist->p_input, "next-title", val );
1045         } else
1046             vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1047     }
1048     vlc_mutex_unlock( &p_playlist->object_lock );
1049 #endif
1050     playlist_Next( p_playlist );
1051     vlc_object_release( p_playlist );
1052 }
1053
1054 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1055 {
1056     input_thread_t *p_input =
1057         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1058                                            FIND_ANYWHERE );
1059     if( p_input )
1060     {
1061         vlc_value_t val; val.b_bool = VLC_TRUE;
1062
1063         var_Set( p_input, "rate-slower", val );
1064         vlc_object_release( p_input );
1065     }
1066 }
1067
1068 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1069 {
1070     input_thread_t *p_input =
1071         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1072                                            FIND_ANYWHERE );
1073     if( p_input )
1074     {
1075         vlc_value_t val; val.b_bool = VLC_TRUE;
1076
1077         var_Set( p_input, "rate-faster", val );
1078         vlc_object_release( p_input );
1079     }
1080 }
1081
1082 void Interface::TogglePlayButton( int i_playing_status )
1083 {
1084     if( i_playing_status == i_old_playing_status )
1085         return;
1086
1087     wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
1088         GetToolBar()->GetToolClientData( PlayStream_Event );
1089     if( !p_tool ) return;
1090
1091     if( i_playing_status == PLAYING_S )
1092     {
1093         p_tool->SetNormalBitmap( wxBitmap( pause_xpm ) );
1094         p_tool->SetLabel( wxU(_("Pause")) );
1095         p_tool->SetShortHelp( wxU(_(HELP_PAUSE)) );
1096     }
1097     else
1098     {
1099         p_tool->SetNormalBitmap( wxBitmap( play_xpm ) );
1100         p_tool->SetLabel( wxU(_("Play")) );
1101         p_tool->SetShortHelp( wxU(_(HELP_PLAY)) );
1102     }
1103
1104     GetToolBar()->Realize();
1105
1106     i_old_playing_status = i_playing_status;
1107 }
1108
1109 void Interface::OnDiscMenu( wxCommandEvent& WXUNUSED(event) )
1110 {
1111     input_thread_t *p_input =
1112         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1113                                            FIND_ANYWHERE );
1114     if( p_input )
1115     {
1116         vlc_value_t val; val.i_int = 2;
1117
1118         var_Set( p_input, "title  0", val);
1119         vlc_object_release( p_input );
1120     }
1121 }
1122
1123 void Interface::OnDiscPrev( wxCommandEvent& WXUNUSED(event) )
1124 {
1125     input_thread_t *p_input =
1126         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1127                                            FIND_ANYWHERE );
1128     if( p_input )
1129     {
1130         int i_type = var_Type( p_input, "prev-chapter" );
1131         vlc_value_t val; val.b_bool = VLC_TRUE;
1132
1133         var_Set( p_input, ( i_type & VLC_VAR_TYPE ) != 0 ?
1134                  "prev-chapter" : "prev-title", val );
1135
1136         vlc_object_release( p_input );
1137     }
1138 }
1139
1140 void Interface::OnDiscNext( wxCommandEvent& WXUNUSED(event) )
1141 {
1142     input_thread_t *p_input =
1143         (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1144                                            FIND_ANYWHERE );
1145     if( p_input )
1146     {
1147         int i_type = var_Type( p_input, "next-chapter" );
1148         vlc_value_t val; val.b_bool = VLC_TRUE;
1149
1150         var_Set( p_input, ( i_type & VLC_VAR_TYPE ) != 0 ?
1151                  "next-chapter" : "next-title", val );
1152
1153         vlc_object_release( p_input );
1154     }
1155 }
1156
1157 #if wxUSE_DRAG_AND_DROP
1158 /*****************************************************************************
1159  * Definition of DragAndDrop class.
1160  *****************************************************************************/
1161 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
1162 {
1163     p_intf = _p_intf;
1164     b_enqueue = _b_enqueue;
1165 }
1166
1167 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1168                                const wxArrayString& filenames )
1169 {
1170     /* Add dropped files to the playlist */
1171
1172     playlist_t *p_playlist =
1173         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1174                                        FIND_ANYWHERE );
1175     if( p_playlist == NULL )
1176     {
1177         return FALSE;
1178     }
1179
1180     for( size_t i = 0; i < filenames.GetCount(); i++ )
1181         playlist_Add( p_playlist, (const char *)filenames[i].mb_str(),
1182                       (const char *)filenames[i].mb_str(),
1183                       PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
1184                       PLAYLIST_END );
1185
1186     vlc_object_release( p_playlist );
1187
1188     return TRUE;
1189 }
1190 #endif
1191
1192 /*****************************************************************************
1193  * Definition of VolCtrl class.
1194  *****************************************************************************/
1195 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1196                       wxPoint point, wxSize size )
1197   : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
1198 {
1199     p_intf = _p_intf;
1200     UpdateVolume();
1201 }
1202
1203 void wxVolCtrl::OnChange( wxMouseEvent& event )
1204 {
1205     if( !event.LeftDown() && !event.LeftIsDown() ) return;
1206
1207     int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
1208     aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1209     UpdateVolume();
1210 }
1211
1212 void wxVolCtrl::UpdateVolume()
1213 {
1214     audio_volume_t i_volume;
1215     aout_VolumeGet( p_intf, &i_volume );
1216
1217     int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
1218     if( i_gauge_volume == GetValue() ) return;
1219
1220     SetValue( i_gauge_volume );
1221     SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
1222                 i_gauge_volume / 2 ) );
1223 }