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 *****************************************************************************/
27 #include "interface.hpp"
28 #include "extrapanel.hpp"
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"
51 #define TOOLBAR_BMP_WIDTH 16
52 #define TOOLBAR_BMP_HEIGHT 16
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"
61 /*****************************************************************************
62 * Local class declarations.
63 *****************************************************************************/
64 class wxMenuExt: public wxMenu
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,
73 virtual ~wxMenuExt() {};
85 class VLCVolCtrl : public wxControl
88 VLCVolCtrl( intf_thread_t *p_intf, wxWindow *p_parent );
89 virtual ~VLCVolCtrl() {};
91 virtual void OnPaint( wxPaintEvent &event );
92 void OnChange( wxMouseEvent& event );
101 intf_thread_t *p_intf;
104 BEGIN_EVENT_TABLE(VLCVolCtrl, wxControl)
105 EVT_PAINT(VLCVolCtrl::OnPaint)
108 EVT_LEFT_UP(VLCVolCtrl::OnChange)
111 /*****************************************************************************
113 *****************************************************************************/
115 DEFINE_LOCAL_EVENT_TYPE( wxEVT_INTF );
117 /* IDs for the controls and the menu commands */
121 MenuDummy_Event = wxID_HIGHEST + 1000,
122 Exit_Event = wxID_HIGHEST,
123 OpenFileSimple_Event,
158 /* it is important for the id corresponding to the "About" command to have
159 * this standard value as otherwise it won't be handled properly under Mac
160 * (where it is special and put into the "Apple" menu) */
161 About_Event = wxID_ABOUT,
168 BEGIN_EVENT_TABLE(Interface, wxFrame)
170 EVT_MENU(Exit_Event, Interface::OnExit)
171 EVT_MENU(About_Event, Interface::OnAbout)
172 EVT_MENU(UpdateVLC_Event, Interface::OnShowDialog)
173 EVT_MENU(VLM_Event, Interface::OnShowDialog)
175 EVT_MENU(Playlist_Event, Interface::OnShowDialog)
176 EVT_MENU(Logs_Event, Interface::OnShowDialog)
177 EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
178 EVT_MENU(Prefs_Event, Interface::OnShowDialog)
180 EVT_MENU_OPEN(Interface::OnMenuOpen)
182 EVT_MENU( Extended_Event, Interface::OnExtended )
183 // EVT_MENU( Undock_Event, Interface::OnUndock )
185 EVT_MENU( Bookmarks_Event, Interface::OnShowDialog)
187 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
188 EVT_CONTEXT_MENU(Interface::OnContextMenu2)
190 EVT_RIGHT_UP(Interface::OnContextMenu)
193 EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
194 EVT_MENU(OpenAdv_Event, Interface::OnShowDialog)
195 EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
196 EVT_MENU(OpenDir_Event, Interface::OnShowDialog)
197 EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
198 EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
199 EVT_MENU(OpenCapture_Event, Interface::OnShowDialog)
200 EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
201 EVT_MENU(Wizard_Event, Interface::OnShowDialog)
202 EVT_MENU(StopStream_Event, Interface::OnStopStream)
203 EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
204 EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
205 EVT_MENU(NextStream_Event, Interface::OnNextStream)
206 EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
207 EVT_MENU(FastStream_Event, Interface::OnFastStream)
209 /* Disc Buttons events */
210 EVT_BUTTON(DiscMenu_Event, Interface::OnDiscMenu)
211 EVT_BUTTON(DiscPrev_Event, Interface::OnDiscPrev)
212 EVT_BUTTON(DiscNext_Event, Interface::OnDiscNext)
215 EVT_COMMAND_SCROLL(SliderScroll_Event, Interface::OnSliderUpdate)
218 EVT_COMMAND(0, wxEVT_INTF, Interface::OnControlEvent)
219 EVT_COMMAND(1, wxEVT_INTF, Interface::OnControlEvent)
221 EVT_TIMER(ID_CONTROLS_TIMER, Interface::OnControlsTimer)
222 EVT_TIMER(ID_SLIDER_TIMER, Interface::OnSliderTimer)
225 /*****************************************************************************
227 *****************************************************************************/
228 Interface::Interface( intf_thread_t *_p_intf, long style ):
229 wxFrame( NULL, -1, wxT("VLC media player"),
230 wxDefaultPosition, wxSize(700,100), style )
232 /* Initializations */
234 i_old_playing_status = PAUSE_S;
236 // b_undock = VLC_FALSE;
241 /* Give our interface a nice little icon */
242 SetIcon( wxIcon( vlc_xpm ) );
244 /* Create a sizer for the main frame */
245 frame_sizer = new wxBoxSizer( wxVERTICAL );
246 SetSizer( frame_sizer );
248 /* Create a dummy widget that can get the keyboard focus */
249 wxWindow *p_dummy = new wxWindow( this, 0, wxDefaultPosition,
251 #if defined(__WXGTK20__) && wxCHECK_VERSION(2,5,6)
252 /* As ugly as your butt! Please remove when wxWidgets 2.6 fixed their
253 * Accelerators bug. */
254 p_dummy->m_imData = 0;
258 frame_sizer->Add( p_dummy, 0, 0 );
260 #ifdef wxHAS_TASK_BAR_ICON
261 /* Systray integration */
263 if ( config_GetInt( p_intf, "wx-systray" ) )
265 p_systray = new Systray(this, p_intf);
266 p_systray->SetIcon( wxIcon( vlc16x16_xpm ), wxT("VLC media player") );
267 if ( (! p_systray->IsOk()) || (! p_systray->IsIconInstalled()) )
269 msg_Warn(p_intf, "Cannot set systray icon, weird things may happen");
274 /* Creation of the menu bar */
277 /* Creation of the tool bar */
280 /* Create the extra panel */
281 extra_frame = new ExtraPanel( p_intf, this );
282 frame_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
283 frame_sizer->Hide( extra_frame );
285 /* Creation of the status bar
286 * Helptext for menu items and toolbar tools will automatically get
288 int i_status_width[3] = {-6, -2, -9};
289 statusbar = CreateStatusBar( 3 ); /* 2 fields */
290 statusbar->SetStatusWidths( 3, i_status_width );
291 statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
295 if( config_GetInt( p_intf, "wx-embed" ) )
297 video_window = CreateVideoWindow( p_intf, this );
298 frame_sizer->Add( p_intf->p_sys->p_video_sizer, 1, wxEXPAND, 0 );
301 /* Creation of the slider sub-window */
303 frame_sizer->Add( slider_frame, 0, wxEXPAND , 0 );
304 frame_sizer->Hide( slider_frame );
306 /* Make sure we've got the right background colour */
307 SetBackgroundColour( slider_frame->GetBackgroundColour() );
309 /* Layout everything */
310 frame_sizer->Layout();
311 frame_sizer->Fit(this);
313 #if wxUSE_DRAG_AND_DROP
314 /* Associate drop targets with the main interface */
315 SetDropTarget( new DragAndDrop( p_intf ) );
320 m_controls_timer.SetOwner(this, ID_CONTROLS_TIMER);
321 m_slider_timer.SetOwner(this, ID_SLIDER_TIMER);
324 timer = new Timer( p_intf, this );
327 WindowSettings *ws = p_intf->p_sys->p_window_settings;
332 ws->SetScreen( wxSystemSettings::GetMetric( wxSYS_SCREEN_X ),
333 wxSystemSettings::GetMetric( wxSYS_SCREEN_Y ) );
335 if( ws->GetSettings( WindowSettings::ID_MAIN, b_shown, p, s ) )
338 /* Set minimum window size to prevent user from glitching it */
340 if( config_GetInt( p_intf, "wx-embed" ) )
343 s2 = video_window->GetSize();
344 s.SetHeight( s.GetHeight() - s2.GetHeight() );
348 /* Show extended GUI if requested */
349 if( ( b_extra = config_GetInt( p_intf, "wx-extended" ) ) )
350 frame_sizer->Show( extra_frame );
353 Interface::~Interface()
355 WindowSettings *ws = p_intf->p_sys->p_window_settings;
359 ws->SetSettings( WindowSettings::ID_MAIN, true,
360 GetPosition(), GetSize() );
363 PopEventHandler(true);
365 if( video_window ) delete video_window;
367 #ifdef wxHAS_TASK_BAR_ICON
368 if( p_systray ) delete p_systray;
371 if( p_intf->p_sys->p_wxwindow ) delete p_intf->p_sys->p_wxwindow;
377 void Interface::Init()
383 void Interface::Update()
386 ((VLCVolCtrl *)volctrl)->UpdateVolume();
389 void Interface::OnControlEvent( wxCommandEvent& event )
391 switch( event.GetId() )
395 if( p_intf->p_sys->b_video_autosize )
397 frame_sizer->Layout();
398 frame_sizer->Fit(this);
404 long i_style = GetWindowStyle();
405 if( event.GetInt() ) i_style |= wxSTAY_ON_TOP;
406 else i_style &= ~wxSTAY_ON_TOP;
407 SetWindowStyle( i_style );
412 /*****************************************************************************
414 *****************************************************************************/
415 void Interface::CreateOurMenuBar()
417 int minimal = config_GetInt( p_intf, "wx-minimal" );
419 /* Create the "File" menu */
420 wxMenu *file_menu = new wxMenu;
424 file_menu->Append( OpenFileSimple_Event,
425 wxU(_("Quick &Open File...\tCtrl-O")) );
427 file_menu->AppendSeparator();
428 file_menu->Append( OpenFile_Event, wxU(_("Open &File...\tCtrl-F")) );
429 file_menu->Append( OpenDir_Event, wxU(_("Open Dir&ectory...\tCtrl-E")) );
430 file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...\tCtrl-D")) );
431 file_menu->Append( OpenNet_Event,
432 wxU(_("Open &Network Stream...\tCtrl-N")) );
433 file_menu->Append( OpenCapture_Event,
434 wxU(_("Open C&apture Device...\tCtrl-A")) );
436 file_menu->AppendSeparator();
437 file_menu->Append( Wizard_Event, wxU(_("&Wizard...\tCtrl-W")) );
438 file_menu->AppendSeparator();
440 file_menu->Append( Exit_Event, wxU(_("E&xit\tCtrl-X")) );
442 /* Create the "View" menu */
443 wxMenu *view_menu = new wxMenu;
446 view_menu->Append( Playlist_Event, wxU(_("&Playlist...\tCtrl-P")) );
448 view_menu->Append( Logs_Event, wxU(_("&Messages...\tCtrl-M")) );
449 view_menu->Append( FileInfo_Event,
450 wxU(_("Stream and Media &info...\tCtrl-I")) );
451 view_menu->Append( VLM_Event,
452 wxU(_("VLM Control...\tCtrl-I")) );
454 /* Create the "Auto-generated" menus */
455 p_settings_menu = SettingsMenu( p_intf, this );
456 p_audio_menu = AudioMenu( p_intf, this );
457 p_video_menu = VideoMenu( p_intf, this );
458 p_navig_menu = NavigMenu( p_intf, this );
460 /* Create the "Help" menu */
461 wxMenu *help_menu = new wxMenu;
462 help_menu->Append( About_Event, wxU(_("About VLC media player")) );
463 help_menu->AppendSeparator();
464 help_menu->Append( UpdateVLC_Event, wxU(_("Check for updates ...")) );
466 /* Append the freshly created menus to the menu bar... */
467 wxMenuBar *menubar = new wxMenuBar();
468 menubar->Append( file_menu, wxU(_("&File")) );
469 menubar->Append( view_menu, wxU(_("&View")) );
470 menubar->Append( p_settings_menu, wxU(_("&Settings")) );
471 menubar->Append( p_audio_menu, wxU(_("&Audio")) );
472 menubar->Append( p_video_menu, wxU(_("&Video")) );
473 menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
474 menubar->Append( help_menu, wxU(_("&Help")) );
476 /* Attach the menu bar to the frame */
477 SetMenuBar( menubar );
479 /* Find out size of menu bar */
481 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
483 int i_width, i_height;
484 menubar->GetTextExtent( menubar->GetLabelTop(i), &i_width, &i_height );
486 #if defined(__WXGTK__)
487 22 /* approximate margin */;
489 #if (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 5) && (wxRELEASE_NUMBER < 3)
490 4 /* approximate margin */;
492 18 /* approximate margin */;
497 /* Patch by zcot for menu wrapping */
499 /* Find out size of msw menu bar */
502 HDC hdc = GetDC( NULL );
503 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
505 // [ MENU BUTTON WIDTH CALCULATION ]
506 // [ SM_CXDLGFRAME + pixels + textextent + pixels + SM_CXDLGFRAME ]
507 GetTextExtentPoint32( hdc, menubar->GetLabelTop(i).c_str(),
508 menubar->GetLabelTop(i).Length(), &sizing );
511 // +1 more pixel on each size
513 // width of 2 DLGFRAME
514 i_size += GetSystemMetrics( SM_CXDLGFRAME ) * 2;
516 ReleaseDC( NULL, hdc );
517 // Width of 2 edges of app window
518 i_size += GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
519 // + 2 more pixels on each side..
522 /* End patch by zcot */
524 frame_sizer->SetMinSize( i_size, -1 );
526 /* Intercept all menu events in our custom event handler */
527 PushEventHandler( new MenuEvtHandler( p_intf, this ) );
529 #if wxUSE_DRAG_AND_DROP
530 /* Associate drop targets with the menubar */
531 menubar->SetDropTarget( new DragAndDrop( p_intf ) );
535 void Interface::CreateOurToolBar()
537 #define HELP_OPEN N_("Open")
538 #define HELP_STOP N_("Stop")
539 #define HELP_PLAY N_("Play")
540 #define HELP_PAUSE N_("Pause")
541 #define HELP_PLO N_("Playlist")
542 #define HELP_PLP N_("Previous playlist item")
543 #define HELP_PLN N_("Next playlist item")
544 #define HELP_SLOW N_("Play slower")
545 #define HELP_FAST N_("Play faster")
547 int minimal = config_GetInt( p_intf, "wx-minimal" );
549 wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
550 * version because we don't include wx.rc */
553 CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
555 toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
559 toolbar->AddTool( OpenFile_Event, wxT(""),
560 wxBitmap( eject_xpm ), wxU(_(HELP_OPEN)) );
561 toolbar->AddSeparator();
564 wxToolBarToolBase *p_tool = toolbar->AddTool( PlayStream_Event, wxT(""),
565 wxBitmap( play_xpm ), wxU(_(HELP_PLAY)), wxITEM_CHECK );
566 p_tool->SetClientData( p_tool );
570 toolbar->AddTool( StopStream_Event, wxT(""), wxBitmap( stop_xpm ),
572 toolbar->AddSeparator();
574 toolbar->AddTool( PrevStream_Event, wxT(""),
575 wxBitmap( prev_xpm ), wxU(_(HELP_PLP)) );
576 toolbar->AddTool( SlowStream_Event, wxT(""),
577 wxBitmap( slow_xpm ), wxU(_(HELP_SLOW)) );
578 toolbar->AddTool( FastStream_Event, wxT(""),
579 wxBitmap( fast_xpm ), wxU(_(HELP_FAST)) );
580 toolbar->AddTool( NextStream_Event, wxT(""), wxBitmap( next_xpm ),
582 toolbar->AddSeparator();
583 toolbar->AddTool( Playlist_Event, wxT(""), wxBitmap( playlist_xpm ),
587 #if !( (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 6) && (wxRELEASE_NUMBER < 2) )
588 wxControl *p_dummy_ctrl =
589 new wxControl( toolbar, -1, wxDefaultPosition,
590 wxSize(35, 16 ), wxBORDER_NONE );
592 toolbar->AddControl( p_dummy_ctrl );
595 volctrl = new VLCVolCtrl( p_intf, toolbar );
596 toolbar->AddControl( volctrl );
600 #if wxUSE_DRAG_AND_DROP
601 /* Associate drop targets with the toolbar */
602 toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
606 void Interface::CreateOurSlider()
608 /* Create a new frame and sizer containing the slider */
609 slider_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
610 slider_frame->SetAutoLayout( TRUE );
611 slider_sizer = new wxBoxSizer( wxHORIZONTAL );
612 //slider_sizer->SetMinSize( -1, 50 );
615 slider = new wxSlider( slider_frame, SliderScroll_Event, 0, 0,
616 SLIDER_MAX_POS, wxDefaultPosition, wxDefaultSize );
618 /* Add Disc Buttons */
619 disc_frame = new wxPanel( slider_frame, -1, wxDefaultPosition,
621 disc_frame->SetAutoLayout( TRUE );
622 disc_sizer = new wxBoxSizer( wxHORIZONTAL );
624 disc_menu_button = new wxBitmapButton( disc_frame, DiscMenu_Event,
625 wxBitmap( playlist_xpm ) );
626 disc_prev_button = new wxBitmapButton( disc_frame, DiscPrev_Event,
627 wxBitmap( prev_xpm ) );
628 disc_next_button = new wxBitmapButton( disc_frame, DiscNext_Event,
629 wxBitmap( next_xpm ) );
631 disc_sizer->Add( disc_menu_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
632 disc_sizer->Add( disc_prev_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
633 disc_sizer->Add( disc_next_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
635 disc_frame->SetSizer( disc_sizer );
636 disc_sizer->Layout();
638 /* Add everything to the frame */
639 slider_sizer->Add( slider, 1, wxEXPAND | wxALL, 5 );
640 slider_sizer->Add( disc_frame, 0, wxALL, 2 );
641 slider_frame->SetSizer( slider_sizer );
644 slider_sizer->Hide( disc_frame );
646 slider_sizer->Layout();
647 slider_sizer->Fit( slider_frame );
649 /* Hide the slider by default */
650 slider_frame->Hide();
653 static int ConvertHotkeyModifiers( int i_hotkey )
655 int i_accel_flags = 0;
656 if( i_hotkey & KEY_MODIFIER_ALT ) i_accel_flags |= wxACCEL_ALT;
657 if( i_hotkey & KEY_MODIFIER_CTRL ) i_accel_flags |= wxACCEL_CTRL;
658 if( i_hotkey & KEY_MODIFIER_SHIFT ) i_accel_flags |= wxACCEL_SHIFT;
659 if( !i_accel_flags ) i_accel_flags = wxACCEL_NORMAL;
660 return i_accel_flags;
663 static int ConvertHotkey( int i_hotkey )
665 int i_key = i_hotkey & ~KEY_MODIFIER;
666 if( i_key & KEY_ASCII ) return i_key & KEY_ASCII;
667 else if( i_key & KEY_SPECIAL )
671 case KEY_LEFT: return WXK_LEFT;
672 case KEY_RIGHT: return WXK_RIGHT;
673 case KEY_UP: return WXK_UP;
674 case KEY_DOWN: return WXK_DOWN;
675 case KEY_SPACE: return WXK_SPACE;
676 case KEY_ENTER: return WXK_RETURN;
677 case KEY_F1: return WXK_F1;
678 case KEY_F2: return WXK_F2;
679 case KEY_F3: return WXK_F3;
680 case KEY_F4: return WXK_F4;
681 case KEY_F5: return WXK_F5;
682 case KEY_F6: return WXK_F6;
683 case KEY_F7: return WXK_F7;
684 case KEY_F8: return WXK_F8;
685 case KEY_F9: return WXK_F9;
686 case KEY_F10: return WXK_F10;
687 case KEY_F11: return WXK_F11;
688 case KEY_F12: return WXK_F12;
689 case KEY_HOME: return WXK_HOME;
690 case KEY_END: return WXK_END;
691 case KEY_INSERT: return WXK_INSERT;
692 case KEY_DELETE: return WXK_DELETE;
693 case KEY_MENU: return WXK_MENU;
694 case KEY_ESC: return WXK_ESCAPE;
695 case KEY_PAGEUP: return WXK_PRIOR;
696 case KEY_PAGEDOWN: return WXK_NEXT;
697 case KEY_TAB: return WXK_TAB;
698 case KEY_BACKSPACE: return WXK_BACK;
704 void Interface::SetupHotkeys()
706 struct vlc_t::hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
709 /* Count number of hoteys */
710 for( i_hotkeys = 0; p_hotkeys[i_hotkeys].psz_action != NULL; i_hotkeys++ );
712 p_intf->p_sys->i_first_hotkey_event = wxID_HIGHEST + 7000;
713 p_intf->p_sys->i_hotkeys = i_hotkeys;
715 wxAcceleratorEntry *p_entries = new wxAcceleratorEntry[i_hotkeys];
717 /* Setup the hotkeys as accelerators */
718 for( int i = 0; i < i_hotkeys; i++ )
720 int i_mod = ConvertHotkeyModifiers( p_hotkeys[i].i_key );
721 int i_key = ConvertHotkey( p_hotkeys[i].i_key );
724 if( !(p_hotkeys[i].i_key & KEY_SPECIAL) && i_mod )
725 i_key = toupper(i_key);
728 p_entries[i].Set( i_mod, i_key,
729 p_intf->p_sys->i_first_hotkey_event + i );
732 wxAcceleratorTable accel( i_hotkeys, p_entries );
736 msg_Err( p_intf, "invalid accelerator table" );
740 SetAcceleratorTable( accel );
746 void Interface::HideSlider( bool layout )
748 fprintf( stderr, "Hiding slider\n");
749 ShowSlider( false, layout );
752 void Interface::ShowSlider( bool show, bool layout )
756 //prevent the hide timers from hiding it now
757 m_slider_timer.Stop();
758 m_controls_timer.Stop();
760 //prevent continuous layout
761 if( slider_frame->IsShown() ) return;
765 //prevent continuous layout
766 if( !slider_frame->IsShown() ) return;
769 if( layout && p_intf->p_sys->b_video_autosize )
770 UpdateVideoWindow( p_intf, video_window );
772 slider_frame->Show( show );
773 frame_sizer->Show( slider_frame, show );
777 frame_sizer->Layout();
778 if( p_intf->p_sys->b_video_autosize ) frame_sizer->Fit( this );
782 void Interface::HideDiscFrame( bool layout )
784 ShowDiscFrame( false, layout );
787 void Interface::ShowDiscFrame( bool show, bool layout )
791 //prevent the hide timer from hiding it now
792 m_controls_timer.Stop();
794 //prevent continuous layout
795 if( disc_frame->IsShown() ) return;
799 //prevent continuous layout
800 if( !disc_frame->IsShown() ) return;
803 if( layout && p_intf->p_sys->b_video_autosize )
804 UpdateVideoWindow( p_intf, video_window );
806 disc_frame->Show( show );
807 slider_sizer->Show( disc_frame, show );
811 slider_sizer->Layout();
812 if( p_intf->p_sys->b_video_autosize )
813 slider_sizer->Fit( slider_frame );
817 /*****************************************************************************
819 *****************************************************************************/
820 void Interface::OnControlsTimer( wxTimerEvent& WXUNUSED(event) )
822 if( p_intf->p_sys->b_video_autosize )
823 UpdateVideoWindow( p_intf, video_window );
825 /* Hide slider and Disc Buttons */
826 //postpone layout, we'll do it ourselves
827 HideDiscFrame( false );
830 slider_sizer->Layout();
831 if( p_intf->p_sys->b_video_autosize )
833 slider_sizer->Fit( slider_frame );
834 frame_sizer->Fit( this );
838 void Interface::OnSliderTimer( wxTimerEvent& WXUNUSED(event) )
843 void Interface::OnMenuOpen( wxMenuEvent& event )
845 #if defined( __WXMSW__ )
846 # define GetEventObject GetMenu
849 if( event.GetEventObject() == p_settings_menu )
851 p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );
853 /* Add static items */
854 p_settings_menu->AppendCheckItem( Extended_Event,
855 wxU(_("Extended &GUI\tCtrl-G") ) );
856 if( b_extra ) p_settings_menu->Check( Extended_Event, TRUE );
858 p_settings_menu->AppendCheckItem( Undock_Event,
859 wxU(_("&Undock Ext. GUI") ) );
860 if( b_undock ) p_settings_menu->Check( Undock_Event, TRUE );
862 p_settings_menu->Append( Bookmarks_Event,
863 wxU(_("&Bookmarks...\tCtrl-B") ) );
864 p_settings_menu->Append( Prefs_Event,
865 wxU(_("Preference&s...\tCtrl-S")) );
868 else if( event.GetEventObject() == p_audio_menu )
870 p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
873 else if( event.GetEventObject() == p_video_menu )
875 p_video_menu = VideoMenu( p_intf, this, p_video_menu );
878 else if( event.GetEventObject() == p_navig_menu )
880 p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
883 #if defined( __WXMSW__ )
884 # undef GetEventObject
888 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
889 void Interface::OnContextMenu2(wxContextMenuEvent& event)
891 /* Only show the context menu for the main interface */
892 if( GetId() != event.GetId() )
898 if( p_intf->p_sys->pf_show_dialog )
899 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
902 void Interface::OnContextMenu(wxMouseEvent& event)
904 if( p_intf->p_sys->pf_show_dialog )
905 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
908 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
910 /* TRUE is to force the frame to close. */
914 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
917 msg.Printf( wxString(wxT("VLC media player " PACKAGE_VERSION)) +
918 wxU(_(" (wxWidgets interface)\n\n")) +
919 wxU(_("(c) 1996-2005 - the VideoLAN Team\n\n")) +
920 wxU(_("Compiled by "))+ wxU(VLC_CompileBy())+ wxU("@") +
921 wxU(VLC_CompileHost())+ wxT(".")+ wxU(VLC_CompileDomain())+ wxT(".\n") +
922 wxU(_("Compiler: "))+ wxU(VLC_Compiler())+wxT( ".\n") +
923 wxU(_("Based on SVN revision: "))+wxU(VLC_Changeset())+wxT(".\n\n") +
925 wxU( vlc_wraptext(INTF_ABOUT_MSG,WRAPCOUNT,VLC_TRUE) ) + wxT("\n\n") +
927 wxU( INTF_ABOUT_MSG ) + wxT("\n\n") +
929 wxU(_("The VideoLAN team <videolan@videolan.org>\n"
930 "http://www.videolan.org/\n\n")) );
932 wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
933 wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
936 void Interface::OnShowDialog( wxCommandEvent& event )
938 if( p_intf->p_sys->pf_show_dialog )
942 switch( event.GetId() )
944 case OpenFileSimple_Event:
945 i_id = INTF_DIALOG_FILE_SIMPLE;
948 i_id = INTF_DIALOG_FILE;
951 i_id = INTF_DIALOG_FILE;
954 i_id = INTF_DIALOG_DIRECTORY;
957 i_id = INTF_DIALOG_DISC;
960 i_id = INTF_DIALOG_NET;
962 case OpenCapture_Event:
963 i_id = INTF_DIALOG_CAPTURE;
966 i_id = INTF_DIALOG_SAT;
969 i_id = INTF_DIALOG_PLAYLIST;
972 i_id = INTF_DIALOG_MESSAGES;
975 i_id = INTF_DIALOG_FILEINFO;
978 i_id = INTF_DIALOG_PREFS;
981 i_id = INTF_DIALOG_WIZARD;
983 case Bookmarks_Event:
984 i_id = INTF_DIALOG_BOOKMARKS;
986 case UpdateVLC_Event:
987 i_id = INTF_DIALOG_UPDATEVLC;
990 i_id = INTF_DIALOG_VLM;
993 i_id = INTF_DIALOG_FILE;
997 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
1001 void Interface::OnExtended(wxCommandEvent& event)
1003 b_extra = (b_extra == VLC_TRUE ? VLC_FALSE : VLC_TRUE );
1005 if( b_extra == VLC_FALSE )
1007 extra_frame->Hide();
1008 frame_sizer->Hide( extra_frame );
1012 extra_frame->Show();
1013 frame_sizer->Show( extra_frame );
1015 frame_sizer->Layout();
1016 frame_sizer->Fit(this);
1019 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
1024 void Interface::PlayStream()
1026 wxCommandEvent dummy;
1027 playlist_t *p_playlist =
1028 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1030 if( p_playlist == NULL ) return;
1032 if( p_playlist->i_size && p_playlist->i_enabled )
1036 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
1039 if( p_input == NULL )
1041 /* No stream was playing, start one */
1042 playlist_Play( p_playlist );
1043 TogglePlayButton( PLAYING_S );
1044 vlc_object_release( p_playlist );
1048 var_Get( p_input, "state", &state );
1050 if( state.i_int != PAUSE_S )
1052 /* A stream is being played, pause it */
1053 state.i_int = PAUSE_S;
1057 /* Stream is paused, resume it */
1058 state.i_int = PLAYING_S;
1060 var_Set( p_input, "state", state );
1062 TogglePlayButton( state.i_int );
1063 vlc_object_release( p_input );
1064 vlc_object_release( p_playlist );
1068 /* If the playlist is empty, open a file requester instead */
1069 vlc_object_release( p_playlist );
1070 OnShowDialog( dummy );
1074 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
1078 void Interface::StopStream()
1080 playlist_t * p_playlist =
1081 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1083 if( p_playlist == NULL )
1088 playlist_Stop( p_playlist );
1089 TogglePlayButton( PAUSE_S );
1090 vlc_object_release( p_playlist );
1093 void Interface::OnSliderUpdate( wxScrollEvent& event )
1095 vlc_mutex_lock( &p_intf->change_lock );
1098 if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
1099 || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
1102 if( p_intf->p_sys->i_slider_pos != event.GetPosition()
1103 && p_intf->p_sys->p_input )
1106 pos.f_float = (float)event.GetPosition() / (float)SLIDER_MAX_POS;
1108 var_Set( p_intf->p_sys->p_input, "position", pos );
1112 p_intf->p_sys->b_slider_free = VLC_TRUE;
1116 p_intf->p_sys->b_slider_free = VLC_FALSE;
1118 if( p_intf->p_sys->p_input )
1120 /* Update stream date */
1121 char psz_time[ MSTRTIME_MAX_SIZE ], psz_total[ MSTRTIME_MAX_SIZE ];
1124 i_seconds = var_GetTime( p_intf->p_sys->p_input, "length" ) /
1126 secstotimestr( psz_total, i_seconds );
1128 i_seconds = var_GetTime( p_intf->p_sys->p_input, "time" ) /
1130 secstotimestr( psz_time, i_seconds );
1132 statusbar->SetStatusText( wxU(psz_time) + wxString(wxT(" / ") ) +
1133 wxU(psz_total), 0 );
1139 vlc_mutex_unlock( &p_intf->change_lock );
1142 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
1147 void Interface::PrevStream()
1149 playlist_t * p_playlist =
1150 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1152 if( p_playlist == NULL )
1157 playlist_Prev( p_playlist );
1158 vlc_object_release( p_playlist );
1161 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1166 void Interface::NextStream()
1168 playlist_t * p_playlist =
1169 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1171 if( p_playlist == NULL )
1175 playlist_Next( p_playlist );
1176 vlc_object_release( p_playlist );
1179 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1181 input_thread_t *p_input =
1182 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1186 vlc_value_t val; val.b_bool = VLC_TRUE;
1188 var_Set( p_input, "rate-slower", val );
1189 vlc_object_release( p_input );
1193 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1195 input_thread_t *p_input =
1196 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1200 vlc_value_t val; val.b_bool = VLC_TRUE;
1202 var_Set( p_input, "rate-faster", val );
1203 vlc_object_release( p_input );
1207 void Interface::TogglePlayButton( int i_playing_status )
1209 if( i_playing_status == i_old_playing_status )
1212 wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
1213 GetToolBar()->GetToolClientData( PlayStream_Event );
1214 if( !p_tool ) return;
1216 if( i_playing_status == PLAYING_S )
1218 p_tool->SetNormalBitmap( wxBitmap( pause_xpm ) );
1219 p_tool->SetLabel( wxU(_("Pause")) );
1220 p_tool->SetShortHelp( wxU(_(HELP_PAUSE)) );
1224 p_tool->SetNormalBitmap( wxBitmap( play_xpm ) );
1225 p_tool->SetLabel( wxU(_("Play")) );
1226 p_tool->SetShortHelp( wxU(_(HELP_PLAY)) );
1229 GetToolBar()->Realize();
1230 GetToolBar()->ToggleTool( PlayStream_Event, true );
1231 GetToolBar()->ToggleTool( PlayStream_Event, false );
1233 i_old_playing_status = i_playing_status;
1236 void Interface::OnDiscMenu( wxCommandEvent& WXUNUSED(event) )
1238 input_thread_t *p_input =
1239 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1243 vlc_value_t val; val.i_int = 2;
1245 var_Set( p_input, "title 0", val);
1246 vlc_object_release( p_input );
1250 void Interface::OnDiscPrev( wxCommandEvent& WXUNUSED(event) )
1252 input_thread_t *p_input =
1253 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1257 int i_type = var_Type( p_input, "prev-chapter" );
1258 vlc_value_t val; val.b_bool = VLC_TRUE;
1260 var_Set( p_input, ( i_type & VLC_VAR_TYPE ) != 0 ?
1261 "prev-chapter" : "prev-title", val );
1263 vlc_object_release( p_input );
1267 void Interface::OnDiscNext( wxCommandEvent& WXUNUSED(event) )
1269 input_thread_t *p_input =
1270 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1274 int i_type = var_Type( p_input, "next-chapter" );
1275 vlc_value_t val; val.b_bool = VLC_TRUE;
1277 var_Set( p_input, ( i_type & VLC_VAR_TYPE ) != 0 ?
1278 "next-chapter" : "next-title", val );
1280 vlc_object_release( p_input );
1284 #if wxUSE_DRAG_AND_DROP
1285 /*****************************************************************************
1286 * Definition of DragAndDrop class.
1287 *****************************************************************************/
1288 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
1291 b_enqueue = _b_enqueue;
1294 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1295 const wxArrayString& filenames )
1297 /* Add dropped files to the playlist */
1299 playlist_t *p_playlist =
1300 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1302 if( p_playlist == NULL )
1307 for( size_t i = 0; i < filenames.GetCount(); i++ )
1309 char *psz_utf8 = wxFromLocale( filenames[i] );
1311 playlist_Add( p_playlist, psz_utf8, psz_utf8,
1312 PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
1314 wxLocaleFree( psz_utf8 );
1317 vlc_object_release( p_playlist );
1323 /*****************************************************************************
1324 * Definition of VolCtrl class.
1325 *****************************************************************************/
1326 class wxVolCtrl: public wxGauge
1330 wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1331 wxPoint = wxDefaultPosition, wxSize = wxSize( 20, -1 ) );
1332 virtual ~wxVolCtrl() {};
1334 void UpdateVolume();
1337 void OnChange( wxMouseEvent& event );
1340 intf_thread_t *p_intf;
1342 DECLARE_EVENT_TABLE();
1345 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
1347 EVT_LEFT_DOWN(wxVolCtrl::OnChange)
1348 EVT_MOTION(wxVolCtrl::OnChange)
1351 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1352 wxPoint point, wxSize size )
1353 : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
1359 void wxVolCtrl::OnChange( wxMouseEvent& event )
1361 if( !event.LeftDown() && !event.LeftIsDown() ) return;
1363 int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
1364 aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1368 void wxVolCtrl::UpdateVolume()
1370 audio_volume_t i_volume;
1371 aout_VolumeGet( p_intf, &i_volume );
1373 int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
1374 if( i_gauge_volume == GetValue() ) return;
1376 SetValue( i_gauge_volume );
1377 SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
1378 i_gauge_volume / 2 ) );
1381 #if defined(__WXGTK__)
1382 #define VLCVOL_HEIGHT p_parent->GetSize().GetHeight()
1384 #define VLCVOL_HEIGHT TOOLBAR_BMP_HEIGHT
1386 VLCVolCtrl::VLCVolCtrl( intf_thread_t *_p_intf, wxWindow *p_parent )
1387 :wxControl( p_parent, -1, wxDefaultPosition, wxSize(64, VLCVOL_HEIGHT ),
1389 i_y_offset((VLCVOL_HEIGHT - TOOLBAR_BMP_HEIGHT) / 2),
1390 b_mute(0), p_intf(_p_intf)
1392 gauge = new wxVolCtrl( p_intf, this, -1, wxPoint( 18, i_y_offset ),
1393 wxSize( 44, TOOLBAR_BMP_HEIGHT ) );
1396 void VLCVolCtrl::OnPaint( wxPaintEvent &evt )
1398 wxPaintDC dc( this );
1399 wxBitmap mPlayBitmap( b_mute ? speaker_mute_xpm : speaker_xpm );
1400 dc.DrawBitmap( mPlayBitmap, 0, i_y_offset, TRUE );
1403 void VLCVolCtrl::OnChange( wxMouseEvent& event )
1405 if( event.GetX() < TOOLBAR_BMP_WIDTH )
1408 aout_VolumeMute( p_intf, (audio_volume_t *)&i_volume );
1415 void VLCVolCtrl::UpdateVolume()
1417 gauge->UpdateVolume();
1419 int i_volume = gauge->GetValue();
1420 if( !!i_volume == !b_mute ) return;
1425 /*****************************************************************************
1427 *****************************************************************************/
1429 #ifdef wxHAS_TASK_BAR_ICON
1431 BEGIN_EVENT_TABLE(Systray, wxTaskBarIcon)
1434 EVT_TASKBAR_LEFT_DCLICK(Systray::OnLeftClick)
1436 EVT_TASKBAR_LEFT_DOWN(Systray::OnLeftClick)
1439 EVT_MENU(Iconize_Event, Systray::OnMenuIconize)
1440 EVT_MENU(Exit_Event, Systray::OnExit)
1441 EVT_MENU(PlayStream_Event, Systray::OnPlayStream)
1442 EVT_MENU(NextStream_Event, Systray::OnNextStream)
1443 EVT_MENU(PrevStream_Event, Systray::OnPrevStream)
1444 EVT_MENU(StopStream_Event, Systray::OnStopStream)
1447 Systray::Systray( Interface *_p_main_interface, intf_thread_t *_p_intf )
1449 p_main_interface = _p_main_interface;
1453 /* Event handlers */
1454 void Systray::OnMenuIconize( wxCommandEvent& event )
1456 p_main_interface->Show( ! p_main_interface->IsShown() );
1457 if ( p_main_interface->IsShown() ) p_main_interface->Raise();
1460 void Systray::OnLeftClick( wxTaskBarIconEvent& event )
1462 wxCommandEvent cevent;
1463 OnMenuIconize(cevent);
1466 void Systray::OnExit( wxCommandEvent& event )
1468 p_main_interface->Close(TRUE);
1471 void Systray::OnPrevStream( wxCommandEvent& event )
1473 p_main_interface->PrevStream();
1476 void Systray::OnNextStream( wxCommandEvent& event )
1478 p_main_interface->NextStream();
1481 void Systray::OnPlayStream( wxCommandEvent& event )
1483 p_main_interface->PlayStream();
1486 void Systray::OnStopStream( wxCommandEvent& event )
1488 p_main_interface->StopStream();
1491 /* Systray popup menu */
1492 wxMenu* Systray::CreatePopupMenu()
1494 int minimal = config_GetInt( p_intf, "wx-minimal" );
1496 wxMenu* systray_menu = new wxMenu;
1497 systray_menu->Append( Exit_Event, wxU(_("Quit VLC")) );
1498 systray_menu->AppendSeparator();
1499 systray_menu->Append( PlayStream_Event, wxU(_("Play/Pause")) );
1503 systray_menu->Append( PrevStream_Event, wxU(_("Previous")) );
1504 systray_menu->Append( NextStream_Event, wxU(_("Next")) );
1505 systray_menu->Append( StopStream_Event, wxU(_("Stop")) );
1507 systray_menu->AppendSeparator();
1508 systray_menu->Append( Iconize_Event, wxU(_("Show/Hide interface")) );
1509 return systray_menu;
1512 void Systray::UpdateTooltip( const wxChar* tooltip )
1514 SetIcon( wxIcon( vlc16x16_xpm ), tooltip );