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 "extrapanel.hpp"
38 /* include the toolbar graphics */
39 #include "bitmaps/play.xpm"
40 #include "bitmaps/pause.xpm"
41 #include "bitmaps/stop.xpm"
42 #include "bitmaps/prev.xpm"
43 #include "bitmaps/next.xpm"
44 #include "bitmaps/eject.xpm"
45 #include "bitmaps/slow.xpm"
46 #include "bitmaps/fast.xpm"
47 #include "bitmaps/playlist.xpm"
48 #include "bitmaps/speaker.xpm"
49 #include "bitmaps/speaker_mute.xpm"
51 #define TOOLBAR_BMP_WIDTH 16
52 #define TOOLBAR_BMP_HEIGHT 16
54 /* include the icon graphic */
55 #include "../../../share/vlc32x32.xpm"
56 /* include a small icon graphic for the systray icon */
57 #ifdef wxHAS_TASK_BAR_ICON
58 #include "../../../share/vlc16x16.xpm"
61 /*****************************************************************************
62 * Local class declarations.
63 *****************************************************************************/
64 class wxMenuExt: public wxMenu
68 wxMenuExt( wxMenu* parentMenu, int id, const wxString& text,
69 const wxString& helpString, wxItemKind kind,
70 char *_psz_var, int _i_object_id, vlc_value_t _val,
73 virtual ~wxMenuExt() {};
85 class VLCVolCtrl : public wxControl
88 VLCVolCtrl( intf_thread_t *p_intf, wxWindow *p_parent );
89 virtual ~VLCVolCtrl() {};
91 virtual void OnPaint( wxPaintEvent &event );
92 void OnChange( wxMouseEvent& event );
101 intf_thread_t *p_intf;
104 BEGIN_EVENT_TABLE(VLCVolCtrl, wxControl)
105 EVT_PAINT(VLCVolCtrl::OnPaint)
108 EVT_LEFT_UP(VLCVolCtrl::OnChange)
111 /*****************************************************************************
113 *****************************************************************************/
115 DEFINE_LOCAL_EVENT_TYPE( wxEVT_INTF );
117 /* IDs for the controls and the menu commands */
121 MenuDummy_Event = wxID_HIGHEST + 1000,
122 Exit_Event = wxID_HIGHEST,
123 OpenFileSimple_Event,
152 /* it is important for the id corresponding to the "About" command to have
153 * this standard value as otherwise it won't be handled properly under Mac
154 * (where it is special and put into the "Apple" menu) */
155 About_Event = wxID_ABOUT,
162 BEGIN_EVENT_TABLE(Interface, wxFrame)
164 EVT_MENU(Exit_Event, Interface::OnExit)
165 EVT_MENU(About_Event, Interface::OnAbout)
166 EVT_MENU(UpdateVLC_Event, Interface::OnShowDialog)
167 EVT_MENU(VLM_Event, Interface::OnShowDialog)
169 EVT_MENU(Playlist_Event, Interface::OnShowDialog)
170 EVT_MENU(Logs_Event, Interface::OnShowDialog)
171 EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
172 EVT_MENU(Prefs_Event, Interface::OnShowDialog)
174 EVT_MENU_OPEN(Interface::OnMenuOpen)
176 EVT_MENU( Extended_Event, Interface::OnExtended )
178 EVT_MENU( Bookmarks_Event, Interface::OnShowDialog)
180 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
181 EVT_CONTEXT_MENU(Interface::OnContextMenu2)
183 EVT_RIGHT_UP(Interface::OnContextMenu)
186 EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
187 EVT_MENU(OpenAdv_Event, Interface::OnShowDialog)
188 EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
189 EVT_MENU(OpenDir_Event, Interface::OnShowDialog)
190 EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
191 EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
192 EVT_MENU(OpenCapture_Event, Interface::OnShowDialog)
193 EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
194 EVT_MENU(Wizard_Event, Interface::OnShowDialog)
195 EVT_MENU(StopStream_Event, Interface::OnStopStream)
196 EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
197 EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
198 EVT_MENU(NextStream_Event, Interface::OnNextStream)
199 EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
200 EVT_MENU(FastStream_Event, Interface::OnFastStream)
203 EVT_COMMAND(0, wxEVT_INTF, Interface::OnControlEvent)
204 EVT_COMMAND(1, wxEVT_INTF, Interface::OnControlEvent)
207 /*****************************************************************************
209 *****************************************************************************/
210 Interface::Interface( intf_thread_t *_p_intf, long style ):
211 wxFrame( NULL, -1, wxT("VLC media player"),
212 wxDefaultPosition, wxSize(700,100), style )
214 /* Initializations */
219 /* Give our interface a nice little icon */
220 SetIcon( wxIcon( vlc_xpm ) );
222 /* Create a main panel that will fill in the interface window */
223 main_sizer = new wxBoxSizer( wxVERTICAL );
224 SetSizer( main_sizer );
225 main_panel = new wxPanel( this );
226 main_sizer->Add( main_panel, 1, wxEXPAND );
227 main_panel->SetFocus();
229 #if defined(__WXGTK20__) && wxCHECK_VERSION(2,5,6)
230 /* As ugly as your butt! Please remove when wxWidgets 2.6 fixed their
231 * Accelerators bug. */
232 main_panel->m_imData = 0;
236 /* Create a sizer for the main frame */
237 panel_sizer = new wxBoxSizer( wxVERTICAL );
238 main_panel->SetSizer( panel_sizer );
240 #ifdef wxHAS_TASK_BAR_ICON
241 /* Systray integration */
243 if( config_GetInt( p_intf, "wx-systray" ) )
245 p_systray = new Systray( this, p_intf );
249 /* Creation of the menu bar */
252 /* Creation of the tool bar */
255 /* Creation of the status bar
256 * Helptext for menu items and toolbar tools will automatically get
258 int i_status_width[3] = {-6, -2, -9};
259 statusbar = CreateStatusBar( 3 ); /* 2 fields */
260 statusbar->SetStatusWidths( 3, i_status_width );
261 statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
265 if( config_GetInt( p_intf, "wx-embed" ) )
267 video_window = CreateVideoWindow( p_intf, main_panel );
268 panel_sizer->Add( p_intf->p_sys->p_video_sizer, 1, wxEXPAND, 0 );
271 /* Creation of the input manager panel */
272 input_manager = new InputManager( p_intf, this, main_panel );
273 panel_sizer->Add( input_manager, 0, wxEXPAND , 0 );
275 /* Layout everything */
276 panel_sizer->Layout();
277 panel_sizer->Fit( main_panel );
278 main_sizer->Layout();
279 main_sizer->Fit( this );
281 #if wxUSE_DRAG_AND_DROP
282 /* Associate drop targets with the main interface */
283 SetDropTarget( new DragAndDrop( p_intf ) );
289 timer = new Timer( p_intf, this );
291 /* Restore previous position / settings */
292 WindowSettings *ws = p_intf->p_sys->p_window_settings;
297 ws->SetScreen( wxSystemSettings::GetMetric( wxSYS_SCREEN_X ),
298 wxSystemSettings::GetMetric( wxSYS_SCREEN_Y ) );
300 if( ws->GetSettings( WindowSettings::ID_MAIN, b_shown, p, s ) ) Move( p );
302 /* Get minimum window size to prevent user from glitching it */
304 if( video_window && video_window->IsShown() )
305 s.SetHeight( s.GetHeight() - video_window->GetSize().GetHeight() );
308 /* Show extended GUI if requested */
309 wxCommandEvent dummy;
310 if( config_GetInt( p_intf, "wx-extended" ) ) OnExtended( dummy );
315 Interface::~Interface()
317 WindowSettings *ws = p_intf->p_sys->p_window_settings;
321 ws->SetSettings( WindowSettings::ID_MAIN, true,
322 GetPosition(), GetSize() );
325 PopEventHandler(true);
327 if( video_window ) delete video_window;
329 #ifdef wxHAS_TASK_BAR_ICON
330 if( p_systray ) delete p_systray;
333 if( p_intf->p_sys->p_wxwindow ) delete p_intf->p_sys->p_wxwindow;
339 void Interface::Init()
345 void Interface::Update()
348 ((VLCVolCtrl *)volctrl)->UpdateVolume();
351 void Interface::OnControlEvent( wxCommandEvent& event )
353 switch( event.GetId() )
356 if( p_intf->p_sys->b_video_autosize )
358 main_sizer->Layout();
359 main_sizer->Fit(this);
364 long i_style = GetWindowStyle();
365 if( event.GetInt() ) i_style |= wxSTAY_ON_TOP;
366 else i_style &= ~wxSTAY_ON_TOP;
367 SetWindowStyle( i_style );
372 /*****************************************************************************
374 *****************************************************************************/
375 void Interface::CreateOurMenuBar()
377 int minimal = config_GetInt( p_intf, "wx-minimal" );
379 /* Create the "File" menu */
380 wxMenu *file_menu = new wxMenu;
384 file_menu->Append( OpenFileSimple_Event,
385 wxU(_("Quick &Open File...\tCtrl-O")) );
387 file_menu->AppendSeparator();
388 file_menu->Append( OpenFile_Event, wxU(_("Open &File...\tCtrl-F")) );
389 file_menu->Append( OpenDir_Event, wxU(_("Open Dir&ectory...\tCtrl-E")) );
390 file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...\tCtrl-D")) );
391 file_menu->Append( OpenNet_Event,
392 wxU(_("Open &Network Stream...\tCtrl-N")) );
393 file_menu->Append( OpenCapture_Event,
394 wxU(_("Open C&apture Device...\tCtrl-A")) );
396 file_menu->AppendSeparator();
397 file_menu->Append( Wizard_Event, wxU(_("&Wizard...\tCtrl-W")) );
398 file_menu->AppendSeparator();
400 file_menu->Append( Exit_Event, wxU(_("E&xit\tCtrl-X")) );
402 /* Create the "View" menu */
403 wxMenu *view_menu = new wxMenu;
406 view_menu->Append( Playlist_Event, wxU(_("&Playlist...\tCtrl-P")) );
408 view_menu->Append( Logs_Event, wxU(_("&Messages...\tCtrl-M")) );
409 view_menu->Append( FileInfo_Event,
410 wxU(_("Stream and Media &info...\tCtrl-I")) );
411 view_menu->Append( VLM_Event,
412 wxU(_("VLM Control...\tCtrl-V")) );
414 /* Create the "Auto-generated" menus */
415 p_settings_menu = SettingsMenu( p_intf, this );
416 p_audio_menu = AudioMenu( p_intf, this );
417 p_video_menu = VideoMenu( p_intf, this );
418 p_navig_menu = NavigMenu( p_intf, this );
420 /* Create the "Help" menu */
421 wxMenu *help_menu = new wxMenu;
422 help_menu->Append( About_Event, wxU(_("About VLC media player")) );
423 help_menu->AppendSeparator();
424 help_menu->Append( UpdateVLC_Event, wxU(_("Check for updates ...")) );
426 /* Append the freshly created menus to the menu bar... */
427 wxMenuBar *menubar = new wxMenuBar();
428 menubar->Append( file_menu, wxU(_("&File")) );
429 menubar->Append( view_menu, wxU(_("&View")) );
430 menubar->Append( p_settings_menu, wxU(_("&Settings")) );
431 menubar->Append( p_audio_menu, wxU(_("&Audio")) );
432 menubar->Append( p_video_menu, wxU(_("&Video")) );
433 menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
434 menubar->Append( help_menu, wxU(_("&Help")) );
436 /* Attach the menu bar to the frame */
437 SetMenuBar( menubar );
439 /* Find out size of menu bar */
441 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
443 int i_width, i_height;
444 menubar->GetTextExtent( menubar->GetLabelTop(i), &i_width, &i_height );
446 #if defined(__WXGTK__)
447 22 /* approximate margin */;
449 #if (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 5) && (wxRELEASE_NUMBER < 3)
450 4 /* approximate margin */;
452 18 /* approximate margin */;
457 /* Patch by zcot for menu wrapping */
459 /* Find out size of msw menu bar */
462 HDC hdc = GetDC( NULL );
463 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
465 GetTextExtentPoint32( hdc, menubar->GetLabelTop(i).c_str(),
466 menubar->GetLabelTop(i).Length(), &sizing );
468 // [ SM_CXDLGFRAME + pixels + textextent + pixels + SM_CXDLGFRAME ]
469 i_size += sizing.cx + 2 + GetSystemMetrics( SM_CXDLGFRAME ) * 2;
471 ReleaseDC( NULL, hdc );
472 i_size += GetSystemMetrics( SM_CXSIZEFRAME ) * 2 + 4;
474 /* End patch by zcot */
476 panel_sizer->SetMinSize( i_size, -1 );
478 /* Intercept all menu events in our custom event handler */
479 PushEventHandler( new MenuEvtHandler( p_intf, this ) );
481 #if wxUSE_DRAG_AND_DROP
482 /* Associate drop targets with the menubar */
483 menubar->SetDropTarget( new DragAndDrop( p_intf ) );
487 void Interface::CreateOurToolBar()
489 #define HELP_OPEN N_("Open")
490 #define HELP_STOP N_("Stop")
491 #define HELP_PLAY N_("Play")
492 #define HELP_PAUSE N_("Pause")
493 #define HELP_PLO N_("Playlist")
494 #define HELP_PLP N_("Previous playlist item")
495 #define HELP_PLN N_("Next playlist item")
496 #define HELP_SLOW N_("Play slower")
497 #define HELP_FAST N_("Play faster")
499 int minimal = config_GetInt( p_intf, "wx-minimal" );
501 wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
502 * version because we don't include wx.rc */
505 CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
507 toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
511 toolbar->AddTool( OpenFile_Event, wxT(""),
512 wxBitmap( eject_xpm ), wxU(_(HELP_OPEN)) );
513 toolbar->AddSeparator();
516 wxToolBarToolBase *p_tool = toolbar->AddTool( PlayStream_Event, wxT(""),
517 wxBitmap( play_xpm ), wxU(_(HELP_PLAY)), wxITEM_CHECK );
518 p_tool->SetClientData( p_tool );
522 toolbar->AddTool( StopStream_Event, wxT(""), wxBitmap( stop_xpm ),
524 toolbar->AddSeparator();
526 toolbar->AddTool( PrevStream_Event, wxT(""),
527 wxBitmap( prev_xpm ), wxU(_(HELP_PLP)) );
528 toolbar->AddTool( SlowStream_Event, wxT(""),
529 wxBitmap( slow_xpm ), wxU(_(HELP_SLOW)) );
530 toolbar->AddTool( FastStream_Event, wxT(""),
531 wxBitmap( fast_xpm ), wxU(_(HELP_FAST)) );
532 toolbar->AddTool( NextStream_Event, wxT(""), wxBitmap( next_xpm ),
534 toolbar->AddSeparator();
535 toolbar->AddTool( Playlist_Event, wxT(""), wxBitmap( playlist_xpm ),
539 #if !( (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 6) && (wxRELEASE_NUMBER < 2) )
540 wxControl *p_dummy_ctrl =
541 new wxControl( toolbar, -1, wxDefaultPosition,
542 wxSize(35, 16 ), wxBORDER_NONE );
544 toolbar->AddControl( p_dummy_ctrl );
547 volctrl = new VLCVolCtrl( p_intf, toolbar );
548 toolbar->AddControl( volctrl );
552 #if wxUSE_DRAG_AND_DROP
553 /* Associate drop targets with the toolbar */
554 toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
558 static int ConvertHotkeyModifiers( int i_hotkey )
560 int i_accel_flags = 0;
561 if( i_hotkey & KEY_MODIFIER_ALT ) i_accel_flags |= wxACCEL_ALT;
562 if( i_hotkey & KEY_MODIFIER_CTRL ) i_accel_flags |= wxACCEL_CTRL;
563 if( i_hotkey & KEY_MODIFIER_SHIFT ) i_accel_flags |= wxACCEL_SHIFT;
564 if( !i_accel_flags ) i_accel_flags = wxACCEL_NORMAL;
565 return i_accel_flags;
568 static int ConvertHotkey( int i_hotkey )
570 int i_key = i_hotkey & ~KEY_MODIFIER;
571 if( i_key & KEY_ASCII ) return i_key & KEY_ASCII;
572 else if( i_key & KEY_SPECIAL )
576 case KEY_LEFT: return WXK_LEFT;
577 case KEY_RIGHT: return WXK_RIGHT;
578 case KEY_UP: return WXK_UP;
579 case KEY_DOWN: return WXK_DOWN;
580 case KEY_SPACE: return WXK_SPACE;
581 case KEY_ENTER: return WXK_RETURN;
582 case KEY_F1: return WXK_F1;
583 case KEY_F2: return WXK_F2;
584 case KEY_F3: return WXK_F3;
585 case KEY_F4: return WXK_F4;
586 case KEY_F5: return WXK_F5;
587 case KEY_F6: return WXK_F6;
588 case KEY_F7: return WXK_F7;
589 case KEY_F8: return WXK_F8;
590 case KEY_F9: return WXK_F9;
591 case KEY_F10: return WXK_F10;
592 case KEY_F11: return WXK_F11;
593 case KEY_F12: return WXK_F12;
594 case KEY_HOME: return WXK_HOME;
595 case KEY_END: return WXK_END;
596 case KEY_INSERT: return WXK_INSERT;
597 case KEY_DELETE: return WXK_DELETE;
598 case KEY_MENU: return WXK_MENU;
599 case KEY_ESC: return WXK_ESCAPE;
600 case KEY_PAGEUP: return WXK_PRIOR;
601 case KEY_PAGEDOWN: return WXK_NEXT;
602 case KEY_TAB: return WXK_TAB;
603 case KEY_BACKSPACE: return WXK_BACK;
609 void Interface::SetupHotkeys()
611 struct vlc_t::hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
614 /* Count number of hoteys */
615 for( i_hotkeys = 0; p_hotkeys[i_hotkeys].psz_action != NULL; i_hotkeys++ );
617 p_intf->p_sys->i_first_hotkey_event = wxID_HIGHEST + 7000;
618 p_intf->p_sys->i_hotkeys = i_hotkeys;
620 wxAcceleratorEntry *p_entries = new wxAcceleratorEntry[i_hotkeys];
622 /* Setup the hotkeys as accelerators */
623 for( int i = 0; i < i_hotkeys; i++ )
625 int i_mod = ConvertHotkeyModifiers( p_hotkeys[i].i_key );
626 int i_key = ConvertHotkey( p_hotkeys[i].i_key );
629 if( !(p_hotkeys[i].i_key & KEY_SPECIAL) && i_mod )
630 i_key = toupper(i_key);
633 p_entries[i].Set( i_mod, i_key,
634 p_intf->p_sys->i_first_hotkey_event + i );
637 wxAcceleratorTable accel( i_hotkeys, p_entries );
641 msg_Err( p_intf, "invalid accelerator table" );
645 SetAcceleratorTable( accel );
651 void Interface::SetIntfMinSize()
653 wxSize ms = main_min_size;
655 if( extra_frame && extra_frame->IsShown() )
657 ms.SetHeight( ms.GetHeight() + ext_min_size.GetHeight() );
658 if( ext_min_size.GetWidth() > ms.GetWidth() )
659 ms.SetWidth( ext_min_size.GetWidth() );
662 #if ( wxCHECK_VERSION( 2,5,4 ) )
665 main_sizer->SetMinSize( ms );
669 /*****************************************************************************
671 *****************************************************************************/
672 void Interface::OnMenuOpen( wxMenuEvent& event )
674 #if defined( __WXMSW__ )
675 # define GetEventObject GetMenu
678 if( event.GetEventObject() == p_settings_menu )
680 p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );
682 /* Add static items */
683 p_settings_menu->AppendCheckItem( Extended_Event,
684 wxU(_("Extended &GUI\tCtrl-G") ) );
685 if( b_extra ) p_settings_menu->Check( Extended_Event, TRUE );
686 p_settings_menu->Append( Bookmarks_Event,
687 wxU(_("&Bookmarks...\tCtrl-B") ) );
688 p_settings_menu->Append( Prefs_Event,
689 wxU(_("Preference&s...\tCtrl-S")) );
692 else if( event.GetEventObject() == p_audio_menu )
694 p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
697 else if( event.GetEventObject() == p_video_menu )
699 p_video_menu = VideoMenu( p_intf, this, p_video_menu );
702 else if( event.GetEventObject() == p_navig_menu )
704 p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
707 #if defined( __WXMSW__ )
708 # undef GetEventObject
712 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
713 void Interface::OnContextMenu2(wxContextMenuEvent& event)
715 /* Only show the context menu for the main interface */
716 if( GetId() != event.GetId() )
722 if( p_intf->p_sys->pf_show_dialog )
723 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
726 void Interface::OnContextMenu(wxMouseEvent& event)
728 if( p_intf->p_sys->pf_show_dialog )
729 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
732 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
734 /* TRUE is to force the frame to close. */
738 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
741 msg.Printf( wxString(wxT("VLC media player " PACKAGE_VERSION)) +
742 wxU(_(" (wxWidgets interface)\n\n")) +
743 wxU(_("(c) 1996-2005 - the VideoLAN Team\n\n")) +
744 wxU(_("Compiled by "))+ wxU(VLC_CompileBy())+ wxU("@") +
745 wxU(VLC_CompileHost())+ wxT(".")+ wxU(VLC_CompileDomain())+ wxT(".\n") +
746 wxU(_("Compiler: "))+ wxU(VLC_Compiler())+wxT( ".\n") +
747 wxU(_("Based on SVN revision: "))+wxU(VLC_Changeset())+wxT(".\n\n") +
749 wxU( vlc_wraptext(LICENSE_MSG,WRAPCOUNT,VLC_TRUE) ) + wxT("\n\n") +
751 wxU( LICENSE_MSG ) + wxT("\n\n") +
753 wxU(_("The VideoLAN team <videolan@videolan.org>\n"
754 "http://www.videolan.org/\n\n")) );
756 wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
757 wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
760 void Interface::OnShowDialog( wxCommandEvent& event )
762 if( p_intf->p_sys->pf_show_dialog )
766 switch( event.GetId() )
768 case OpenFileSimple_Event:
769 i_id = INTF_DIALOG_FILE_SIMPLE;
772 i_id = INTF_DIALOG_FILE;
775 i_id = INTF_DIALOG_FILE;
778 i_id = INTF_DIALOG_DIRECTORY;
781 i_id = INTF_DIALOG_DISC;
784 i_id = INTF_DIALOG_NET;
786 case OpenCapture_Event:
787 i_id = INTF_DIALOG_CAPTURE;
790 i_id = INTF_DIALOG_SAT;
793 i_id = INTF_DIALOG_PLAYLIST;
796 i_id = INTF_DIALOG_MESSAGES;
799 i_id = INTF_DIALOG_FILEINFO;
802 i_id = INTF_DIALOG_PREFS;
805 i_id = INTF_DIALOG_WIZARD;
807 case Bookmarks_Event:
808 i_id = INTF_DIALOG_BOOKMARKS;
810 case UpdateVLC_Event:
811 i_id = INTF_DIALOG_UPDATEVLC;
814 i_id = INTF_DIALOG_VLM;
817 i_id = INTF_DIALOG_FILE;
821 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
825 void Interface::OnExtended( wxCommandEvent& WXUNUSED(event) )
829 /* Create the extra panel */
830 extra_frame = new ExtraPanel( p_intf, main_panel );
831 panel_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
832 ext_min_size = extra_frame->GetBestSize();
837 panel_sizer->Show( extra_frame, b_extra );
840 main_sizer->Layout();
841 main_sizer->Fit( this );
844 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
849 void Interface::PlayStream()
851 wxCommandEvent dummy;
852 playlist_t *p_playlist =
853 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
855 if( p_playlist == NULL ) return;
857 if( p_playlist->i_size && p_playlist->i_enabled )
861 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
864 if( p_input == NULL )
866 /* No stream was playing, start one */
867 playlist_Play( p_playlist );
868 vlc_object_release( p_playlist );
869 input_manager->Update();
873 var_Get( p_input, "state", &state );
874 if( state.i_int != PAUSE_S )
876 /* A stream is being played, pause it */
877 state.i_int = PAUSE_S;
881 /* Stream is paused, resume it */
882 state.i_int = PLAYING_S;
884 var_Set( p_input, "state", state );
886 vlc_object_release( p_input );
887 vlc_object_release( p_playlist );
888 input_manager->Update();
892 /* If the playlist is empty, open a file requester instead */
893 vlc_object_release( p_playlist );
894 OnShowDialog( dummy );
898 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
902 void Interface::StopStream()
904 playlist_t * p_playlist =
905 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
907 if( p_playlist == NULL )
912 playlist_Stop( p_playlist );
913 vlc_object_release( p_playlist );
914 input_manager->Update();
917 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
922 void Interface::PrevStream()
924 playlist_t * p_playlist =
925 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
927 if( p_playlist == NULL )
932 playlist_Prev( p_playlist );
933 vlc_object_release( p_playlist );
936 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
941 void Interface::NextStream()
943 playlist_t * p_playlist =
944 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
946 if( p_playlist == NULL )
950 playlist_Next( p_playlist );
951 vlc_object_release( p_playlist );
954 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
956 input_thread_t *p_input =
957 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
961 vlc_value_t val; val.b_bool = VLC_TRUE;
963 var_Set( p_input, "rate-slower", val );
964 vlc_object_release( p_input );
968 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
970 input_thread_t *p_input =
971 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
975 vlc_value_t val; val.b_bool = VLC_TRUE;
977 var_Set( p_input, "rate-faster", val );
978 vlc_object_release( p_input );
982 void Interface::TogglePlayButton( int i_playing_status )
984 wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
985 GetToolBar()->GetToolClientData( PlayStream_Event );
986 if( !p_tool ) return;
988 if( i_playing_status == PLAYING_S )
990 p_tool->SetNormalBitmap( wxBitmap( pause_xpm ) );
991 p_tool->SetLabel( wxU(_("Pause")) );
992 p_tool->SetShortHelp( wxU(_(HELP_PAUSE)) );
996 p_tool->SetNormalBitmap( wxBitmap( play_xpm ) );
997 p_tool->SetLabel( wxU(_("Play")) );
998 p_tool->SetShortHelp( wxU(_(HELP_PLAY)) );
1001 GetToolBar()->Realize();
1002 GetToolBar()->ToggleTool( PlayStream_Event, true );
1003 GetToolBar()->ToggleTool( PlayStream_Event, false );
1006 #if wxUSE_DRAG_AND_DROP
1007 /*****************************************************************************
1008 * Definition of DragAndDrop class.
1009 *****************************************************************************/
1010 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
1013 b_enqueue = _b_enqueue;
1016 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1017 const wxArrayString& filenames )
1019 /* Add dropped files to the playlist */
1021 playlist_t *p_playlist =
1022 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1024 if( p_playlist == NULL )
1029 for( size_t i = 0; i < filenames.GetCount(); i++ )
1031 char *psz_utf8 = wxFromLocale( filenames[i] );
1033 playlist_Add( p_playlist, psz_utf8, psz_utf8,
1034 PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
1036 wxLocaleFree( psz_utf8 );
1039 vlc_object_release( p_playlist );
1045 /*****************************************************************************
1046 * Definition of VolCtrl class.
1047 *****************************************************************************/
1048 class wxVolCtrl: public wxGauge
1052 wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1053 wxPoint = wxDefaultPosition, wxSize = wxSize( 20, -1 ) );
1054 virtual ~wxVolCtrl() {};
1056 void UpdateVolume();
1059 void OnChange( wxMouseEvent& event );
1062 intf_thread_t *p_intf;
1064 DECLARE_EVENT_TABLE();
1067 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
1069 EVT_LEFT_DOWN(wxVolCtrl::OnChange)
1070 EVT_MOTION(wxVolCtrl::OnChange)
1073 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1074 wxPoint point, wxSize size )
1075 : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
1081 void wxVolCtrl::OnChange( wxMouseEvent& event )
1083 if( !event.LeftDown() && !event.LeftIsDown() ) return;
1085 int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
1086 aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1090 void wxVolCtrl::UpdateVolume()
1092 audio_volume_t i_volume;
1093 aout_VolumeGet( p_intf, &i_volume );
1095 int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
1096 if( i_gauge_volume == GetValue() ) return;
1098 SetValue( i_gauge_volume );
1099 SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
1100 i_gauge_volume / 2 ) );
1103 #if defined(__WXGTK__)
1104 #define VLCVOL_HEIGHT p_parent->GetSize().GetHeight()
1106 #define VLCVOL_HEIGHT TOOLBAR_BMP_HEIGHT
1108 VLCVolCtrl::VLCVolCtrl( intf_thread_t *_p_intf, wxWindow *p_parent )
1109 :wxControl( p_parent, -1, wxDefaultPosition, wxSize(64, VLCVOL_HEIGHT ),
1111 i_y_offset((VLCVOL_HEIGHT - TOOLBAR_BMP_HEIGHT) / 2),
1112 b_mute(0), p_intf(_p_intf)
1114 gauge = new wxVolCtrl( p_intf, this, -1, wxPoint( 18, i_y_offset ),
1115 wxSize( 44, TOOLBAR_BMP_HEIGHT ) );
1118 void VLCVolCtrl::OnPaint( wxPaintEvent &evt )
1120 wxPaintDC dc( this );
1121 wxBitmap mPlayBitmap( b_mute ? speaker_mute_xpm : speaker_xpm );
1122 dc.DrawBitmap( mPlayBitmap, 0, i_y_offset, TRUE );
1125 void VLCVolCtrl::OnChange( wxMouseEvent& event )
1127 if( event.GetX() < TOOLBAR_BMP_WIDTH )
1130 aout_VolumeMute( p_intf, (audio_volume_t *)&i_volume );
1137 void VLCVolCtrl::UpdateVolume()
1139 gauge->UpdateVolume();
1141 int i_volume = gauge->GetValue();
1142 if( !!i_volume == !b_mute ) return;
1147 /*****************************************************************************
1149 *****************************************************************************/
1151 #ifdef wxHAS_TASK_BAR_ICON
1153 BEGIN_EVENT_TABLE(Systray, wxTaskBarIcon)
1156 EVT_TASKBAR_LEFT_DCLICK(Systray::OnLeftClick)
1158 EVT_TASKBAR_LEFT_DOWN(Systray::OnLeftClick)
1161 EVT_MENU(Iconize_Event, Systray::OnMenuIconize)
1162 EVT_MENU(Exit_Event, Systray::OnExit)
1163 EVT_MENU(PlayStream_Event, Systray::OnPlayStream)
1164 EVT_MENU(NextStream_Event, Systray::OnNextStream)
1165 EVT_MENU(PrevStream_Event, Systray::OnPrevStream)
1166 EVT_MENU(StopStream_Event, Systray::OnStopStream)
1169 Systray::Systray( Interface *_p_main_interface, intf_thread_t *_p_intf )
1171 p_main_interface = _p_main_interface;
1174 SetIcon( wxIcon( vlc16x16_xpm ), wxT("VLC media player") );
1175 if( !IsOk() || !IsIconInstalled() )
1177 msg_Warn(p_intf, "cannot set systray icon, weird things may happen");
1181 /* Event handlers */
1182 void Systray::OnMenuIconize( wxCommandEvent& event )
1184 p_main_interface->Show( ! p_main_interface->IsShown() );
1185 if ( p_main_interface->IsShown() ) p_main_interface->Raise();
1188 void Systray::OnLeftClick( wxTaskBarIconEvent& event )
1190 wxCommandEvent cevent;
1191 OnMenuIconize(cevent);
1194 void Systray::OnExit( wxCommandEvent& event )
1196 p_main_interface->Close(TRUE);
1199 void Systray::OnPrevStream( wxCommandEvent& event )
1201 p_main_interface->PrevStream();
1204 void Systray::OnNextStream( wxCommandEvent& event )
1206 p_main_interface->NextStream();
1209 void Systray::OnPlayStream( wxCommandEvent& event )
1211 p_main_interface->PlayStream();
1214 void Systray::OnStopStream( wxCommandEvent& event )
1216 p_main_interface->StopStream();
1219 /* Systray popup menu */
1220 wxMenu* Systray::CreatePopupMenu()
1222 int minimal = config_GetInt( p_intf, "wx-minimal" );
1224 wxMenu* systray_menu = new wxMenu;
1225 systray_menu->Append( Exit_Event, wxU(_("Quit VLC")) );
1226 systray_menu->AppendSeparator();
1227 systray_menu->Append( PlayStream_Event, wxU(_("Play/Pause")) );
1231 systray_menu->Append( PrevStream_Event, wxU(_("Previous")) );
1232 systray_menu->Append( NextStream_Event, wxU(_("Next")) );
1233 systray_menu->Append( StopStream_Event, wxU(_("Stop")) );
1235 systray_menu->AppendSeparator();
1236 systray_menu->Append( Iconize_Event, wxU(_("Show/Hide interface")) );
1237 return systray_menu;
1240 void Systray::UpdateTooltip( const wxChar* tooltip )
1242 SetIcon( wxIcon( vlc16x16_xpm ), tooltip );