1 /*****************************************************************************
2 * interface.cpp : wxWidgets plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2005 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@videolan.org>
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
30 #include <vlc/input.h>
33 #include "wxwidgets.h"
35 /* include the toolbar graphics */
36 #include "bitmaps/play.xpm"
37 #include "bitmaps/pause.xpm"
38 #include "bitmaps/stop.xpm"
39 #include "bitmaps/prev.xpm"
40 #include "bitmaps/next.xpm"
41 #include "bitmaps/eject.xpm"
42 #include "bitmaps/slow.xpm"
43 #include "bitmaps/fast.xpm"
44 #include "bitmaps/playlist.xpm"
45 #include "bitmaps/speaker.xpm"
46 #include "bitmaps/speaker_mute.xpm"
48 #define TOOLBAR_BMP_WIDTH 16
49 #define TOOLBAR_BMP_HEIGHT 16
51 /* include the icon graphic */
52 #include "../../../share/vlc32x32.xpm"
53 /* include a small icon graphic for the systray icon */
54 #ifdef wxHAS_TASK_BAR_ICON
55 #include "../../../share/vlc16x16.xpm"
58 /*****************************************************************************
59 * Local class declarations.
60 *****************************************************************************/
61 class wxMenuExt: public wxMenu
65 wxMenuExt( wxMenu* parentMenu, int id, const wxString& text,
66 const wxString& helpString, wxItemKind kind,
67 char *_psz_var, int _i_object_id, vlc_value_t _val,
70 virtual ~wxMenuExt() {};
82 class VLCVolCtrl : public wxControl
85 VLCVolCtrl( intf_thread_t *p_intf, wxWindow *p_parent );
86 virtual ~VLCVolCtrl() {};
88 virtual void OnPaint( wxPaintEvent &event );
89 void OnChange( wxMouseEvent& event );
98 intf_thread_t *p_intf;
101 BEGIN_EVENT_TABLE(VLCVolCtrl, wxControl)
102 EVT_PAINT(VLCVolCtrl::OnPaint)
105 EVT_LEFT_UP(VLCVolCtrl::OnChange)
108 /*****************************************************************************
110 *****************************************************************************/
112 DEFINE_LOCAL_EVENT_TYPE( wxEVT_INTF );
114 /* IDs for the controls and the menu commands */
118 MenuDummy_Event = wxID_HIGHEST + 1000,
119 Exit_Event = wxID_HIGHEST,
120 OpenFileSimple_Event,
155 /* it is important for the id corresponding to the "About" command to have
156 * this standard value as otherwise it won't be handled properly under Mac
157 * (where it is special and put into the "Apple" menu) */
158 About_Event = wxID_ABOUT,
164 BEGIN_EVENT_TABLE(Interface, wxFrame)
166 EVT_MENU(Exit_Event, Interface::OnExit)
167 EVT_MENU(About_Event, Interface::OnAbout)
168 EVT_MENU(UpdateVLC_Event, Interface::OnShowDialog)
170 EVT_MENU(Playlist_Event, Interface::OnShowDialog)
171 EVT_MENU(Logs_Event, Interface::OnShowDialog)
172 EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
173 EVT_MENU(Prefs_Event, Interface::OnShowDialog)
175 EVT_MENU_OPEN(Interface::OnMenuOpen)
177 EVT_MENU( Extended_Event, Interface::OnExtended )
178 // EVT_MENU( Undock_Event, Interface::OnUndock )
180 EVT_MENU( Bookmarks_Event, Interface::OnShowDialog)
182 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
183 EVT_CONTEXT_MENU(Interface::OnContextMenu2)
185 EVT_RIGHT_UP(Interface::OnContextMenu)
188 EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
189 EVT_MENU(OpenAdv_Event, Interface::OnShowDialog)
190 EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
191 EVT_MENU(OpenDir_Event, Interface::OnShowDialog)
192 EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
193 EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
194 EVT_MENU(OpenCapture_Event, Interface::OnShowDialog)
195 EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
196 EVT_MENU(Wizard_Event, Interface::OnShowDialog)
197 EVT_MENU(StopStream_Event, Interface::OnStopStream)
198 EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
199 EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
200 EVT_MENU(NextStream_Event, Interface::OnNextStream)
201 EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
202 EVT_MENU(FastStream_Event, Interface::OnFastStream)
204 /* Disc Buttons events */
205 EVT_BUTTON(DiscMenu_Event, Interface::OnDiscMenu)
206 EVT_BUTTON(DiscPrev_Event, Interface::OnDiscPrev)
207 EVT_BUTTON(DiscNext_Event, Interface::OnDiscNext)
210 EVT_COMMAND_SCROLL(SliderScroll_Event, Interface::OnSliderUpdate)
213 EVT_COMMAND(0, wxEVT_INTF, Interface::OnControlEvent)
214 EVT_COMMAND(1, wxEVT_INTF, Interface::OnControlEvent)
216 EVT_TIMER(ID_CONTROLS_TIMER, Interface::OnControlsTimer)
217 EVT_TIMER(ID_SLIDER_TIMER, Interface::OnSliderTimer)
220 /*****************************************************************************
222 *****************************************************************************/
223 Interface::Interface( intf_thread_t *_p_intf, long style ):
224 wxFrame( NULL, -1, wxT("VLC media player"),
225 wxDefaultPosition, wxSize(700,100), style )
227 /* Initializations */
229 i_old_playing_status = PAUSE_S;
231 // b_undock = VLC_FALSE;
236 /* Give our interface a nice little icon */
237 SetIcon( wxIcon( vlc_xpm ) );
239 /* Create a sizer for the main frame */
240 frame_sizer = new wxBoxSizer( wxVERTICAL );
241 SetSizer( frame_sizer );
243 /* Create a dummy widget that can get the keyboard focus */
244 wxWindow *p_dummy = new wxWindow( this, 0, wxDefaultPosition,
246 #if defined(__WXGTK20__) && wxCHECK_VERSION(2,5,6)
247 /* As ugly as your butt! Please remove when wxWidgets 2.6 fixed their
248 * Accelerators bug. */
249 p_dummy->m_imData = 0;
253 frame_sizer->Add( p_dummy, 0, 0 );
255 #ifdef wxHAS_TASK_BAR_ICON
256 /* Systray integration */
258 if ( config_GetInt( p_intf, "wx-systray" ) )
260 p_systray = new Systray(this, p_intf);
261 p_systray->SetIcon( wxIcon( vlc16x16_xpm ), wxT("VLC media player") );
262 if ( (! p_systray->IsOk()) || (! p_systray->IsIconInstalled()) )
264 msg_Warn(p_intf, "Cannot set systray icon, weird things may happen");
269 /* Creation of the menu bar */
272 /* Creation of the tool bar */
275 /* Create the extra panel */
276 extra_frame = new ExtraPanel( p_intf, this );
277 frame_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
278 frame_sizer->Hide( extra_frame );
280 /* Creation of the status bar
281 * Helptext for menu items and toolbar tools will automatically get
283 int i_status_width[3] = {-6, -2, -9};
284 statusbar = CreateStatusBar( 3 ); /* 2 fields */
285 statusbar->SetStatusWidths( 3, i_status_width );
286 statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
290 if( config_GetInt( p_intf, "wx-embed" ) )
292 video_window = CreateVideoWindow( p_intf, this );
293 frame_sizer->Add( p_intf->p_sys->p_video_sizer, 1, wxEXPAND, 0 );
296 /* Creation of the slider sub-window */
298 frame_sizer->Add( slider_frame, 0, wxEXPAND , 0 );
299 frame_sizer->Hide( slider_frame );
301 /* Make sure we've got the right background colour */
302 SetBackgroundColour( slider_frame->GetBackgroundColour() );
304 /* Layout everything */
305 frame_sizer->Layout();
306 frame_sizer->Fit(this);
308 #if wxUSE_DRAG_AND_DROP
309 /* Associate drop targets with the main interface */
310 SetDropTarget( new DragAndDrop( p_intf ) );
315 m_controls_timer.SetOwner(this, ID_CONTROLS_TIMER);
316 m_slider_timer.SetOwner(this, ID_SLIDER_TIMER);
319 timer = new Timer( p_intf, this );
322 WindowSettings *ws = p_intf->p_sys->p_window_settings;
327 ws->SetScreen( wxSystemSettings::GetMetric( wxSYS_SCREEN_X ),
328 wxSystemSettings::GetMetric( wxSYS_SCREEN_Y ) );
330 if( ws->GetSettings( WindowSettings::ID_MAIN, b_shown, p, s ) )
334 Interface::~Interface()
336 WindowSettings *ws = p_intf->p_sys->p_window_settings;
340 ws->SetSettings( WindowSettings::ID_MAIN, true,
341 GetPosition(), GetSize() );
344 if( video_window ) delete video_window;
346 #ifdef wxHAS_TASK_BAR_ICON
347 if( p_systray ) delete p_systray;
350 if( p_intf->p_sys->p_wxwindow ) delete p_intf->p_sys->p_wxwindow;
356 void Interface::Init()
362 void Interface::Update()
365 ((VLCVolCtrl *)volctrl)->UpdateVolume();
368 void Interface::OnControlEvent( wxCommandEvent& event )
370 switch( event.GetId() )
374 if( p_intf->p_sys->b_video_autosize )
376 frame_sizer->Layout();
377 frame_sizer->Fit(this);
383 long i_style = GetWindowStyle();
384 if( event.GetInt() ) i_style |= wxSTAY_ON_TOP;
385 else i_style &= ~wxSTAY_ON_TOP;
386 SetWindowStyle( i_style );
391 /*****************************************************************************
393 *****************************************************************************/
394 void Interface::CreateOurMenuBar()
396 int minimal = config_GetInt( p_intf, "wx-minimal" );
398 /* Create the "File" menu */
399 wxMenu *file_menu = new wxMenu;
403 file_menu->Append( OpenFileSimple_Event,
404 wxU(_("Quick &Open File...\tCtrl-O")) );
406 file_menu->AppendSeparator();
407 file_menu->Append( OpenFile_Event, wxU(_("Open &File...\tCtrl-F")) );
408 file_menu->Append( OpenDir_Event, wxU(_("Open Dir&ectory...\tCtrl-E")) );
409 file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...\tCtrl-D")) );
410 file_menu->Append( OpenNet_Event,
411 wxU(_("Open &Network Stream...\tCtrl-N")) );
412 file_menu->Append( OpenCapture_Event,
413 wxU(_("Open C&apture Device...\tCtrl-A")) );
415 file_menu->AppendSeparator();
416 file_menu->Append( Wizard_Event, wxU(_("&Wizard...\tCtrl-W")) );
417 file_menu->AppendSeparator();
419 file_menu->Append( Exit_Event, wxU(_("E&xit\tCtrl-X")) );
421 /* Create the "View" menu */
422 wxMenu *view_menu = new wxMenu;
425 view_menu->Append( Playlist_Event, wxU(_("&Playlist...\tCtrl-P")) );
427 view_menu->Append( Logs_Event, wxU(_("&Messages...\tCtrl-M")) );
428 view_menu->Append( FileInfo_Event,
429 wxU(_("Stream and Media &info...\tCtrl-I")) );
431 /* Create the "Auto-generated" menus */
432 p_settings_menu = SettingsMenu( p_intf, this );
433 p_audio_menu = AudioMenu( p_intf, this );
434 p_video_menu = VideoMenu( p_intf, this );
435 p_navig_menu = NavigMenu( p_intf, this );
437 /* Create the "Help" menu */
438 wxMenu *help_menu = new wxMenu;
439 help_menu->Append( About_Event, wxU(_("About VLC media player")) );
440 help_menu->AppendSeparator();
441 help_menu->Append( UpdateVLC_Event, wxU(_("Check for updates ...")) );
443 /* Append the freshly created menus to the menu bar... */
444 wxMenuBar *menubar = new wxMenuBar();
445 menubar->Append( file_menu, wxU(_("&File")) );
446 menubar->Append( view_menu, wxU(_("&View")) );
447 menubar->Append( p_settings_menu, wxU(_("&Settings")) );
448 menubar->Append( p_audio_menu, wxU(_("&Audio")) );
449 menubar->Append( p_video_menu, wxU(_("&Video")) );
450 menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
451 menubar->Append( help_menu, wxU(_("&Help")) );
453 /* Attach the menu bar to the frame */
454 SetMenuBar( menubar );
456 /* Find out size of menu bar */
458 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
460 int i_width, i_height;
461 menubar->GetTextExtent( menubar->GetLabelTop(i), &i_width, &i_height );
463 #if defined(__WXGTK__)
464 22 /* approximate margin */;
466 #if (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 5) && (wxRELEASE_NUMBER < 3)
467 4 /* approximate margin */;
469 18 /* approximate margin */;
473 frame_sizer->SetMinSize( i_size, -1 );
475 /* Intercept all menu events in our custom event handler */
476 PushEventHandler( new MenuEvtHandler( p_intf, this ) );
478 #if wxUSE_DRAG_AND_DROP
479 /* Associate drop targets with the menubar */
480 menubar->SetDropTarget( new DragAndDrop( p_intf ) );
484 void Interface::CreateOurToolBar()
486 #define HELP_OPEN N_("Open")
487 #define HELP_STOP N_("Stop")
488 #define HELP_PLAY N_("Play")
489 #define HELP_PAUSE N_("Pause")
490 #define HELP_PLO N_("Playlist")
491 #define HELP_PLP N_("Previous playlist item")
492 #define HELP_PLN N_("Next playlist item")
493 #define HELP_SLOW N_("Play slower")
494 #define HELP_FAST N_("Play faster")
496 int minimal = config_GetInt( p_intf, "wx-minimal" );
498 wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
499 * version because we don't include wx.rc */
502 CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
504 toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
508 toolbar->AddTool( OpenFile_Event, wxT(""),
509 wxBitmap( eject_xpm ), wxU(_(HELP_OPEN)) );
510 toolbar->AddSeparator();
513 wxToolBarToolBase *p_tool = toolbar->AddTool( PlayStream_Event, wxT(""),
514 wxBitmap( play_xpm ), wxU(_(HELP_PLAY)), wxITEM_CHECK );
515 p_tool->SetClientData( p_tool );
519 toolbar->AddTool( StopStream_Event, wxT(""), wxBitmap( stop_xpm ),
521 toolbar->AddSeparator();
523 toolbar->AddTool( PrevStream_Event, wxT(""),
524 wxBitmap( prev_xpm ), wxU(_(HELP_PLP)) );
525 toolbar->AddTool( SlowStream_Event, wxT(""),
526 wxBitmap( slow_xpm ), wxU(_(HELP_SLOW)) );
527 toolbar->AddTool( FastStream_Event, wxT(""),
528 wxBitmap( fast_xpm ), wxU(_(HELP_FAST)) );
529 toolbar->AddTool( NextStream_Event, wxT(""), wxBitmap( next_xpm ),
531 toolbar->AddSeparator();
532 toolbar->AddTool( Playlist_Event, wxT(""), wxBitmap( playlist_xpm ),
536 wxControl *p_dummy_ctrl =
537 new wxControl( toolbar, -1, wxDefaultPosition,
538 wxSize(35, 16 ), wxBORDER_NONE );
540 toolbar->AddControl( p_dummy_ctrl );
542 volctrl = new VLCVolCtrl( p_intf, toolbar );
543 toolbar->AddControl( volctrl );
547 #if wxUSE_DRAG_AND_DROP
548 /* Associate drop targets with the toolbar */
549 toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
553 void Interface::CreateOurSlider()
555 /* Create a new frame and sizer containing the slider */
556 slider_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
557 slider_frame->SetAutoLayout( TRUE );
558 slider_sizer = new wxBoxSizer( wxHORIZONTAL );
559 //slider_sizer->SetMinSize( -1, 50 );
562 slider = new wxSlider( slider_frame, SliderScroll_Event, 0, 0,
563 SLIDER_MAX_POS, wxDefaultPosition, wxDefaultSize );
565 /* Add Disc Buttons */
566 disc_frame = new wxPanel( slider_frame, -1, wxDefaultPosition,
568 disc_frame->SetAutoLayout( TRUE );
569 disc_sizer = new wxBoxSizer( wxHORIZONTAL );
571 disc_menu_button = new wxBitmapButton( disc_frame, DiscMenu_Event,
572 wxBitmap( playlist_xpm ) );
573 disc_prev_button = new wxBitmapButton( disc_frame, DiscPrev_Event,
574 wxBitmap( prev_xpm ) );
575 disc_next_button = new wxBitmapButton( disc_frame, DiscNext_Event,
576 wxBitmap( next_xpm ) );
578 disc_sizer->Add( disc_menu_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
579 disc_sizer->Add( disc_prev_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
580 disc_sizer->Add( disc_next_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
582 disc_frame->SetSizer( disc_sizer );
583 disc_sizer->Layout();
585 /* Add everything to the frame */
586 slider_sizer->Add( slider, 1, wxEXPAND | wxALL, 5 );
587 slider_sizer->Add( disc_frame, 0, wxALL, 2 );
588 slider_frame->SetSizer( slider_sizer );
591 slider_sizer->Hide( disc_frame );
593 slider_sizer->Layout();
594 slider_sizer->Fit( slider_frame );
596 /* Hide the slider by default */
597 slider_frame->Hide();
600 static int ConvertHotkeyModifiers( int i_hotkey )
602 int i_accel_flags = 0;
603 if( i_hotkey & KEY_MODIFIER_ALT ) i_accel_flags |= wxACCEL_ALT;
604 if( i_hotkey & KEY_MODIFIER_CTRL ) i_accel_flags |= wxACCEL_CTRL;
605 if( i_hotkey & KEY_MODIFIER_SHIFT ) i_accel_flags |= wxACCEL_SHIFT;
606 if( !i_accel_flags ) i_accel_flags = wxACCEL_NORMAL;
607 return i_accel_flags;
610 static int ConvertHotkey( int i_hotkey )
612 int i_key = i_hotkey & ~KEY_MODIFIER;
613 if( i_key & KEY_ASCII ) return i_key & KEY_ASCII;
614 else if( i_key & KEY_SPECIAL )
618 case KEY_LEFT: return WXK_LEFT;
619 case KEY_RIGHT: return WXK_RIGHT;
620 case KEY_UP: return WXK_UP;
621 case KEY_DOWN: return WXK_DOWN;
622 case KEY_SPACE: return WXK_SPACE;
623 case KEY_ENTER: return WXK_RETURN;
624 case KEY_F1: return WXK_F1;
625 case KEY_F2: return WXK_F2;
626 case KEY_F3: return WXK_F3;
627 case KEY_F4: return WXK_F4;
628 case KEY_F5: return WXK_F5;
629 case KEY_F6: return WXK_F6;
630 case KEY_F7: return WXK_F7;
631 case KEY_F8: return WXK_F8;
632 case KEY_F9: return WXK_F9;
633 case KEY_F10: return WXK_F10;
634 case KEY_F11: return WXK_F11;
635 case KEY_F12: return WXK_F12;
636 case KEY_HOME: return WXK_HOME;
637 case KEY_END: return WXK_END;
638 case KEY_INSERT: return WXK_INSERT;
639 case KEY_DELETE: return WXK_DELETE;
640 case KEY_MENU: return WXK_MENU;
641 case KEY_ESC: return WXK_ESCAPE;
642 case KEY_PAGEUP: return WXK_PRIOR;
643 case KEY_PAGEDOWN: return WXK_NEXT;
644 case KEY_TAB: return WXK_TAB;
645 case KEY_BACKSPACE: return WXK_BACK;
651 void Interface::SetupHotkeys()
653 struct vlc_t::hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
656 /* Count number of hoteys */
657 for( i_hotkeys = 0; p_hotkeys[i_hotkeys].psz_action != NULL; i_hotkeys++ );
659 p_intf->p_sys->i_first_hotkey_event = wxID_HIGHEST + 7000;
660 p_intf->p_sys->i_hotkeys = i_hotkeys;
662 wxAcceleratorEntry *p_entries = new wxAcceleratorEntry[i_hotkeys];
664 /* Setup the hotkeys as accelerators */
665 for( int i = 0; i < i_hotkeys; i++ )
667 int i_mod = ConvertHotkeyModifiers( p_hotkeys[i].i_key );
668 int i_key = ConvertHotkey( p_hotkeys[i].i_key );
671 if( !(p_hotkeys[i].i_key & KEY_SPECIAL) && i_mod )
672 i_key = toupper(i_key);
675 p_entries[i].Set( i_mod, i_key,
676 p_intf->p_sys->i_first_hotkey_event + i );
679 wxAcceleratorTable accel( i_hotkeys, p_entries );
683 msg_Err( p_intf, "invalid accelerator table" );
687 SetAcceleratorTable( accel );
693 void Interface::HideSlider( bool layout )
695 ShowSlider( false, layout );
698 void Interface::ShowSlider( bool show, bool layout )
702 //prevent the hide timers from hiding it now
703 m_slider_timer.Stop();
704 m_controls_timer.Stop();
706 //prevent continuous layout
707 if( slider_frame->IsShown() ) return;
711 //prevent continuous layout
712 if( !slider_frame->IsShown() ) return;
715 if( layout && p_intf->p_sys->b_video_autosize )
716 UpdateVideoWindow( p_intf, video_window );
718 slider_frame->Show( show );
719 frame_sizer->Show( slider_frame, show );
723 frame_sizer->Layout();
724 if( p_intf->p_sys->b_video_autosize ) frame_sizer->Fit( this );
728 void Interface::HideDiscFrame( bool layout )
730 ShowDiscFrame( false, layout );
733 void Interface::ShowDiscFrame( bool show, bool layout )
737 //prevent the hide timer from hiding it now
738 m_controls_timer.Stop();
740 //prevent continuous layout
741 if( disc_frame->IsShown() ) return;
745 //prevent continuous layout
746 if( !disc_frame->IsShown() ) return;
749 if( layout && p_intf->p_sys->b_video_autosize )
750 UpdateVideoWindow( p_intf, video_window );
752 disc_frame->Show( show );
753 slider_sizer->Show( disc_frame, show );
757 slider_sizer->Layout();
758 if( p_intf->p_sys->b_video_autosize )
759 slider_sizer->Fit( slider_frame );
763 /*****************************************************************************
765 *****************************************************************************/
766 void Interface::OnControlsTimer( wxTimerEvent& WXUNUSED(event) )
768 if( p_intf->p_sys->b_video_autosize )
769 UpdateVideoWindow( p_intf, video_window );
771 /* Hide slider and Disc Buttons */
772 //postpone layout, we'll do it ourselves
773 HideDiscFrame( false );
776 slider_sizer->Layout();
777 if( p_intf->p_sys->b_video_autosize )
779 slider_sizer->Fit( slider_frame );
780 frame_sizer->Fit( this );
784 void Interface::OnSliderTimer( wxTimerEvent& WXUNUSED(event) )
789 void Interface::OnMenuOpen( wxMenuEvent& event )
791 #if defined( __WXMSW__ )
792 # define GetEventObject GetMenu
795 if( event.GetEventObject() == p_settings_menu )
797 p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );
799 /* Add static items */
800 p_settings_menu->AppendCheckItem( Extended_Event,
801 wxU(_("Extended &GUI\tCtrl-G") ) );
802 if( b_extra ) p_settings_menu->Check( Extended_Event, TRUE );
804 p_settings_menu->AppendCheckItem( Undock_Event,
805 wxU(_("&Undock Ext. GUI") ) );
806 if( b_undock ) p_settings_menu->Check( Undock_Event, TRUE );
808 p_settings_menu->Append( Bookmarks_Event,
809 wxU(_("&Bookmarks...\tCtrl-B") ) );
810 p_settings_menu->Append( Prefs_Event,
811 wxU(_("Preference&s...\tCtrl-S")) );
814 else if( event.GetEventObject() == p_audio_menu )
816 p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
819 else if( event.GetEventObject() == p_video_menu )
821 p_video_menu = VideoMenu( p_intf, this, p_video_menu );
824 else if( event.GetEventObject() == p_navig_menu )
826 p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
829 #if defined( __WXMSW__ )
830 # undef GetEventObject
834 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
835 void Interface::OnContextMenu2(wxContextMenuEvent& event)
837 /* Only show the context menu for the main interface */
838 if( GetId() != event.GetId() )
844 if( p_intf->p_sys->pf_show_dialog )
845 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
848 void Interface::OnContextMenu(wxMouseEvent& event)
850 if( p_intf->p_sys->pf_show_dialog )
851 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
854 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
856 /* TRUE is to force the frame to close. */
860 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
863 msg.Printf( wxString(wxT("VLC media player " PACKAGE_VERSION)) +
864 wxU(_(" (wxWidgets interface)\n\n")) +
865 wxU(_("(c) 1996-2005 - the VideoLAN Team\n\n")) +
866 wxU(_("Compiled by "))+ wxU(VLC_CompileBy())+ wxU("@") +
867 wxU(VLC_CompileHost())+ wxT(".")+ wxU(VLC_CompileDomain())+ wxT(".\n") +
868 wxU(_("Compiler: "))+ wxU(VLC_Compiler())+wxT( ".\n") +
869 wxU(_("Based on SVN revision: "))+wxU(VLC_Changeset())+wxT(".\n\n") +
871 wxU( vlc_wraptext(INTF_ABOUT_MSG,WRAPCOUNT,VLC_TRUE) ) + wxT("\n\n") +
873 wxU( INTF_ABOUT_MSG ) + wxT("\n\n") +
875 wxU(_("The VideoLAN team <videolan@videolan.org>\n"
876 "http://www.videolan.org/\n\n")) );
878 wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
879 wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
882 void Interface::OnShowDialog( wxCommandEvent& event )
884 if( p_intf->p_sys->pf_show_dialog )
888 switch( event.GetId() )
890 case OpenFileSimple_Event:
891 i_id = INTF_DIALOG_FILE_SIMPLE;
894 i_id = INTF_DIALOG_FILE;
896 i_id = INTF_DIALOG_FILE;
899 i_id = INTF_DIALOG_DIRECTORY;
902 i_id = INTF_DIALOG_DISC;
905 i_id = INTF_DIALOG_NET;
907 case OpenCapture_Event:
908 i_id = INTF_DIALOG_CAPTURE;
911 i_id = INTF_DIALOG_SAT;
914 i_id = INTF_DIALOG_PLAYLIST;
917 i_id = INTF_DIALOG_MESSAGES;
920 i_id = INTF_DIALOG_FILEINFO;
923 i_id = INTF_DIALOG_PREFS;
926 i_id = INTF_DIALOG_WIZARD;
928 case Bookmarks_Event:
929 i_id = INTF_DIALOG_BOOKMARKS;
931 case UpdateVLC_Event:
932 i_id = INTF_DIALOG_UPDATEVLC;
935 i_id = INTF_DIALOG_FILE;
939 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
943 void Interface::OnExtended(wxCommandEvent& event)
945 b_extra = (b_extra == VLC_TRUE ? VLC_FALSE : VLC_TRUE );
947 if( b_extra == VLC_FALSE )
950 frame_sizer->Hide( extra_frame );
955 frame_sizer->Show( extra_frame );
957 frame_sizer->Layout();
958 frame_sizer->Fit(this);
962 if( b_undock == VLC_TRUE )
964 fprintf(stderr,"Deleting window\n");
974 frame_sizer->Hide( extra_frame );
975 frame_sizer->Layout();
976 frame_sizer->Fit(this);
981 if( b_undock == VLC_TRUE )
983 fprintf(stderr,"Creating window\n");
985 frame_sizer->Hide( extra_frame );
986 #if (wxCHECK_VERSION(2,5,0))
987 frame_sizer->Detach( extra_frame );
989 frame_sizer->Remove( extra_frame );
991 frame_sizer->Layout();
992 frame_sizer->Fit(this);
993 extra_window = new ExtraWindow( p_intf, this, extra_frame );
997 fprintf(stderr,"Deleting window\n");
1000 delete extra_window;
1002 extra_frame->Show();
1003 frame_sizer->Show( extra_frame );
1004 frame_sizer->Layout();
1005 frame_sizer->Fit(this);
1010 void Interface::OnUndock(wxCommandEvent& event)
1012 b_undock = (b_undock == VLC_TRUE ? VLC_FALSE : VLC_TRUE );
1014 if( b_extra == VLC_TRUE )
1016 if( b_undock == VLC_FALSE )
1018 fprintf(stderr,"Deleting window\n");
1021 delete extra_window;
1022 extra_window = NULL;
1024 extra_frame->Show();
1025 frame_sizer->Show( extra_frame );
1026 frame_sizer->Layout();
1027 frame_sizer->Fit(this);
1031 fprintf(stderr,"Creating window\n");
1032 extra_frame->Hide();
1033 frame_sizer->Hide( extra_frame );
1034 #if (wxCHECK_VERSION(2,5,0))
1035 frame_sizer->Detach( extra_frame );
1037 frame_sizer->Remove( extra_frame );
1039 frame_sizer->Layout();
1040 frame_sizer->Fit(this);
1041 extra_window = new ExtraWindow( p_intf, this, extra_frame );
1048 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
1053 void Interface::PlayStream()
1055 wxCommandEvent dummy;
1056 playlist_t *p_playlist =
1057 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1059 if( p_playlist == NULL ) return;
1061 if( p_playlist->i_size && p_playlist->i_enabled )
1065 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
1068 if( p_input == NULL )
1070 /* No stream was playing, start one */
1071 playlist_Play( p_playlist );
1072 TogglePlayButton( PLAYING_S );
1073 vlc_object_release( p_playlist );
1077 var_Get( p_input, "state", &state );
1079 if( state.i_int != PAUSE_S )
1081 /* A stream is being played, pause it */
1082 state.i_int = PAUSE_S;
1086 /* Stream is paused, resume it */
1087 state.i_int = PLAYING_S;
1089 var_Set( p_input, "state", state );
1091 TogglePlayButton( state.i_int );
1092 vlc_object_release( p_input );
1093 vlc_object_release( p_playlist );
1097 /* If the playlist is empty, open a file requester instead */
1098 vlc_object_release( p_playlist );
1099 OnShowDialog( dummy );
1103 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
1107 void Interface::StopStream()
1109 playlist_t * p_playlist =
1110 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1112 if( p_playlist == NULL )
1117 playlist_Stop( p_playlist );
1118 TogglePlayButton( PAUSE_S );
1119 vlc_object_release( p_playlist );
1122 void Interface::OnSliderUpdate( wxScrollEvent& event )
1124 vlc_mutex_lock( &p_intf->change_lock );
1127 if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
1128 || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
1131 if( p_intf->p_sys->i_slider_pos != event.GetPosition()
1132 && p_intf->p_sys->p_input )
1135 pos.f_float = (float)event.GetPosition() / (float)SLIDER_MAX_POS;
1137 var_Set( p_intf->p_sys->p_input, "position", pos );
1141 p_intf->p_sys->b_slider_free = VLC_TRUE;
1145 p_intf->p_sys->b_slider_free = VLC_FALSE;
1147 if( p_intf->p_sys->p_input )
1149 /* Update stream date */
1150 char psz_time[ MSTRTIME_MAX_SIZE ], psz_total[ MSTRTIME_MAX_SIZE ];
1153 i_seconds = var_GetTime( p_intf->p_sys->p_input, "length" ) /
1155 secstotimestr( psz_total, i_seconds );
1157 i_seconds = var_GetTime( p_intf->p_sys->p_input, "time" ) /
1159 secstotimestr( psz_time, i_seconds );
1161 statusbar->SetStatusText( wxU(psz_time) + wxString(wxT(" / ") ) +
1162 wxU(psz_total), 0 );
1168 vlc_mutex_unlock( &p_intf->change_lock );
1171 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
1176 void Interface::PrevStream()
1178 playlist_t * p_playlist =
1179 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1181 if( p_playlist == NULL )
1186 /* FIXME --fenrir */
1188 if( p_playlist->p_input != NULL )
1190 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1191 if( p_playlist->p_input->stream.p_selected_area->i_id > 1 )
1193 vlc_value_t val; val.b_bool = VLC_TRUE;
1194 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1195 var_Set( p_playlist->p_input, "prev-title", val );
1197 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1199 vlc_mutex_unlock( &p_playlist->object_lock );
1202 playlist_Prev( p_playlist );
1203 vlc_object_release( p_playlist );
1206 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1211 void Interface::NextStream()
1213 playlist_t * p_playlist =
1214 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1216 if( p_playlist == NULL )
1221 /* FIXME --fenrir */
1223 var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
1224 vlc_mutex_lock( &p_playlist->object_lock );
1225 if( p_playlist->p_input != NULL )
1227 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1228 if( p_playlist->p_input->stream.i_area_nb > 1 &&
1229 p_playlist->p_input->stream.p_selected_area->i_id <
1230 p_playlist->p_input->stream.i_area_nb - 1 )
1232 vlc_value_t val; val.b_bool = VLC_TRUE;
1233 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1234 var_Set( p_playlist->p_input, "next-title", val );
1236 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1238 vlc_mutex_unlock( &p_playlist->object_lock );
1240 playlist_Next( p_playlist );
1241 vlc_object_release( p_playlist );
1244 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1246 input_thread_t *p_input =
1247 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1251 vlc_value_t val; val.b_bool = VLC_TRUE;
1253 var_Set( p_input, "rate-slower", val );
1254 vlc_object_release( p_input );
1258 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1260 input_thread_t *p_input =
1261 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1265 vlc_value_t val; val.b_bool = VLC_TRUE;
1267 var_Set( p_input, "rate-faster", val );
1268 vlc_object_release( p_input );
1272 void Interface::TogglePlayButton( int i_playing_status )
1274 if( i_playing_status == i_old_playing_status )
1277 wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
1278 GetToolBar()->GetToolClientData( PlayStream_Event );
1279 if( !p_tool ) return;
1281 if( i_playing_status == PLAYING_S )
1283 p_tool->SetNormalBitmap( wxBitmap( pause_xpm ) );
1284 p_tool->SetLabel( wxU(_("Pause")) );
1285 p_tool->SetShortHelp( wxU(_(HELP_PAUSE)) );
1289 p_tool->SetNormalBitmap( wxBitmap( play_xpm ) );
1290 p_tool->SetLabel( wxU(_("Play")) );
1291 p_tool->SetShortHelp( wxU(_(HELP_PLAY)) );
1294 GetToolBar()->Realize();
1295 GetToolBar()->ToggleTool( PlayStream_Event, true );
1296 GetToolBar()->ToggleTool( PlayStream_Event, false );
1298 i_old_playing_status = i_playing_status;
1301 void Interface::OnDiscMenu( wxCommandEvent& WXUNUSED(event) )
1303 input_thread_t *p_input =
1304 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1308 vlc_value_t val; val.i_int = 2;
1310 var_Set( p_input, "title 0", val);
1311 vlc_object_release( p_input );
1315 void Interface::OnDiscPrev( wxCommandEvent& WXUNUSED(event) )
1317 input_thread_t *p_input =
1318 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1322 int i_type = var_Type( p_input, "prev-chapter" );
1323 vlc_value_t val; val.b_bool = VLC_TRUE;
1325 var_Set( p_input, ( i_type & VLC_VAR_TYPE ) != 0 ?
1326 "prev-chapter" : "prev-title", val );
1328 vlc_object_release( p_input );
1332 void Interface::OnDiscNext( wxCommandEvent& WXUNUSED(event) )
1334 input_thread_t *p_input =
1335 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1339 int i_type = var_Type( p_input, "next-chapter" );
1340 vlc_value_t val; val.b_bool = VLC_TRUE;
1342 var_Set( p_input, ( i_type & VLC_VAR_TYPE ) != 0 ?
1343 "next-chapter" : "next-title", val );
1345 vlc_object_release( p_input );
1349 #if wxUSE_DRAG_AND_DROP
1350 /*****************************************************************************
1351 * Definition of DragAndDrop class.
1352 *****************************************************************************/
1353 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
1356 b_enqueue = _b_enqueue;
1359 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1360 const wxArrayString& filenames )
1362 /* Add dropped files to the playlist */
1364 playlist_t *p_playlist =
1365 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1367 if( p_playlist == NULL )
1372 for( size_t i = 0; i < filenames.GetCount(); i++ )
1374 char *psz_utf8 = FromLocale( filenames[i].mb_str() );
1375 playlist_Add( p_playlist, psz_utf8, psz_utf8,
1376 PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
1378 LocaleFree( psz_utf8 );
1381 vlc_object_release( p_playlist );
1387 /*****************************************************************************
1388 * Definition of VolCtrl class.
1389 *****************************************************************************/
1390 class wxVolCtrl: public wxGauge
1394 wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1395 wxPoint = wxDefaultPosition, wxSize = wxSize( 20, -1 ) );
1396 virtual ~wxVolCtrl() {};
1398 void UpdateVolume();
1401 void OnChange( wxMouseEvent& event );
1404 intf_thread_t *p_intf;
1406 DECLARE_EVENT_TABLE();
1409 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
1411 EVT_LEFT_DOWN(wxVolCtrl::OnChange)
1412 EVT_MOTION(wxVolCtrl::OnChange)
1415 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1416 wxPoint point, wxSize size )
1417 : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
1423 void wxVolCtrl::OnChange( wxMouseEvent& event )
1425 if( !event.LeftDown() && !event.LeftIsDown() ) return;
1427 int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
1428 aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1432 void wxVolCtrl::UpdateVolume()
1434 audio_volume_t i_volume;
1435 aout_VolumeGet( p_intf, &i_volume );
1437 int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
1438 if( i_gauge_volume == GetValue() ) return;
1440 SetValue( i_gauge_volume );
1441 SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
1442 i_gauge_volume / 2 ) );
1445 #if defined(__WXGTK__)
1446 #define VLCVOL_HEIGHT p_parent->GetSize().GetHeight()
1448 #define VLCVOL_HEIGHT TOOLBAR_BMP_HEIGHT
1450 VLCVolCtrl::VLCVolCtrl( intf_thread_t *_p_intf, wxWindow *p_parent )
1451 :wxControl( p_parent, -1, wxDefaultPosition, wxSize(64, VLCVOL_HEIGHT ),
1453 i_y_offset((VLCVOL_HEIGHT - TOOLBAR_BMP_HEIGHT) / 2),
1454 b_mute(0), p_intf(_p_intf)
1456 gauge = new wxVolCtrl( p_intf, this, -1, wxPoint( 18, i_y_offset ),
1457 wxSize( 44, TOOLBAR_BMP_HEIGHT ) );
1460 void VLCVolCtrl::OnPaint( wxPaintEvent &evt )
1462 wxPaintDC dc( this );
1463 wxBitmap mPlayBitmap( b_mute ? speaker_mute_xpm : speaker_xpm );
1464 dc.DrawBitmap( mPlayBitmap, 0, i_y_offset, TRUE );
1467 void VLCVolCtrl::OnChange( wxMouseEvent& event )
1469 if( event.GetX() < TOOLBAR_BMP_WIDTH )
1472 aout_VolumeMute( p_intf, (audio_volume_t *)&i_volume );
1479 void VLCVolCtrl::UpdateVolume()
1481 gauge->UpdateVolume();
1483 int i_volume = gauge->GetValue();
1484 if( !!i_volume == !b_mute ) return;
1489 /*****************************************************************************
1491 *****************************************************************************/
1493 #ifdef wxHAS_TASK_BAR_ICON
1495 BEGIN_EVENT_TABLE(Systray, wxTaskBarIcon)
1498 EVT_TASKBAR_LEFT_DCLICK(Systray::OnLeftClick)
1500 EVT_TASKBAR_LEFT_DOWN(Systray::OnLeftClick)
1503 EVT_MENU(Iconize_Event, Systray::OnMenuIconize)
1504 EVT_MENU(Exit_Event, Systray::OnExit)
1505 EVT_MENU(PlayStream_Event, Systray::OnPlayStream)
1506 EVT_MENU(NextStream_Event, Systray::OnNextStream)
1507 EVT_MENU(PrevStream_Event, Systray::OnPrevStream)
1508 EVT_MENU(StopStream_Event, Systray::OnStopStream)
1511 Systray::Systray( Interface *_p_main_interface, intf_thread_t *_p_intf )
1513 p_main_interface = _p_main_interface;
1517 /* Event handlers */
1518 void Systray::OnMenuIconize( wxCommandEvent& event )
1520 p_main_interface->Show( ! p_main_interface->IsShown() );
1521 if ( p_main_interface->IsShown() ) p_main_interface->Raise();
1524 void Systray::OnLeftClick( wxTaskBarIconEvent& event )
1526 wxCommandEvent cevent;
1527 OnMenuIconize(cevent);
1530 void Systray::OnExit( wxCommandEvent& event )
1532 p_main_interface->Close(TRUE);
1535 void Systray::OnPrevStream( wxCommandEvent& event )
1537 p_main_interface->PrevStream();
1540 void Systray::OnNextStream( wxCommandEvent& event )
1542 p_main_interface->NextStream();
1545 void Systray::OnPlayStream( wxCommandEvent& event )
1547 p_main_interface->PlayStream();
1550 void Systray::OnStopStream( wxCommandEvent& event )
1552 p_main_interface->StopStream();
1555 /* Systray popup menu */
1556 wxMenu* Systray::CreatePopupMenu()
1558 int minimal = config_GetInt( p_intf, "wx-minimal" );
1560 wxMenu* systray_menu = new wxMenu;
1561 systray_menu->Append( Exit_Event, wxU(_("Quit VLC")) );
1562 systray_menu->AppendSeparator();
1563 systray_menu->Append( PlayStream_Event, wxU(_("Play/Pause")) );
1567 systray_menu->Append( PrevStream_Event, wxU(_("Previous")) );
1568 systray_menu->Append( NextStream_Event, wxU(_("Next")) );
1569 systray_menu->Append( StopStream_Event, wxU(_("Stop")) );
1571 systray_menu->AppendSeparator();
1572 systray_menu->Append( Iconize_Event, wxU(_("Show/Hide interface")) );
1573 return systray_menu;
1576 void Systray::UpdateTooltip( const wxChar* tooltip )
1578 SetIcon( wxIcon( vlc16x16_xpm ), tooltip );