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 the toolbar graphics */
40 #include "bitmaps/play.xpm"
41 #include "bitmaps/pause.xpm"
42 #include "bitmaps/stop.xpm"
43 #include "bitmaps/prev.xpm"
44 #include "bitmaps/next.xpm"
45 #include "bitmaps/eject.xpm"
46 #include "bitmaps/slow.xpm"
47 #include "bitmaps/fast.xpm"
48 #include "bitmaps/playlist.xpm"
49 #include "bitmaps/playlist_small.xpm"
50 #include "bitmaps/speaker.xpm"
51 #include "bitmaps/speaker_mute.xpm"
53 #define TOOLBAR_BMP_WIDTH 16
54 #define TOOLBAR_BMP_HEIGHT 16
56 /* include the icon graphic */
57 #include "../../../share/vlc32x32.xpm"
58 /* include a small icon graphic for the systray icon */
59 #ifdef wxHAS_TASK_BAR_ICON
60 #include "../../../share/vlc16x16.xpm"
63 /*****************************************************************************
64 * Local class declarations.
65 *****************************************************************************/
66 class wxMenuExt: public wxMenu
70 wxMenuExt( wxMenu* parentMenu, int id, const wxString& text,
71 const wxString& helpString, wxItemKind kind,
72 char *_psz_var, int _i_object_id, vlc_value_t _val,
75 virtual ~wxMenuExt() {};
87 class VLCVolCtrl : public wxControl
90 VLCVolCtrl( intf_thread_t *p_intf, wxWindow *p_parent );
91 virtual ~VLCVolCtrl() {};
93 virtual void OnPaint( wxPaintEvent &event );
94 void OnChange( wxMouseEvent& event );
103 intf_thread_t *p_intf;
106 BEGIN_EVENT_TABLE(VLCVolCtrl, wxControl)
107 EVT_PAINT(VLCVolCtrl::OnPaint)
110 EVT_LEFT_UP(VLCVolCtrl::OnChange)
113 /*****************************************************************************
115 *****************************************************************************/
117 DEFINE_LOCAL_EVENT_TYPE( wxEVT_INTF );
119 /* IDs for the controls and the menu commands */
123 MenuDummy_Event = wxID_HIGHEST + 1000,
124 Exit_Event = wxID_HIGHEST,
125 OpenFileSimple_Event,
155 /* it is important for the id corresponding to the "About" command to have
156 * this standard value as otherwise it won't be handled properly under Mac
157 * (where it is special and put into the "Apple" menu) */
158 About_Event = wxID_ABOUT,
165 BEGIN_EVENT_TABLE(Interface, wxFrame)
167 EVT_MENU(Exit_Event, Interface::OnExit)
168 EVT_MENU(About_Event, Interface::OnAbout)
169 EVT_MENU(UpdateVLC_Event, Interface::OnShowDialog)
170 EVT_MENU(VLM_Event, Interface::OnShowDialog)
172 EVT_MENU(Playlist_Event, Interface::OnShowDialog)
173 EVT_MENU(PlaylistSmall_Event, Interface::OnSmallPlaylist)
174 EVT_MENU(Logs_Event, Interface::OnShowDialog)
175 EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
176 EVT_MENU(Prefs_Event, Interface::OnShowDialog)
178 EVT_MENU_OPEN(Interface::OnMenuOpen)
180 EVT_MENU( Extended_Event, Interface::OnExtended )
182 EVT_MENU( Bookmarks_Event, Interface::OnShowDialog)
184 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
185 EVT_CONTEXT_MENU(Interface::OnContextMenu2)
187 EVT_RIGHT_UP(Interface::OnContextMenu)
190 EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
191 EVT_MENU(OpenAdv_Event, Interface::OnShowDialog)
192 EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
193 EVT_MENU(OpenDir_Event, Interface::OnShowDialog)
194 EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
195 EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
196 EVT_MENU(OpenCapture_Event, Interface::OnShowDialog)
197 EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
198 EVT_MENU(Wizard_Event, Interface::OnShowDialog)
199 EVT_MENU(StopStream_Event, Interface::OnStopStream)
200 EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
201 EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
202 EVT_MENU(NextStream_Event, Interface::OnNextStream)
203 EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
204 EVT_MENU(FastStream_Event, Interface::OnFastStream)
207 EVT_COMMAND(0, wxEVT_INTF, Interface::OnControlEvent)
208 EVT_COMMAND(1, wxEVT_INTF, Interface::OnControlEvent)
211 /*****************************************************************************
213 *****************************************************************************/
214 Interface::Interface( intf_thread_t *_p_intf, long style ):
215 wxFrame( NULL, -1, wxT("VLC media player"),
216 wxDefaultPosition, wxSize(700,100), style )
218 /* Initializations */
222 b_playlist_manager = VLC_FALSE;
223 playlist_manager = 0;
225 /* Give our interface a nice little icon */
226 SetIcon( wxIcon( vlc_xpm ) );
228 /* Create a main panel that will fill in the interface window */
229 main_sizer = new wxBoxSizer( wxVERTICAL );
230 SetSizer( main_sizer );
231 main_panel = new wxPanel( this, -1, wxPoint(0,0), wxSize(0,0),
233 main_sizer->Add( main_panel, 1, wxEXPAND );
234 main_panel->SetFocus();
236 #if defined(__WXGTK20__) && wxCHECK_VERSION(2,5,6)
237 /* As ugly as your butt! Please remove when wxWidgets 2.6 fixed their
238 * Accelerators bug. */
239 main_panel->m_imData = 0;
243 /* Create a sizer for the main frame */
244 panel_sizer = new wxBoxSizer( wxVERTICAL );
245 main_panel->SetSizer( panel_sizer );
247 #ifdef wxHAS_TASK_BAR_ICON
248 /* Systray integration */
250 if( config_GetInt( p_intf, "wx-systray" ) )
252 p_systray = new Systray( this, p_intf );
256 /* Creation of the menu bar */
259 /* Creation of the tool bar */
262 /* Creation of the status bar
263 * Helptext for menu items and toolbar tools will automatically get
265 int i_status_width[3] = {-6, -2, -9};
266 statusbar = CreateStatusBar( 3 ); /* 2 fields */
267 statusbar->SetStatusWidths( 3, i_status_width );
268 statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
270 /* Get minimum window size to prevent user from glitching it */
271 main_panel->SetSizeHints( wxSize(-1,0) );
272 panel_sizer->Layout(); panel_sizer->Fit( main_panel );
273 main_sizer->Layout(); main_sizer->Fit( this );
274 main_min_size = GetSize();
275 main_panel->SetSizeHints( wxSize(-1,-1) );
279 if( config_GetInt( p_intf, "wx-embed" ) )
281 video_window = CreateVideoWindow( p_intf, main_panel );
282 panel_sizer->Add( p_intf->p_sys->p_video_sizer, 1, wxEXPAND, 0 );
285 /* Creation of the input manager panel */
286 input_manager = new InputManager( p_intf, this, main_panel );
287 panel_sizer->Add( input_manager, 0, wxEXPAND , 0 );
289 /* Layout everything */
290 main_panel->SetSizeHints( wxSize(-1,0) );
291 panel_sizer->Layout(); panel_sizer->Fit( main_panel );
292 main_sizer->Layout(); main_sizer->Fit( this );
293 main_panel->SetSizeHints( wxSize(-1,-1) );
295 #if wxUSE_DRAG_AND_DROP
296 /* Associate drop targets with the main interface */
297 SetDropTarget( new DragAndDrop( p_intf ) );
303 timer = new Timer( p_intf, this );
305 /* Restore previous position / settings */
306 WindowSettings *ws = p_intf->p_sys->p_window_settings;
311 ws->SetScreen( wxSystemSettings::GetMetric( wxSYS_SCREEN_X ),
312 wxSystemSettings::GetMetric( wxSYS_SCREEN_Y ) );
314 if( ws->GetSettings( WindowSettings::ID_MAIN, b_shown, p, s ) ) Move( p );
316 /* Show extended GUI if requested */
317 wxCommandEvent dummy;
318 if( config_GetInt( p_intf, "wx-extended" ) ) OnExtended( dummy );
323 Interface::~Interface()
325 WindowSettings *ws = p_intf->p_sys->p_window_settings;
329 ws->SetSettings( WindowSettings::ID_MAIN, true,
330 GetPosition(), GetSize() );
333 PopEventHandler(true);
335 if( video_window ) delete video_window;
337 #ifdef wxHAS_TASK_BAR_ICON
338 if( p_systray ) delete p_systray;
341 if( p_intf->p_sys->p_wxwindow ) delete p_intf->p_sys->p_wxwindow;
347 void Interface::Init()
353 void Interface::Update()
356 ((VLCVolCtrl *)volctrl)->UpdateVolume();
358 if( playlist_manager ) playlist_manager->Update();
361 void Interface::OnControlEvent( wxCommandEvent& event )
363 switch( event.GetId() )
366 main_sizer->Layout();
367 main_sizer->Fit( this );
371 long i_style = GetWindowStyle();
372 if( event.GetInt() ) i_style |= wxSTAY_ON_TOP;
373 else i_style &= ~wxSTAY_ON_TOP;
374 SetWindowStyle( i_style );
379 /*****************************************************************************
381 *****************************************************************************/
382 void Interface::CreateOurMenuBar()
384 int minimal = config_GetInt( p_intf, "wx-minimal" );
386 /* Create the "File" menu */
387 wxMenu *file_menu = new wxMenu;
391 file_menu->Append( OpenFileSimple_Event,
392 wxU(_("Quick &Open File...\tCtrl-O")) );
394 file_menu->AppendSeparator();
395 file_menu->Append( OpenFile_Event, wxU(_("Open &File...\tCtrl-F")) );
396 file_menu->Append( OpenDir_Event, wxU(_("Open Dir&ectory...\tCtrl-E")) );
397 file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...\tCtrl-D")) );
398 file_menu->Append( OpenNet_Event,
399 wxU(_("Open &Network Stream...\tCtrl-N")) );
400 file_menu->Append( OpenCapture_Event,
401 wxU(_("Open C&apture Device...\tCtrl-A")) );
403 file_menu->AppendSeparator();
404 file_menu->Append( Wizard_Event, wxU(_("&Wizard...\tCtrl-W")) );
405 file_menu->AppendSeparator();
407 file_menu->Append( Exit_Event, wxU(_("E&xit\tCtrl-X")) );
409 /* Create the "View" menu */
410 wxMenu *view_menu = new wxMenu;
413 view_menu->Append( Playlist_Event, wxU(_("&Playlist...\tCtrl-P")) );
415 view_menu->Append( Logs_Event, wxU(_("&Messages...\tCtrl-M")) );
416 view_menu->Append( FileInfo_Event,
417 wxU(_("Stream and Media &info...\tCtrl-I")) );
418 view_menu->Append( VLM_Event,
419 wxU(_("VLM Control...\tCtrl-V")) );
421 /* Create the "Auto-generated" menus */
422 p_settings_menu = SettingsMenu( p_intf, this );
423 p_audio_menu = AudioMenu( p_intf, this );
424 p_video_menu = VideoMenu( p_intf, this );
425 p_navig_menu = NavigMenu( p_intf, this );
427 /* Create the "Help" menu */
428 wxMenu *help_menu = new wxMenu;
429 help_menu->Append( About_Event, wxU(_("About VLC media player")) );
430 help_menu->AppendSeparator();
431 help_menu->Append( UpdateVLC_Event, wxU(_("Check for updates ...")) );
433 /* Append the freshly created menus to the menu bar... */
434 wxMenuBar *menubar = new wxMenuBar();
435 menubar->Append( file_menu, wxU(_("&File")) );
436 menubar->Append( view_menu, wxU(_("&View")) );
437 menubar->Append( p_settings_menu, wxU(_("&Settings")) );
438 menubar->Append( p_audio_menu, wxU(_("&Audio")) );
439 menubar->Append( p_video_menu, wxU(_("&Video")) );
440 menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
441 menubar->Append( help_menu, wxU(_("&Help")) );
443 /* Attach the menu bar to the frame */
444 SetMenuBar( menubar );
446 /* Find out size of menu bar */
448 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
450 int i_width, i_height;
451 menubar->GetTextExtent( menubar->GetLabelTop(i), &i_width, &i_height );
453 #if defined(__WXGTK__)
454 22 /* approximate margin */;
456 #if (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 5) && (wxRELEASE_NUMBER < 3)
457 4 /* approximate margin */;
459 18 /* approximate margin */;
464 /* Patch by zcot for menu wrapping */
466 /* Find out size of msw menu bar */
469 HDC hdc = GetDC( NULL );
470 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
472 GetTextExtentPoint32( hdc, menubar->GetLabelTop(i).c_str(),
473 menubar->GetLabelTop(i).Length(), &sizing );
475 // [ SM_CXDLGFRAME + pixels + textextent + pixels + SM_CXDLGFRAME ]
476 i_size += sizing.cx + 2 + GetSystemMetrics( SM_CXDLGFRAME ) * 2;
478 ReleaseDC( NULL, hdc );
479 i_size += GetSystemMetrics( SM_CXSIZEFRAME ) * 2 + 4;
481 /* End patch by zcot */
483 panel_sizer->SetMinSize( i_size, -1 );
485 /* Intercept all menu events in our custom event handler */
486 PushEventHandler( new MenuEvtHandler( p_intf, this ) );
488 #if wxUSE_DRAG_AND_DROP
489 /* Associate drop targets with the menubar */
490 menubar->SetDropTarget( new DragAndDrop( p_intf ) );
494 void Interface::CreateOurToolBar()
496 #define HELP_OPEN N_("Open")
497 #define HELP_STOP N_("Stop")
498 #define HELP_PLAY N_("Play")
499 #define HELP_PAUSE N_("Pause")
500 #define HELP_PLO N_("Playlist")
501 #define HELP_SPLO N_("Small playlist")
502 #define HELP_PLP N_("Previous playlist item")
503 #define HELP_PLN N_("Next playlist item")
504 #define HELP_SLOW N_("Play slower")
505 #define HELP_FAST N_("Play faster")
507 int minimal = config_GetInt( p_intf, "wx-minimal" );
509 wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
510 * version because we don't include wx.rc */
513 CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
515 toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
519 toolbar->AddTool( OpenFile_Event, wxT(""),
520 wxBitmap( eject_xpm ), wxU(_(HELP_OPEN)) );
521 toolbar->AddSeparator();
524 wxToolBarToolBase *p_tool = toolbar->AddTool( PlayStream_Event, wxT(""),
525 wxBitmap( play_xpm ), wxU(_(HELP_PLAY)), wxITEM_CHECK );
526 p_tool->SetClientData( p_tool );
530 toolbar->AddTool( StopStream_Event, wxT(""), wxBitmap( stop_xpm ),
532 toolbar->AddSeparator();
534 toolbar->AddTool( PrevStream_Event, wxT(""),
535 wxBitmap( prev_xpm ), wxU(_(HELP_PLP)) );
536 toolbar->AddTool( SlowStream_Event, wxT(""),
537 wxBitmap( slow_xpm ), wxU(_(HELP_SLOW)) );
538 toolbar->AddTool( FastStream_Event, wxT(""),
539 wxBitmap( fast_xpm ), wxU(_(HELP_FAST)) );
540 toolbar->AddTool( NextStream_Event, wxT(""), wxBitmap( next_xpm ),
542 toolbar->AddSeparator();
543 toolbar->AddTool( Playlist_Event, wxT(""), wxBitmap( playlist_xpm ),
545 toolbar->AddTool( PlaylistSmall_Event, wxT(""),
546 wxBitmap( playlist_small_xpm ), wxU(_(HELP_SPLO)) );
549 wxControl *p_dummy_ctrl =
550 new wxControl( toolbar, -1, wxDefaultPosition,
551 wxSize(16, 16 ), wxBORDER_NONE );
553 toolbar->AddControl( p_dummy_ctrl );
555 volctrl = new VLCVolCtrl( p_intf, toolbar );
556 toolbar->AddControl( volctrl );
560 #if wxUSE_DRAG_AND_DROP
561 /* Associate drop targets with the toolbar */
562 toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
566 static int ConvertHotkeyModifiers( int i_hotkey )
568 int i_accel_flags = 0;
569 if( i_hotkey & KEY_MODIFIER_ALT ) i_accel_flags |= wxACCEL_ALT;
570 if( i_hotkey & KEY_MODIFIER_CTRL ) i_accel_flags |= wxACCEL_CTRL;
571 if( i_hotkey & KEY_MODIFIER_SHIFT ) i_accel_flags |= wxACCEL_SHIFT;
572 if( !i_accel_flags ) i_accel_flags = wxACCEL_NORMAL;
573 return i_accel_flags;
576 static int ConvertHotkey( int i_hotkey )
578 int i_key = i_hotkey & ~KEY_MODIFIER;
579 if( i_key & KEY_ASCII ) return i_key & KEY_ASCII;
580 else if( i_key & KEY_SPECIAL )
584 case KEY_LEFT: return WXK_LEFT;
585 case KEY_RIGHT: return WXK_RIGHT;
586 case KEY_UP: return WXK_UP;
587 case KEY_DOWN: return WXK_DOWN;
588 case KEY_SPACE: return WXK_SPACE;
589 case KEY_ENTER: return WXK_RETURN;
590 case KEY_F1: return WXK_F1;
591 case KEY_F2: return WXK_F2;
592 case KEY_F3: return WXK_F3;
593 case KEY_F4: return WXK_F4;
594 case KEY_F5: return WXK_F5;
595 case KEY_F6: return WXK_F6;
596 case KEY_F7: return WXK_F7;
597 case KEY_F8: return WXK_F8;
598 case KEY_F9: return WXK_F9;
599 case KEY_F10: return WXK_F10;
600 case KEY_F11: return WXK_F11;
601 case KEY_F12: return WXK_F12;
602 case KEY_HOME: return WXK_HOME;
603 case KEY_END: return WXK_END;
604 case KEY_INSERT: return WXK_INSERT;
605 case KEY_DELETE: return WXK_DELETE;
606 case KEY_MENU: return WXK_MENU;
607 case KEY_ESC: return WXK_ESCAPE;
608 case KEY_PAGEUP: return WXK_PRIOR;
609 case KEY_PAGEDOWN: return WXK_NEXT;
610 case KEY_TAB: return WXK_TAB;
611 case KEY_BACKSPACE: return WXK_BACK;
617 void Interface::SetupHotkeys()
619 struct vlc_t::hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
622 /* Count number of hoteys */
623 for( i_hotkeys = 0; p_hotkeys[i_hotkeys].psz_action != NULL; i_hotkeys++ );
625 p_intf->p_sys->i_first_hotkey_event = wxID_HIGHEST + 7000;
626 p_intf->p_sys->i_hotkeys = i_hotkeys;
628 wxAcceleratorEntry *p_entries = new wxAcceleratorEntry[i_hotkeys];
630 /* Setup the hotkeys as accelerators */
631 for( int i = 0; i < i_hotkeys; i++ )
633 int i_mod = ConvertHotkeyModifiers( p_hotkeys[i].i_key );
634 int i_key = ConvertHotkey( p_hotkeys[i].i_key );
637 if( !(p_hotkeys[i].i_key & KEY_SPECIAL) && i_mod )
638 i_key = toupper(i_key);
641 p_entries[i].Set( i_mod, i_key,
642 p_intf->p_sys->i_first_hotkey_event + i );
645 wxAcceleratorTable accel( i_hotkeys, p_entries );
649 msg_Err( p_intf, "invalid accelerator table" );
653 SetAcceleratorTable( accel );
659 void Interface::SetIntfMinSize()
661 wxSize ms = main_min_size;
663 if( extra_frame && extra_frame->IsShown() )
665 ms.SetHeight( ms.GetHeight() + ext_min_size.GetHeight() );
666 if( ext_min_size.GetWidth() > ms.GetWidth() )
667 ms.SetWidth( ext_min_size.GetWidth() );
670 if( playlist_manager && playlist_manager->IsShown() )
672 ms.SetHeight( ms.GetHeight() + playlist_min_size.GetHeight() );
673 if( playlist_min_size.GetWidth() > ms.GetWidth() )
674 ms.SetWidth( playlist_min_size.GetWidth() );
680 /*****************************************************************************
682 *****************************************************************************/
683 void Interface::OnMenuOpen( wxMenuEvent& event )
685 #if defined( __WXMSW__ )
686 # define GetEventObject GetMenu
689 if( event.GetEventObject() == p_settings_menu )
691 p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );
693 /* Add static items */
694 p_settings_menu->AppendCheckItem( Extended_Event,
695 wxU(_("Extended &GUI\tCtrl-G") ) );
696 if( b_extra ) p_settings_menu->Check( Extended_Event, TRUE );
697 p_settings_menu->Append( Bookmarks_Event,
698 wxU(_("&Bookmarks...\tCtrl-B") ) );
699 p_settings_menu->Append( Prefs_Event,
700 wxU(_("Preference&s...\tCtrl-S")) );
703 else if( event.GetEventObject() == p_audio_menu )
705 p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
708 else if( event.GetEventObject() == p_video_menu )
710 p_video_menu = VideoMenu( p_intf, this, p_video_menu );
713 else if( event.GetEventObject() == p_navig_menu )
715 p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
718 #if defined( __WXMSW__ )
719 # undef GetEventObject
723 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
724 void Interface::OnContextMenu2(wxContextMenuEvent& event)
726 /* Only show the context menu for the main interface */
727 if( GetId() != event.GetId() )
733 if( p_intf->p_sys->pf_show_dialog )
734 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
737 void Interface::OnContextMenu(wxMouseEvent& event)
739 if( p_intf->p_sys->pf_show_dialog )
740 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
743 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
745 /* TRUE is to force the frame to close. */
749 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
752 msg.Printf( wxString(wxT("VLC media player " PACKAGE_VERSION)) +
753 wxU(_(" (wxWidgets interface)\n\n")) +
754 wxU(_("(c) 1996-2005 - the VideoLAN Team\n\n")) +
755 wxU(_("Compiled by "))+ wxU(VLC_CompileBy())+ wxU("@") +
756 wxU(VLC_CompileHost())+ wxT(".")+ wxU(VLC_CompileDomain())+ wxT(".\n") +
757 wxU(_("Compiler: "))+ wxU(VLC_Compiler())+wxT( ".\n") +
758 wxU(_("Based on SVN revision: "))+wxU(VLC_Changeset())+wxT(".\n\n") +
760 wxU( vlc_wraptext(LICENSE_MSG,WRAPCOUNT,VLC_TRUE) ) + wxT("\n\n") +
762 wxU( LICENSE_MSG ) + wxT("\n\n") +
764 wxU(_("The VideoLAN team <videolan@videolan.org>\n"
765 "http://www.videolan.org/\n\n")) );
767 wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
768 wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
771 void Interface::OnShowDialog( wxCommandEvent& event )
773 if( p_intf->p_sys->pf_show_dialog )
777 switch( event.GetId() )
779 case OpenFileSimple_Event:
780 i_id = INTF_DIALOG_FILE_SIMPLE;
783 i_id = INTF_DIALOG_FILE;
786 i_id = INTF_DIALOG_FILE;
789 i_id = INTF_DIALOG_DIRECTORY;
792 i_id = INTF_DIALOG_DISC;
795 i_id = INTF_DIALOG_NET;
797 case OpenCapture_Event:
798 i_id = INTF_DIALOG_CAPTURE;
801 i_id = INTF_DIALOG_SAT;
804 i_id = INTF_DIALOG_PLAYLIST;
807 i_id = INTF_DIALOG_MESSAGES;
810 i_id = INTF_DIALOG_FILEINFO;
813 i_id = INTF_DIALOG_PREFS;
816 i_id = INTF_DIALOG_WIZARD;
818 case Bookmarks_Event:
819 i_id = INTF_DIALOG_BOOKMARKS;
821 case UpdateVLC_Event:
822 i_id = INTF_DIALOG_UPDATEVLC;
825 i_id = INTF_DIALOG_VLM;
828 i_id = INTF_DIALOG_FILE;
832 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
836 void Interface::OnExtended( wxCommandEvent& WXUNUSED(event) )
838 UpdateVideoWindow( p_intf, video_window );
842 /* Create the extra panel */
843 extra_frame = new ExtraPanel( p_intf, main_panel );
844 panel_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
845 ext_min_size = extra_frame->GetBestSize();
849 panel_sizer->Show( extra_frame, b_extra );
852 main_sizer->Layout();
853 main_sizer->Fit( this );
856 void Interface::OnSmallPlaylist( wxCommandEvent& WXUNUSED(event) )
858 UpdateVideoWindow( p_intf, video_window );
860 if( !playlist_manager )
862 /* Create the extra panel */
863 playlist_manager = new PlaylistManager( p_intf, main_panel );
864 panel_sizer->Add( playlist_manager, 0, wxEXPAND , 0 );
865 playlist_min_size = playlist_manager->GetBestSize();
868 b_playlist_manager = !b_playlist_manager;
869 panel_sizer->Show( playlist_manager, b_playlist_manager );
872 main_sizer->Layout();
873 main_sizer->Fit( this );
876 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
881 void Interface::PlayStream()
883 wxCommandEvent dummy;
884 playlist_t *p_playlist =
885 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
887 if( p_playlist == NULL ) return;
889 if( p_playlist->i_size && p_playlist->i_enabled )
893 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
896 if( p_input == NULL )
898 /* No stream was playing, start one */
899 playlist_Play( p_playlist );
900 vlc_object_release( p_playlist );
901 input_manager->Update();
905 var_Get( p_input, "state", &state );
906 if( state.i_int != PAUSE_S )
908 /* A stream is being played, pause it */
909 state.i_int = PAUSE_S;
913 /* Stream is paused, resume it */
914 state.i_int = PLAYING_S;
916 var_Set( p_input, "state", state );
918 vlc_object_release( p_input );
919 vlc_object_release( p_playlist );
920 input_manager->Update();
924 /* If the playlist is empty, open a file requester instead */
925 vlc_object_release( p_playlist );
926 OnShowDialog( dummy );
930 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
934 void Interface::StopStream()
936 playlist_t * p_playlist =
937 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
939 if( p_playlist == NULL )
944 playlist_Stop( p_playlist );
945 vlc_object_release( p_playlist );
946 input_manager->Update();
949 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
954 void Interface::PrevStream()
956 playlist_t * p_playlist =
957 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
959 if( p_playlist == NULL )
964 playlist_Prev( p_playlist );
965 vlc_object_release( p_playlist );
968 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
973 void Interface::NextStream()
975 playlist_t * p_playlist =
976 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
978 if( p_playlist == NULL )
982 playlist_Next( p_playlist );
983 vlc_object_release( p_playlist );
986 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
988 input_thread_t *p_input =
989 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
993 vlc_value_t val; val.b_bool = VLC_TRUE;
995 var_Set( p_input, "rate-slower", val );
996 vlc_object_release( p_input );
1000 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1002 input_thread_t *p_input =
1003 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1007 vlc_value_t val; val.b_bool = VLC_TRUE;
1009 var_Set( p_input, "rate-faster", val );
1010 vlc_object_release( p_input );
1014 void Interface::TogglePlayButton( int i_playing_status )
1016 wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
1017 GetToolBar()->GetToolClientData( PlayStream_Event );
1018 if( !p_tool ) return;
1020 if( i_playing_status == PLAYING_S )
1022 p_tool->SetNormalBitmap( wxBitmap( pause_xpm ) );
1023 p_tool->SetLabel( wxU(_("Pause")) );
1024 p_tool->SetShortHelp( wxU(_(HELP_PAUSE)) );
1028 p_tool->SetNormalBitmap( wxBitmap( play_xpm ) );
1029 p_tool->SetLabel( wxU(_("Play")) );
1030 p_tool->SetShortHelp( wxU(_(HELP_PLAY)) );
1033 GetToolBar()->Realize();
1035 #if defined( __WXMSW__ )
1036 /* Needed to work around a bug in wxToolBar::Realize() */
1037 GetToolBar()->SetSize( GetSize().GetWidth(),
1038 GetToolBar()->GetSize().GetHeight() );
1039 GetToolBar()->Update();
1042 GetToolBar()->ToggleTool( PlayStream_Event, true );
1043 GetToolBar()->ToggleTool( PlayStream_Event, false );
1046 #if wxUSE_DRAG_AND_DROP
1047 /*****************************************************************************
1048 * Definition of DragAndDrop class.
1049 *****************************************************************************/
1050 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
1053 b_enqueue = _b_enqueue;
1056 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1057 const wxArrayString& filenames )
1059 /* Add dropped files to the playlist */
1061 playlist_t *p_playlist =
1062 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1064 if( p_playlist == NULL )
1069 for( size_t i = 0; i < filenames.GetCount(); i++ )
1071 char *psz_utf8 = wxFromLocale( filenames[i] );
1073 playlist_Add( p_playlist, psz_utf8, psz_utf8,
1074 PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
1076 wxLocaleFree( psz_utf8 );
1079 vlc_object_release( p_playlist );
1085 /*****************************************************************************
1086 * Definition of VolCtrl class.
1087 *****************************************************************************/
1088 class wxVolCtrl: public wxGauge
1092 wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1093 wxPoint = wxDefaultPosition, wxSize = wxSize( 20, -1 ) );
1094 virtual ~wxVolCtrl() {};
1096 void UpdateVolume();
1099 void OnChange( wxMouseEvent& event );
1102 intf_thread_t *p_intf;
1104 DECLARE_EVENT_TABLE();
1107 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
1109 EVT_LEFT_DOWN(wxVolCtrl::OnChange)
1110 EVT_MOTION(wxVolCtrl::OnChange)
1113 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1114 wxPoint point, wxSize size )
1115 : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
1121 void wxVolCtrl::OnChange( wxMouseEvent& event )
1123 if( !event.LeftDown() && !event.LeftIsDown() ) return;
1125 int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
1126 aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1130 void wxVolCtrl::UpdateVolume()
1132 audio_volume_t i_volume;
1133 aout_VolumeGet( p_intf, &i_volume );
1135 int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
1136 if( i_gauge_volume == GetValue() ) return;
1138 SetValue( i_gauge_volume );
1139 SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
1140 i_gauge_volume / 2 ) );
1143 #if defined(__WXGTK__)
1144 #define VLCVOL_HEIGHT p_parent->GetSize().GetHeight()
1146 #define VLCVOL_HEIGHT TOOLBAR_BMP_HEIGHT
1148 VLCVolCtrl::VLCVolCtrl( intf_thread_t *_p_intf, wxWindow *p_parent )
1149 :wxControl( p_parent, -1, wxDefaultPosition, wxSize(64, VLCVOL_HEIGHT ),
1151 i_y_offset((VLCVOL_HEIGHT - TOOLBAR_BMP_HEIGHT) / 2),
1152 b_mute(0), p_intf(_p_intf)
1154 gauge = new wxVolCtrl( p_intf, this, -1, wxPoint( 18, i_y_offset ),
1155 wxSize( 44, TOOLBAR_BMP_HEIGHT ) );
1158 void VLCVolCtrl::OnPaint( wxPaintEvent &evt )
1160 wxPaintDC dc( this );
1161 wxBitmap mPlayBitmap( b_mute ? speaker_mute_xpm : speaker_xpm );
1162 dc.DrawBitmap( mPlayBitmap, 0, i_y_offset, TRUE );
1165 void VLCVolCtrl::OnChange( wxMouseEvent& event )
1167 if( event.GetX() < TOOLBAR_BMP_WIDTH )
1170 aout_VolumeMute( p_intf, (audio_volume_t *)&i_volume );
1177 void VLCVolCtrl::UpdateVolume()
1179 gauge->UpdateVolume();
1181 int i_volume = gauge->GetValue();
1182 if( !!i_volume == !b_mute ) return;
1187 /*****************************************************************************
1189 *****************************************************************************/
1191 #ifdef wxHAS_TASK_BAR_ICON
1193 BEGIN_EVENT_TABLE(Systray, wxTaskBarIcon)
1196 EVT_TASKBAR_LEFT_DCLICK(Systray::OnLeftClick)
1198 EVT_TASKBAR_LEFT_DOWN(Systray::OnLeftClick)
1201 EVT_MENU(Iconize_Event, Systray::OnMenuIconize)
1202 EVT_MENU(Exit_Event, Systray::OnExit)
1203 EVT_MENU(PlayStream_Event, Systray::OnPlayStream)
1204 EVT_MENU(NextStream_Event, Systray::OnNextStream)
1205 EVT_MENU(PrevStream_Event, Systray::OnPrevStream)
1206 EVT_MENU(StopStream_Event, Systray::OnStopStream)
1209 Systray::Systray( Interface *_p_main_interface, intf_thread_t *_p_intf )
1211 p_main_interface = _p_main_interface;
1214 SetIcon( wxIcon( vlc16x16_xpm ), wxT("VLC media player") );
1215 if( !IsOk() || !IsIconInstalled() )
1217 msg_Warn(p_intf, "cannot set systray icon, weird things may happen");
1221 /* Event handlers */
1222 void Systray::OnMenuIconize( wxCommandEvent& event )
1224 p_main_interface->Show( ! p_main_interface->IsShown() );
1225 if ( p_main_interface->IsShown() ) p_main_interface->Raise();
1228 void Systray::OnLeftClick( wxTaskBarIconEvent& event )
1230 wxCommandEvent cevent;
1231 OnMenuIconize(cevent);
1234 void Systray::OnExit( wxCommandEvent& event )
1236 p_main_interface->Close(TRUE);
1239 void Systray::OnPrevStream( wxCommandEvent& event )
1241 p_main_interface->PrevStream();
1244 void Systray::OnNextStream( wxCommandEvent& event )
1246 p_main_interface->NextStream();
1249 void Systray::OnPlayStream( wxCommandEvent& event )
1251 p_main_interface->PlayStream();
1254 void Systray::OnStopStream( wxCommandEvent& event )
1256 p_main_interface->StopStream();
1259 /* Systray popup menu */
1260 wxMenu* Systray::CreatePopupMenu()
1262 int minimal = config_GetInt( p_intf, "wx-minimal" );
1264 wxMenu* systray_menu = new wxMenu;
1265 systray_menu->Append( Exit_Event, wxU(_("Quit VLC")) );
1266 systray_menu->AppendSeparator();
1267 systray_menu->Append( PlayStream_Event, wxU(_("Play/Pause")) );
1271 systray_menu->Append( PrevStream_Event, wxU(_("Previous")) );
1272 systray_menu->Append( NextStream_Event, wxU(_("Next")) );
1273 systray_menu->Append( StopStream_Event, wxU(_("Stop")) );
1275 systray_menu->AppendSeparator();
1276 systray_menu->Append( Iconize_Event, wxU(_("Show/Hide interface")) );
1277 return systray_menu;
1280 void Systray::UpdateTooltip( const wxChar* tooltip )
1282 SetIcon( wxIcon( vlc16x16_xpm ), tooltip );