1 /*****************************************************************************
2 * interface.cpp : wxWidgets plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2005 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include "interface.hpp"
28 #include "playlist_manager.hpp"
29 #include "extrapanel.hpp"
39 #include <wx/splitter.h>
41 /* include the toolbar graphics */
42 #include "bitmaps/play.xpm"
43 #include "bitmaps/pause.xpm"
44 #include "bitmaps/stop.xpm"
45 #include "bitmaps/prev.xpm"
46 #include "bitmaps/next.xpm"
47 #include "bitmaps/eject.xpm"
48 #include "bitmaps/slow.xpm"
49 #include "bitmaps/fast.xpm"
50 #include "bitmaps/playlist.xpm"
51 #include "bitmaps/playlist_small.xpm"
52 #include "bitmaps/speaker.xpm"
53 #include "bitmaps/speaker_mute.xpm"
55 #define TOOLBAR_BMP_WIDTH 16
56 #define TOOLBAR_BMP_HEIGHT 16
58 /* include the icon graphic */
59 #include "../../../share/vlc32x32.xpm"
60 /* include a small icon graphic for the systray icon */
61 #ifdef wxHAS_TASK_BAR_ICON
62 #include "../../../share/vlc16x16.xpm"
65 /*****************************************************************************
67 *****************************************************************************/
68 static int DoInteract( intf_thread_t *, interaction_dialog_t *, int );
70 /*****************************************************************************
71 * Local class declarations.
72 *****************************************************************************/
73 class wxMenuExt: public wxMenu
77 wxMenuExt( wxMenu* parentMenu, int id, const wxString& text,
78 const wxString& helpString, wxItemKind kind,
79 char *_psz_var, int _i_object_id, vlc_value_t _val,
82 virtual ~wxMenuExt() {};
94 class VLCVolCtrl : public wxControl
97 VLCVolCtrl( intf_thread_t *p_intf, wxWindow *p_parent );
98 virtual ~VLCVolCtrl() {};
100 virtual void OnPaint( wxPaintEvent &event );
101 void OnChange( wxMouseEvent& event );
105 DECLARE_EVENT_TABLE()
110 intf_thread_t *p_intf;
113 BEGIN_EVENT_TABLE(VLCVolCtrl, wxControl)
114 EVT_PAINT(VLCVolCtrl::OnPaint)
117 EVT_LEFT_UP(VLCVolCtrl::OnChange)
120 class Splitter : public wxSplitterWindow
123 Splitter( wxWindow *p_parent, intf_thread_t *_p_intf )
124 : wxSplitterWindow( p_parent, -1, wxDefaultPosition, wxSize(0,0),
125 #if defined( __WXMSW__ )
128 wxCLIP_CHILDREN | wxSP_3DSASH ),
130 p_intf(_p_intf), i_sash_position(150), i_width(-1),
131 b_video(0), i_delay(0)
136 virtual ~Splitter() {};
138 virtual bool Split( wxWindow* window1, wxWindow* window2 )
141 wxSize size = wxSize( i_width, i_sash_position );
142 if( window2->GetSizer() ) window2->GetSizer()->SetMinSize( size );
144 return wxSplitterWindow::SplitHorizontally( window1, window2,
148 virtual bool Unsplit( wxWindow* window )
151 return wxSplitterWindow::Unsplit( window );
155 DECLARE_EVENT_TABLE()
157 void OnSize( wxSizeEvent &event )
159 /* If we display video, then resize the video window */
161 p_intf->p_sys->p_video_window && p_intf->p_sys->p_video_sizer &&
162 p_intf->p_sys->p_video_sizer->GetMinSize() != wxSize(0,0) )
164 if( !b_video ) i_delay = mdate() + 1000000;
169 #if defined( __WXMSW__ )
170 SetSashPosition( event.GetSize().GetHeight() - i_sash_position );
172 SetSashPosition( event.GetSize().GetHeight() -
173 i_sash_position - GetSashSize() );
176 else if( GetWindow2() && GetWindow1() && GetWindow1()->GetSizer() )
178 wxSize size = GetWindow1()->GetSizer()->GetMinSize();
180 if( b_video ) i_delay = mdate() + 1000000;
183 if( event.GetSize().GetHeight() - size.GetHeight() )
187 SetSashPosition( size.GetHeight() ? size.GetHeight() : 1 );
189 if( i_delay < mdate() )
191 i_sash_position = event.GetSize().GetHeight() -
193 i_width = event.GetSize().GetWidth();
195 size = wxSize( i_width, i_sash_position );
196 if( GetWindow2()->GetSizer() )
197 GetWindow2()->GetSizer()->SetMinSize( size );
205 void OnSashPosChanged( wxSplitterEvent &event )
207 if( !GetSize().GetHeight() ){ event.Skip(); return; }
209 if( i_delay < mdate() )
211 i_sash_position = GetSize().GetHeight() - event.GetSashPosition();
213 wxSize size = wxSize( i_width, i_sash_position );
214 if( GetWindow2()->GetSizer() )
215 GetWindow2()->GetSizer()->SetMinSize( size );
220 intf_thread_t *p_intf;
227 BEGIN_EVENT_TABLE(Splitter, wxSplitterWindow)
228 EVT_SIZE( Splitter::OnSize )
229 EVT_SPLITTER_SASH_POS_CHANGED(-1, Splitter::OnSashPosChanged)
232 /*****************************************************************************
234 *****************************************************************************/
236 DEFINE_LOCAL_EVENT_TYPE( wxEVT_INTF );
238 /* IDs for the controls and the menu commands */
242 MenuDummy_Event = wxID_HIGHEST + 1000,
243 Exit_Event = wxID_HIGHEST,
244 OpenFileSimple_Event,
274 /* it is important for the id corresponding to the "About" command to have
275 * this standard value as otherwise it won't be handled properly under Mac
276 * (where it is special and put into the "Apple" menu) */
277 About_Event = wxID_ABOUT,
284 BEGIN_EVENT_TABLE(Interface, wxFrame)
286 EVT_MENU(Exit_Event, Interface::OnExit)
287 EVT_MENU(About_Event, Interface::OnAbout)
288 EVT_MENU(UpdateVLC_Event, Interface::OnShowDialog)
289 EVT_MENU(VLM_Event, Interface::OnShowDialog)
291 EVT_MENU(Playlist_Event, Interface::OnShowDialog)
292 EVT_MENU(PlaylistSmall_Event, Interface::OnSmallPlaylist)
293 EVT_MENU(Logs_Event, Interface::OnShowDialog)
294 EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
295 EVT_MENU(Prefs_Event, Interface::OnShowDialog)
297 EVT_MENU_OPEN(Interface::OnMenuOpen)
299 EVT_MENU( Extended_Event, Interface::OnExtended )
301 EVT_MENU( Bookmarks_Event, Interface::OnShowDialog)
303 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
304 EVT_CONTEXT_MENU(Interface::OnContextMenu2)
306 EVT_RIGHT_UP(Interface::OnContextMenu)
309 EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
310 EVT_MENU(OpenAdv_Event, Interface::OnShowDialog)
311 EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
312 EVT_MENU(OpenDir_Event, Interface::OnShowDialog)
313 EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
314 EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
315 EVT_MENU(OpenCapture_Event, Interface::OnShowDialog)
316 EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
317 EVT_MENU(Wizard_Event, Interface::OnShowDialog)
318 EVT_MENU(StopStream_Event, Interface::OnStopStream)
319 EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
320 EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
321 EVT_MENU(NextStream_Event, Interface::OnNextStream)
322 EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
323 EVT_MENU(FastStream_Event, Interface::OnFastStream)
326 EVT_COMMAND(0, wxEVT_INTF, Interface::OnControlEvent)
327 EVT_COMMAND(1, wxEVT_INTF, Interface::OnControlEvent)
330 /*****************************************************************************
332 *****************************************************************************/
333 Interface::Interface( intf_thread_t *_p_intf, long style ):
334 wxFrame( NULL, -1, wxT("VLC media player"),
335 wxDefaultPosition, wxSize(700,100), style )
337 /* Initializations */
341 playlist_manager = 0;
343 p_intf->pf_interact = DoInteract;
345 /* Give our interface a nice little icon */
346 SetIcon( wxIcon( vlc_xpm ) );
348 /* Create a splitter window that will fill in the interface window.
349 * We need a splitter bar in order to make the embedded playlist
351 splitter = new Splitter( this, p_intf );
352 main_sizer = new wxBoxSizer( wxVERTICAL );
353 main_sizer->Add( splitter, 1, wxEXPAND );
354 SetSizer( main_sizer );
356 /* Create a main panel that will fill in the interface window */
357 main_panel = new wxPanel( splitter, -1, wxPoint(0,0), wxSize(0,0),
359 main_panel->SetFocus();
361 #if defined(__WXGTK20__) && wxCHECK_VERSION(2,5,6)
362 /* As ugly as your butt! Please remove when wxWidgets 2.6 fixed their
363 * Accelerators bug. */
364 main_panel->m_imData = 0;
368 /* Create a sizer for the main frame */
369 panel_sizer = new wxBoxSizer( wxVERTICAL );
370 main_panel->SetSizer( panel_sizer );
372 /* Put this in the splitter */
373 splitter->Initialize( main_panel );
375 #ifdef wxHAS_TASK_BAR_ICON
376 /* Systray integration */
378 if( config_GetInt( p_intf, "wx-systray" ) )
380 p_systray = new Systray( this, p_intf );
384 /* Creation of the menu bar */
387 /* Creation of the tool bar */
390 /* Creation of the status bar
391 * Helptext for menu items and toolbar tools will automatically get
393 int i_status_width[3] = {100, 40, -1};
394 statusbar = CreateStatusBar( 3 ); /* 2 fields */
395 statusbar->SetStatusWidths( 3, i_status_width );
396 statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
398 /* Get minimum window size to prevent user from glitching it */
399 splitter->SetSizeHints( -1, 0 );
400 panel_sizer->Layout(); panel_sizer->Fit( main_panel );
401 main_sizer->Layout(); main_sizer->Fit( this );
402 main_min_size = GetSize();
403 splitter->SetSizeHints( -1, -1 );
407 if( config_GetInt( p_intf, "wx-embed" ) )
409 video_window = CreateVideoWindow( p_intf, main_panel );
410 panel_sizer->Add( p_intf->p_sys->p_video_sizer, 1, wxEXPAND, 0 );
413 /* Creation of the input manager panel */
414 input_manager = new InputManager( p_intf, this, main_panel );
415 panel_sizer->Add( input_manager, 0, wxEXPAND , 0 );
417 /* Layout everything */
418 splitter->SetSizeHints( -1, 0 );
419 panel_sizer->Layout(); panel_sizer->Fit( main_panel );
420 main_sizer->Layout(); main_sizer->Fit( this );
421 splitter->SetSizeHints( -1, -1 );
423 #if wxUSE_DRAG_AND_DROP
424 /* Associate drop targets with the main interface */
425 SetDropTarget( new DragAndDrop( p_intf ) );
431 timer = new Timer( p_intf, this );
433 /* Restore previous position / settings */
434 WindowSettings *ws = p_intf->p_sys->p_window_settings;
439 ws->SetScreen( wxSystemSettings::GetMetric( wxSYS_SCREEN_X ),
440 wxSystemSettings::GetMetric( wxSYS_SCREEN_Y ) );
442 if( ws->GetSettings( WindowSettings::ID_MAIN, b_shown, p, s ) ) Move( p );
444 /* Show extended GUI if requested */
445 wxCommandEvent dummy;
446 if( config_GetInt( p_intf, "wx-extended" ) ) OnExtended( dummy );
451 Interface::~Interface()
453 WindowSettings *ws = p_intf->p_sys->p_window_settings;
457 ws->SetSettings( WindowSettings::ID_MAIN, true,
458 GetPosition(), GetSize() );
461 PopEventHandler(true);
463 if( video_window ) delete video_window;
465 #ifdef wxHAS_TASK_BAR_ICON
466 if( p_systray ) delete p_systray;
469 if( p_intf->p_sys->p_wxwindow ) delete p_intf->p_sys->p_wxwindow;
475 void Interface::Init()
481 void Interface::Update()
484 ((VLCVolCtrl *)volctrl)->UpdateVolume();
486 if( playlist_manager ) playlist_manager->Update();
489 void Interface::OnControlEvent( wxCommandEvent& event )
491 switch( event.GetId() )
494 main_sizer->Layout();
495 main_sizer->Fit( this );
499 long i_style = GetWindowStyle();
500 if( event.GetInt() ) i_style |= wxSTAY_ON_TOP;
501 else i_style &= ~wxSTAY_ON_TOP;
502 SetWindowStyle( i_style );
507 /*****************************************************************************
509 *****************************************************************************/
510 void Interface::CreateOurMenuBar()
512 int minimal = config_GetInt( p_intf, "wx-minimal" );
514 /* Create the "File" menu */
515 wxMenu *file_menu = new wxMenu;
519 file_menu->Append( OpenFileSimple_Event,
520 wxU(_("Quick &Open File...\tCtrl-O")) );
522 file_menu->AppendSeparator();
523 file_menu->Append( OpenFile_Event, wxU(_("Open &File...\tCtrl-F")) );
524 file_menu->Append( OpenDir_Event, wxU(_("Open Dir&ectory...\tCtrl-E")) );
525 file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...\tCtrl-D")) );
526 file_menu->Append( OpenNet_Event,
527 wxU(_("Open &Network Stream...\tCtrl-N")) );
528 file_menu->Append( OpenCapture_Event,
529 wxU(_("Open C&apture Device...\tCtrl-A")) );
531 file_menu->AppendSeparator();
532 file_menu->Append( Wizard_Event, wxU(_("&Wizard...\tCtrl-W")) );
533 file_menu->AppendSeparator();
535 file_menu->Append( Exit_Event, wxU(_("E&xit\tCtrl-X")) );
537 /* Create the "View" menu */
538 wxMenu *view_menu = new wxMenu;
541 view_menu->Append( Playlist_Event, wxU(_("&Playlist...\tCtrl-P")) );
543 view_menu->Append( Logs_Event, wxU(_("&Messages...\tCtrl-M")) );
544 view_menu->Append( FileInfo_Event,
545 wxU(_("Stream and Media &info...\tCtrl-I")) );
546 view_menu->Append( VLM_Event,
547 wxU(_("VLM Control...\tCtrl-V")) );
549 /* Create the "Auto-generated" menus */
550 p_settings_menu = SettingsMenu( p_intf, this );
551 p_audio_menu = AudioMenu( p_intf, this );
552 p_video_menu = VideoMenu( p_intf, this );
553 p_navig_menu = NavigMenu( p_intf, this );
555 /* Create the "Help" menu */
556 wxMenu *help_menu = new wxMenu;
557 help_menu->Append( About_Event, wxU(_("About VLC media player")) );
558 help_menu->AppendSeparator();
559 help_menu->Append( UpdateVLC_Event, wxU(_("Check for updates ...")) );
561 /* Append the freshly created menus to the menu bar... */
562 wxMenuBar *menubar = new wxMenuBar();
563 menubar->Append( file_menu, wxU(_("&File")) );
564 menubar->Append( view_menu, wxU(_("&View")) );
565 menubar->Append( p_settings_menu, wxU(_("&Settings")) );
566 menubar->Append( p_audio_menu, wxU(_("&Audio")) );
567 menubar->Append( p_video_menu, wxU(_("&Video")) );
568 menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
569 menubar->Append( help_menu, wxU(_("&Help")) );
571 /* Attach the menu bar to the frame */
572 SetMenuBar( menubar );
574 /* Find out size of menu bar */
576 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
578 int i_width, i_height;
579 menubar->GetTextExtent( menubar->GetLabelTop(i), &i_width, &i_height );
581 #if defined(__WXGTK__)
582 22 /* approximate margin */;
584 #if (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 5) && (wxRELEASE_NUMBER < 3)
585 4 /* approximate margin */;
587 18 /* approximate margin */;
592 /* Patch by zcot for menu wrapping */
594 /* Find out size of msw menu bar */
597 HDC hdc = GetDC( NULL );
598 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
600 GetTextExtentPoint32( hdc, menubar->GetLabelTop(i).c_str(),
601 menubar->GetLabelTop(i).Length(), &sizing );
603 // [ SM_CXDLGFRAME + pixels + textextent + pixels + SM_CXDLGFRAME ]
604 i_size += sizing.cx + 2 + GetSystemMetrics( SM_CXDLGFRAME ) * 2;
606 ReleaseDC( NULL, hdc );
607 i_size += GetSystemMetrics( SM_CXSIZEFRAME ) * 2 + 4;
609 /* End patch by zcot */
611 panel_sizer->SetMinSize( i_size, -1 );
613 /* Intercept all menu events in our custom event handler */
614 PushEventHandler( new MenuEvtHandler( p_intf, this ) );
616 #if wxUSE_DRAG_AND_DROP
617 /* Associate drop targets with the menubar */
618 menubar->SetDropTarget( new DragAndDrop( p_intf ) );
622 void Interface::CreateOurToolBar()
624 #define HELP_OPEN N_("Open")
625 #define HELP_STOP N_("Stop")
626 #define HELP_PLAY N_("Play")
627 #define HELP_PAUSE N_("Pause")
628 #define HELP_PLO N_("Playlist")
629 #define HELP_SPLO N_("Small playlist")
630 #define HELP_PLP N_("Previous playlist item")
631 #define HELP_PLN N_("Next playlist item")
632 #define HELP_SLOW N_("Play slower")
633 #define HELP_FAST N_("Play faster")
635 int minimal = config_GetInt( p_intf, "wx-minimal" );
637 wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
638 * version because we don't include wx.rc */
641 CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
643 toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
647 toolbar->AddTool( OpenFile_Event, wxT(""),
648 wxBitmap( eject_xpm ), wxU(_(HELP_OPEN)) );
649 toolbar->AddSeparator();
652 wxToolBarToolBase *p_tool = toolbar->AddTool( PlayStream_Event, wxT(""),
653 wxBitmap( play_xpm ), wxU(_(HELP_PLAY)), wxITEM_CHECK );
654 p_tool->SetClientData( p_tool );
658 toolbar->AddTool( StopStream_Event, wxT(""), wxBitmap( stop_xpm ),
660 toolbar->AddSeparator();
662 toolbar->AddTool( PrevStream_Event, wxT(""),
663 wxBitmap( prev_xpm ), wxU(_(HELP_PLP)) );
664 toolbar->AddTool( SlowStream_Event, wxT(""),
665 wxBitmap( slow_xpm ), wxU(_(HELP_SLOW)) );
666 toolbar->AddTool( FastStream_Event, wxT(""),
667 wxBitmap( fast_xpm ), wxU(_(HELP_FAST)) );
668 toolbar->AddTool( NextStream_Event, wxT(""), wxBitmap( next_xpm ),
670 toolbar->AddSeparator();
671 toolbar->AddTool( Playlist_Event, wxT(""), wxBitmap( playlist_xpm ),
673 toolbar->AddTool( PlaylistSmall_Event, wxT(""),
674 wxBitmap( playlist_small_xpm ), wxU(_(HELP_SPLO)) );
677 wxControl *p_dummy_ctrl =
678 new wxControl( toolbar, -1, wxDefaultPosition,
679 wxSize(16, 16 ), wxBORDER_NONE );
681 toolbar->AddControl( p_dummy_ctrl );
683 volctrl = new VLCVolCtrl( p_intf, toolbar );
684 toolbar->AddControl( volctrl );
688 #if wxUSE_DRAG_AND_DROP
689 /* Associate drop targets with the toolbar */
690 toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
694 static int ConvertHotkeyModifiers( int i_hotkey )
696 int i_accel_flags = 0;
697 if( i_hotkey & KEY_MODIFIER_ALT ) i_accel_flags |= wxACCEL_ALT;
698 if( i_hotkey & KEY_MODIFIER_CTRL ) i_accel_flags |= wxACCEL_CTRL;
699 if( i_hotkey & KEY_MODIFIER_SHIFT ) i_accel_flags |= wxACCEL_SHIFT;
700 if( !i_accel_flags ) i_accel_flags = wxACCEL_NORMAL;
701 return i_accel_flags;
704 static int ConvertHotkey( int i_hotkey )
706 int i_key = i_hotkey & ~KEY_MODIFIER;
707 if( i_key & KEY_ASCII ) return i_key & KEY_ASCII;
708 else if( i_key & KEY_SPECIAL )
712 case KEY_LEFT: return WXK_LEFT;
713 case KEY_RIGHT: return WXK_RIGHT;
714 case KEY_UP: return WXK_UP;
715 case KEY_DOWN: return WXK_DOWN;
716 case KEY_SPACE: return WXK_SPACE;
717 case KEY_ENTER: return WXK_RETURN;
718 case KEY_F1: return WXK_F1;
719 case KEY_F2: return WXK_F2;
720 case KEY_F3: return WXK_F3;
721 case KEY_F4: return WXK_F4;
722 case KEY_F5: return WXK_F5;
723 case KEY_F6: return WXK_F6;
724 case KEY_F7: return WXK_F7;
725 case KEY_F8: return WXK_F8;
726 case KEY_F9: return WXK_F9;
727 case KEY_F10: return WXK_F10;
728 case KEY_F11: return WXK_F11;
729 case KEY_F12: return WXK_F12;
730 case KEY_HOME: return WXK_HOME;
731 case KEY_END: return WXK_END;
732 case KEY_INSERT: return WXK_INSERT;
733 case KEY_DELETE: return WXK_DELETE;
734 case KEY_MENU: return WXK_MENU;
735 case KEY_ESC: return WXK_ESCAPE;
736 case KEY_PAGEUP: return WXK_PRIOR;
737 case KEY_PAGEDOWN: return WXK_NEXT;
738 case KEY_TAB: return WXK_TAB;
739 case KEY_BACKSPACE: return WXK_BACK;
745 void Interface::SetupHotkeys()
747 struct vlc_t::hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
750 /* Count number of hoteys */
751 for( i_hotkeys = 0; p_hotkeys[i_hotkeys].psz_action != NULL; i_hotkeys++ );
753 p_intf->p_sys->i_first_hotkey_event = wxID_HIGHEST + 7000;
754 p_intf->p_sys->i_hotkeys = i_hotkeys;
756 wxAcceleratorEntry *p_entries = new wxAcceleratorEntry[i_hotkeys];
758 /* Setup the hotkeys as accelerators */
759 for( int i = 0; i < i_hotkeys; i++ )
761 int i_mod = ConvertHotkeyModifiers( p_hotkeys[i].i_key );
762 int i_key = ConvertHotkey( p_hotkeys[i].i_key );
765 if( !(p_hotkeys[i].i_key & KEY_SPECIAL) && i_mod )
766 i_key = toupper(i_key);
769 p_entries[i].Set( i_mod, i_key,
770 p_intf->p_sys->i_first_hotkey_event + i );
773 wxAcceleratorTable accel( i_hotkeys, p_entries );
777 msg_Err( p_intf, "invalid accelerator table" );
781 SetAcceleratorTable( accel );
787 void Interface::SetIntfMinSize()
789 wxSize ms = main_min_size;
791 if( extra_frame && extra_frame->IsShown() )
793 ms.SetHeight( ms.GetHeight() + ext_min_size.GetHeight() );
794 if( ext_min_size.GetWidth() > ms.GetWidth() )
795 ms.SetWidth( ext_min_size.GetWidth() );
798 SetSizeHints( ms.GetWidth(), ms.GetHeight() );
801 /*****************************************************************************
803 *****************************************************************************/
804 void Interface::OnMenuOpen( wxMenuEvent& event )
806 #if defined( __WXMSW__ )
807 # define GetEventObject GetMenu
810 if( event.GetEventObject() == p_settings_menu )
812 p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );
814 /* Add static items */
815 p_settings_menu->AppendCheckItem( Extended_Event,
816 wxU(_("Extended &GUI\tCtrl-G") ) );
817 if( b_extra ) p_settings_menu->Check( Extended_Event, TRUE );
818 p_settings_menu->Append( Bookmarks_Event,
819 wxU(_("&Bookmarks...\tCtrl-B") ) );
820 p_settings_menu->Append( Prefs_Event,
821 wxU(_("Preference&s...\tCtrl-S")) );
824 else if( event.GetEventObject() == p_audio_menu )
826 p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
829 else if( event.GetEventObject() == p_video_menu )
831 p_video_menu = VideoMenu( p_intf, this, p_video_menu );
834 else if( event.GetEventObject() == p_navig_menu )
836 p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
839 #if defined( __WXMSW__ )
840 # undef GetEventObject
844 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
845 void Interface::OnContextMenu2(wxContextMenuEvent& event)
847 /* Only show the context menu for the main interface */
848 if( GetId() != event.GetId() )
854 if( p_intf->p_sys->pf_show_dialog )
855 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
858 void Interface::OnContextMenu(wxMouseEvent& event)
860 if( p_intf->p_sys->pf_show_dialog )
861 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
864 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
866 /* TRUE is to force the frame to close. */
870 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
873 msg.Printf( wxString(wxT("VLC media player " PACKAGE_VERSION)) +
874 wxU(_(" (wxWidgets interface)\n\n")) +
875 wxU(_("(c) 1996-2005 - the VideoLAN Team\n\n")) +
876 wxU(_("Compiled by "))+ wxU(VLC_CompileBy())+ wxU("@") +
877 wxU(VLC_CompileHost())+ wxT(".")+ wxU(VLC_CompileDomain())+ wxT(".\n") +
878 wxU(_("Compiler: "))+ wxU(VLC_Compiler())+wxT( ".\n") +
879 wxU(_("Based on SVN revision: "))+wxU(VLC_Changeset())+wxT(".\n\n") +
881 wxU( vlc_wraptext(LICENSE_MSG,WRAPCOUNT,VLC_TRUE) ) + wxT("\n\n") +
883 wxU( LICENSE_MSG ) + wxT("\n\n") +
885 wxU(_("The VideoLAN team <videolan@videolan.org>\n"
886 "http://www.videolan.org/\n\n")) );
888 wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
889 wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
892 void Interface::OnShowDialog( wxCommandEvent& event )
894 if( p_intf->p_sys->pf_show_dialog )
898 switch( event.GetId() )
900 case OpenFileSimple_Event:
901 i_id = INTF_DIALOG_FILE_SIMPLE;
904 i_id = INTF_DIALOG_FILE;
907 i_id = INTF_DIALOG_FILE;
910 i_id = INTF_DIALOG_DIRECTORY;
913 i_id = INTF_DIALOG_DISC;
916 i_id = INTF_DIALOG_NET;
918 case OpenCapture_Event:
919 i_id = INTF_DIALOG_CAPTURE;
922 i_id = INTF_DIALOG_SAT;
925 i_id = INTF_DIALOG_PLAYLIST;
928 i_id = INTF_DIALOG_MESSAGES;
931 i_id = INTF_DIALOG_FILEINFO;
934 i_id = INTF_DIALOG_PREFS;
937 i_id = INTF_DIALOG_WIZARD;
939 case Bookmarks_Event:
940 i_id = INTF_DIALOG_BOOKMARKS;
942 case UpdateVLC_Event:
943 i_id = INTF_DIALOG_UPDATEVLC;
946 i_id = INTF_DIALOG_VLM;
949 i_id = INTF_DIALOG_FILE;
953 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
957 void Interface::OnExtended( wxCommandEvent& WXUNUSED(event) )
959 UpdateVideoWindow( p_intf, video_window );
963 /* Create the extra panel */
964 extra_frame = new ExtraPanel( p_intf, main_panel );
965 panel_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
966 ext_min_size = extra_frame->GetBestSize();
970 panel_sizer->Show( extra_frame, b_extra );
973 main_sizer->Layout();
974 main_sizer->Fit( this );
977 void Interface::OnSmallPlaylist( wxCommandEvent& WXUNUSED(event) )
979 UpdateVideoWindow( p_intf, video_window );
981 if( !playlist_manager )
983 /* Create the extra panel */
984 playlist_manager = new PlaylistManager( p_intf, splitter );
987 if( !splitter->IsSplit() ) splitter->Split( main_panel, playlist_manager );
988 else splitter->Unsplit( playlist_manager );
991 main_sizer->Layout();
992 main_sizer->Fit( this );
995 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
1000 void Interface::PlayStream()
1002 wxCommandEvent dummy;
1003 playlist_t *p_playlist =
1004 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1006 if( p_playlist == NULL ) return;
1008 if( p_playlist->i_size && p_playlist->i_enabled )
1012 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
1015 if( p_input == NULL )
1017 /* No stream was playing, start one */
1018 playlist_Play( p_playlist );
1019 vlc_object_release( p_playlist );
1020 input_manager->Update();
1024 var_Get( p_input, "state", &state );
1025 if( state.i_int != PAUSE_S )
1027 /* A stream is being played, pause it */
1028 state.i_int = PAUSE_S;
1032 /* Stream is paused, resume it */
1033 state.i_int = PLAYING_S;
1035 var_Set( p_input, "state", state );
1037 vlc_object_release( p_input );
1038 vlc_object_release( p_playlist );
1039 input_manager->Update();
1043 /* If the playlist is empty, open a file requester instead */
1044 vlc_object_release( p_playlist );
1045 OnShowDialog( dummy );
1049 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
1053 void Interface::StopStream()
1055 playlist_t * p_playlist =
1056 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1058 if( p_playlist == NULL )
1063 playlist_Stop( p_playlist );
1064 vlc_object_release( p_playlist );
1065 input_manager->Update();
1068 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
1073 void Interface::PrevStream()
1075 playlist_t * p_playlist =
1076 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1078 if( p_playlist == NULL )
1083 playlist_Prev( p_playlist );
1084 vlc_object_release( p_playlist );
1087 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1092 void Interface::NextStream()
1094 playlist_t * p_playlist =
1095 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1097 if( p_playlist == NULL )
1101 playlist_Next( p_playlist );
1102 vlc_object_release( p_playlist );
1105 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1107 input_thread_t *p_input =
1108 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1112 vlc_value_t val; val.b_bool = VLC_TRUE;
1114 var_Set( p_input, "rate-slower", val );
1115 vlc_object_release( p_input );
1119 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1121 input_thread_t *p_input =
1122 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1126 vlc_value_t val; val.b_bool = VLC_TRUE;
1128 var_Set( p_input, "rate-faster", val );
1129 vlc_object_release( p_input );
1133 void Interface::TogglePlayButton( int i_playing_status )
1135 wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
1136 GetToolBar()->GetToolClientData( PlayStream_Event );
1137 if( !p_tool ) return;
1139 if( i_playing_status == PLAYING_S )
1141 p_tool->SetNormalBitmap( wxBitmap( pause_xpm ) );
1142 p_tool->SetLabel( wxU(_("Pause")) );
1143 p_tool->SetShortHelp( wxU(_(HELP_PAUSE)) );
1147 p_tool->SetNormalBitmap( wxBitmap( play_xpm ) );
1148 p_tool->SetLabel( wxU(_("Play")) );
1149 p_tool->SetShortHelp( wxU(_(HELP_PLAY)) );
1152 GetToolBar()->Realize();
1154 #if defined( __WXMSW__ )
1155 /* Needed to work around a bug in wxToolBar::Realize() */
1156 GetToolBar()->SetSize( GetSize().GetWidth(),
1157 GetToolBar()->GetSize().GetHeight() );
1158 GetToolBar()->Update();
1161 GetToolBar()->ToggleTool( PlayStream_Event, true );
1162 GetToolBar()->ToggleTool( PlayStream_Event, false );
1165 static int DoInteract( intf_thread_t *, interaction_dialog_t *, int )
1167 fprintf( stderr, "Doing interaction \n" );
1173 #if wxUSE_DRAG_AND_DROP
1174 /*****************************************************************************
1175 * Definition of DragAndDrop class.
1176 *****************************************************************************/
1177 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
1180 b_enqueue = _b_enqueue;
1183 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1184 const wxArrayString& filenames )
1186 /* Add dropped files to the playlist */
1188 playlist_t *p_playlist =
1189 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1191 if( p_playlist == NULL )
1196 for( size_t i = 0; i < filenames.GetCount(); i++ )
1198 char *psz_utf8 = wxFromLocale( filenames[i] );
1200 playlist_Add( p_playlist, psz_utf8, psz_utf8,
1201 PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
1203 wxLocaleFree( psz_utf8 );
1206 vlc_object_release( p_playlist );
1212 /*****************************************************************************
1213 * Definition of VolCtrl class.
1214 *****************************************************************************/
1215 class wxVolCtrl: public wxGauge
1219 wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1220 wxPoint = wxDefaultPosition, wxSize = wxSize( 20, -1 ) );
1221 virtual ~wxVolCtrl() {};
1223 void UpdateVolume();
1226 void OnChange( wxMouseEvent& event );
1229 intf_thread_t *p_intf;
1231 DECLARE_EVENT_TABLE();
1234 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
1236 EVT_LEFT_DOWN(wxVolCtrl::OnChange)
1237 EVT_MOTION(wxVolCtrl::OnChange)
1240 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1241 wxPoint point, wxSize size )
1242 : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
1248 void wxVolCtrl::OnChange( wxMouseEvent& event )
1250 if( !event.LeftDown() && !event.LeftIsDown() ) return;
1252 int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
1253 aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1257 void wxVolCtrl::UpdateVolume()
1259 audio_volume_t i_volume;
1260 aout_VolumeGet( p_intf, &i_volume );
1262 int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
1263 if( i_gauge_volume == GetValue() ) return;
1265 SetValue( i_gauge_volume );
1266 SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
1267 i_gauge_volume / 2 ) );
1270 #if defined(__WXGTK__)
1271 #define VLCVOL_HEIGHT p_parent->GetSize().GetHeight()
1273 #define VLCVOL_HEIGHT TOOLBAR_BMP_HEIGHT
1275 VLCVolCtrl::VLCVolCtrl( intf_thread_t *_p_intf, wxWindow *p_parent )
1276 :wxControl( p_parent, -1, wxDefaultPosition, wxSize(64, VLCVOL_HEIGHT ),
1278 i_y_offset((VLCVOL_HEIGHT - TOOLBAR_BMP_HEIGHT) / 2),
1279 b_mute(0), p_intf(_p_intf)
1281 gauge = new wxVolCtrl( p_intf, this, -1, wxPoint( 18, i_y_offset ),
1282 wxSize( 44, TOOLBAR_BMP_HEIGHT ) );
1285 void VLCVolCtrl::OnPaint( wxPaintEvent &evt )
1287 wxPaintDC dc( this );
1288 wxBitmap mPlayBitmap( b_mute ? speaker_mute_xpm : speaker_xpm );
1289 dc.DrawBitmap( mPlayBitmap, 0, i_y_offset, TRUE );
1292 void VLCVolCtrl::OnChange( wxMouseEvent& event )
1294 if( event.GetX() < TOOLBAR_BMP_WIDTH )
1297 aout_VolumeMute( p_intf, (audio_volume_t *)&i_volume );
1304 void VLCVolCtrl::UpdateVolume()
1306 gauge->UpdateVolume();
1308 int i_volume = gauge->GetValue();
1309 if( !!i_volume == !b_mute ) return;
1314 /*****************************************************************************
1316 *****************************************************************************/
1318 #ifdef wxHAS_TASK_BAR_ICON
1320 BEGIN_EVENT_TABLE(Systray, wxTaskBarIcon)
1323 EVT_TASKBAR_LEFT_DCLICK(Systray::OnLeftClick)
1325 EVT_TASKBAR_LEFT_DOWN(Systray::OnLeftClick)
1328 EVT_MENU(Iconize_Event, Systray::OnMenuIconize)
1329 EVT_MENU(Exit_Event, Systray::OnExit)
1330 EVT_MENU(PlayStream_Event, Systray::OnPlayStream)
1331 EVT_MENU(NextStream_Event, Systray::OnNextStream)
1332 EVT_MENU(PrevStream_Event, Systray::OnPrevStream)
1333 EVT_MENU(StopStream_Event, Systray::OnStopStream)
1336 Systray::Systray( Interface *_p_main_interface, intf_thread_t *_p_intf )
1338 p_main_interface = _p_main_interface;
1341 SetIcon( wxIcon( vlc16x16_xpm ), wxT("VLC media player") );
1342 if( !IsOk() || !IsIconInstalled() )
1344 msg_Warn(p_intf, "cannot set systray icon, weird things may happen");
1348 /* Event handlers */
1349 void Systray::OnMenuIconize( wxCommandEvent& event )
1351 p_main_interface->Show( ! p_main_interface->IsShown() );
1352 if ( p_main_interface->IsShown() ) p_main_interface->Raise();
1355 void Systray::OnLeftClick( wxTaskBarIconEvent& event )
1357 wxCommandEvent cevent;
1358 OnMenuIconize(cevent);
1361 void Systray::OnExit( wxCommandEvent& event )
1363 p_main_interface->Close(TRUE);
1366 void Systray::OnPrevStream( wxCommandEvent& event )
1368 p_main_interface->PrevStream();
1371 void Systray::OnNextStream( wxCommandEvent& event )
1373 p_main_interface->NextStream();
1376 void Systray::OnPlayStream( wxCommandEvent& event )
1378 p_main_interface->PlayStream();
1381 void Systray::OnStopStream( wxCommandEvent& event )
1383 p_main_interface->StopStream();
1386 /* Systray popup menu */
1387 wxMenu* Systray::CreatePopupMenu()
1389 int minimal = config_GetInt( p_intf, "wx-minimal" );
1391 wxMenu* systray_menu = new wxMenu;
1392 systray_menu->Append( Exit_Event, wxU(_("Quit VLC")) );
1393 systray_menu->AppendSeparator();
1394 systray_menu->Append( PlayStream_Event, wxU(_("Play/Pause")) );
1398 systray_menu->Append( PrevStream_Event, wxU(_("Previous")) );
1399 systray_menu->Append( NextStream_Event, wxU(_("Next")) );
1400 systray_menu->Append( StopStream_Event, wxU(_("Stop")) );
1402 systray_menu->AppendSeparator();
1403 systray_menu->Append( Iconize_Event, wxU(_("Show/Hide interface")) );
1404 return systray_menu;
1407 void Systray::UpdateTooltip( const wxChar* tooltip )
1409 SetIcon( wxIcon( vlc16x16_xpm ), tooltip );