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 <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 #ifdef wxHAS_TASK_BAR_ICON
400 /* Systray integration */
402 if( config_GetInt( p_intf, "wx-systray" ) )
404 p_systray = new Systray( this, p_intf );
408 /* Creation of the menu bar */
411 /* Creation of the tool bar */
414 /* Creation of the status bar
415 * Helptext for menu items and toolbar tools will automatically get
417 int i_status_width[3] = {100, 40, -1};
418 statusbar = CreateStatusBar( 3 ); /* 2 fields */
419 statusbar->SetStatusWidths( 3, i_status_width );
420 statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
422 /* Get minimum window size to prevent user from glitching it */
423 splitter->SetSizeHints( -1, 0 );
424 panel_sizer->Layout(); panel_sizer->Fit( main_panel );
425 main_sizer->Layout(); main_sizer->Fit( this );
426 main_min_size = GetSize();
427 splitter->SetSizeHints( -1, -1 );
431 if( config_GetInt( p_intf, "wx-embed" ) )
433 video_window = CreateVideoWindow( p_intf, main_panel );
434 panel_sizer->Add( p_intf->p_sys->p_video_sizer, 1, wxEXPAND, 0 );
437 /* Creation of the input manager panel */
438 input_manager = new InputManager( p_intf, this, main_panel );
439 panel_sizer->Add( input_manager, 0, wxEXPAND , 0 );
441 /* Layout everything */
442 splitter->SetSizeHints( -1, 0 );
443 panel_sizer->Layout(); panel_sizer->Fit( main_panel );
444 main_sizer->Layout(); main_sizer->Fit( this );
445 splitter->SetSizeHints( -1, -1 );
447 #if wxUSE_DRAG_AND_DROP
448 /* Associate drop targets with the main interface */
449 SetDropTarget( new DragAndDrop( p_intf ) );
455 timer = new Timer( p_intf, this );
457 /* Restore previous position / settings */
458 WindowSettings *ws = p_intf->p_sys->p_window_settings;
463 ws->SetScreen( wxSystemSettings::GetMetric( wxSYS_SCREEN_X ),
464 wxSystemSettings::GetMetric( wxSYS_SCREEN_Y ) );
466 if( ws->GetSettings( WindowSettings::ID_MAIN, b_shown, p, s ) ) Move( p );
468 /* Show extended GUI if requested */
469 wxCommandEvent dummy;
470 if( config_GetInt( p_intf, "wx-extended" ) ) OnExtended( dummy );
474 fprintf( stderr, "Adding callback to object %i\n", p_intf->i_object_id );
476 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
477 var_AddCallback( p_intf, "interaction", InteractCallback, this );
478 p_intf->b_interaction = VLC_TRUE;
480 /* Show embedded playlist if requested */
481 if( splitter->ShowOnStart() ) OnSmallPlaylist( dummy );
484 Interface::~Interface()
486 WindowSettings *ws = p_intf->p_sys->p_window_settings;
490 ws->SetSettings( WindowSettings::ID_MAIN, true,
491 GetPosition(), GetSize() );
494 PopEventHandler(true);
496 if( video_window ) delete video_window;
498 #ifdef wxHAS_TASK_BAR_ICON
499 if( p_systray ) delete p_systray;
502 p_intf->b_interaction = VLC_FALSE;
503 var_DelCallback( p_intf, "interaction", InteractCallback, this );
505 if( p_intf->p_sys->p_wxwindow ) delete p_intf->p_sys->p_wxwindow;
512 void Interface::Init()
518 void Interface::Update()
521 ((VLCVolCtrl *)volctrl)->UpdateVolume();
523 if( playlist_manager ) playlist_manager->Update();
526 void Interface::OnControlEvent( wxCommandEvent& event )
528 switch( event.GetId() )
531 main_sizer->Layout();
532 main_sizer->Fit( this );
536 long i_style = GetWindowStyle();
537 if( event.GetInt() ) i_style |= wxSTAY_ON_TOP;
538 else i_style &= ~wxSTAY_ON_TOP;
539 SetWindowStyle( i_style );
544 /*****************************************************************************
546 *****************************************************************************/
547 void Interface::CreateOurMenuBar()
549 int minimal = config_GetInt( p_intf, "wx-minimal" );
551 /* Create the "File" menu */
552 wxMenu *file_menu = new wxMenu;
556 file_menu->Append( OpenFileSimple_Event,
557 wxU(_("Quick &Open File...\tCtrl-O")) );
559 file_menu->AppendSeparator();
560 file_menu->Append( OpenFile_Event, wxU(_("Open &File...\tCtrl-F")) );
561 file_menu->Append( OpenDir_Event, wxU(_("Open Dir&ectory...\tCtrl-E")) );
562 file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...\tCtrl-D")) );
563 file_menu->Append( OpenNet_Event,
564 wxU(_("Open &Network Stream...\tCtrl-N")) );
565 file_menu->Append( OpenCapture_Event,
566 wxU(_("Open C&apture Device...\tCtrl-A")) );
568 file_menu->AppendSeparator();
569 file_menu->Append( Wizard_Event, wxU(_("&Wizard...\tCtrl-W")) );
570 file_menu->AppendSeparator();
572 file_menu->Append( Exit_Event, wxU(_("E&xit\tCtrl-X")) );
574 /* Create the "View" menu */
575 wxMenu *view_menu = new wxMenu;
578 view_menu->Append( Playlist_Event, wxU(_("&Playlist...\tCtrl-P")) );
580 view_menu->Append( Logs_Event, wxU(_("&Messages...\tCtrl-M")) );
581 view_menu->Append( FileInfo_Event,
582 wxU(_("Stream and Media &info...\tCtrl-I")) );
583 view_menu->Append( VLM_Event,
584 wxU(_("VLM Control...\tCtrl-V")) );
586 /* Create the "Auto-generated" menus */
587 p_settings_menu = SettingsMenu( p_intf, this );
588 p_audio_menu = AudioMenu( p_intf, this );
589 p_video_menu = VideoMenu( p_intf, this );
590 p_navig_menu = NavigMenu( p_intf, this );
592 /* Create the "Help" menu */
593 wxMenu *help_menu = new wxMenu;
594 help_menu->Append( About_Event, wxU(_("About VLC media player")) );
595 help_menu->AppendSeparator();
596 help_menu->Append( UpdateVLC_Event, wxU(_("Check for updates ...")) );
598 /* Append the freshly created menus to the menu bar... */
599 wxMenuBar *menubar = new wxMenuBar();
600 menubar->Append( file_menu, wxU(_("&File")) );
601 menubar->Append( view_menu, wxU(_("&View")) );
602 menubar->Append( p_settings_menu, wxU(_("&Settings")) );
603 menubar->Append( p_audio_menu, wxU(_("&Audio")) );
604 menubar->Append( p_video_menu, wxU(_("&Video")) );
605 menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
606 menubar->Append( help_menu, wxU(_("&Help")) );
608 /* Attach the menu bar to the frame */
609 SetMenuBar( menubar );
611 /* Find out size of menu bar */
613 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
615 int i_width, i_height;
616 menubar->GetTextExtent( menubar->GetLabelTop(i), &i_width, &i_height );
618 #if defined(__WXGTK__)
619 22 /* approximate margin */;
621 #if (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 5) && (wxRELEASE_NUMBER < 3)
622 4 /* approximate margin */;
624 18 /* approximate margin */;
629 /* Patch by zcot for menu wrapping */
631 /* Find out size of msw menu bar */
634 HDC hdc = GetDC( NULL );
635 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
637 GetTextExtentPoint32( hdc, menubar->GetLabelTop(i).c_str(),
638 menubar->GetLabelTop(i).Length(), &sizing );
640 // [ SM_CXDLGFRAME + pixels + textextent + pixels + SM_CXDLGFRAME ]
641 i_size += sizing.cx + 2 + GetSystemMetrics( SM_CXDLGFRAME ) * 2;
643 ReleaseDC( NULL, hdc );
644 i_size += GetSystemMetrics( SM_CXSIZEFRAME ) * 2 + 4;
646 /* End patch by zcot */
648 panel_sizer->SetMinSize( i_size, -1 );
650 /* Intercept all menu events in our custom event handler */
651 PushEventHandler( new MenuEvtHandler( p_intf, this ) );
653 #if wxUSE_DRAG_AND_DROP
654 /* Associate drop targets with the menubar */
655 menubar->SetDropTarget( new DragAndDrop( p_intf ) );
659 void Interface::CreateOurToolBar()
661 #define HELP_OPEN N_("Open")
662 #define HELP_STOP N_("Stop")
663 #define HELP_PLAY N_("Play")
664 #define HELP_PAUSE N_("Pause")
665 #define HELP_PLO N_("Playlist")
666 #define HELP_SPLO N_("Small playlist")
667 #define HELP_PLP N_("Previous playlist item")
668 #define HELP_PLN N_("Next playlist item")
669 #define HELP_SLOW N_("Play slower")
670 #define HELP_FAST N_("Play faster")
672 int minimal = config_GetInt( p_intf, "wx-minimal" );
674 wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
675 * version because we don't include wx.rc */
678 CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
680 toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
684 toolbar->AddTool( OpenFile_Event, wxT(""),
685 wxBitmap( eject_xpm ), wxU(_(HELP_OPEN)) );
686 toolbar->AddSeparator();
689 wxToolBarToolBase *p_tool = toolbar->AddTool( PlayStream_Event, wxT(""),
690 wxBitmap( play_xpm ), wxU(_(HELP_PLAY)), wxITEM_CHECK );
691 p_tool->SetClientData( p_tool );
695 toolbar->AddTool( StopStream_Event, wxT(""), wxBitmap( stop_xpm ),
697 toolbar->AddSeparator();
699 toolbar->AddTool( PrevStream_Event, wxT(""),
700 wxBitmap( prev_xpm ), wxU(_(HELP_PLP)) );
701 toolbar->AddTool( SlowStream_Event, wxT(""),
702 wxBitmap( slow_xpm ), wxU(_(HELP_SLOW)) );
703 toolbar->AddTool( FastStream_Event, wxT(""),
704 wxBitmap( fast_xpm ), wxU(_(HELP_FAST)) );
705 toolbar->AddTool( NextStream_Event, wxT(""), wxBitmap( next_xpm ),
707 toolbar->AddSeparator();
708 toolbar->AddTool( Playlist_Event, wxT(""), wxBitmap( playlist_xpm ),
710 toolbar->AddTool( PlaylistSmall_Event, wxT(""),
711 wxBitmap( playlist_small_xpm ), wxU(_(HELP_SPLO)) );
714 wxControl *p_dummy_ctrl =
715 new wxControl( toolbar, -1, wxDefaultPosition,
716 wxSize(16, 16 ), wxBORDER_NONE );
718 toolbar->AddControl( p_dummy_ctrl );
720 volctrl = new VLCVolCtrl( p_intf, toolbar );
721 toolbar->AddControl( volctrl );
725 #if wxUSE_DRAG_AND_DROP
726 /* Associate drop targets with the toolbar */
727 toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
731 static int ConvertHotkeyModifiers( int i_hotkey )
733 int i_accel_flags = 0;
734 if( i_hotkey & KEY_MODIFIER_ALT ) i_accel_flags |= wxACCEL_ALT;
735 if( i_hotkey & KEY_MODIFIER_CTRL ) i_accel_flags |= wxACCEL_CTRL;
736 if( i_hotkey & KEY_MODIFIER_SHIFT ) i_accel_flags |= wxACCEL_SHIFT;
737 if( !i_accel_flags ) i_accel_flags = wxACCEL_NORMAL;
738 return i_accel_flags;
741 static int ConvertHotkey( int i_hotkey )
743 int i_key = i_hotkey & ~KEY_MODIFIER;
744 if( i_key & KEY_ASCII ) return i_key & KEY_ASCII;
745 else if( i_key & KEY_SPECIAL )
749 case KEY_LEFT: return WXK_LEFT;
750 case KEY_RIGHT: return WXK_RIGHT;
751 case KEY_UP: return WXK_UP;
752 case KEY_DOWN: return WXK_DOWN;
753 case KEY_SPACE: return WXK_SPACE;
754 case KEY_ENTER: return WXK_RETURN;
755 case KEY_F1: return WXK_F1;
756 case KEY_F2: return WXK_F2;
757 case KEY_F3: return WXK_F3;
758 case KEY_F4: return WXK_F4;
759 case KEY_F5: return WXK_F5;
760 case KEY_F6: return WXK_F6;
761 case KEY_F7: return WXK_F7;
762 case KEY_F8: return WXK_F8;
763 case KEY_F9: return WXK_F9;
764 case KEY_F10: return WXK_F10;
765 case KEY_F11: return WXK_F11;
766 case KEY_F12: return WXK_F12;
767 case KEY_HOME: return WXK_HOME;
768 case KEY_END: return WXK_END;
769 case KEY_INSERT: return WXK_INSERT;
770 case KEY_DELETE: return WXK_DELETE;
771 case KEY_MENU: return WXK_MENU;
772 case KEY_ESC: return WXK_ESCAPE;
773 case KEY_PAGEUP: return WXK_PRIOR;
774 case KEY_PAGEDOWN: return WXK_NEXT;
775 case KEY_TAB: return WXK_TAB;
776 case KEY_BACKSPACE: return WXK_BACK;
782 void Interface::SetupHotkeys()
784 struct vlc_t::hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
787 /* Count number of hoteys */
788 for( i_hotkeys = 0; p_hotkeys[i_hotkeys].psz_action != NULL; i_hotkeys++ );
790 p_intf->p_sys->i_first_hotkey_event = wxID_HIGHEST + 7000;
791 p_intf->p_sys->i_hotkeys = i_hotkeys;
793 wxAcceleratorEntry *p_entries = new wxAcceleratorEntry[i_hotkeys];
795 /* Setup the hotkeys as accelerators */
796 for( int i = 0; i < i_hotkeys; i++ )
798 int i_mod = ConvertHotkeyModifiers( p_hotkeys[i].i_key );
799 int i_key = ConvertHotkey( p_hotkeys[i].i_key );
802 if( !(p_hotkeys[i].i_key & KEY_SPECIAL) && i_mod )
803 i_key = toupper(i_key);
806 p_entries[i].Set( i_mod, i_key,
807 p_intf->p_sys->i_first_hotkey_event + i );
810 wxAcceleratorTable accel( i_hotkeys, p_entries );
814 msg_Err( p_intf, "invalid accelerator table" );
818 SetAcceleratorTable( accel );
824 void Interface::SetIntfMinSize()
826 wxSize ms = main_min_size;
828 if( extra_frame && extra_frame->IsShown() )
830 ms.SetHeight( ms.GetHeight() + ext_min_size.GetHeight() );
831 if( ext_min_size.GetWidth() > ms.GetWidth() )
832 ms.SetWidth( ext_min_size.GetWidth() );
835 SetSizeHints( ms.GetWidth(), ms.GetHeight() );
838 /*****************************************************************************
840 *****************************************************************************/
841 void Interface::OnMenuOpen( wxMenuEvent& event )
843 #if defined( __WXMSW__ )
844 # define GetEventObject GetMenu
847 if( event.GetEventObject() == p_settings_menu )
849 p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );
851 /* Add static items */
852 p_settings_menu->AppendCheckItem( Extended_Event,
853 wxU(_("Extended &GUI\tCtrl-G") ) );
854 if( b_extra ) p_settings_menu->Check( Extended_Event, TRUE );
855 p_settings_menu->Append( Bookmarks_Event,
856 wxU(_("&Bookmarks...\tCtrl-B") ) );
857 p_settings_menu->Append( Prefs_Event,
858 wxU(_("Preference&s...\tCtrl-S")) );
861 else if( event.GetEventObject() == p_audio_menu )
863 p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
866 else if( event.GetEventObject() == p_video_menu )
868 p_video_menu = VideoMenu( p_intf, this, p_video_menu );
871 else if( event.GetEventObject() == p_navig_menu )
873 p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
876 #if defined( __WXMSW__ )
877 # undef GetEventObject
881 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
882 void Interface::OnContextMenu2(wxContextMenuEvent& event)
884 /* Only show the context menu for the main interface */
885 if( GetId() != event.GetId() )
891 if( p_intf->p_sys->pf_show_dialog )
892 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
895 void Interface::OnContextMenu(wxMouseEvent& event)
897 if( p_intf->p_sys->pf_show_dialog )
898 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
901 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
903 /* TRUE is to force the frame to close. */
907 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
910 msg.Printf( wxString(wxT("VLC media player " PACKAGE_VERSION)) +
911 wxU(_(" (wxWidgets interface)\n\n")) +
912 wxU(_("(c) 1996-2005 - the VideoLAN Team\n\n")) +
913 wxU(_("Compiled by "))+ wxU(VLC_CompileBy())+ wxU("@") +
914 wxU(VLC_CompileHost())+ wxT(".")+ wxU(VLC_CompileDomain())+ wxT(".\n") +
915 wxU(_("Compiler: "))+ wxU(VLC_Compiler())+wxT( ".\n") +
916 wxU(_("Based on SVN revision: "))+wxU(VLC_Changeset())+wxT(".\n\n") +
918 wxU( vlc_wraptext(LICENSE_MSG,WRAPCOUNT,VLC_TRUE) ) + wxT("\n\n") +
920 wxU( LICENSE_MSG ) + wxT("\n\n") +
922 wxU(_("The VideoLAN team <videolan@videolan.org>\n"
923 "http://www.videolan.org/\n\n")) );
925 wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
926 wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
929 void Interface::OnShowDialog( wxCommandEvent& event )
931 if( p_intf->p_sys->pf_show_dialog )
935 switch( event.GetId() )
937 case OpenFileSimple_Event:
938 i_id = INTF_DIALOG_FILE_SIMPLE;
941 i_id = INTF_DIALOG_FILE;
944 i_id = INTF_DIALOG_FILE;
947 i_id = INTF_DIALOG_DIRECTORY;
950 i_id = INTF_DIALOG_DISC;
953 i_id = INTF_DIALOG_NET;
955 case OpenCapture_Event:
956 i_id = INTF_DIALOG_CAPTURE;
959 i_id = INTF_DIALOG_SAT;
962 i_id = INTF_DIALOG_PLAYLIST;
965 i_id = INTF_DIALOG_MESSAGES;
968 i_id = INTF_DIALOG_FILEINFO;
971 i_id = INTF_DIALOG_PREFS;
974 i_id = INTF_DIALOG_WIZARD;
976 case Bookmarks_Event:
977 i_id = INTF_DIALOG_BOOKMARKS;
979 case UpdateVLC_Event:
980 i_id = INTF_DIALOG_UPDATEVLC;
983 i_id = INTF_DIALOG_VLM;
986 i_id = INTF_DIALOG_FILE;
990 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
994 void Interface::OnExtended( wxCommandEvent& WXUNUSED(event) )
996 UpdateVideoWindow( p_intf, video_window );
1000 /* Create the extra panel */
1001 extra_frame = new ExtraPanel( p_intf, main_panel );
1002 panel_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
1003 ext_min_size = extra_frame->GetBestSize();
1007 panel_sizer->Show( extra_frame, b_extra );
1010 main_sizer->Layout();
1011 main_sizer->Fit( this );
1014 void Interface::OnSmallPlaylist( wxCommandEvent& WXUNUSED(event) )
1016 UpdateVideoWindow( p_intf, video_window );
1018 if( !playlist_manager )
1020 /* Create the extra panel */
1021 playlist_manager = new PlaylistManager( p_intf, splitter );
1024 if( !splitter->IsSplit() ) splitter->Split( main_panel, playlist_manager );
1025 else splitter->Unsplit( playlist_manager );
1028 main_sizer->Layout();
1029 main_sizer->Fit( this );
1032 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
1037 void Interface::PlayStream()
1039 wxCommandEvent dummy;
1040 playlist_t *p_playlist =
1041 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1043 if( p_playlist == NULL ) return;
1045 if( p_playlist->i_size && p_playlist->i_enabled )
1049 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
1052 if( p_input == NULL )
1054 /* No stream was playing, start one */
1055 playlist_Play( p_playlist );
1056 vlc_object_release( p_playlist );
1057 input_manager->Update();
1061 var_Get( p_input, "state", &state );
1062 if( state.i_int != PAUSE_S )
1064 /* A stream is being played, pause it */
1065 state.i_int = PAUSE_S;
1069 /* Stream is paused, resume it */
1070 state.i_int = PLAYING_S;
1072 var_Set( p_input, "state", state );
1074 vlc_object_release( p_input );
1075 vlc_object_release( p_playlist );
1076 input_manager->Update();
1080 /* If the playlist is empty, open a file requester instead */
1081 vlc_object_release( p_playlist );
1082 OnShowDialog( dummy );
1086 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
1090 void Interface::StopStream()
1092 playlist_t * p_playlist =
1093 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1095 if( p_playlist == NULL )
1100 playlist_Stop( p_playlist );
1101 vlc_object_release( p_playlist );
1102 input_manager->Update();
1105 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
1110 void Interface::PrevStream()
1112 playlist_t * p_playlist =
1113 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1115 if( p_playlist == NULL )
1120 playlist_Prev( p_playlist );
1121 vlc_object_release( p_playlist );
1124 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1129 void Interface::NextStream()
1131 playlist_t * p_playlist =
1132 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1134 if( p_playlist == NULL )
1138 playlist_Next( p_playlist );
1139 vlc_object_release( p_playlist );
1142 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1144 input_thread_t *p_input =
1145 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1149 vlc_value_t val; val.b_bool = VLC_TRUE;
1151 var_Set( p_input, "rate-slower", val );
1152 vlc_object_release( p_input );
1156 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1158 input_thread_t *p_input =
1159 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1163 vlc_value_t val; val.b_bool = VLC_TRUE;
1165 var_Set( p_input, "rate-faster", val );
1166 vlc_object_release( p_input );
1170 void Interface::TogglePlayButton( int i_playing_status )
1172 wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
1173 GetToolBar()->GetToolClientData( PlayStream_Event );
1174 if( !p_tool ) return;
1176 if( i_playing_status == PLAYING_S )
1178 p_tool->SetNormalBitmap( wxBitmap( pause_xpm ) );
1179 p_tool->SetLabel( wxU(_("Pause")) );
1180 p_tool->SetShortHelp( wxU(_(HELP_PAUSE)) );
1184 p_tool->SetNormalBitmap( wxBitmap( play_xpm ) );
1185 p_tool->SetLabel( wxU(_("Play")) );
1186 p_tool->SetShortHelp( wxU(_(HELP_PLAY)) );
1189 GetToolBar()->Realize();
1191 #if defined( __WXMSW__ )
1192 /* Needed to work around a bug in wxToolBar::Realize() */
1193 GetToolBar()->SetSize( GetSize().GetWidth(),
1194 GetToolBar()->GetSize().GetHeight() );
1195 GetToolBar()->Update();
1198 GetToolBar()->ToggleTool( PlayStream_Event, true );
1199 GetToolBar()->ToggleTool( PlayStream_Event, false );
1202 void Interface::OnInteraction( wxCommandEvent& event )
1204 interaction_dialog_t *p_dialog = (interaction_dialog_t *)
1205 event.GetClientData();
1206 if( p_dialog->i_widgets == 0 ) return;
1208 /// \todo : Code this . This is only test code. No locking, ...
1209 wxString message = wxU( p_dialog->pp_widgets[0]->psz_text );
1210 REMOVE_ELEM( p_dialog->pp_widgets, p_dialog->i_widgets, 0 );
1211 wxMessageBox( message, wxU( p_dialog->psz_title ) );
1212 p_dialog->i_status = ANSWERED_DIALOG;
1215 static int InteractCallback( vlc_object_t *p_this,
1216 const char *psz_var, vlc_value_t old_val,
1217 vlc_value_t new_val, void *param )
1219 Interface *p_interface = (Interface*)param;
1220 interaction_dialog_t *p_dialog = (interaction_dialog_t*)(new_val.p_address);
1223 if( p_dialog->i_action == INTERACT_HIDE )
1225 p_dialog->i_status = HIDDEN_DIALOG;
1229 wxCommandEvent event( wxEVT_INTERACTION, -1 );
1230 event.SetClientData( new_val.p_address );
1231 p_interface->AddPendingEvent( event );
1235 #if wxUSE_DRAG_AND_DROP
1236 /*****************************************************************************
1237 * Definition of DragAndDrop class.
1238 *****************************************************************************/
1239 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
1242 b_enqueue = _b_enqueue;
1245 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1246 const wxArrayString& filenames )
1248 /* Add dropped files to the playlist */
1250 playlist_t *p_playlist =
1251 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1253 if( p_playlist == NULL )
1258 for( size_t i = 0; i < filenames.GetCount(); i++ )
1260 char *psz_utf8 = wxFromLocale( filenames[i] );
1262 playlist_Add( p_playlist, psz_utf8, psz_utf8,
1263 PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
1265 wxLocaleFree( psz_utf8 );
1268 vlc_object_release( p_playlist );
1274 /*****************************************************************************
1275 * Definition of VolCtrl class.
1276 *****************************************************************************/
1277 class wxVolCtrl: public wxGauge
1281 wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1282 wxPoint = wxDefaultPosition, wxSize = wxSize( 20, -1 ) );
1283 virtual ~wxVolCtrl() {};
1285 void UpdateVolume();
1288 void OnChange( wxMouseEvent& event );
1291 intf_thread_t *p_intf;
1293 DECLARE_EVENT_TABLE();
1296 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
1298 EVT_LEFT_DOWN(wxVolCtrl::OnChange)
1299 EVT_MOTION(wxVolCtrl::OnChange)
1302 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1303 wxPoint point, wxSize size )
1304 : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
1310 void wxVolCtrl::OnChange( wxMouseEvent& event )
1312 if( !event.LeftDown() && !event.LeftIsDown() ) return;
1314 int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
1315 aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1319 void wxVolCtrl::UpdateVolume()
1321 audio_volume_t i_volume;
1322 aout_VolumeGet( p_intf, &i_volume );
1324 int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
1325 if( i_gauge_volume == GetValue() ) return;
1327 SetValue( i_gauge_volume );
1328 SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
1329 i_gauge_volume / 2 ) );
1332 #if defined(__WXGTK__)
1333 #define VLCVOL_HEIGHT p_parent->GetSize().GetHeight()
1335 #define VLCVOL_HEIGHT TOOLBAR_BMP_HEIGHT
1337 VLCVolCtrl::VLCVolCtrl( intf_thread_t *_p_intf, wxWindow *p_parent )
1338 :wxControl( p_parent, -1, wxDefaultPosition, wxSize(64, VLCVOL_HEIGHT ),
1340 i_y_offset((VLCVOL_HEIGHT - TOOLBAR_BMP_HEIGHT) / 2),
1341 b_mute(0), p_intf(_p_intf)
1343 gauge = new wxVolCtrl( p_intf, this, -1, wxPoint( 18, i_y_offset ),
1344 wxSize( 44, TOOLBAR_BMP_HEIGHT ) );
1347 void VLCVolCtrl::OnPaint( wxPaintEvent &evt )
1349 wxPaintDC dc( this );
1350 wxBitmap mPlayBitmap( b_mute ? speaker_mute_xpm : speaker_xpm );
1351 dc.DrawBitmap( mPlayBitmap, 0, i_y_offset, TRUE );
1354 void VLCVolCtrl::OnChange( wxMouseEvent& event )
1356 if( event.GetX() < TOOLBAR_BMP_WIDTH )
1359 aout_VolumeMute( p_intf, (audio_volume_t *)&i_volume );
1366 void VLCVolCtrl::UpdateVolume()
1368 gauge->UpdateVolume();
1370 int i_volume = gauge->GetValue();
1371 if( !!i_volume == !b_mute ) return;
1376 /*****************************************************************************
1378 *****************************************************************************/
1380 #ifdef wxHAS_TASK_BAR_ICON
1382 BEGIN_EVENT_TABLE(Systray, wxTaskBarIcon)
1385 EVT_TASKBAR_LEFT_DCLICK(Systray::OnLeftClick)
1387 EVT_TASKBAR_LEFT_DOWN(Systray::OnLeftClick)
1390 EVT_MENU(Iconize_Event, Systray::OnMenuIconize)
1391 EVT_MENU(Exit_Event, Systray::OnExit)
1392 EVT_MENU(PlayStream_Event, Systray::OnPlayStream)
1393 EVT_MENU(NextStream_Event, Systray::OnNextStream)
1394 EVT_MENU(PrevStream_Event, Systray::OnPrevStream)
1395 EVT_MENU(StopStream_Event, Systray::OnStopStream)
1398 Systray::Systray( Interface *_p_main_interface, intf_thread_t *_p_intf )
1400 p_main_interface = _p_main_interface;
1403 SetIcon( wxIcon( vlc16x16_xpm ), wxT("VLC media player") );
1404 if( !IsOk() || !IsIconInstalled() )
1406 msg_Warn(p_intf, "cannot set systray icon, weird things may happen");
1410 /* Event handlers */
1411 void Systray::OnMenuIconize( wxCommandEvent& event )
1413 p_main_interface->Show( ! p_main_interface->IsShown() );
1414 if ( p_main_interface->IsShown() ) p_main_interface->Raise();
1417 void Systray::OnLeftClick( wxTaskBarIconEvent& event )
1419 wxCommandEvent cevent;
1420 OnMenuIconize(cevent);
1423 void Systray::OnExit( wxCommandEvent& event )
1425 p_main_interface->Close(TRUE);
1428 void Systray::OnPrevStream( wxCommandEvent& event )
1430 p_main_interface->PrevStream();
1433 void Systray::OnNextStream( wxCommandEvent& event )
1435 p_main_interface->NextStream();
1438 void Systray::OnPlayStream( wxCommandEvent& event )
1440 p_main_interface->PlayStream();
1443 void Systray::OnStopStream( wxCommandEvent& event )
1445 p_main_interface->StopStream();
1448 /* Systray popup menu */
1449 wxMenu* Systray::CreatePopupMenu()
1451 int minimal = config_GetInt( p_intf, "wx-minimal" );
1453 wxMenu* systray_menu = new wxMenu;
1454 systray_menu->Append( Exit_Event, wxU(_("Quit VLC")) );
1455 systray_menu->AppendSeparator();
1456 systray_menu->Append( PlayStream_Event, wxU(_("Play/Pause")) );
1460 systray_menu->Append( PrevStream_Event, wxU(_("Previous")) );
1461 systray_menu->Append( NextStream_Event, wxU(_("Next")) );
1462 systray_menu->Append( StopStream_Event, wxU(_("Stop")) );
1464 systray_menu->AppendSeparator();
1465 systray_menu->Append( Iconize_Event, wxU(_("Show/Hide interface")) );
1466 return systray_menu;
1469 void Systray::UpdateTooltip( const wxChar* tooltip )
1471 SetIcon( wxIcon( vlc16x16_xpm ), tooltip );