1 /*****************************************************************************
2 * interface.cpp : wxWidgets plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2006 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include "interface.hpp"
28 #include "playlist_manager.hpp"
29 #include "extrapanel.hpp"
39 #include <vlc_interaction.h>
41 #include <wx/splitter.h>
43 /* include the toolbar graphics */
44 #include "bitmaps/play.xpm"
45 #include "bitmaps/pause.xpm"
46 #include "bitmaps/stop.xpm"
47 #include "bitmaps/prev.xpm"
48 #include "bitmaps/next.xpm"
49 #include "bitmaps/eject.xpm"
50 #include "bitmaps/slow.xpm"
51 #include "bitmaps/fast.xpm"
52 #include "bitmaps/playlist.xpm"
53 #include "bitmaps/playlist_small.xpm"
54 #include "bitmaps/speaker.xpm"
55 #include "bitmaps/speaker_mute.xpm"
57 #define TOOLBAR_BMP_WIDTH 16
58 #define TOOLBAR_BMP_HEIGHT 16
60 /* include the icon graphic */
61 #include "../../../share/vlc32x32.xpm"
62 /* include a small icon graphic for the systray icon */
63 #ifdef wxHAS_TASK_BAR_ICON
64 #include "../../../share/vlc16x16.xpm"
67 /*****************************************************************************
69 *****************************************************************************/
70 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
73 /*****************************************************************************
74 * Local class declarations.
75 *****************************************************************************/
76 class wxMenuExt: public wxMenu
80 wxMenuExt( wxMenu* parentMenu, int id, const wxString& text,
81 const wxString& helpString, wxItemKind kind,
82 char *_psz_var, int _i_object_id, vlc_value_t _val,
85 virtual ~wxMenuExt() {};
97 class VLCVolCtrl : public wxControl
100 VLCVolCtrl( intf_thread_t *p_intf, wxWindow *p_parent );
101 virtual ~VLCVolCtrl() {};
103 virtual void OnPaint( wxPaintEvent &event );
104 void OnChange( wxMouseEvent& event );
108 DECLARE_EVENT_TABLE()
113 intf_thread_t *p_intf;
116 BEGIN_EVENT_TABLE(VLCVolCtrl, wxControl)
117 EVT_PAINT(VLCVolCtrl::OnPaint)
120 EVT_LEFT_UP(VLCVolCtrl::OnChange)
123 class Splitter : public wxSplitterWindow
126 Splitter( wxWindow *p_parent, intf_thread_t *_p_intf )
127 : wxSplitterWindow( p_parent, -1, wxDefaultPosition, wxSize(0,0),
128 #if defined( __WXMSW__ )
131 wxCLIP_CHILDREN | wxSP_3DSASH ),
133 p_intf(_p_intf), b_video(0), i_delay(0)
137 wxSize size = wxSize(-1, 150);
138 wxPoint p = wxPoint(0,0);
140 WindowSettings *ws = p_intf->p_sys->p_window_settings;
141 ws->GetSettings( WindowSettings::ID_SMALL_PLAYLIST, b_dummy, p, size );
143 i_width = size.GetWidth();
144 i_sash_position = size.GetHeight();
145 b_show_on_start = !!p.x;
150 WindowSettings *ws = p_intf->p_sys->p_window_settings;
151 ws->SetSettings( WindowSettings::ID_SMALL_PLAYLIST, true,
152 wxPoint(!!GetWindow2(),0),
153 wxSize(i_width, i_sash_position) );
156 virtual bool Split( wxWindow* window1, wxWindow* window2 )
159 wxSize size = wxSize( i_width, i_sash_position );
160 if( window2->GetSizer() ) window2->GetSizer()->SetMinSize( size );
162 return wxSplitterWindow::SplitHorizontally( window1, window2,
166 virtual bool Unsplit( wxWindow* window )
169 return wxSplitterWindow::Unsplit( window );
172 bool ShowOnStart() { return b_show_on_start; }
175 DECLARE_EVENT_TABLE()
177 void OnSize( wxSizeEvent &event )
179 /* If we display video, then resize the video window */
181 p_intf->p_sys->p_video_window && p_intf->p_sys->p_video_sizer &&
182 p_intf->p_sys->p_video_sizer->GetMinSize() != wxSize(0,0) )
184 if( !b_video ) i_delay = mdate() + 1000000;
189 #if defined( __WXMSW__ )
190 SetSashPosition( event.GetSize().GetHeight() - i_sash_position );
192 SetSashPosition( event.GetSize().GetHeight() -
193 i_sash_position - GetSashSize() );
196 else if( GetWindow2() && GetWindow1() && GetWindow1()->GetSizer() )
198 wxSize size = GetWindow1()->GetSizer()->GetMinSize();
200 if( b_video ) i_delay = mdate() + 1000000;
203 if( event.GetSize().GetHeight() - size.GetHeight() )
207 SetSashPosition( size.GetHeight() ? size.GetHeight() : 1 );
209 if( i_delay < mdate() )
211 i_sash_position = event.GetSize().GetHeight() -
213 i_width = event.GetSize().GetWidth();
215 size = wxSize( i_width, i_sash_position );
216 if( GetWindow2()->GetSizer() )
217 GetWindow2()->GetSizer()->SetMinSize( size );
225 void OnSashPosChanged( wxSplitterEvent &event )
227 if( !GetSize().GetHeight() ){ event.Skip(); return; }
229 if( i_delay < mdate() )
231 i_sash_position = GetSize().GetHeight() - event.GetSashPosition();
233 wxSize size = wxSize( i_width, i_sash_position );
234 if( GetWindow2()->GetSizer() )
235 GetWindow2()->GetSizer()->SetMinSize( size );
240 intf_thread_t *p_intf;
245 vlc_bool_t b_show_on_start;
248 BEGIN_EVENT_TABLE(Splitter, wxSplitterWindow)
249 EVT_SIZE( Splitter::OnSize )
250 EVT_SPLITTER_SASH_POS_CHANGED(-1, Splitter::OnSashPosChanged)
253 /*****************************************************************************
255 *****************************************************************************/
257 DEFINE_LOCAL_EVENT_TYPE( wxEVT_INTF );
259 /* IDs for the controls and the menu commands */
263 MenuDummy_Event = wxID_HIGHEST + 1000,
264 Exit_Event = wxID_HIGHEST,
265 OpenFileSimple_Event,
295 /* it is important for the id corresponding to the "About" command to have
296 * this standard value as otherwise it won't be handled properly under Mac
297 * (where it is special and put into the "Apple" menu) */
298 About_Event = wxID_ABOUT,
305 DEFINE_LOCAL_EVENT_TYPE( wxEVT_INTERACTION );
307 BEGIN_EVENT_TABLE(Interface, wxFrame)
309 EVT_MENU(Exit_Event, Interface::OnExit)
310 EVT_MENU(About_Event, Interface::OnAbout)
311 EVT_MENU(UpdateVLC_Event, Interface::OnShowDialog)
312 EVT_MENU(VLM_Event, Interface::OnShowDialog)
314 EVT_MENU(Playlist_Event, Interface::OnShowDialog)
315 EVT_MENU(PlaylistSmall_Event, Interface::OnSmallPlaylist)
316 EVT_MENU(Logs_Event, Interface::OnShowDialog)
317 EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
318 EVT_MENU(Prefs_Event, Interface::OnShowDialog)
320 EVT_MENU_OPEN(Interface::OnMenuOpen)
322 EVT_MENU( Extended_Event, Interface::OnExtended )
324 EVT_MENU( Bookmarks_Event, Interface::OnShowDialog)
326 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
327 EVT_CONTEXT_MENU(Interface::OnContextMenu2)
329 EVT_RIGHT_UP(Interface::OnContextMenu)
332 EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
333 EVT_MENU(OpenAdv_Event, Interface::OnShowDialog)
334 EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
335 EVT_MENU(OpenDir_Event, Interface::OnShowDialog)
336 EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
337 EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
338 EVT_MENU(OpenCapture_Event, Interface::OnShowDialog)
339 EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
340 EVT_MENU(Wizard_Event, Interface::OnShowDialog)
341 EVT_MENU(StopStream_Event, Interface::OnStopStream)
342 EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
343 EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
344 EVT_MENU(NextStream_Event, Interface::OnNextStream)
345 EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
346 EVT_MENU(FastStream_Event, Interface::OnFastStream)
349 EVT_COMMAND(0, wxEVT_INTF, Interface::OnControlEvent)
350 EVT_COMMAND(1, wxEVT_INTF, Interface::OnControlEvent)
352 EVT_COMMAND( -1, wxEVT_INTERACTION, Interface::OnInteraction )
355 /*****************************************************************************
357 *****************************************************************************/
358 Interface::Interface( intf_thread_t *_p_intf, long style ):
359 wxFrame( NULL, -1, wxT("VLC media player"),
360 wxDefaultPosition, wxSize(700,100), style )
362 /* Initializations */
366 playlist_manager = 0;
369 /* Give our interface a nice little icon */
370 SetIcon( wxIcon( vlc_xpm ) );
372 /* Create a splitter window that will fill in the interface window.
373 * We need a splitter bar in order to make the embedded playlist
375 splitter = new Splitter( this, p_intf );
376 main_sizer = new wxBoxSizer( wxVERTICAL );
377 main_sizer->Add( splitter, 1, wxEXPAND );
378 SetSizer( main_sizer );
380 /* Create a main panel that will fill in the interface window */
381 main_panel = new wxPanel( splitter, -1, wxPoint(0,0), wxSize(0,0),
383 main_panel->SetFocus();
385 #if defined(__WXGTK20__) && wxCHECK_VERSION(2,5,6)
386 /* As ugly as your butt! Please remove when wxWidgets 2.6 fixed their
387 * Accelerators bug. */
388 main_panel->m_imData = 0;
392 /* Create a sizer for the main frame */
393 panel_sizer = new wxBoxSizer( wxVERTICAL );
394 main_panel->SetSizer( panel_sizer );
396 /* Put this in the splitter */
397 splitter->Initialize( main_panel );
399 /* wxCocoa pretends to support this, but at least 2.6.x doesn't */
401 #ifdef wxHAS_TASK_BAR_ICON
402 /* Systray integration */
404 if( config_GetInt( p_intf, "wx-systray" ) )
406 p_systray = new Systray( this, p_intf );
411 /* Creation of the menu bar */
414 /* Creation of the tool bar */
417 /* Creation of the status bar
418 * Helptext for menu items and toolbar tools will automatically get
420 int i_status_width[3] = {100, 40, -1};
421 statusbar = CreateStatusBar( 3 ); /* 2 fields */
422 statusbar->SetStatusWidths( 3, i_status_width );
423 statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
425 /* Get minimum window size to prevent user from glitching it */
426 splitter->SetSizeHints( -1, 0 );
427 panel_sizer->Layout(); panel_sizer->Fit( main_panel );
428 main_sizer->Layout(); main_sizer->Fit( this );
429 main_min_size = GetSize();
430 splitter->SetSizeHints( -1, -1 );
434 if( config_GetInt( p_intf, "wx-embed" ) )
436 video_window = CreateVideoWindow( p_intf, main_panel );
437 panel_sizer->Add( p_intf->p_sys->p_video_sizer, 1, wxEXPAND, 0 );
440 /* Creation of the input manager panel */
441 input_manager = new InputManager( p_intf, this, main_panel );
442 panel_sizer->Add( input_manager, 0, wxEXPAND , 0 );
444 /* Layout everything */
445 splitter->SetSizeHints( -1, 0 );
446 panel_sizer->Layout(); panel_sizer->Fit( main_panel );
447 main_sizer->Layout(); main_sizer->Fit( this );
448 splitter->SetSizeHints( -1, -1 );
450 #if wxUSE_DRAG_AND_DROP
451 /* Associate drop targets with the main interface */
452 SetDropTarget( new DragAndDrop( p_intf ) );
458 timer = new Timer( p_intf, this );
460 /* Restore previous position / settings */
461 WindowSettings *ws = p_intf->p_sys->p_window_settings;
466 ws->SetScreen( wxSystemSettings::GetMetric( wxSYS_SCREEN_X ),
467 wxSystemSettings::GetMetric( wxSYS_SCREEN_Y ) );
469 if( ws->GetSettings( WindowSettings::ID_MAIN, b_shown, p, s ) ) Move( p );
471 /* Show extended GUI if requested */
472 wxCommandEvent dummy;
473 if( config_GetInt( p_intf, "wx-extended" ) ) OnExtended( dummy );
477 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
478 var_AddCallback( p_intf, "interaction", InteractCallback, this );
479 p_intf->b_interaction = VLC_TRUE;
481 /* Show embedded playlist if requested */
482 if( splitter->ShowOnStart() ) OnSmallPlaylist( dummy );
485 Interface::~Interface()
487 WindowSettings *ws = p_intf->p_sys->p_window_settings;
491 ws->SetSettings( WindowSettings::ID_MAIN, true,
492 GetPosition(), GetSize() );
495 PopEventHandler(true);
497 if( video_window ) delete video_window;
499 /* wxCocoa pretends to support this, but at least 2.6.x doesn't */
501 #ifdef wxHAS_TASK_BAR_ICON
502 if( p_systray ) delete p_systray;
506 p_intf->b_interaction = VLC_FALSE;
507 var_DelCallback( p_intf, "interaction", InteractCallback, this );
509 if( p_intf->p_sys->p_wxwindow ) delete p_intf->p_sys->p_wxwindow;
516 void Interface::Init()
522 void Interface::Update()
525 ((VLCVolCtrl *)volctrl)->UpdateVolume();
527 if( playlist_manager ) playlist_manager->Update();
530 void Interface::OnControlEvent( wxCommandEvent& event )
532 switch( event.GetId() )
535 main_sizer->Layout();
536 main_sizer->Fit( this );
540 long i_style = GetWindowStyle();
541 if( event.GetInt() ) i_style |= wxSTAY_ON_TOP;
542 else i_style &= ~wxSTAY_ON_TOP;
543 SetWindowStyle( i_style );
548 /*****************************************************************************
550 *****************************************************************************/
551 void Interface::CreateOurMenuBar()
553 int minimal = config_GetInt( p_intf, "wx-minimal" );
555 /* Create the "File" menu */
556 wxMenu *file_menu = new wxMenu;
560 file_menu->Append( OpenFileSimple_Event,
561 wxU(_("Quick &Open File...\tCtrl-O")) );
563 file_menu->AppendSeparator();
564 file_menu->Append( OpenFile_Event, wxU(_("Open &File...\tCtrl-F")) );
565 file_menu->Append( OpenDir_Event, wxU(_("Open Dir&ectory...\tCtrl-E")) );
566 file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...\tCtrl-D")) );
567 file_menu->Append( OpenNet_Event,
568 wxU(_("Open &Network Stream...\tCtrl-N")) );
569 file_menu->Append( OpenCapture_Event,
570 wxU(_("Open C&apture Device...\tCtrl-A")) );
572 file_menu->AppendSeparator();
573 file_menu->Append( Wizard_Event, wxU(_("&Wizard...\tCtrl-W")) );
574 file_menu->AppendSeparator();
576 file_menu->Append( Exit_Event, wxU(_("E&xit\tCtrl-X")) );
578 /* Create the "View" menu */
579 wxMenu *view_menu = new wxMenu;
582 view_menu->Append( Playlist_Event, wxU(_("&Playlist...\tCtrl-P")) );
584 view_menu->Append( Logs_Event, wxU(_("&Messages...\tCtrl-M")) );
585 view_menu->Append( FileInfo_Event,
586 wxU(_("Stream and Media &info...\tCtrl-I")) );
587 view_menu->Append( VLM_Event,
588 wxU(_("VLM Control...\tCtrl-V")) );
590 /* Create the "Auto-generated" menus */
591 p_settings_menu = SettingsMenu( p_intf, this );
592 p_audio_menu = AudioMenu( p_intf, this );
593 p_video_menu = VideoMenu( p_intf, this );
594 p_navig_menu = NavigMenu( p_intf, this );
596 /* Create the "Help" menu */
597 wxMenu *help_menu = new wxMenu;
598 help_menu->Append( About_Event, wxU(_("About VLC media player")) );
600 help_menu->AppendSeparator();
601 help_menu->Append( UpdateVLC_Event, wxU(_("Check for updates ...")) );
604 /* Append the freshly created menus to the menu bar... */
605 wxMenuBar *menubar = new wxMenuBar();
606 menubar->Append( file_menu, wxU(_("&File")) );
607 menubar->Append( view_menu, wxU(_("&View")) );
608 menubar->Append( p_settings_menu, wxU(_("&Settings")) );
609 menubar->Append( p_audio_menu, wxU(_("&Audio")) );
610 menubar->Append( p_video_menu, wxU(_("&Video")) );
611 menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
612 menubar->Append( help_menu, wxU(_("&Help")) );
614 /* Attach the menu bar to the frame */
615 SetMenuBar( menubar );
617 /* Find out size of menu bar */
619 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
621 int i_width, i_height;
622 menubar->GetTextExtent( menubar->GetLabelTop(i), &i_width, &i_height );
624 #if defined(__WXGTK__)
625 22 /* approximate margin */;
627 #if (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 5) && (wxRELEASE_NUMBER < 3)
628 4 /* approximate margin */;
630 18 /* approximate margin */;
635 /* Patch by zcot for menu wrapping */
637 /* Find out size of msw menu bar */
640 HDC hdc = GetDC( NULL );
641 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
643 GetTextExtentPoint32( hdc, menubar->GetLabelTop(i).c_str(),
644 menubar->GetLabelTop(i).Length(), &sizing );
646 // [ SM_CXDLGFRAME + pixels + textextent + pixels + SM_CXDLGFRAME ]
647 i_size += sizing.cx + 2 + GetSystemMetrics( SM_CXDLGFRAME ) * 2;
649 ReleaseDC( NULL, hdc );
650 i_size += GetSystemMetrics( SM_CXSIZEFRAME ) * 2 + 4;
652 /* End patch by zcot */
654 panel_sizer->SetMinSize( i_size, -1 );
656 /* Intercept all menu events in our custom event handler */
657 PushEventHandler( new MenuEvtHandler( p_intf, this ) );
659 #if wxUSE_DRAG_AND_DROP
660 /* Associate drop targets with the menubar */
661 menubar->SetDropTarget( new DragAndDrop( p_intf ) );
665 void Interface::CreateOurToolBar()
667 #define HELP_OPEN N_("Open")
668 #define HELP_STOP N_("Stop")
669 #define HELP_PLAY N_("Play")
670 #define HELP_PAUSE N_("Pause")
671 #define HELP_PLO N_("Playlist")
672 #define HELP_SPLO N_("Embedded playlist")
673 #define HELP_PLP N_("Previous playlist item")
674 #define HELP_PLN N_("Next playlist item")
675 #define HELP_SLOW N_("Play slower")
676 #define HELP_FAST N_("Play faster")
678 int minimal = config_GetInt( p_intf, "wx-minimal" );
680 wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
681 * version because we don't include wx.rc */
684 CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
686 toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
690 toolbar->AddTool( OpenFile_Event, wxT(""),
691 wxBitmap( eject_xpm ), wxU(_(HELP_OPEN)) );
692 toolbar->AddSeparator();
695 wxToolBarToolBase *p_tool = toolbar->AddTool( PlayStream_Event, wxT(""),
696 wxBitmap( play_xpm ), wxU(_(HELP_PLAY)), wxITEM_CHECK );
697 p_tool->SetClientData( p_tool );
701 toolbar->AddTool( StopStream_Event, wxT(""), wxBitmap( stop_xpm ),
703 toolbar->AddSeparator();
705 toolbar->AddTool( PrevStream_Event, wxT(""),
706 wxBitmap( prev_xpm ), wxU(_(HELP_PLP)) );
707 toolbar->AddTool( SlowStream_Event, wxT(""),
708 wxBitmap( slow_xpm ), wxU(_(HELP_SLOW)) );
709 toolbar->AddTool( FastStream_Event, wxT(""),
710 wxBitmap( fast_xpm ), wxU(_(HELP_FAST)) );
711 toolbar->AddTool( NextStream_Event, wxT(""), wxBitmap( next_xpm ),
713 toolbar->AddSeparator();
714 if( config_GetInt( p_intf, "wx-playlist-view" ) != 1 )
715 toolbar->AddTool( Playlist_Event, wxT(""), wxBitmap( playlist_xpm ),
717 if( config_GetInt( p_intf, "wx-playlist-view" ) >= 1 )
718 toolbar->AddTool( PlaylistSmall_Event, wxT(""),
719 wxBitmap( playlist_small_xpm ), wxU(_(HELP_SPLO)) );
722 wxControl *p_dummy_ctrl =
723 new wxControl( toolbar, -1, wxDefaultPosition,
724 wxSize(16, 16 ), wxBORDER_NONE );
726 toolbar->AddControl( p_dummy_ctrl );
728 volctrl = new VLCVolCtrl( p_intf, toolbar );
729 toolbar->AddControl( volctrl );
733 #if wxUSE_DRAG_AND_DROP
734 /* Associate drop targets with the toolbar */
735 toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
739 static int ConvertHotkeyModifiers( int i_hotkey )
741 int i_accel_flags = 0;
742 if( i_hotkey & KEY_MODIFIER_ALT ) i_accel_flags |= wxACCEL_ALT;
743 if( i_hotkey & KEY_MODIFIER_CTRL ) i_accel_flags |= wxACCEL_CTRL;
744 if( i_hotkey & KEY_MODIFIER_SHIFT ) i_accel_flags |= wxACCEL_SHIFT;
745 if( !i_accel_flags ) i_accel_flags = wxACCEL_NORMAL;
746 return i_accel_flags;
749 static int ConvertHotkey( int i_hotkey )
751 int i_key = i_hotkey & ~KEY_MODIFIER;
752 if( i_key & KEY_ASCII ) return i_key & KEY_ASCII;
753 else if( i_key & KEY_SPECIAL )
757 case KEY_LEFT: return WXK_LEFT;
758 case KEY_RIGHT: return WXK_RIGHT;
759 case KEY_UP: return WXK_UP;
760 case KEY_DOWN: return WXK_DOWN;
761 case KEY_SPACE: return WXK_SPACE;
762 case KEY_ENTER: return WXK_RETURN;
763 case KEY_F1: return WXK_F1;
764 case KEY_F2: return WXK_F2;
765 case KEY_F3: return WXK_F3;
766 case KEY_F4: return WXK_F4;
767 case KEY_F5: return WXK_F5;
768 case KEY_F6: return WXK_F6;
769 case KEY_F7: return WXK_F7;
770 case KEY_F8: return WXK_F8;
771 case KEY_F9: return WXK_F9;
772 case KEY_F10: return WXK_F10;
773 case KEY_F11: return WXK_F11;
774 case KEY_F12: return WXK_F12;
775 case KEY_HOME: return WXK_HOME;
776 case KEY_END: return WXK_END;
777 case KEY_INSERT: return WXK_INSERT;
778 case KEY_DELETE: return WXK_DELETE;
779 case KEY_MENU: return WXK_MENU;
780 case KEY_ESC: return WXK_ESCAPE;
781 case KEY_PAGEUP: return WXK_PRIOR;
782 case KEY_PAGEDOWN: return WXK_NEXT;
783 case KEY_TAB: return WXK_TAB;
784 case KEY_BACKSPACE: return WXK_BACK;
790 void Interface::SetupHotkeys()
792 struct vlc_t::hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
795 /* Count number of hoteys */
796 for( i_hotkeys = 0; p_hotkeys[i_hotkeys].psz_action != NULL; i_hotkeys++ );
798 p_intf->p_sys->i_first_hotkey_event = wxID_HIGHEST + 7000;
799 p_intf->p_sys->i_hotkeys = i_hotkeys;
801 wxAcceleratorEntry *p_entries = new wxAcceleratorEntry[i_hotkeys];
803 /* Setup the hotkeys as accelerators */
804 for( int i = 0; i < i_hotkeys; i++ )
806 int i_mod = ConvertHotkeyModifiers( p_hotkeys[i].i_key );
807 int i_key = ConvertHotkey( p_hotkeys[i].i_key );
810 if( !(p_hotkeys[i].i_key & KEY_SPECIAL) && i_mod )
811 i_key = toupper(i_key);
814 p_entries[i].Set( i_mod, i_key,
815 p_intf->p_sys->i_first_hotkey_event + i );
818 wxAcceleratorTable accel( i_hotkeys, p_entries );
822 msg_Err( p_intf, "invalid accelerator table" );
826 SetAcceleratorTable( accel );
832 void Interface::SetIntfMinSize()
834 wxSize ms = main_min_size;
836 if( extra_frame && extra_frame->IsShown() )
838 ms.SetHeight( ms.GetHeight() + ext_min_size.GetHeight() );
839 if( ext_min_size.GetWidth() > ms.GetWidth() )
840 ms.SetWidth( ext_min_size.GetWidth() );
843 SetSizeHints( ms.GetWidth(), ms.GetHeight() );
846 /*****************************************************************************
848 *****************************************************************************/
849 void Interface::OnMenuOpen( wxMenuEvent& event )
851 #if defined( __WXMSW__ )
852 # define GetEventObject GetMenu
855 if( event.GetEventObject() == p_settings_menu )
857 p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );
859 /* Add static items */
860 p_settings_menu->AppendCheckItem( Extended_Event,
861 wxU(_("Extended &GUI\tCtrl-G") ) );
862 if( b_extra ) p_settings_menu->Check( Extended_Event, TRUE );
863 p_settings_menu->Append( Bookmarks_Event,
864 wxU(_("&Bookmarks...\tCtrl-B") ) );
865 p_settings_menu->Append( Prefs_Event,
866 wxU(_("Preference&s...\tCtrl-S")) );
869 else if( event.GetEventObject() == p_audio_menu )
871 p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
874 else if( event.GetEventObject() == p_video_menu )
876 p_video_menu = VideoMenu( p_intf, this, p_video_menu );
879 else if( event.GetEventObject() == p_navig_menu )
881 p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
884 #if defined( __WXMSW__ )
885 # undef GetEventObject
889 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
890 void Interface::OnContextMenu2(wxContextMenuEvent& event)
892 /* Only show the context menu for the main interface */
893 if( GetId() != event.GetId() )
899 if( p_intf->p_sys->pf_show_dialog )
900 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
903 void Interface::OnContextMenu(wxMouseEvent& event)
905 if( p_intf->p_sys->pf_show_dialog )
906 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
909 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
911 /* TRUE is to force the frame to close. */
915 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
918 msg.Printf( wxString(wxT("VLC media player " PACKAGE_VERSION)) +
919 wxU(_(" (wxWidgets interface)\n\n")) +
920 wxU(_("(c) 1996-2006 - the VideoLAN Team\n\n")) +
921 wxU(_("Compiled by "))+ wxU(VLC_CompileBy())+ wxU("@") +
922 wxU(VLC_CompileHost())+ wxT(".")+ wxU(VLC_CompileDomain())+ wxT(".\n") +
923 wxU(_("Compiler: "))+ wxU(VLC_Compiler())+wxT( ".\n") +
924 #ifndef HAVE_SHARED_LIBVLC
925 wxU(_("Based on SVN revision: "))+wxU(VLC_Changeset())+wxT(".\n\n") +
928 wxU( vlc_wraptext(LICENSE_MSG,WRAPCOUNT) ) + wxT("\n\n") +
930 wxU( LICENSE_MSG ) + wxT("\n\n") +
932 wxU(_("The VideoLAN team <videolan@videolan.org>\n"
933 "http://www.videolan.org/\n\n")) );
935 wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
936 wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
939 void Interface::OnShowDialog( wxCommandEvent& event )
941 if( p_intf->p_sys->pf_show_dialog )
945 switch( event.GetId() )
947 case OpenFileSimple_Event:
948 i_id = INTF_DIALOG_FILE_SIMPLE;
951 i_id = INTF_DIALOG_FILE;
954 i_id = INTF_DIALOG_FILE;
957 i_id = INTF_DIALOG_DIRECTORY;
960 i_id = INTF_DIALOG_DISC;
963 i_id = INTF_DIALOG_NET;
965 case OpenCapture_Event:
966 i_id = INTF_DIALOG_CAPTURE;
969 i_id = INTF_DIALOG_SAT;
972 i_id = INTF_DIALOG_PLAYLIST;
975 i_id = INTF_DIALOG_MESSAGES;
978 i_id = INTF_DIALOG_FILEINFO;
981 i_id = INTF_DIALOG_PREFS;
984 i_id = INTF_DIALOG_WIZARD;
986 case Bookmarks_Event:
987 i_id = INTF_DIALOG_BOOKMARKS;
989 case UpdateVLC_Event:
990 i_id = INTF_DIALOG_UPDATEVLC;
993 i_id = INTF_DIALOG_VLM;
996 i_id = INTF_DIALOG_FILE;
1000 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
1004 void Interface::OnExtended( wxCommandEvent& WXUNUSED(event) )
1006 UpdateVideoWindow( p_intf, video_window );
1010 /* Create the extra panel */
1011 extra_frame = new ExtraPanel( p_intf, main_panel );
1012 panel_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
1013 ext_min_size = extra_frame->GetBestSize();
1017 panel_sizer->Show( extra_frame, b_extra );
1020 main_sizer->Layout();
1021 main_sizer->Fit( this );
1024 void Interface::OnSmallPlaylist( wxCommandEvent& WXUNUSED(event) )
1026 UpdateVideoWindow( p_intf, video_window );
1028 if( !playlist_manager )
1030 /* Create the extra panel */
1031 playlist_manager = new PlaylistManager( p_intf, splitter );
1034 if( !splitter->IsSplit() ) splitter->Split( main_panel, playlist_manager );
1035 else splitter->Unsplit( playlist_manager );
1038 main_sizer->Layout();
1039 main_sizer->Fit( this );
1042 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
1047 void Interface::PlayStream()
1049 wxCommandEvent dummy;
1050 playlist_t *p_playlist =
1051 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1053 if( p_playlist == NULL ) return;
1055 if( p_playlist->i_size && p_playlist->i_enabled )
1059 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
1062 if( p_input == NULL )
1064 /* No stream was playing, start one */
1065 playlist_Play( p_playlist );
1066 vlc_object_release( p_playlist );
1067 input_manager->Update();
1071 var_Get( p_input, "state", &state );
1072 if( state.i_int != PAUSE_S )
1074 /* A stream is being played, pause it */
1075 state.i_int = PAUSE_S;
1079 /* Stream is paused, resume it */
1080 state.i_int = PLAYING_S;
1082 var_Set( p_input, "state", state );
1084 vlc_object_release( p_input );
1085 vlc_object_release( p_playlist );
1086 input_manager->Update();
1090 /* If the playlist is empty, open a file requester instead */
1091 vlc_object_release( p_playlist );
1092 OnShowDialog( dummy );
1096 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
1100 void Interface::StopStream()
1102 playlist_t * p_playlist =
1103 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1105 if( p_playlist == NULL )
1110 playlist_Stop( p_playlist );
1111 vlc_object_release( p_playlist );
1112 input_manager->Update();
1115 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
1120 void Interface::PrevStream()
1122 playlist_t * p_playlist =
1123 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1125 if( p_playlist == NULL )
1130 playlist_Prev( p_playlist );
1131 vlc_object_release( p_playlist );
1134 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1139 void Interface::NextStream()
1141 playlist_t * p_playlist =
1142 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1144 if( p_playlist == NULL )
1148 playlist_Next( p_playlist );
1149 vlc_object_release( p_playlist );
1152 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1154 input_thread_t *p_input =
1155 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1159 vlc_value_t val; val.b_bool = VLC_TRUE;
1161 var_Set( p_input, "rate-slower", val );
1162 vlc_object_release( p_input );
1166 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1168 input_thread_t *p_input =
1169 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1173 vlc_value_t val; val.b_bool = VLC_TRUE;
1175 var_Set( p_input, "rate-faster", val );
1176 vlc_object_release( p_input );
1180 void Interface::TogglePlayButton( int i_playing_status )
1182 wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
1183 GetToolBar()->GetToolClientData( PlayStream_Event );
1184 if( !p_tool ) return;
1186 if( i_playing_status == PLAYING_S )
1188 p_tool->SetNormalBitmap( wxBitmap( pause_xpm ) );
1189 p_tool->SetLabel( wxU(_("Pause")) );
1190 p_tool->SetShortHelp( wxU(_(HELP_PAUSE)) );
1194 p_tool->SetNormalBitmap( wxBitmap( play_xpm ) );
1195 p_tool->SetLabel( wxU(_("Play")) );
1196 p_tool->SetShortHelp( wxU(_(HELP_PLAY)) );
1199 GetToolBar()->Realize();
1201 #if defined( __WXMSW__ )
1202 /* Needed to work around a bug in wxToolBar::Realize() */
1203 GetToolBar()->SetSize( GetSize().GetWidth(),
1204 GetToolBar()->GetSize().GetHeight() );
1205 GetToolBar()->Update();
1208 GetToolBar()->ToggleTool( PlayStream_Event, true );
1209 GetToolBar()->ToggleTool( PlayStream_Event, false );
1212 void Interface::OnInteraction( wxCommandEvent& event )
1214 interaction_dialog_t *p_dialog = (interaction_dialog_t *)
1215 event.GetClientData();
1217 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1218 p_arg->p_dialog = p_dialog;
1219 p_arg->p_intf = p_intf;
1221 if( p_dialog->i_type == INTERACT_PROGRESS )
1223 /// \todo Handle progress in the interface
1227 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_INTERACTION,
1232 static int InteractCallback( vlc_object_t *p_this,
1233 const char *psz_var, vlc_value_t old_val,
1234 vlc_value_t new_val, void *param )
1236 Interface *p_interface = (Interface*)param;
1237 /*interaction_dialog_t *p_dialog = (interaction_dialog_t*)(new_val.p_address);*/
1239 wxCommandEvent event( wxEVT_INTERACTION, -1 );
1240 event.SetClientData( new_val.p_address );
1241 p_interface->AddPendingEvent( event );
1245 #if wxUSE_DRAG_AND_DROP
1246 /*****************************************************************************
1247 * Definition of DragAndDrop class.
1248 *****************************************************************************/
1249 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
1252 b_enqueue = _b_enqueue;
1255 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1256 const wxArrayString& filenames )
1258 /* Add dropped files to the playlist */
1260 playlist_t *p_playlist =
1261 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1263 if( p_playlist == NULL )
1268 for( size_t i = 0; i < filenames.GetCount(); i++ )
1270 char *psz_utf8 = wxDnDFromLocale( filenames[i] );
1272 playlist_Add( p_playlist, psz_utf8, psz_utf8,
1273 PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
1276 wxDnDLocaleFree( psz_utf8 );
1279 vlc_object_release( p_playlist );
1285 /*****************************************************************************
1286 * Definition of VolCtrl class.
1287 *****************************************************************************/
1288 class wxVolCtrl: public wxGauge
1292 wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1293 wxPoint = wxDefaultPosition, wxSize = wxSize( 20, -1 ) );
1294 virtual ~wxVolCtrl() {};
1296 void UpdateVolume();
1299 void OnChange( wxMouseEvent& event );
1302 intf_thread_t *p_intf;
1304 DECLARE_EVENT_TABLE();
1307 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
1309 EVT_LEFT_DOWN(wxVolCtrl::OnChange)
1310 EVT_MOTION(wxVolCtrl::OnChange)
1313 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1314 wxPoint point, wxSize size )
1315 : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
1321 void wxVolCtrl::OnChange( wxMouseEvent& event )
1323 if( !event.LeftDown() && !event.LeftIsDown() ) return;
1325 int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
1326 aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1330 void wxVolCtrl::UpdateVolume()
1332 audio_volume_t i_volume;
1333 aout_VolumeGet( p_intf, &i_volume );
1335 int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
1336 if( i_gauge_volume == GetValue() ) return;
1338 SetValue( i_gauge_volume );
1339 SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
1340 i_gauge_volume / 2 ) );
1343 #if defined(__WXGTK__)
1344 #define VLCVOL_HEIGHT p_parent->GetSize().GetHeight()
1346 #define VLCVOL_HEIGHT TOOLBAR_BMP_HEIGHT
1348 VLCVolCtrl::VLCVolCtrl( intf_thread_t *_p_intf, wxWindow *p_parent )
1349 :wxControl( p_parent, -1, wxDefaultPosition, wxSize(64, VLCVOL_HEIGHT ),
1351 i_y_offset((VLCVOL_HEIGHT - TOOLBAR_BMP_HEIGHT) / 2),
1352 b_mute(0), p_intf(_p_intf)
1354 gauge = new wxVolCtrl( p_intf, this, -1, wxPoint( 18, i_y_offset ),
1355 wxSize( 44, TOOLBAR_BMP_HEIGHT ) );
1358 void VLCVolCtrl::OnPaint( wxPaintEvent &evt )
1360 wxPaintDC dc( this );
1361 wxBitmap mPlayBitmap( b_mute ? speaker_mute_xpm : speaker_xpm );
1362 dc.DrawBitmap( mPlayBitmap, 0, i_y_offset, TRUE );
1365 void VLCVolCtrl::OnChange( wxMouseEvent& event )
1367 if( event.GetX() < TOOLBAR_BMP_WIDTH )
1370 aout_VolumeMute( p_intf, (audio_volume_t *)&i_volume );
1377 void VLCVolCtrl::UpdateVolume()
1379 gauge->UpdateVolume();
1381 int i_volume = gauge->GetValue();
1382 if( !!i_volume == !b_mute ) return;
1387 /*****************************************************************************
1389 *****************************************************************************/
1391 /* wxCocoa pretends to support this, but at least 2.6.x doesn't */
1393 #ifdef wxHAS_TASK_BAR_ICON
1395 BEGIN_EVENT_TABLE(Systray, wxTaskBarIcon)
1398 EVT_TASKBAR_LEFT_DCLICK(Systray::OnLeftClick)
1400 EVT_TASKBAR_LEFT_DOWN(Systray::OnLeftClick)
1403 EVT_MENU(Iconize_Event, Systray::OnMenuIconize)
1404 EVT_MENU(Exit_Event, Systray::OnExit)
1405 EVT_MENU(PlayStream_Event, Systray::OnPlayStream)
1406 EVT_MENU(NextStream_Event, Systray::OnNextStream)
1407 EVT_MENU(PrevStream_Event, Systray::OnPrevStream)
1408 EVT_MENU(StopStream_Event, Systray::OnStopStream)
1411 Systray::Systray( Interface *_p_main_interface, intf_thread_t *_p_intf )
1413 p_main_interface = _p_main_interface;
1416 SetIcon( wxIcon( vlc16x16_xpm ), wxT("VLC media player") );
1417 if( !IsOk() || !IsIconInstalled() )
1419 msg_Warn(p_intf, "cannot set systray icon, weird things may happen");
1423 /* Event handlers */
1424 void Systray::OnMenuIconize( wxCommandEvent& event )
1426 p_main_interface->Show( ! p_main_interface->IsShown() );
1427 if ( p_main_interface->IsShown() ) p_main_interface->Raise();
1430 void Systray::OnLeftClick( wxTaskBarIconEvent& event )
1432 wxCommandEvent cevent;
1433 OnMenuIconize(cevent);
1436 void Systray::OnExit( wxCommandEvent& event )
1438 p_main_interface->Close(TRUE);
1441 void Systray::OnPrevStream( wxCommandEvent& event )
1443 p_main_interface->PrevStream();
1446 void Systray::OnNextStream( wxCommandEvent& event )
1448 p_main_interface->NextStream();
1451 void Systray::OnPlayStream( wxCommandEvent& event )
1453 p_main_interface->PlayStream();
1456 void Systray::OnStopStream( wxCommandEvent& event )
1458 p_main_interface->StopStream();
1461 /* Systray popup menu */
1462 wxMenu* Systray::CreatePopupMenu()
1464 int minimal = config_GetInt( p_intf, "wx-minimal" );
1466 wxMenu* systray_menu = new wxMenu;
1467 systray_menu->Append( Exit_Event, wxU(_("Quit VLC")) );
1468 systray_menu->AppendSeparator();
1469 systray_menu->Append( PlayStream_Event, wxU(_("Play/Pause")) );
1473 systray_menu->Append( PrevStream_Event, wxU(_("Previous")) );
1474 systray_menu->Append( NextStream_Event, wxU(_("Next")) );
1475 systray_menu->Append( StopStream_Event, wxU(_("Stop")) );
1477 systray_menu->AppendSeparator();
1478 systray_menu->Append( Iconize_Event, wxU(_("Show/Hide interface")) );
1479 return systray_menu;
1482 void Systray::UpdateTooltip( const wxChar* tooltip )
1484 SetIcon( wxIcon( vlc16x16_xpm ), tooltip );