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 "playlist_manager.hpp"
29 #include "extrapanel.hpp"
39 #include <wx/splitter.h>
41 /* include the toolbar graphics */
42 #include "bitmaps/play.xpm"
43 #include "bitmaps/pause.xpm"
44 #include "bitmaps/stop.xpm"
45 #include "bitmaps/prev.xpm"
46 #include "bitmaps/next.xpm"
47 #include "bitmaps/eject.xpm"
48 #include "bitmaps/slow.xpm"
49 #include "bitmaps/fast.xpm"
50 #include "bitmaps/playlist.xpm"
51 #include "bitmaps/playlist_small.xpm"
52 #include "bitmaps/speaker.xpm"
53 #include "bitmaps/speaker_mute.xpm"
55 #define TOOLBAR_BMP_WIDTH 16
56 #define TOOLBAR_BMP_HEIGHT 16
58 /* include the icon graphic */
59 #include "../../../share/vlc32x32.xpm"
60 /* include a small icon graphic for the systray icon */
61 #ifdef wxHAS_TASK_BAR_ICON
62 #include "../../../share/vlc16x16.xpm"
65 /*****************************************************************************
66 * Local class declarations.
67 *****************************************************************************/
68 class wxMenuExt: public wxMenu
72 wxMenuExt( wxMenu* parentMenu, int id, const wxString& text,
73 const wxString& helpString, wxItemKind kind,
74 char *_psz_var, int _i_object_id, vlc_value_t _val,
77 virtual ~wxMenuExt() {};
89 class VLCVolCtrl : public wxControl
92 VLCVolCtrl( intf_thread_t *p_intf, wxWindow *p_parent );
93 virtual ~VLCVolCtrl() {};
95 virtual void OnPaint( wxPaintEvent &event );
96 void OnChange( wxMouseEvent& event );
100 DECLARE_EVENT_TABLE()
105 intf_thread_t *p_intf;
108 BEGIN_EVENT_TABLE(VLCVolCtrl, wxControl)
109 EVT_PAINT(VLCVolCtrl::OnPaint)
112 EVT_LEFT_UP(VLCVolCtrl::OnChange)
115 class Splitter : public wxSplitterWindow
118 Splitter( wxWindow *p_parent, intf_thread_t *_p_intf )
119 : wxSplitterWindow( p_parent, -1, wxDefaultPosition, wxSize(0,0),
120 #if defined( __WXMSW__ )
123 wxCLIP_CHILDREN | wxSP_3DSASH ),
125 p_intf(_p_intf), i_sash_position(150), i_width(-1),
126 b_video(0), i_delay(0)
131 virtual ~Splitter() {};
133 virtual bool Split( wxWindow* window1, wxWindow* window2 )
136 wxSize size = wxSize( i_width, i_sash_position );
137 if( window2->GetSizer() ) window2->GetSizer()->SetMinSize( size );
139 return wxSplitterWindow::SplitHorizontally( window1, window2,
143 virtual bool Unsplit( wxWindow* window )
146 return wxSplitterWindow::Unsplit( window );
150 DECLARE_EVENT_TABLE()
152 void OnSize( wxSizeEvent &event )
154 /* If we display video, then resize the video window */
156 p_intf->p_sys->p_video_window && p_intf->p_sys->p_video_sizer &&
157 p_intf->p_sys->p_video_sizer->GetMinSize() != wxSize(0,0) )
159 if( !b_video ) i_delay = mdate() + 1000000;
164 #if defined( __WXMSW__ )
165 SetSashPosition( event.GetSize().GetHeight() - i_sash_position );
167 SetSashPosition( event.GetSize().GetHeight() -
168 i_sash_position - GetSashSize() );
171 else if( GetWindow2() && GetWindow1() && GetWindow1()->GetSizer() )
173 wxSize size = GetWindow1()->GetSizer()->GetMinSize();
175 if( b_video ) i_delay = mdate() + 1000000;
178 if( event.GetSize().GetHeight() - size.GetHeight() )
182 SetSashPosition( size.GetHeight() ? size.GetHeight() : 1 );
184 if( i_delay < mdate() )
186 i_sash_position = event.GetSize().GetHeight() -
188 i_width = event.GetSize().GetWidth();
190 size = wxSize( i_width, i_sash_position );
191 if( GetWindow2()->GetSizer() )
192 GetWindow2()->GetSizer()->SetMinSize( size );
200 void OnSashPosChanged( wxSplitterEvent &event )
202 if( !GetSize().GetHeight() ){ event.Skip(); return; }
204 if( i_delay < mdate() )
206 i_sash_position = GetSize().GetHeight() - event.GetSashPosition();
208 wxSize size = wxSize( i_width, i_sash_position );
209 if( GetWindow2()->GetSizer() )
210 GetWindow2()->GetSizer()->SetMinSize( size );
215 intf_thread_t *p_intf;
222 BEGIN_EVENT_TABLE(Splitter, wxSplitterWindow)
223 EVT_SIZE( Splitter::OnSize )
224 EVT_SPLITTER_SASH_POS_CHANGED(-1, Splitter::OnSashPosChanged)
227 /*****************************************************************************
229 *****************************************************************************/
231 DEFINE_LOCAL_EVENT_TYPE( wxEVT_INTF );
233 /* IDs for the controls and the menu commands */
237 MenuDummy_Event = wxID_HIGHEST + 1000,
238 Exit_Event = wxID_HIGHEST,
239 OpenFileSimple_Event,
269 /* it is important for the id corresponding to the "About" command to have
270 * this standard value as otherwise it won't be handled properly under Mac
271 * (where it is special and put into the "Apple" menu) */
272 About_Event = wxID_ABOUT,
279 BEGIN_EVENT_TABLE(Interface, wxFrame)
281 EVT_MENU(Exit_Event, Interface::OnExit)
282 EVT_MENU(About_Event, Interface::OnAbout)
283 EVT_MENU(UpdateVLC_Event, Interface::OnShowDialog)
284 EVT_MENU(VLM_Event, Interface::OnShowDialog)
286 EVT_MENU(Playlist_Event, Interface::OnShowDialog)
287 EVT_MENU(PlaylistSmall_Event, Interface::OnSmallPlaylist)
288 EVT_MENU(Logs_Event, Interface::OnShowDialog)
289 EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
290 EVT_MENU(Prefs_Event, Interface::OnShowDialog)
292 EVT_MENU_OPEN(Interface::OnMenuOpen)
294 EVT_MENU( Extended_Event, Interface::OnExtended )
296 EVT_MENU( Bookmarks_Event, Interface::OnShowDialog)
298 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
299 EVT_CONTEXT_MENU(Interface::OnContextMenu2)
301 EVT_RIGHT_UP(Interface::OnContextMenu)
304 EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
305 EVT_MENU(OpenAdv_Event, Interface::OnShowDialog)
306 EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
307 EVT_MENU(OpenDir_Event, Interface::OnShowDialog)
308 EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
309 EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
310 EVT_MENU(OpenCapture_Event, Interface::OnShowDialog)
311 EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
312 EVT_MENU(Wizard_Event, Interface::OnShowDialog)
313 EVT_MENU(StopStream_Event, Interface::OnStopStream)
314 EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
315 EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
316 EVT_MENU(NextStream_Event, Interface::OnNextStream)
317 EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
318 EVT_MENU(FastStream_Event, Interface::OnFastStream)
321 EVT_COMMAND(0, wxEVT_INTF, Interface::OnControlEvent)
322 EVT_COMMAND(1, wxEVT_INTF, Interface::OnControlEvent)
325 /*****************************************************************************
327 *****************************************************************************/
328 Interface::Interface( intf_thread_t *_p_intf, long style ):
329 wxFrame( NULL, -1, wxT("VLC media player"),
330 wxDefaultPosition, wxSize(700,100), style )
332 /* Initializations */
336 playlist_manager = 0;
338 /* Give our interface a nice little icon */
339 SetIcon( wxIcon( vlc_xpm ) );
341 /* Create a splitter window that will fill in the interface window.
342 * We need a splitter bar in order to make the embedded playlist
344 splitter = new Splitter( this, p_intf );
345 main_sizer = new wxBoxSizer( wxVERTICAL );
346 main_sizer->Add( splitter, 1, wxEXPAND );
347 SetSizer( main_sizer );
349 /* Create a main panel that will fill in the interface window */
350 main_panel = new wxPanel( splitter, -1, wxPoint(0,0), wxSize(0,0),
352 main_panel->SetFocus();
354 #if defined(__WXGTK20__) && wxCHECK_VERSION(2,5,6)
355 /* As ugly as your butt! Please remove when wxWidgets 2.6 fixed their
356 * Accelerators bug. */
357 main_panel->m_imData = 0;
361 /* Create a sizer for the main frame */
362 panel_sizer = new wxBoxSizer( wxVERTICAL );
363 main_panel->SetSizer( panel_sizer );
365 /* Put this in the splitter */
366 splitter->Initialize( main_panel );
368 #ifdef wxHAS_TASK_BAR_ICON
369 /* Systray integration */
371 if( config_GetInt( p_intf, "wx-systray" ) )
373 p_systray = new Systray( this, p_intf );
377 /* Creation of the menu bar */
380 /* Creation of the tool bar */
383 /* Creation of the status bar
384 * Helptext for menu items and toolbar tools will automatically get
386 int i_status_width[3] = {100, 40, -1};
387 statusbar = CreateStatusBar( 3 ); /* 2 fields */
388 statusbar->SetStatusWidths( 3, i_status_width );
389 statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
391 /* Get minimum window size to prevent user from glitching it */
392 splitter->SetSizeHints( -1, 0 );
393 panel_sizer->Layout(); panel_sizer->Fit( main_panel );
394 main_sizer->Layout(); main_sizer->Fit( this );
395 main_min_size = GetSize();
396 splitter->SetSizeHints( -1, -1 );
400 if( config_GetInt( p_intf, "wx-embed" ) )
402 video_window = CreateVideoWindow( p_intf, main_panel );
403 panel_sizer->Add( p_intf->p_sys->p_video_sizer, 1, wxEXPAND, 0 );
406 /* Creation of the input manager panel */
407 input_manager = new InputManager( p_intf, this, main_panel );
408 panel_sizer->Add( input_manager, 0, wxEXPAND , 0 );
410 /* Layout everything */
411 splitter->SetSizeHints( -1, 0 );
412 panel_sizer->Layout(); panel_sizer->Fit( main_panel );
413 main_sizer->Layout(); main_sizer->Fit( this );
414 splitter->SetSizeHints( -1, -1 );
416 #if wxUSE_DRAG_AND_DROP
417 /* Associate drop targets with the main interface */
418 SetDropTarget( new DragAndDrop( p_intf ) );
424 timer = new Timer( p_intf, this );
426 /* Restore previous position / settings */
427 WindowSettings *ws = p_intf->p_sys->p_window_settings;
432 ws->SetScreen( wxSystemSettings::GetMetric( wxSYS_SCREEN_X ),
433 wxSystemSettings::GetMetric( wxSYS_SCREEN_Y ) );
435 if( ws->GetSettings( WindowSettings::ID_MAIN, b_shown, p, s ) ) Move( p );
437 /* Show extended GUI if requested */
438 wxCommandEvent dummy;
439 if( config_GetInt( p_intf, "wx-extended" ) ) OnExtended( dummy );
444 Interface::~Interface()
446 WindowSettings *ws = p_intf->p_sys->p_window_settings;
450 ws->SetSettings( WindowSettings::ID_MAIN, true,
451 GetPosition(), GetSize() );
454 PopEventHandler(true);
456 if( video_window ) delete video_window;
458 #ifdef wxHAS_TASK_BAR_ICON
459 if( p_systray ) delete p_systray;
462 if( p_intf->p_sys->p_wxwindow ) delete p_intf->p_sys->p_wxwindow;
468 void Interface::Init()
474 void Interface::Update()
477 ((VLCVolCtrl *)volctrl)->UpdateVolume();
479 if( playlist_manager ) playlist_manager->Update();
482 void Interface::OnControlEvent( wxCommandEvent& event )
484 switch( event.GetId() )
487 main_sizer->Layout();
488 main_sizer->Fit( this );
492 long i_style = GetWindowStyle();
493 if( event.GetInt() ) i_style |= wxSTAY_ON_TOP;
494 else i_style &= ~wxSTAY_ON_TOP;
495 SetWindowStyle( i_style );
500 /*****************************************************************************
502 *****************************************************************************/
503 void Interface::CreateOurMenuBar()
505 int minimal = config_GetInt( p_intf, "wx-minimal" );
507 /* Create the "File" menu */
508 wxMenu *file_menu = new wxMenu;
512 file_menu->Append( OpenFileSimple_Event,
513 wxU(_("Quick &Open File...\tCtrl-O")) );
515 file_menu->AppendSeparator();
516 file_menu->Append( OpenFile_Event, wxU(_("Open &File...\tCtrl-F")) );
517 file_menu->Append( OpenDir_Event, wxU(_("Open Dir&ectory...\tCtrl-E")) );
518 file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...\tCtrl-D")) );
519 file_menu->Append( OpenNet_Event,
520 wxU(_("Open &Network Stream...\tCtrl-N")) );
521 file_menu->Append( OpenCapture_Event,
522 wxU(_("Open C&apture Device...\tCtrl-A")) );
524 file_menu->AppendSeparator();
525 file_menu->Append( Wizard_Event, wxU(_("&Wizard...\tCtrl-W")) );
526 file_menu->AppendSeparator();
528 file_menu->Append( Exit_Event, wxU(_("E&xit\tCtrl-X")) );
530 /* Create the "View" menu */
531 wxMenu *view_menu = new wxMenu;
534 view_menu->Append( Playlist_Event, wxU(_("&Playlist...\tCtrl-P")) );
536 view_menu->Append( Logs_Event, wxU(_("&Messages...\tCtrl-M")) );
537 view_menu->Append( FileInfo_Event,
538 wxU(_("Stream and Media &info...\tCtrl-I")) );
539 view_menu->Append( VLM_Event,
540 wxU(_("VLM Control...\tCtrl-V")) );
542 /* Create the "Auto-generated" menus */
543 p_settings_menu = SettingsMenu( p_intf, this );
544 p_audio_menu = AudioMenu( p_intf, this );
545 p_video_menu = VideoMenu( p_intf, this );
546 p_navig_menu = NavigMenu( p_intf, this );
548 /* Create the "Help" menu */
549 wxMenu *help_menu = new wxMenu;
550 help_menu->Append( About_Event, wxU(_("About VLC media player")) );
551 help_menu->AppendSeparator();
552 help_menu->Append( UpdateVLC_Event, wxU(_("Check for updates ...")) );
554 /* Append the freshly created menus to the menu bar... */
555 wxMenuBar *menubar = new wxMenuBar();
556 menubar->Append( file_menu, wxU(_("&File")) );
557 menubar->Append( view_menu, wxU(_("&View")) );
558 menubar->Append( p_settings_menu, wxU(_("&Settings")) );
559 menubar->Append( p_audio_menu, wxU(_("&Audio")) );
560 menubar->Append( p_video_menu, wxU(_("&Video")) );
561 menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
562 menubar->Append( help_menu, wxU(_("&Help")) );
564 /* Attach the menu bar to the frame */
565 SetMenuBar( menubar );
567 /* Find out size of menu bar */
569 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
571 int i_width, i_height;
572 menubar->GetTextExtent( menubar->GetLabelTop(i), &i_width, &i_height );
574 #if defined(__WXGTK__)
575 22 /* approximate margin */;
577 #if (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 5) && (wxRELEASE_NUMBER < 3)
578 4 /* approximate margin */;
580 18 /* approximate margin */;
585 /* Patch by zcot for menu wrapping */
587 /* Find out size of msw menu bar */
590 HDC hdc = GetDC( NULL );
591 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
593 GetTextExtentPoint32( hdc, menubar->GetLabelTop(i).c_str(),
594 menubar->GetLabelTop(i).Length(), &sizing );
596 // [ SM_CXDLGFRAME + pixels + textextent + pixels + SM_CXDLGFRAME ]
597 i_size += sizing.cx + 2 + GetSystemMetrics( SM_CXDLGFRAME ) * 2;
599 ReleaseDC( NULL, hdc );
600 i_size += GetSystemMetrics( SM_CXSIZEFRAME ) * 2 + 4;
602 /* End patch by zcot */
604 panel_sizer->SetMinSize( i_size, -1 );
606 /* Intercept all menu events in our custom event handler */
607 PushEventHandler( new MenuEvtHandler( p_intf, this ) );
609 #if wxUSE_DRAG_AND_DROP
610 /* Associate drop targets with the menubar */
611 menubar->SetDropTarget( new DragAndDrop( p_intf ) );
615 void Interface::CreateOurToolBar()
617 #define HELP_OPEN N_("Open")
618 #define HELP_STOP N_("Stop")
619 #define HELP_PLAY N_("Play")
620 #define HELP_PAUSE N_("Pause")
621 #define HELP_PLO N_("Playlist")
622 #define HELP_SPLO N_("Small playlist")
623 #define HELP_PLP N_("Previous playlist item")
624 #define HELP_PLN N_("Next playlist item")
625 #define HELP_SLOW N_("Play slower")
626 #define HELP_FAST N_("Play faster")
628 int minimal = config_GetInt( p_intf, "wx-minimal" );
630 wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
631 * version because we don't include wx.rc */
634 CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
636 toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
640 toolbar->AddTool( OpenFile_Event, wxT(""),
641 wxBitmap( eject_xpm ), wxU(_(HELP_OPEN)) );
642 toolbar->AddSeparator();
645 wxToolBarToolBase *p_tool = toolbar->AddTool( PlayStream_Event, wxT(""),
646 wxBitmap( play_xpm ), wxU(_(HELP_PLAY)), wxITEM_CHECK );
647 p_tool->SetClientData( p_tool );
651 toolbar->AddTool( StopStream_Event, wxT(""), wxBitmap( stop_xpm ),
653 toolbar->AddSeparator();
655 toolbar->AddTool( PrevStream_Event, wxT(""),
656 wxBitmap( prev_xpm ), wxU(_(HELP_PLP)) );
657 toolbar->AddTool( SlowStream_Event, wxT(""),
658 wxBitmap( slow_xpm ), wxU(_(HELP_SLOW)) );
659 toolbar->AddTool( FastStream_Event, wxT(""),
660 wxBitmap( fast_xpm ), wxU(_(HELP_FAST)) );
661 toolbar->AddTool( NextStream_Event, wxT(""), wxBitmap( next_xpm ),
663 toolbar->AddSeparator();
664 toolbar->AddTool( Playlist_Event, wxT(""), wxBitmap( playlist_xpm ),
666 toolbar->AddTool( PlaylistSmall_Event, wxT(""),
667 wxBitmap( playlist_small_xpm ), wxU(_(HELP_SPLO)) );
670 wxControl *p_dummy_ctrl =
671 new wxControl( toolbar, -1, wxDefaultPosition,
672 wxSize(16, 16 ), wxBORDER_NONE );
674 toolbar->AddControl( p_dummy_ctrl );
676 volctrl = new VLCVolCtrl( p_intf, toolbar );
677 toolbar->AddControl( volctrl );
681 #if wxUSE_DRAG_AND_DROP
682 /* Associate drop targets with the toolbar */
683 toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
687 static int ConvertHotkeyModifiers( int i_hotkey )
689 int i_accel_flags = 0;
690 if( i_hotkey & KEY_MODIFIER_ALT ) i_accel_flags |= wxACCEL_ALT;
691 if( i_hotkey & KEY_MODIFIER_CTRL ) i_accel_flags |= wxACCEL_CTRL;
692 if( i_hotkey & KEY_MODIFIER_SHIFT ) i_accel_flags |= wxACCEL_SHIFT;
693 if( !i_accel_flags ) i_accel_flags = wxACCEL_NORMAL;
694 return i_accel_flags;
697 static int ConvertHotkey( int i_hotkey )
699 int i_key = i_hotkey & ~KEY_MODIFIER;
700 if( i_key & KEY_ASCII ) return i_key & KEY_ASCII;
701 else if( i_key & KEY_SPECIAL )
705 case KEY_LEFT: return WXK_LEFT;
706 case KEY_RIGHT: return WXK_RIGHT;
707 case KEY_UP: return WXK_UP;
708 case KEY_DOWN: return WXK_DOWN;
709 case KEY_SPACE: return WXK_SPACE;
710 case KEY_ENTER: return WXK_RETURN;
711 case KEY_F1: return WXK_F1;
712 case KEY_F2: return WXK_F2;
713 case KEY_F3: return WXK_F3;
714 case KEY_F4: return WXK_F4;
715 case KEY_F5: return WXK_F5;
716 case KEY_F6: return WXK_F6;
717 case KEY_F7: return WXK_F7;
718 case KEY_F8: return WXK_F8;
719 case KEY_F9: return WXK_F9;
720 case KEY_F10: return WXK_F10;
721 case KEY_F11: return WXK_F11;
722 case KEY_F12: return WXK_F12;
723 case KEY_HOME: return WXK_HOME;
724 case KEY_END: return WXK_END;
725 case KEY_INSERT: return WXK_INSERT;
726 case KEY_DELETE: return WXK_DELETE;
727 case KEY_MENU: return WXK_MENU;
728 case KEY_ESC: return WXK_ESCAPE;
729 case KEY_PAGEUP: return WXK_PRIOR;
730 case KEY_PAGEDOWN: return WXK_NEXT;
731 case KEY_TAB: return WXK_TAB;
732 case KEY_BACKSPACE: return WXK_BACK;
738 void Interface::SetupHotkeys()
740 struct vlc_t::hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
743 /* Count number of hoteys */
744 for( i_hotkeys = 0; p_hotkeys[i_hotkeys].psz_action != NULL; i_hotkeys++ );
746 p_intf->p_sys->i_first_hotkey_event = wxID_HIGHEST + 7000;
747 p_intf->p_sys->i_hotkeys = i_hotkeys;
749 wxAcceleratorEntry *p_entries = new wxAcceleratorEntry[i_hotkeys];
751 /* Setup the hotkeys as accelerators */
752 for( int i = 0; i < i_hotkeys; i++ )
754 int i_mod = ConvertHotkeyModifiers( p_hotkeys[i].i_key );
755 int i_key = ConvertHotkey( p_hotkeys[i].i_key );
758 if( !(p_hotkeys[i].i_key & KEY_SPECIAL) && i_mod )
759 i_key = toupper(i_key);
762 p_entries[i].Set( i_mod, i_key,
763 p_intf->p_sys->i_first_hotkey_event + i );
766 wxAcceleratorTable accel( i_hotkeys, p_entries );
770 msg_Err( p_intf, "invalid accelerator table" );
774 SetAcceleratorTable( accel );
780 void Interface::SetIntfMinSize()
782 wxSize ms = main_min_size;
784 if( extra_frame && extra_frame->IsShown() )
786 ms.SetHeight( ms.GetHeight() + ext_min_size.GetHeight() );
787 if( ext_min_size.GetWidth() > ms.GetWidth() )
788 ms.SetWidth( ext_min_size.GetWidth() );
791 SetSizeHints( ms.GetWidth(), ms.GetHeight() );
794 /*****************************************************************************
796 *****************************************************************************/
797 void Interface::OnMenuOpen( wxMenuEvent& event )
799 #if defined( __WXMSW__ )
800 # define GetEventObject GetMenu
803 if( event.GetEventObject() == p_settings_menu )
805 p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );
807 /* Add static items */
808 p_settings_menu->AppendCheckItem( Extended_Event,
809 wxU(_("Extended &GUI\tCtrl-G") ) );
810 if( b_extra ) p_settings_menu->Check( Extended_Event, TRUE );
811 p_settings_menu->Append( Bookmarks_Event,
812 wxU(_("&Bookmarks...\tCtrl-B") ) );
813 p_settings_menu->Append( Prefs_Event,
814 wxU(_("Preference&s...\tCtrl-S")) );
817 else if( event.GetEventObject() == p_audio_menu )
819 p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
822 else if( event.GetEventObject() == p_video_menu )
824 p_video_menu = VideoMenu( p_intf, this, p_video_menu );
827 else if( event.GetEventObject() == p_navig_menu )
829 p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
832 #if defined( __WXMSW__ )
833 # undef GetEventObject
837 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
838 void Interface::OnContextMenu2(wxContextMenuEvent& event)
840 /* Only show the context menu for the main interface */
841 if( GetId() != event.GetId() )
847 if( p_intf->p_sys->pf_show_dialog )
848 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
851 void Interface::OnContextMenu(wxMouseEvent& event)
853 if( p_intf->p_sys->pf_show_dialog )
854 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
857 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
859 /* TRUE is to force the frame to close. */
863 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
866 msg.Printf( wxString(wxT("VLC media player " PACKAGE_VERSION)) +
867 wxU(_(" (wxWidgets interface)\n\n")) +
868 wxU(_("(c) 1996-2005 - the VideoLAN Team\n\n")) +
869 wxU(_("Compiled by "))+ wxU(VLC_CompileBy())+ wxU("@") +
870 wxU(VLC_CompileHost())+ wxT(".")+ wxU(VLC_CompileDomain())+ wxT(".\n") +
871 wxU(_("Compiler: "))+ wxU(VLC_Compiler())+wxT( ".\n") +
872 wxU(_("Based on SVN revision: "))+wxU(VLC_Changeset())+wxT(".\n\n") +
874 wxU( vlc_wraptext(LICENSE_MSG,WRAPCOUNT,VLC_TRUE) ) + wxT("\n\n") +
876 wxU( LICENSE_MSG ) + wxT("\n\n") +
878 wxU(_("The VideoLAN team <videolan@videolan.org>\n"
879 "http://www.videolan.org/\n\n")) );
881 wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
882 wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
885 void Interface::OnShowDialog( wxCommandEvent& event )
887 if( p_intf->p_sys->pf_show_dialog )
891 switch( event.GetId() )
893 case OpenFileSimple_Event:
894 i_id = INTF_DIALOG_FILE_SIMPLE;
897 i_id = INTF_DIALOG_FILE;
900 i_id = INTF_DIALOG_FILE;
903 i_id = INTF_DIALOG_DIRECTORY;
906 i_id = INTF_DIALOG_DISC;
909 i_id = INTF_DIALOG_NET;
911 case OpenCapture_Event:
912 i_id = INTF_DIALOG_CAPTURE;
915 i_id = INTF_DIALOG_SAT;
918 i_id = INTF_DIALOG_PLAYLIST;
921 i_id = INTF_DIALOG_MESSAGES;
924 i_id = INTF_DIALOG_FILEINFO;
927 i_id = INTF_DIALOG_PREFS;
930 i_id = INTF_DIALOG_WIZARD;
932 case Bookmarks_Event:
933 i_id = INTF_DIALOG_BOOKMARKS;
935 case UpdateVLC_Event:
936 i_id = INTF_DIALOG_UPDATEVLC;
939 i_id = INTF_DIALOG_VLM;
942 i_id = INTF_DIALOG_FILE;
946 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
950 void Interface::OnExtended( wxCommandEvent& WXUNUSED(event) )
952 UpdateVideoWindow( p_intf, video_window );
956 /* Create the extra panel */
957 extra_frame = new ExtraPanel( p_intf, main_panel );
958 panel_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
959 ext_min_size = extra_frame->GetBestSize();
963 panel_sizer->Show( extra_frame, b_extra );
966 main_sizer->Layout();
967 main_sizer->Fit( this );
970 void Interface::OnSmallPlaylist( wxCommandEvent& WXUNUSED(event) )
972 UpdateVideoWindow( p_intf, video_window );
974 if( !playlist_manager )
976 /* Create the extra panel */
977 playlist_manager = new PlaylistManager( p_intf, splitter );
980 if( !splitter->IsSplit() ) splitter->Split( main_panel, playlist_manager );
981 else splitter->Unsplit( playlist_manager );
984 main_sizer->Layout();
985 main_sizer->Fit( this );
988 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
993 void Interface::PlayStream()
995 wxCommandEvent dummy;
996 playlist_t *p_playlist =
997 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
999 if( p_playlist == NULL ) return;
1001 if( p_playlist->i_size && p_playlist->i_enabled )
1005 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
1008 if( p_input == NULL )
1010 /* No stream was playing, start one */
1011 playlist_Play( p_playlist );
1012 vlc_object_release( p_playlist );
1013 input_manager->Update();
1017 var_Get( p_input, "state", &state );
1018 if( state.i_int != PAUSE_S )
1020 /* A stream is being played, pause it */
1021 state.i_int = PAUSE_S;
1025 /* Stream is paused, resume it */
1026 state.i_int = PLAYING_S;
1028 var_Set( p_input, "state", state );
1030 vlc_object_release( p_input );
1031 vlc_object_release( p_playlist );
1032 input_manager->Update();
1036 /* If the playlist is empty, open a file requester instead */
1037 vlc_object_release( p_playlist );
1038 OnShowDialog( dummy );
1042 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
1046 void Interface::StopStream()
1048 playlist_t * p_playlist =
1049 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1051 if( p_playlist == NULL )
1056 playlist_Stop( p_playlist );
1057 vlc_object_release( p_playlist );
1058 input_manager->Update();
1061 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
1066 void Interface::PrevStream()
1068 playlist_t * p_playlist =
1069 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1071 if( p_playlist == NULL )
1076 playlist_Prev( p_playlist );
1077 vlc_object_release( p_playlist );
1080 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1085 void Interface::NextStream()
1087 playlist_t * p_playlist =
1088 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1090 if( p_playlist == NULL )
1094 playlist_Next( p_playlist );
1095 vlc_object_release( p_playlist );
1098 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1100 input_thread_t *p_input =
1101 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1105 vlc_value_t val; val.b_bool = VLC_TRUE;
1107 var_Set( p_input, "rate-slower", val );
1108 vlc_object_release( p_input );
1112 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1114 input_thread_t *p_input =
1115 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1119 vlc_value_t val; val.b_bool = VLC_TRUE;
1121 var_Set( p_input, "rate-faster", val );
1122 vlc_object_release( p_input );
1126 void Interface::TogglePlayButton( int i_playing_status )
1128 wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
1129 GetToolBar()->GetToolClientData( PlayStream_Event );
1130 if( !p_tool ) return;
1132 if( i_playing_status == PLAYING_S )
1134 p_tool->SetNormalBitmap( wxBitmap( pause_xpm ) );
1135 p_tool->SetLabel( wxU(_("Pause")) );
1136 p_tool->SetShortHelp( wxU(_(HELP_PAUSE)) );
1140 p_tool->SetNormalBitmap( wxBitmap( play_xpm ) );
1141 p_tool->SetLabel( wxU(_("Play")) );
1142 p_tool->SetShortHelp( wxU(_(HELP_PLAY)) );
1145 GetToolBar()->Realize();
1147 #if defined( __WXMSW__ )
1148 /* Needed to work around a bug in wxToolBar::Realize() */
1149 GetToolBar()->SetSize( GetSize().GetWidth(),
1150 GetToolBar()->GetSize().GetHeight() );
1151 GetToolBar()->Update();
1154 GetToolBar()->ToggleTool( PlayStream_Event, true );
1155 GetToolBar()->ToggleTool( PlayStream_Event, false );
1158 #if wxUSE_DRAG_AND_DROP
1159 /*****************************************************************************
1160 * Definition of DragAndDrop class.
1161 *****************************************************************************/
1162 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
1165 b_enqueue = _b_enqueue;
1168 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1169 const wxArrayString& filenames )
1171 /* Add dropped files to the playlist */
1173 playlist_t *p_playlist =
1174 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1176 if( p_playlist == NULL )
1181 for( size_t i = 0; i < filenames.GetCount(); i++ )
1183 char *psz_utf8 = wxFromLocale( filenames[i] );
1185 playlist_Add( p_playlist, psz_utf8, psz_utf8,
1186 PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
1188 wxLocaleFree( psz_utf8 );
1191 vlc_object_release( p_playlist );
1197 /*****************************************************************************
1198 * Definition of VolCtrl class.
1199 *****************************************************************************/
1200 class wxVolCtrl: public wxGauge
1204 wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1205 wxPoint = wxDefaultPosition, wxSize = wxSize( 20, -1 ) );
1206 virtual ~wxVolCtrl() {};
1208 void UpdateVolume();
1211 void OnChange( wxMouseEvent& event );
1214 intf_thread_t *p_intf;
1216 DECLARE_EVENT_TABLE();
1219 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
1221 EVT_LEFT_DOWN(wxVolCtrl::OnChange)
1222 EVT_MOTION(wxVolCtrl::OnChange)
1225 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1226 wxPoint point, wxSize size )
1227 : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
1233 void wxVolCtrl::OnChange( wxMouseEvent& event )
1235 if( !event.LeftDown() && !event.LeftIsDown() ) return;
1237 int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
1238 aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1242 void wxVolCtrl::UpdateVolume()
1244 audio_volume_t i_volume;
1245 aout_VolumeGet( p_intf, &i_volume );
1247 int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
1248 if( i_gauge_volume == GetValue() ) return;
1250 SetValue( i_gauge_volume );
1251 SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
1252 i_gauge_volume / 2 ) );
1255 #if defined(__WXGTK__)
1256 #define VLCVOL_HEIGHT p_parent->GetSize().GetHeight()
1258 #define VLCVOL_HEIGHT TOOLBAR_BMP_HEIGHT
1260 VLCVolCtrl::VLCVolCtrl( intf_thread_t *_p_intf, wxWindow *p_parent )
1261 :wxControl( p_parent, -1, wxDefaultPosition, wxSize(64, VLCVOL_HEIGHT ),
1263 i_y_offset((VLCVOL_HEIGHT - TOOLBAR_BMP_HEIGHT) / 2),
1264 b_mute(0), p_intf(_p_intf)
1266 gauge = new wxVolCtrl( p_intf, this, -1, wxPoint( 18, i_y_offset ),
1267 wxSize( 44, TOOLBAR_BMP_HEIGHT ) );
1270 void VLCVolCtrl::OnPaint( wxPaintEvent &evt )
1272 wxPaintDC dc( this );
1273 wxBitmap mPlayBitmap( b_mute ? speaker_mute_xpm : speaker_xpm );
1274 dc.DrawBitmap( mPlayBitmap, 0, i_y_offset, TRUE );
1277 void VLCVolCtrl::OnChange( wxMouseEvent& event )
1279 if( event.GetX() < TOOLBAR_BMP_WIDTH )
1282 aout_VolumeMute( p_intf, (audio_volume_t *)&i_volume );
1289 void VLCVolCtrl::UpdateVolume()
1291 gauge->UpdateVolume();
1293 int i_volume = gauge->GetValue();
1294 if( !!i_volume == !b_mute ) return;
1299 /*****************************************************************************
1301 *****************************************************************************/
1303 #ifdef wxHAS_TASK_BAR_ICON
1305 BEGIN_EVENT_TABLE(Systray, wxTaskBarIcon)
1308 EVT_TASKBAR_LEFT_DCLICK(Systray::OnLeftClick)
1310 EVT_TASKBAR_LEFT_DOWN(Systray::OnLeftClick)
1313 EVT_MENU(Iconize_Event, Systray::OnMenuIconize)
1314 EVT_MENU(Exit_Event, Systray::OnExit)
1315 EVT_MENU(PlayStream_Event, Systray::OnPlayStream)
1316 EVT_MENU(NextStream_Event, Systray::OnNextStream)
1317 EVT_MENU(PrevStream_Event, Systray::OnPrevStream)
1318 EVT_MENU(StopStream_Event, Systray::OnStopStream)
1321 Systray::Systray( Interface *_p_main_interface, intf_thread_t *_p_intf )
1323 p_main_interface = _p_main_interface;
1326 SetIcon( wxIcon( vlc16x16_xpm ), wxT("VLC media player") );
1327 if( !IsOk() || !IsIconInstalled() )
1329 msg_Warn(p_intf, "cannot set systray icon, weird things may happen");
1333 /* Event handlers */
1334 void Systray::OnMenuIconize( wxCommandEvent& event )
1336 p_main_interface->Show( ! p_main_interface->IsShown() );
1337 if ( p_main_interface->IsShown() ) p_main_interface->Raise();
1340 void Systray::OnLeftClick( wxTaskBarIconEvent& event )
1342 wxCommandEvent cevent;
1343 OnMenuIconize(cevent);
1346 void Systray::OnExit( wxCommandEvent& event )
1348 p_main_interface->Close(TRUE);
1351 void Systray::OnPrevStream( wxCommandEvent& event )
1353 p_main_interface->PrevStream();
1356 void Systray::OnNextStream( wxCommandEvent& event )
1358 p_main_interface->NextStream();
1361 void Systray::OnPlayStream( wxCommandEvent& event )
1363 p_main_interface->PlayStream();
1366 void Systray::OnStopStream( wxCommandEvent& event )
1368 p_main_interface->StopStream();
1371 /* Systray popup menu */
1372 wxMenu* Systray::CreatePopupMenu()
1374 int minimal = config_GetInt( p_intf, "wx-minimal" );
1376 wxMenu* systray_menu = new wxMenu;
1377 systray_menu->Append( Exit_Event, wxU(_("Quit VLC")) );
1378 systray_menu->AppendSeparator();
1379 systray_menu->Append( PlayStream_Event, wxU(_("Play/Pause")) );
1383 systray_menu->Append( PrevStream_Event, wxU(_("Previous")) );
1384 systray_menu->Append( NextStream_Event, wxU(_("Next")) );
1385 systray_menu->Append( StopStream_Event, wxU(_("Stop")) );
1387 systray_menu->AppendSeparator();
1388 systray_menu->Append( Iconize_Event, wxU(_("Show/Hide interface")) );
1389 return systray_menu;
1392 void Systray::UpdateTooltip( const wxChar* tooltip )
1394 SetIcon( wxIcon( vlc16x16_xpm ), tooltip );