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