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"
34 #include "vlc_charset.h"
37 #include "vlc_charset.h"
39 #include <vlc_interface.h>
41 #include <wx/splitter.h>
43 #include <wx/utils.h> /* wxLaunchDefaultBrowser() */
45 /* include the toolbar graphics */
46 #include "bitmaps/play.xpm"
47 #include "bitmaps/pause.xpm"
48 #include "bitmaps/stop.xpm"
49 #include "bitmaps/prev.xpm"
50 #include "bitmaps/next.xpm"
51 #include "bitmaps/eject.xpm"
52 #include "bitmaps/slow.xpm"
53 #include "bitmaps/fast.xpm"
54 #include "bitmaps/playlist.xpm"
55 #include "bitmaps/playlist_small.xpm"
56 #include "bitmaps/speaker.xpm"
57 #include "bitmaps/speaker_mute.xpm"
59 #define TOOLBAR_BMP_WIDTH 16
60 #define TOOLBAR_BMP_HEIGHT 16
62 /* include the icon graphic */
63 #include "../../../share/vlc32x32.xpm"
64 /* include a small icon graphic for the systray icon */
65 #ifdef wxHAS_TASK_BAR_ICON
66 #include "../../../share/vlc16x16.xpm"
69 /*****************************************************************************
71 *****************************************************************************/
72 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
75 /*****************************************************************************
76 * Local class declarations.
77 *****************************************************************************/
78 class wxMenuExt: public wxMenu
82 wxMenuExt( wxMenu* parentMenu, int id, const wxString& text,
83 const wxString& helpString, wxItemKind kind,
84 char *_psz_var, int _i_object_id, vlc_value_t _val,
87 virtual ~wxMenuExt() {};
99 class VLCVolCtrl : public wxControl
102 VLCVolCtrl( intf_thread_t *p_intf, wxWindow *p_parent );
103 virtual ~VLCVolCtrl() {};
105 virtual void OnPaint( wxPaintEvent &event );
106 void OnChange( wxMouseEvent& event );
110 DECLARE_EVENT_TABLE()
115 intf_thread_t *p_intf;
118 BEGIN_EVENT_TABLE(VLCVolCtrl, wxControl)
119 EVT_PAINT(VLCVolCtrl::OnPaint)
122 EVT_LEFT_UP(VLCVolCtrl::OnChange)
125 class Splitter : public wxSplitterWindow
128 Splitter( wxWindow *p_parent, intf_thread_t *_p_intf )
129 : wxSplitterWindow( p_parent, -1, wxDefaultPosition, wxSize(0,0),
130 #if defined( __WXMSW__ )
133 wxCLIP_CHILDREN | wxSP_3DSASH ),
135 p_intf(_p_intf), b_video(0), i_delay(0)
139 wxSize size = wxSize(-1, 150);
140 wxPoint p = wxPoint(0,0);
142 WindowSettings *ws = p_intf->p_sys->p_window_settings;
143 ws->GetSettings( WindowSettings::ID_SMALL_PLAYLIST, b_dummy, p, size );
145 i_width = size.GetWidth();
146 i_sash_position = size.GetHeight();
147 b_show_on_start = !!p.x;
152 WindowSettings *ws = p_intf->p_sys->p_window_settings;
153 ws->SetSettings( WindowSettings::ID_SMALL_PLAYLIST, true,
154 wxPoint(!!GetWindow2(),0),
155 wxSize(i_width, i_sash_position) );
158 virtual bool Split( wxWindow* window1, wxWindow* window2 )
161 wxSize size = wxSize( i_width, i_sash_position );
162 if( window2->GetSizer() ) window2->GetSizer()->SetMinSize( size );
164 return wxSplitterWindow::SplitHorizontally( window1, window2,
168 virtual bool Unsplit( wxWindow* window )
171 return wxSplitterWindow::Unsplit( window );
174 bool ShowOnStart() { return b_show_on_start; }
177 DECLARE_EVENT_TABLE()
179 void OnSize( wxSizeEvent &event )
181 /* If we display video, then resize the video window */
183 p_intf->p_sys->p_video_window && p_intf->p_sys->p_video_sizer &&
184 p_intf->p_sys->p_video_sizer->GetMinSize() != wxSize(0,0) )
186 if( !b_video ) i_delay = mdate() + 1000000;
191 #if defined( __WXMSW__ )
192 SetSashPosition( event.GetSize().GetHeight() - i_sash_position );
194 SetSashPosition( event.GetSize().GetHeight() -
195 i_sash_position - GetSashSize() );
198 else if( GetWindow2() && GetWindow1() && GetWindow1()->GetSizer() )
200 wxSize size = GetWindow1()->GetSizer()->GetMinSize();
202 if( b_video ) i_delay = mdate() + 1000000;
205 if( event.GetSize().GetHeight() - size.GetHeight() )
209 SetSashPosition( size.GetHeight() ? size.GetHeight() : 1 );
211 if( i_delay < mdate() )
213 i_sash_position = event.GetSize().GetHeight() -
215 i_width = event.GetSize().GetWidth();
217 size = wxSize( i_width, i_sash_position );
218 if( GetWindow2()->GetSizer() )
219 GetWindow2()->GetSizer()->SetMinSize( size );
227 void OnSashPosChanged( wxSplitterEvent &event )
229 if( !GetSize().GetHeight() ){ event.Skip(); return; }
231 if( i_delay < mdate() )
233 i_sash_position = GetSize().GetHeight() - event.GetSashPosition();
235 wxSize size = wxSize( i_width, i_sash_position );
236 if( GetWindow2()->GetSizer() )
237 GetWindow2()->GetSizer()->SetMinSize( size );
242 intf_thread_t *p_intf;
247 vlc_bool_t b_show_on_start;
250 BEGIN_EVENT_TABLE(Splitter, wxSplitterWindow)
251 EVT_SIZE( Splitter::OnSize )
252 EVT_SPLITTER_SASH_POS_CHANGED(-1, Splitter::OnSashPosChanged)
255 /*****************************************************************************
257 *****************************************************************************/
259 DEFINE_LOCAL_EVENT_TYPE( wxEVT_INTF );
261 /* IDs for the controls and the menu commands */
265 MenuDummy_Event = wxID_HIGHEST + 1000,
266 Exit_Event = wxID_HIGHEST,
267 OpenFileSimple_Event,
297 /* it is important for the id corresponding to the "About" command to have
298 * this standard value as otherwise it won't be handled properly under Mac
299 * (where it is special and put into the "Apple" menu) */
300 About_Event = wxID_ABOUT,
311 DEFINE_LOCAL_EVENT_TYPE( wxEVT_INTERACTION );
313 BEGIN_EVENT_TABLE(Interface, wxFrame)
315 EVT_MENU(Exit_Event, Interface::OnExit)
316 EVT_MENU(About_Event, Interface::OnAbout)
317 EVT_MENU(OnWebLink_Event, Interface::OnWebLink)
318 EVT_MENU(OnWebHelp_Event, Interface::OnWebHelp)
320 EVT_MENU(UpdateVLC_Event, Interface::OnShowDialog)
322 //EVT_MENU(VLM_Event, Interface::OnShowDialog)
324 EVT_MENU(Playlist_Event, Interface::OnShowDialog)
325 EVT_MENU(PlaylistSmall_Event, Interface::OnSmallPlaylist)
326 EVT_MENU(Logs_Event, Interface::OnShowDialog)
327 EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
328 EVT_MENU(Prefs_Event, Interface::OnShowDialog)
330 EVT_MENU_OPEN(Interface::OnMenuOpen)
332 EVT_MENU( Extended_Event, Interface::OnExtended )
334 EVT_MENU( Bookmarks_Event, Interface::OnShowDialog)
336 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
337 EVT_CONTEXT_MENU(Interface::OnContextMenu2)
339 EVT_RIGHT_UP(Interface::OnContextMenu)
342 EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
343 EVT_MENU(OpenAdv_Event, Interface::OnShowDialog)
344 EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
345 EVT_MENU(OpenDir_Event, Interface::OnShowDialog)
346 EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
347 EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
348 EVT_MENU(OpenCapture_Event, Interface::OnShowDialog)
349 EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
350 EVT_MENU(Wizard_Event, Interface::OnShowDialog)
351 EVT_MENU(StopStream_Event, Interface::OnStopStream)
352 EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
353 EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
354 EVT_MENU(NextStream_Event, Interface::OnNextStream)
355 EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
356 EVT_MENU(FastStream_Event, Interface::OnFastStream)
359 EVT_COMMAND(0, wxEVT_INTF, Interface::OnControlEvent)
360 EVT_COMMAND(1, wxEVT_INTF, Interface::OnControlEvent)
362 EVT_COMMAND( -1, wxEVT_INTERACTION, Interface::OnInteraction )
365 /*****************************************************************************
367 *****************************************************************************/
368 Interface::Interface( intf_thread_t *_p_intf, long style ):
369 wxFrame( NULL, -1, wxT("VLC media player"),
370 wxDefaultPosition, wxSize(700,100), style )
372 /* Initializations */
376 playlist_manager = 0;
377 i_update_counter = 0;
380 /* Give our interface a nice little icon */
381 SetIcon( wxIcon( (const char**) vlc_xpm ) );
383 /* Create a splitter window that will fill in the interface window.
384 * We need a splitter bar in order to make the embedded playlist
386 splitter = new Splitter( this, p_intf );
387 main_sizer = new wxBoxSizer( wxVERTICAL );
388 main_sizer->Add( splitter, 1, wxEXPAND );
389 SetSizer( main_sizer );
391 /* Create a main panel that will fill in the interface window */
392 main_panel = new wxPanel( splitter, -1, wxPoint(0,0), wxSize(0,0),
394 main_panel->SetFocus();
396 #if defined(__WXGTK20__) && wxCHECK_VERSION(2,5,6)
397 /* As ugly as your butt! Please remove when wxWidgets 2.6 fixed their
398 * Accelerators bug. */
399 main_panel->m_imData = 0;
403 /* Create a sizer for the main frame */
404 panel_sizer = new wxBoxSizer( wxVERTICAL );
405 main_panel->SetSizer( panel_sizer );
407 /* Put this in the splitter */
408 splitter->Initialize( main_panel );
410 /* wxCocoa pretends to support this, but at least 2.6.x doesn't */
412 #ifdef wxHAS_TASK_BAR_ICON
413 /* Systray integration */
415 if( config_GetInt( p_intf, "wx-systray" ) )
417 p_systray = new Systray( this, p_intf );
422 /* Creation of the menu bar */
425 /* Creation of the tool bar */
428 /* Creation of the status bar
429 * Helptext for menu items and toolbar tools will automatically get
431 int i_status_width[3] = {150, 55, -1};
432 statusbar = CreateStatusBar( 3 ); /* 2 fields */
433 statusbar->SetStatusWidths( 3, i_status_width );
434 statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
436 /* Get minimum window size to prevent user from glitching it */
437 splitter->SetSizeHints( -1, 0 );
438 panel_sizer->Layout(); panel_sizer->Fit( main_panel );
439 main_sizer->Layout(); main_sizer->Fit( this );
440 main_min_size = GetSize();
441 /* FIXME HACK as far as i understan (i.e. not a lot) the toolbar
442 * doesn't take the labels into account when it returns its size */
444 if( config_GetInt(p_intf, "wx-labels") )
446 main_min_size.SetWidth(800);
448 splitter->SetSizeHints( -1, -1 );
452 if( config_GetInt( p_intf, "wx-embed" ) )
454 video_window = CreateVideoWindow( p_intf, main_panel );
455 panel_sizer->Add( p_intf->p_sys->p_video_sizer, 1, wxEXPAND, 0 );
458 /* Creation of the input manager panel */
459 input_manager = new InputManager( p_intf, this, main_panel );
460 panel_sizer->Add( input_manager, 0, wxEXPAND , 0 );
462 /* Layout everything */
463 splitter->SetSizeHints( -1, 0 );
464 panel_sizer->Layout(); panel_sizer->Fit( main_panel );
465 main_sizer->Layout(); main_sizer->Fit( this );
466 splitter->SetSizeHints( -1, -1 );
468 #if wxUSE_DRAG_AND_DROP
469 /* Associate drop targets with the main interface */
470 SetDropTarget( new DragAndDrop( p_intf ) );
476 timer = new Timer( p_intf, this );
478 /* Restore previous position / settings */
479 WindowSettings *ws = p_intf->p_sys->p_window_settings;
484 ws->SetScreen( wxSystemSettings::GetMetric( wxSYS_SCREEN_X ),
485 wxSystemSettings::GetMetric( wxSYS_SCREEN_Y ) );
487 if( ws->GetSettings( WindowSettings::ID_MAIN, b_shown, p, s ) ) Move( p );
489 /* Show extended GUI if requested */
490 wxCommandEvent dummy;
491 if( config_GetInt( p_intf, "wx-extended" ) ) OnExtended( dummy );
495 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
496 var_AddCallback( p_intf, "interaction", InteractCallback, this );
497 p_intf->b_interaction = VLC_TRUE;
499 /* Show embedded playlist if requested */
500 if( splitter->ShowOnStart() ) OnSmallPlaylist( dummy );
503 Interface::~Interface()
505 WindowSettings *ws = p_intf->p_sys->p_window_settings;
509 ws->SetSettings( WindowSettings::ID_MAIN, true,
510 GetPosition(), GetSize() );
513 PopEventHandler(true);
517 /* wxCocoa pretends to support this, but at least 2.6.x doesn't */
519 #ifdef wxHAS_TASK_BAR_ICON
524 p_intf->b_interaction = VLC_FALSE;
525 var_DelCallback( p_intf, "interaction", InteractCallback, this );
527 delete p_intf->p_sys->p_wxwindow;
534 void Interface::Init()
540 void Interface::Update()
543 if( !(i_update_counter % 10) ) ((VLCVolCtrl *)volctrl)->UpdateVolume();
545 if( playlist_manager ) playlist_manager->Update();
550 void Interface::OnControlEvent( wxCommandEvent& event )
552 switch( event.GetId() )
555 main_sizer->Layout();
556 main_sizer->Fit( this );
560 long i_style = GetWindowStyle();
561 if( event.GetInt() ) i_style |= wxSTAY_ON_TOP;
562 else i_style &= ~wxSTAY_ON_TOP;
563 SetWindowStyle( i_style );
568 /*****************************************************************************
570 *****************************************************************************/
571 void Interface::CreateOurMenuBar()
573 int minimal = config_GetInt( p_intf, "wx-minimal" );
575 /* Create the "File" menu */
576 wxMenu *file_menu = new wxMenu;
580 file_menu->Append( OpenFileSimple_Event,
581 wxU(_("Quick &Open File...\tCtrl-O")) );
583 file_menu->AppendSeparator();
584 file_menu->Append( OpenFile_Event, wxU(_("Open &File...\tCtrl-F")) );
585 file_menu->Append( OpenDir_Event, wxU(_("Open Dir&ectory...\tCtrl-E")) );
586 file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...\tCtrl-D")) );
587 file_menu->Append( OpenNet_Event,
588 wxU(_("Open &Network Stream...\tCtrl-N")) );
589 file_menu->Append( OpenCapture_Event,
590 wxU(_("Open C&apture Device...\tCtrl-A")) );
592 file_menu->AppendSeparator();
593 file_menu->Append( Wizard_Event, wxU(_("&Wizard...\tCtrl-W")) );
594 file_menu->AppendSeparator();
596 file_menu->Append( Exit_Event, wxU(_("E&xit\tCtrl-X")) );
598 /* Create the "View" menu */
599 wxMenu *view_menu = new wxMenu;
602 view_menu->Append( Playlist_Event, wxU(_("&Playlist...\tCtrl-P")) );
604 view_menu->Append( Logs_Event, wxU(_("&Messages...\tCtrl-M")) );
605 view_menu->Append( FileInfo_Event,
606 wxU(_("Stream and Media &Info...\tCtrl-I")) );
608 view_menu->Append( VLM_Event,
609 wxU(_("VLM Control...\tCtrl-V")) );
612 /* Create the "Auto-generated" menus */
613 p_settings_menu = SettingsMenu( p_intf, this );
614 p_audio_menu = AudioMenu( p_intf, this );
615 p_video_menu = VideoMenu( p_intf, this );
616 p_navig_menu = NavigMenu( p_intf, this );
618 /* Create the "Help" menu */
619 wxMenu *help_menu = new wxMenu;
620 help_menu->Append( OnWebLink_Event, wxU(_("VideoLAN's Website")) );
621 help_menu->Append( OnWebHelp_Event, wxU(_("Online Help")) );
622 help_menu->AppendSeparator();
623 help_menu->Append( About_Event, wxU(_("About...")) );
625 help_menu->AppendSeparator();
626 help_menu->Append( UpdateVLC_Event, wxU(_("Check for Updates...")) );
629 /* Append the freshly created menus to the menu bar... */
630 wxMenuBar *menubar = new wxMenuBar();
631 menubar->Append( file_menu, wxU(_("&File")) );
632 menubar->Append( view_menu, wxU(_("V&iew")) );
633 menubar->Append( p_settings_menu, wxU(_("&Settings")) );
634 menubar->Append( p_audio_menu, wxU(_("&Audio")) );
635 menubar->Append( p_video_menu, wxU(_("&Video")) );
636 menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
637 menubar->Append( help_menu, wxU(_("&Help")) );
639 /* Attach the menu bar to the frame */
640 SetMenuBar( menubar );
642 /* Find out size of menu bar */
644 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
646 int i_width, i_height;
647 menubar->GetTextExtent( menubar->GetLabelTop(i), &i_width, &i_height );
649 #if defined(__WXGTK__)
650 22 /* approximate margin */;
652 #if (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 5) && (wxRELEASE_NUMBER < 3)
653 4 /* approximate margin */;
655 18 /* approximate margin */;
660 /* Patch by zcot for menu wrapping */
662 /* Find out size of msw menu bar */
665 HDC hdc = GetDC( NULL );
666 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
668 GetTextExtentPoint32( hdc, menubar->GetLabelTop(i).c_str(),
669 menubar->GetLabelTop(i).Length(), &sizing );
671 // [ SM_CXDLGFRAME + pixels + textextent + pixels + SM_CXDLGFRAME ]
672 i_size += sizing.cx + 2 + GetSystemMetrics( SM_CXDLGFRAME ) * 2;
674 ReleaseDC( NULL, hdc );
675 i_size += GetSystemMetrics( SM_CXSIZEFRAME ) * 2 + 4;
677 /* End patch by zcot */
679 panel_sizer->SetMinSize( i_size, -1 );
681 /* Intercept all menu events in our custom event handler */
682 PushEventHandler( new MenuEvtHandler( p_intf, this ) );
684 #if wxUSE_DRAG_AND_DROP
685 /* Associate drop targets with the menubar */
686 menubar->SetDropTarget( new DragAndDrop( p_intf ) );
690 void Interface::CreateOurToolBar()
692 #define HELP_OPEN N_("Open")
693 #define HELP_STOP N_("Stop")
694 #define HELP_PLAY N_("Play")
695 #define HELP_PAUSE N_("Pause")
696 #define HELP_PLO N_("Playlist")
697 #define HELP_SPLO N_("Embedded playlist")
698 #define HELP_PLP N_("Previous playlist item")
699 #define HELP_PLN N_("Next playlist item")
700 #define HELP_SLOW N_("Play slower")
701 #define HELP_FAST N_("Play faster")
703 #define LABEL_OPEN N_("Open")
704 #define LABEL_STOP N_("Stop")
705 #define LABEL_PLAY N_("Play")
706 #define LABEL_PAUSE N_("Pause")
707 #define LABEL_PLO N_("Playlist")
708 #define LABEL_SPLO N_("Embedded playlist")
709 #define LABEL_PLP N_("Previous")
710 #define LABEL_PLN N_("Next")
711 #define LABEL_SLOW N_("Slower")
712 #define LABEL_FAST N_("Faster")
713 int minimal = config_GetInt( p_intf, "wx-minimal" );
714 bool label = config_GetInt( p_intf, "wx-labels" );
716 wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
717 * version because we don't include wx.rc */
720 CreateToolBar( label?wxTB_HORIZONTAL | wxTB_FLAT |wxTB_TEXT:
721 wxTB_HORIZONTAL | wxTB_FLAT );
723 toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
727 toolbar->AddTool( OpenFile_Event, wxU(LABEL_OPEN),
728 wxBitmap( eject_xpm ), wxU(_(HELP_OPEN)) );
729 toolbar->AddSeparator();
732 wxToolBarToolBase *p_tool = toolbar->AddTool( PlayStream_Event, wxU(LABEL_PLAY),
733 wxBitmap( play_xpm ), wxU(_(HELP_PLAY)), wxITEM_CHECK );
734 p_tool->SetClientData( p_tool );
738 toolbar->AddTool( StopStream_Event, wxU(LABEL_STOP), wxBitmap( stop_xpm ),
740 toolbar->AddSeparator();
742 toolbar->AddTool( PrevStream_Event, wxU(LABEL_PLP),
743 wxBitmap( prev_xpm ), wxU(_(HELP_PLP)) );
744 toolbar->AddTool( SlowStream_Event, wxU(LABEL_SLOW),
745 wxBitmap( slow_xpm ), wxU(_(HELP_SLOW)) );
746 toolbar->AddTool( FastStream_Event, wxU(LABEL_FAST),
747 wxBitmap( fast_xpm ), wxU(_(HELP_FAST)) );
748 toolbar->AddTool( NextStream_Event, wxU(LABEL_PLN), wxBitmap( next_xpm ),
750 toolbar->AddSeparator();
751 if( config_GetInt( p_intf, "wx-playlist-view" ) != 1 )
752 toolbar->AddTool( Playlist_Event, wxU(LABEL_PLO),
753 wxBitmap( playlist_xpm ), wxU(_(HELP_PLO)) );
754 if( config_GetInt( p_intf, "wx-playlist-view" ) >= 1 )
755 toolbar->AddTool( PlaylistSmall_Event, wxU(LABEL_SPLO),
756 wxBitmap( playlist_small_xpm ), wxU(_(HELP_SPLO)) );
759 wxControl *p_dummy_ctrl =
760 new wxControl( toolbar, -1, wxDefaultPosition,
761 wxSize(16, 16 ), wxBORDER_NONE );
763 toolbar->AddControl( p_dummy_ctrl );
765 volctrl = new VLCVolCtrl( p_intf, toolbar );
766 toolbar->AddControl( volctrl );
770 #if wxUSE_DRAG_AND_DROP
771 /* Associate drop targets with the toolbar */
772 toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
776 static int ConvertHotkeyModifiers( int i_hotkey )
778 int i_accel_flags = 0;
779 if( i_hotkey & KEY_MODIFIER_ALT ) i_accel_flags |= wxACCEL_ALT;
780 if( i_hotkey & KEY_MODIFIER_CTRL ) i_accel_flags |= wxACCEL_CTRL;
781 if( i_hotkey & KEY_MODIFIER_SHIFT ) i_accel_flags |= wxACCEL_SHIFT;
782 if( !i_accel_flags ) i_accel_flags = wxACCEL_NORMAL;
783 return i_accel_flags;
786 static int ConvertHotkey( int i_hotkey )
788 int i_key = i_hotkey & ~KEY_MODIFIER;
789 if( i_key & KEY_ASCII ) return i_key & KEY_ASCII;
790 else if( i_key & KEY_SPECIAL )
794 case KEY_LEFT: return WXK_LEFT;
795 case KEY_RIGHT: return WXK_RIGHT;
796 case KEY_UP: return WXK_UP;
797 case KEY_DOWN: return WXK_DOWN;
798 case KEY_SPACE: return WXK_SPACE;
799 case KEY_ENTER: return WXK_RETURN;
800 case KEY_F1: return WXK_F1;
801 case KEY_F2: return WXK_F2;
802 case KEY_F3: return WXK_F3;
803 case KEY_F4: return WXK_F4;
804 case KEY_F5: return WXK_F5;
805 case KEY_F6: return WXK_F6;
806 case KEY_F7: return WXK_F7;
807 case KEY_F8: return WXK_F8;
808 case KEY_F9: return WXK_F9;
809 case KEY_F10: return WXK_F10;
810 case KEY_F11: return WXK_F11;
811 case KEY_F12: return WXK_F12;
812 case KEY_HOME: return WXK_HOME;
813 case KEY_END: return WXK_END;
814 case KEY_INSERT: return WXK_INSERT;
815 case KEY_DELETE: return WXK_DELETE;
816 case KEY_MENU: return WXK_MENU;
817 case KEY_ESC: return WXK_ESCAPE;
818 case KEY_PAGEUP: return WXK_PRIOR;
819 case KEY_PAGEDOWN: return WXK_NEXT;
820 case KEY_TAB: return WXK_TAB;
821 case KEY_BACKSPACE: return WXK_BACK;
827 void Interface::SetupHotkeys()
829 struct libvlc_int_t::hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
832 /* Count number of hoteys */
833 for( i_hotkeys = 0; p_hotkeys[i_hotkeys].psz_action != NULL; i_hotkeys++ );
835 p_intf->p_sys->i_first_hotkey_event = wxID_HIGHEST + 7000;
836 p_intf->p_sys->i_hotkeys = i_hotkeys;
838 wxAcceleratorEntry *p_entries = new wxAcceleratorEntry[i_hotkeys];
840 /* Setup the hotkeys as accelerators */
841 for( int i = 0; i < i_hotkeys; i++ )
843 int i_mod = ConvertHotkeyModifiers( p_hotkeys[i].i_key );
844 int i_key = ConvertHotkey( p_hotkeys[i].i_key );
847 if( !(p_hotkeys[i].i_key & KEY_SPECIAL) && i_mod )
848 i_key = toupper(i_key);
851 p_entries[i].Set( i_mod, i_key,
852 p_intf->p_sys->i_first_hotkey_event + i );
855 wxAcceleratorTable accel( i_hotkeys, p_entries );
859 msg_Err( p_intf, "invalid accelerator table" );
863 SetAcceleratorTable( accel );
869 void Interface::SetIntfMinSize()
871 wxSize ms = main_min_size;
873 if( extra_frame && extra_frame->IsShown() )
875 ms.SetHeight( ms.GetHeight() + ext_min_size.GetHeight() );
876 if( ext_min_size.GetWidth() > ms.GetWidth() )
877 ms.SetWidth( ext_min_size.GetWidth() );
880 SetSizeHints( ms.GetWidth(), ms.GetHeight() );
883 /*****************************************************************************
885 *****************************************************************************/
886 void Interface::OnMenuOpen( wxMenuEvent& event )
888 #if defined( __WXMSW__ )
889 # define GetEventObject GetMenu
892 if( event.GetEventObject() == p_settings_menu )
894 p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );
896 /* Add static items */
897 p_settings_menu->AppendCheckItem( Extended_Event,
898 wxU(_("Extended &GUI\tCtrl-G") ) );
899 if( b_extra ) p_settings_menu->Check( Extended_Event, TRUE );
900 p_settings_menu->Append( Bookmarks_Event,
901 wxU(_("&Bookmarks...\tCtrl-B") ) );
902 p_settings_menu->Append( Prefs_Event,
903 wxU(_("Preference&s...\tCtrl-S")) );
906 else if( event.GetEventObject() == p_audio_menu )
908 p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
911 else if( event.GetEventObject() == p_video_menu )
913 p_video_menu = VideoMenu( p_intf, this, p_video_menu );
916 else if( event.GetEventObject() == p_navig_menu )
918 p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
921 #if defined( __WXMSW__ )
922 # undef GetEventObject
926 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
927 void Interface::OnContextMenu2(wxContextMenuEvent& event)
929 /* Only show the context menu for the main interface */
930 if( GetId() != event.GetId() )
936 if( p_intf->p_sys->pf_show_dialog )
937 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
940 void Interface::OnContextMenu(wxMouseEvent& event)
942 if( p_intf->p_sys->pf_show_dialog )
943 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
946 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
948 /* TRUE is to force the frame to close. */
952 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
955 msg.Printf( wxString(wxT("VLC media player " VERSION_MESSAGE)) +
956 wxU(_(" (wxWidgets interface)\n\n")) +
957 wxU(_("(c) " COPYRIGHT_YEARS " - the VideoLAN Team\n\n")) +
958 wxU(_("Compiled by "))+ wxU(VLC_CompileBy())+ wxU("@") +
959 wxU(VLC_CompileHost())+ wxT(".")+ wxU(VLC_CompileDomain())+ wxT(".\n") +
960 wxU(_("Compiler: "))+ wxU(VLC_Compiler())+wxT( ".\n") +
961 wxU(_("Based on Git commit: "))+wxU(VLC_Changeset())+wxT(".\n\n") +
963 wxU( vlc_wraptext(LICENSE_MSG,WRAPCOUNT) ) + wxT("\n\n") +
965 wxU( LICENSE_MSG ) + wxT("\n\n") +
967 wxU(_("The VideoLAN team <videolan@videolan.org>\n"
968 "http://www.videolan.org/\n\n")) );
969 wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
970 wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
973 void Interface::OnWebLink( wxCommandEvent& WXUNUSED(event) )
975 wxLaunchDefaultBrowser( wxU("http://videolan.org/") );
978 void Interface::OnWebHelp( wxCommandEvent& WXUNUSED(event) )
980 wxLaunchDefaultBrowser( wxU("http://videolan.org/doc/") );
983 void Interface::OnShowDialog( wxCommandEvent& event )
985 if( p_intf->p_sys->pf_show_dialog )
989 switch( event.GetId() )
991 case OpenFileSimple_Event:
992 i_id = INTF_DIALOG_FILE_SIMPLE;
995 i_id = INTF_DIALOG_FILE;
998 i_id = INTF_DIALOG_FILE;
1001 i_id = INTF_DIALOG_DIRECTORY;
1003 case OpenDisc_Event:
1004 i_id = INTF_DIALOG_DISC;
1007 i_id = INTF_DIALOG_NET;
1009 case OpenCapture_Event:
1010 i_id = INTF_DIALOG_CAPTURE;
1013 i_id = INTF_DIALOG_SAT;
1015 case Playlist_Event:
1016 i_id = INTF_DIALOG_PLAYLIST;
1019 i_id = INTF_DIALOG_MESSAGES;
1021 case FileInfo_Event:
1022 i_id = INTF_DIALOG_FILEINFO;
1025 i_id = INTF_DIALOG_PREFS;
1028 i_id = INTF_DIALOG_WIZARD;
1030 case Bookmarks_Event:
1031 i_id = INTF_DIALOG_BOOKMARKS;
1034 case UpdateVLC_Event:
1035 i_id = INTF_DIALOG_UPDATEVLC;
1040 i_id = INTF_DIALOG_VLM;
1044 i_id = INTF_DIALOG_FILE;
1048 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
1052 void Interface::OnExtended( wxCommandEvent& WXUNUSED(event) )
1054 UpdateVideoWindow( p_intf, video_window );
1058 /* Create the extra panel */
1059 extra_frame = new ExtraPanel( p_intf, main_panel );
1060 panel_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
1061 ext_min_size = extra_frame->GetBestSize();
1065 panel_sizer->Show( extra_frame, b_extra );
1068 main_sizer->Layout();
1069 main_sizer->Fit( this );
1072 void Interface::OnSmallPlaylist( wxCommandEvent& WXUNUSED(event) )
1074 UpdateVideoWindow( p_intf, video_window );
1076 if( !playlist_manager )
1078 /* Create the extra panel */
1079 playlist_manager = new PlaylistManager( p_intf, splitter );
1082 if( !splitter->IsSplit() ) splitter->Split( main_panel, playlist_manager );
1083 else splitter->Unsplit( playlist_manager );
1086 main_sizer->Layout();
1087 main_sizer->Fit( this );
1090 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
1095 void Interface::PlayStream()
1097 wxCommandEvent dummy;
1098 playlist_t *p_playlist =
1099 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1101 if( p_playlist == NULL ) return;
1103 if( !playlist_IsEmpty(p_playlist) && p_playlist->i_enabled )
1107 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
1110 if( p_input == NULL )
1112 /* No stream was playing, start one */
1113 playlist_Play( p_playlist );
1114 vlc_object_release( p_playlist );
1115 input_manager->Update();
1119 var_Get( p_input, "state", &state );
1120 if( state.i_int != PAUSE_S )
1122 /* A stream is being played, pause it */
1123 state.i_int = PAUSE_S;
1127 /* Stream is paused, resume it */
1128 state.i_int = PLAYING_S;
1130 var_Set( p_input, "state", state );
1132 vlc_object_release( p_input );
1133 vlc_object_release( p_playlist );
1134 input_manager->Update();
1138 /* If the playlist is empty, open a file requester instead */
1139 vlc_object_release( p_playlist );
1140 OnShowDialog( dummy );
1141 GetToolBar()->ToggleTool( PlayStream_Event, false );
1145 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
1149 void Interface::StopStream()
1151 playlist_t * p_playlist =
1152 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1154 if( p_playlist == NULL )
1159 playlist_Stop( p_playlist );
1160 vlc_object_release( p_playlist );
1161 input_manager->Update();
1164 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
1169 void Interface::PrevStream()
1171 playlist_t * p_playlist =
1172 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1174 if( p_playlist == NULL )
1179 playlist_Prev( p_playlist );
1180 vlc_object_release( p_playlist );
1183 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1188 void Interface::NextStream()
1190 playlist_t * p_playlist =
1191 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1193 if( p_playlist == NULL )
1197 playlist_Next( p_playlist );
1198 vlc_object_release( p_playlist );
1201 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1203 input_thread_t *p_input =
1204 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1208 vlc_value_t val; val.b_bool = VLC_TRUE;
1210 var_Set( p_input, "rate-slower", val );
1211 vlc_object_release( p_input );
1215 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1217 input_thread_t *p_input =
1218 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1222 vlc_value_t val; val.b_bool = VLC_TRUE;
1224 var_Set( p_input, "rate-faster", val );
1225 vlc_object_release( p_input );
1229 void Interface::TogglePlayButton( int i_playing_status )
1231 wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
1232 GetToolBar()->GetToolClientData( PlayStream_Event );
1233 if( !p_tool ) return;
1235 if( i_playing_status == PLAYING_S )
1237 p_tool->SetNormalBitmap( wxBitmap( pause_xpm ) );
1238 p_tool->SetLabel( wxU(_("Pause")) );
1239 p_tool->SetShortHelp( wxU(_(HELP_PAUSE)) );
1243 p_tool->SetNormalBitmap( wxBitmap( play_xpm ) );
1244 p_tool->SetLabel( wxU(_("Play")) );
1245 p_tool->SetShortHelp( wxU(_(HELP_PLAY)) );
1248 GetToolBar()->Realize();
1250 #if defined( __WXMSW__ )
1251 /* Needed to work around a bug in wxToolBar::Realize() */
1252 GetToolBar()->SetSize( GetSize().GetWidth(),
1253 GetToolBar()->GetSize().GetHeight() );
1254 GetToolBar()->Update();
1257 GetToolBar()->ToggleTool( PlayStream_Event, true );
1258 GetToolBar()->ToggleTool( PlayStream_Event, false );
1261 void Interface::OnInteraction( wxCommandEvent& event )
1263 interaction_dialog_t *p_dialog = (interaction_dialog_t *)
1264 event.GetClientData();
1266 intf_dialog_args_t *p_arg = new intf_dialog_args_t;
1267 p_arg->p_dialog = p_dialog;
1268 p_arg->p_intf = p_intf;
1270 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_INTERACTION,
1275 static int InteractCallback( vlc_object_t *p_this,
1276 const char *psz_var, vlc_value_t old_val,
1277 vlc_value_t new_val, void *param )
1279 Interface *p_interface = (Interface*)param;
1280 /*interaction_dialog_t *p_dialog = (interaction_dialog_t*)(new_val.p_address);*/
1282 wxCommandEvent event( wxEVT_INTERACTION, -1 );
1283 event.SetClientData( new_val.p_address );
1284 p_interface->AddPendingEvent( event );
1288 #if wxUSE_DRAG_AND_DROP
1289 /*****************************************************************************
1290 * Definition of DragAndDrop class.
1291 *****************************************************************************/
1292 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
1295 b_enqueue = _b_enqueue;
1298 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1299 const wxArrayString& filenames )
1301 /* Add dropped files to the playlist */
1303 playlist_t *p_playlist =
1304 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1306 if( p_playlist == NULL )
1311 /* If we drag & drop a subtitle file, add it on the fly */
1312 if( filenames.GetCount() == 1 )
1314 char *psz_utf8 = wxDnDFromLocale( filenames[0] );
1315 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
1316 VLC_OBJECT_INPUT, FIND_ANYWHERE );
1319 if( input_AddSubtitles( p_input, psz_utf8, VLC_TRUE ) )
1321 vlc_object_release( p_input );
1322 wxDnDLocaleFree( psz_utf8 );
1323 vlc_object_release( p_playlist );
1326 vlc_object_release( p_input );
1328 wxDnDLocaleFree( psz_utf8 );
1331 for( size_t i = 0; i < filenames.GetCount(); i++ )
1333 char *psz_utf8 = wxDnDFromLocale( filenames[i] );
1335 playlist_Add( p_playlist, psz_utf8, NULL,
1336 PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
1337 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
1339 wxDnDLocaleFree( psz_utf8 );
1342 vlc_object_release( p_playlist );
1348 /*****************************************************************************
1349 * Definition of VolCtrl class.
1350 *****************************************************************************/
1351 class wxVolCtrl: public wxGauge
1355 wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1356 wxPoint = wxDefaultPosition, wxSize = wxSize( 20, -1 ) );
1357 virtual ~wxVolCtrl() {};
1359 void UpdateVolume();
1362 void OnChange( wxMouseEvent& event );
1365 intf_thread_t *p_intf;
1367 DECLARE_EVENT_TABLE();
1370 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
1372 EVT_LEFT_DOWN(wxVolCtrl::OnChange)
1373 EVT_MOTION(wxVolCtrl::OnChange)
1376 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1377 wxPoint point, wxSize size )
1378 : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
1384 void wxVolCtrl::OnChange( wxMouseEvent& event )
1386 if( !event.LeftDown() && !event.LeftIsDown() ) return;
1388 int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
1389 aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1393 void wxVolCtrl::UpdateVolume()
1395 audio_volume_t i_volume;
1396 aout_VolumeGet( p_intf, &i_volume );
1398 int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
1399 if( i_gauge_volume == GetValue() ) return;
1401 SetValue( i_gauge_volume );
1402 SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
1403 i_gauge_volume / 2 ) );
1406 #if defined(__WXGTK__)
1407 #define VLCVOL_HEIGHT p_parent->GetSize().GetHeight()
1409 #define VLCVOL_HEIGHT TOOLBAR_BMP_HEIGHT
1411 VLCVolCtrl::VLCVolCtrl( intf_thread_t *_p_intf, wxWindow *p_parent )
1412 :wxControl( p_parent, -1, wxDefaultPosition, wxSize(64, VLCVOL_HEIGHT ),
1414 i_y_offset((VLCVOL_HEIGHT - TOOLBAR_BMP_HEIGHT) / 2),
1415 b_mute(0), p_intf(_p_intf)
1417 gauge = new wxVolCtrl( p_intf, this, -1, wxPoint( 18, i_y_offset ),
1418 wxSize( 44, TOOLBAR_BMP_HEIGHT ) );
1421 void VLCVolCtrl::OnPaint( wxPaintEvent &evt )
1423 wxPaintDC dc( this );
1424 wxBitmap mPlayBitmap( b_mute ? speaker_mute_xpm : speaker_xpm );
1425 dc.DrawBitmap( mPlayBitmap, 0, i_y_offset, TRUE );
1428 void VLCVolCtrl::OnChange( wxMouseEvent& event )
1430 if( event.GetX() < TOOLBAR_BMP_WIDTH )
1433 aout_VolumeMute( p_intf, (audio_volume_t *)&i_volume );
1440 void VLCVolCtrl::UpdateVolume()
1442 gauge->UpdateVolume();
1444 int i_volume = gauge->GetValue();
1445 if( !!i_volume == !b_mute ) return;
1450 /*****************************************************************************
1452 *****************************************************************************/
1454 /* wxCocoa pretends to support this, but at least 2.6.x doesn't */
1456 #ifdef wxHAS_TASK_BAR_ICON
1458 BEGIN_EVENT_TABLE(Systray, wxTaskBarIcon)
1461 EVT_TASKBAR_LEFT_DCLICK(Systray::OnLeftClick)
1463 EVT_TASKBAR_LEFT_DOWN(Systray::OnLeftClick)
1466 EVT_MENU(Iconize_Event, Systray::OnMenuIconize)
1467 EVT_MENU(Exit_Event, Systray::OnExit)
1468 EVT_MENU(PlayStream_Event, Systray::OnPlayStream)
1469 EVT_MENU(NextStream_Event, Systray::OnNextStream)
1470 EVT_MENU(PrevStream_Event, Systray::OnPrevStream)
1471 EVT_MENU(StopStream_Event, Systray::OnStopStream)
1474 Systray::Systray( Interface *_p_main_interface, intf_thread_t *_p_intf )
1476 p_main_interface = _p_main_interface;
1479 SetIcon( wxIcon( (const char**) vlc16x16_xpm ), wxT("VLC media player") );
1480 if( !IsOk() || !IsIconInstalled() )
1482 msg_Warn(p_intf, "cannot set systray icon, weird things may happen");
1486 /* Event handlers */
1487 void Systray::OnMenuIconize( wxCommandEvent& event )
1489 p_main_interface->Show( ! p_main_interface->IsShown() );
1490 if ( p_main_interface->IsShown() ) p_main_interface->Raise();
1493 void Systray::OnLeftClick( wxTaskBarIconEvent& event )
1495 wxCommandEvent cevent;
1496 OnMenuIconize(cevent);
1499 void Systray::OnExit( wxCommandEvent& event )
1501 p_main_interface->Close(TRUE);
1504 void Systray::OnPrevStream( wxCommandEvent& event )
1506 p_main_interface->PrevStream();
1509 void Systray::OnNextStream( wxCommandEvent& event )
1511 p_main_interface->NextStream();
1514 void Systray::OnPlayStream( wxCommandEvent& event )
1516 p_main_interface->PlayStream();
1519 void Systray::OnStopStream( wxCommandEvent& event )
1521 p_main_interface->StopStream();
1524 /* Systray popup menu */
1525 wxMenu* Systray::CreatePopupMenu()
1527 int minimal = config_GetInt( p_intf, "wx-minimal" );
1529 wxMenu* systray_menu = new wxMenu;
1530 systray_menu->Append( Exit_Event, wxU(_("Quit VLC")) );
1531 systray_menu->AppendSeparator();
1532 systray_menu->Append( PlayStream_Event, wxU(_("Play/Pause")) );
1536 systray_menu->Append( PrevStream_Event, wxU(_("Previous")) );
1537 systray_menu->Append( NextStream_Event, wxU(_("Next")) );
1538 systray_menu->Append( StopStream_Event, wxU(_("Stop")) );
1540 systray_menu->AppendSeparator();
1541 systray_menu->Append( Iconize_Event, wxU(_("Show/Hide Interface")) );
1542 return systray_menu;
1545 void Systray::UpdateTooltip( const wxChar* tooltip )
1547 SetIcon( wxIcon( (const char**) vlc16x16_xpm ), tooltip );