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 splitter window that will fill in the interface window.
229 * We need a splitter bar in order to make the embedded playlist
231 splitter = new wxSplitterWindow( this, -1, wxDefaultPosition, wxSize(0,0),
232 wxCLIP_CHILDREN|wxSP_3DSASH );
233 main_sizer = new wxBoxSizer( wxVERTICAL );
234 main_sizer->Add( splitter, 1, wxEXPAND );
235 SetSizer( main_sizer );
237 /* Create a main panel that will fill in the interface window */
238 main_panel = new wxPanel( splitter, -1, wxPoint(0,0), wxSize(0,0),
240 main_panel->SetFocus();
242 #if defined(__WXGTK20__) && wxCHECK_VERSION(2,5,6)
243 /* As ugly as your butt! Please remove when wxWidgets 2.6 fixed their
244 * Accelerators bug. */
245 main_panel->m_imData = 0;
249 /* Create a sizer for the main frame */
250 panel_sizer = new wxBoxSizer( wxVERTICAL );
251 main_panel->SetSizer( panel_sizer );
253 /* Put this in the splitter */
254 splitter->Initialize( main_panel );
255 #if wxCHECK_VERSION(2,6,0)
256 splitter->SetSashGravity( 1.0 );
259 #ifdef wxHAS_TASK_BAR_ICON
260 /* Systray integration */
262 if( config_GetInt( p_intf, "wx-systray" ) )
264 p_systray = new Systray( this, p_intf );
268 /* Creation of the menu bar */
271 /* Creation of the tool bar */
274 /* Creation of the status bar
275 * Helptext for menu items and toolbar tools will automatically get
277 int i_status_width[3] = {100, 40, -1};
278 statusbar = CreateStatusBar( 3 ); /* 2 fields */
279 statusbar->SetStatusWidths( 3, i_status_width );
280 statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
282 /* Get minimum window size to prevent user from glitching it */
283 splitter->SetSizeHints( wxSize(-1,0) );
284 panel_sizer->Layout(); panel_sizer->Fit( main_panel );
285 main_sizer->Layout(); main_sizer->Fit( this );
286 main_min_size = GetSize();
287 splitter->SetSizeHints( wxSize(-1,-1) );
291 if( config_GetInt( p_intf, "wx-embed" ) )
293 video_window = CreateVideoWindow( p_intf, main_panel );
294 panel_sizer->Add( p_intf->p_sys->p_video_sizer, 1, wxEXPAND, 0 );
297 /* Creation of the input manager panel */
298 input_manager = new InputManager( p_intf, this, main_panel );
299 panel_sizer->Add( input_manager, 0, wxEXPAND , 0 );
301 /* Layout everything */
302 splitter->SetSizeHints( wxSize(-1,0) );
303 panel_sizer->Layout(); panel_sizer->Fit( main_panel );
304 main_sizer->Layout(); main_sizer->Fit( this );
305 splitter->SetSizeHints( wxSize(-1,-1) );
307 #if wxUSE_DRAG_AND_DROP
308 /* Associate drop targets with the main interface */
309 SetDropTarget( new DragAndDrop( p_intf ) );
315 timer = new Timer( p_intf, this );
317 /* Restore previous position / settings */
318 WindowSettings *ws = p_intf->p_sys->p_window_settings;
323 ws->SetScreen( wxSystemSettings::GetMetric( wxSYS_SCREEN_X ),
324 wxSystemSettings::GetMetric( wxSYS_SCREEN_Y ) );
326 if( ws->GetSettings( WindowSettings::ID_MAIN, b_shown, p, s ) ) Move( p );
328 /* Show extended GUI if requested */
329 wxCommandEvent dummy;
330 if( config_GetInt( p_intf, "wx-extended" ) ) OnExtended( dummy );
335 Interface::~Interface()
337 WindowSettings *ws = p_intf->p_sys->p_window_settings;
341 ws->SetSettings( WindowSettings::ID_MAIN, true,
342 GetPosition(), GetSize() );
345 PopEventHandler(true);
347 if( video_window ) delete video_window;
349 #ifdef wxHAS_TASK_BAR_ICON
350 if( p_systray ) delete p_systray;
353 if( p_intf->p_sys->p_wxwindow ) delete p_intf->p_sys->p_wxwindow;
359 void Interface::Init()
365 void Interface::Update()
368 ((VLCVolCtrl *)volctrl)->UpdateVolume();
370 if( playlist_manager ) playlist_manager->Update();
373 void Interface::OnControlEvent( wxCommandEvent& event )
375 switch( event.GetId() )
378 main_sizer->Layout();
379 main_sizer->Fit( this );
383 long i_style = GetWindowStyle();
384 if( event.GetInt() ) i_style |= wxSTAY_ON_TOP;
385 else i_style &= ~wxSTAY_ON_TOP;
386 SetWindowStyle( i_style );
391 /*****************************************************************************
393 *****************************************************************************/
394 void Interface::CreateOurMenuBar()
396 int minimal = config_GetInt( p_intf, "wx-minimal" );
398 /* Create the "File" menu */
399 wxMenu *file_menu = new wxMenu;
403 file_menu->Append( OpenFileSimple_Event,
404 wxU(_("Quick &Open File...\tCtrl-O")) );
406 file_menu->AppendSeparator();
407 file_menu->Append( OpenFile_Event, wxU(_("Open &File...\tCtrl-F")) );
408 file_menu->Append( OpenDir_Event, wxU(_("Open Dir&ectory...\tCtrl-E")) );
409 file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...\tCtrl-D")) );
410 file_menu->Append( OpenNet_Event,
411 wxU(_("Open &Network Stream...\tCtrl-N")) );
412 file_menu->Append( OpenCapture_Event,
413 wxU(_("Open C&apture Device...\tCtrl-A")) );
415 file_menu->AppendSeparator();
416 file_menu->Append( Wizard_Event, wxU(_("&Wizard...\tCtrl-W")) );
417 file_menu->AppendSeparator();
419 file_menu->Append( Exit_Event, wxU(_("E&xit\tCtrl-X")) );
421 /* Create the "View" menu */
422 wxMenu *view_menu = new wxMenu;
425 view_menu->Append( Playlist_Event, wxU(_("&Playlist...\tCtrl-P")) );
427 view_menu->Append( Logs_Event, wxU(_("&Messages...\tCtrl-M")) );
428 view_menu->Append( FileInfo_Event,
429 wxU(_("Stream and Media &info...\tCtrl-I")) );
430 view_menu->Append( VLM_Event,
431 wxU(_("VLM Control...\tCtrl-V")) );
433 /* Create the "Auto-generated" menus */
434 p_settings_menu = SettingsMenu( p_intf, this );
435 p_audio_menu = AudioMenu( p_intf, this );
436 p_video_menu = VideoMenu( p_intf, this );
437 p_navig_menu = NavigMenu( p_intf, this );
439 /* Create the "Help" menu */
440 wxMenu *help_menu = new wxMenu;
441 help_menu->Append( About_Event, wxU(_("About VLC media player")) );
442 help_menu->AppendSeparator();
443 help_menu->Append( UpdateVLC_Event, wxU(_("Check for updates ...")) );
445 /* Append the freshly created menus to the menu bar... */
446 wxMenuBar *menubar = new wxMenuBar();
447 menubar->Append( file_menu, wxU(_("&File")) );
448 menubar->Append( view_menu, wxU(_("&View")) );
449 menubar->Append( p_settings_menu, wxU(_("&Settings")) );
450 menubar->Append( p_audio_menu, wxU(_("&Audio")) );
451 menubar->Append( p_video_menu, wxU(_("&Video")) );
452 menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
453 menubar->Append( help_menu, wxU(_("&Help")) );
455 /* Attach the menu bar to the frame */
456 SetMenuBar( menubar );
458 /* Find out size of menu bar */
460 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
462 int i_width, i_height;
463 menubar->GetTextExtent( menubar->GetLabelTop(i), &i_width, &i_height );
465 #if defined(__WXGTK__)
466 22 /* approximate margin */;
468 #if (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 5) && (wxRELEASE_NUMBER < 3)
469 4 /* approximate margin */;
471 18 /* approximate margin */;
476 /* Patch by zcot for menu wrapping */
478 /* Find out size of msw menu bar */
481 HDC hdc = GetDC( NULL );
482 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
484 GetTextExtentPoint32( hdc, menubar->GetLabelTop(i).c_str(),
485 menubar->GetLabelTop(i).Length(), &sizing );
487 // [ SM_CXDLGFRAME + pixels + textextent + pixels + SM_CXDLGFRAME ]
488 i_size += sizing.cx + 2 + GetSystemMetrics( SM_CXDLGFRAME ) * 2;
490 ReleaseDC( NULL, hdc );
491 i_size += GetSystemMetrics( SM_CXSIZEFRAME ) * 2 + 4;
493 /* End patch by zcot */
495 panel_sizer->SetMinSize( i_size, -1 );
497 /* Intercept all menu events in our custom event handler */
498 PushEventHandler( new MenuEvtHandler( p_intf, this ) );
500 #if wxUSE_DRAG_AND_DROP
501 /* Associate drop targets with the menubar */
502 menubar->SetDropTarget( new DragAndDrop( p_intf ) );
506 void Interface::CreateOurToolBar()
508 #define HELP_OPEN N_("Open")
509 #define HELP_STOP N_("Stop")
510 #define HELP_PLAY N_("Play")
511 #define HELP_PAUSE N_("Pause")
512 #define HELP_PLO N_("Playlist")
513 #define HELP_SPLO N_("Small playlist")
514 #define HELP_PLP N_("Previous playlist item")
515 #define HELP_PLN N_("Next playlist item")
516 #define HELP_SLOW N_("Play slower")
517 #define HELP_FAST N_("Play faster")
519 int minimal = config_GetInt( p_intf, "wx-minimal" );
521 wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
522 * version because we don't include wx.rc */
525 CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
527 toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
531 toolbar->AddTool( OpenFile_Event, wxT(""),
532 wxBitmap( eject_xpm ), wxU(_(HELP_OPEN)) );
533 toolbar->AddSeparator();
536 wxToolBarToolBase *p_tool = toolbar->AddTool( PlayStream_Event, wxT(""),
537 wxBitmap( play_xpm ), wxU(_(HELP_PLAY)), wxITEM_CHECK );
538 p_tool->SetClientData( p_tool );
542 toolbar->AddTool( StopStream_Event, wxT(""), wxBitmap( stop_xpm ),
544 toolbar->AddSeparator();
546 toolbar->AddTool( PrevStream_Event, wxT(""),
547 wxBitmap( prev_xpm ), wxU(_(HELP_PLP)) );
548 toolbar->AddTool( SlowStream_Event, wxT(""),
549 wxBitmap( slow_xpm ), wxU(_(HELP_SLOW)) );
550 toolbar->AddTool( FastStream_Event, wxT(""),
551 wxBitmap( fast_xpm ), wxU(_(HELP_FAST)) );
552 toolbar->AddTool( NextStream_Event, wxT(""), wxBitmap( next_xpm ),
554 toolbar->AddSeparator();
555 toolbar->AddTool( Playlist_Event, wxT(""), wxBitmap( playlist_xpm ),
557 toolbar->AddTool( PlaylistSmall_Event, wxT(""),
558 wxBitmap( playlist_small_xpm ), wxU(_(HELP_SPLO)) );
561 wxControl *p_dummy_ctrl =
562 new wxControl( toolbar, -1, wxDefaultPosition,
563 wxSize(16, 16 ), wxBORDER_NONE );
565 toolbar->AddControl( p_dummy_ctrl );
567 volctrl = new VLCVolCtrl( p_intf, toolbar );
568 toolbar->AddControl( volctrl );
572 #if wxUSE_DRAG_AND_DROP
573 /* Associate drop targets with the toolbar */
574 toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
578 static int ConvertHotkeyModifiers( int i_hotkey )
580 int i_accel_flags = 0;
581 if( i_hotkey & KEY_MODIFIER_ALT ) i_accel_flags |= wxACCEL_ALT;
582 if( i_hotkey & KEY_MODIFIER_CTRL ) i_accel_flags |= wxACCEL_CTRL;
583 if( i_hotkey & KEY_MODIFIER_SHIFT ) i_accel_flags |= wxACCEL_SHIFT;
584 if( !i_accel_flags ) i_accel_flags = wxACCEL_NORMAL;
585 return i_accel_flags;
588 static int ConvertHotkey( int i_hotkey )
590 int i_key = i_hotkey & ~KEY_MODIFIER;
591 if( i_key & KEY_ASCII ) return i_key & KEY_ASCII;
592 else if( i_key & KEY_SPECIAL )
596 case KEY_LEFT: return WXK_LEFT;
597 case KEY_RIGHT: return WXK_RIGHT;
598 case KEY_UP: return WXK_UP;
599 case KEY_DOWN: return WXK_DOWN;
600 case KEY_SPACE: return WXK_SPACE;
601 case KEY_ENTER: return WXK_RETURN;
602 case KEY_F1: return WXK_F1;
603 case KEY_F2: return WXK_F2;
604 case KEY_F3: return WXK_F3;
605 case KEY_F4: return WXK_F4;
606 case KEY_F5: return WXK_F5;
607 case KEY_F6: return WXK_F6;
608 case KEY_F7: return WXK_F7;
609 case KEY_F8: return WXK_F8;
610 case KEY_F9: return WXK_F9;
611 case KEY_F10: return WXK_F10;
612 case KEY_F11: return WXK_F11;
613 case KEY_F12: return WXK_F12;
614 case KEY_HOME: return WXK_HOME;
615 case KEY_END: return WXK_END;
616 case KEY_INSERT: return WXK_INSERT;
617 case KEY_DELETE: return WXK_DELETE;
618 case KEY_MENU: return WXK_MENU;
619 case KEY_ESC: return WXK_ESCAPE;
620 case KEY_PAGEUP: return WXK_PRIOR;
621 case KEY_PAGEDOWN: return WXK_NEXT;
622 case KEY_TAB: return WXK_TAB;
623 case KEY_BACKSPACE: return WXK_BACK;
629 void Interface::SetupHotkeys()
631 struct vlc_t::hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
634 /* Count number of hoteys */
635 for( i_hotkeys = 0; p_hotkeys[i_hotkeys].psz_action != NULL; i_hotkeys++ );
637 p_intf->p_sys->i_first_hotkey_event = wxID_HIGHEST + 7000;
638 p_intf->p_sys->i_hotkeys = i_hotkeys;
640 wxAcceleratorEntry *p_entries = new wxAcceleratorEntry[i_hotkeys];
642 /* Setup the hotkeys as accelerators */
643 for( int i = 0; i < i_hotkeys; i++ )
645 int i_mod = ConvertHotkeyModifiers( p_hotkeys[i].i_key );
646 int i_key = ConvertHotkey( p_hotkeys[i].i_key );
649 if( !(p_hotkeys[i].i_key & KEY_SPECIAL) && i_mod )
650 i_key = toupper(i_key);
653 p_entries[i].Set( i_mod, i_key,
654 p_intf->p_sys->i_first_hotkey_event + i );
657 wxAcceleratorTable accel( i_hotkeys, p_entries );
661 msg_Err( p_intf, "invalid accelerator table" );
665 SetAcceleratorTable( accel );
671 void Interface::SetIntfMinSize()
673 wxSize ms = main_min_size;
675 if( extra_frame && extra_frame->IsShown() )
677 ms.SetHeight( ms.GetHeight() + ext_min_size.GetHeight() );
678 if( ext_min_size.GetWidth() > ms.GetWidth() )
679 ms.SetWidth( ext_min_size.GetWidth() );
682 if( playlist_manager && playlist_manager->IsShown() )
684 ms.SetHeight( ms.GetHeight() + playlist_min_size.GetHeight() );
685 if( playlist_min_size.GetWidth() > ms.GetWidth() )
686 ms.SetWidth( playlist_min_size.GetWidth() );
692 /*****************************************************************************
694 *****************************************************************************/
695 void Interface::OnMenuOpen( wxMenuEvent& event )
697 #if defined( __WXMSW__ )
698 # define GetEventObject GetMenu
701 if( event.GetEventObject() == p_settings_menu )
703 p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );
705 /* Add static items */
706 p_settings_menu->AppendCheckItem( Extended_Event,
707 wxU(_("Extended &GUI\tCtrl-G") ) );
708 if( b_extra ) p_settings_menu->Check( Extended_Event, TRUE );
709 p_settings_menu->Append( Bookmarks_Event,
710 wxU(_("&Bookmarks...\tCtrl-B") ) );
711 p_settings_menu->Append( Prefs_Event,
712 wxU(_("Preference&s...\tCtrl-S")) );
715 else if( event.GetEventObject() == p_audio_menu )
717 p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
720 else if( event.GetEventObject() == p_video_menu )
722 p_video_menu = VideoMenu( p_intf, this, p_video_menu );
725 else if( event.GetEventObject() == p_navig_menu )
727 p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
730 #if defined( __WXMSW__ )
731 # undef GetEventObject
735 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
736 void Interface::OnContextMenu2(wxContextMenuEvent& event)
738 /* Only show the context menu for the main interface */
739 if( GetId() != event.GetId() )
745 if( p_intf->p_sys->pf_show_dialog )
746 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
749 void Interface::OnContextMenu(wxMouseEvent& event)
751 if( p_intf->p_sys->pf_show_dialog )
752 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
755 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
757 /* TRUE is to force the frame to close. */
761 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
764 msg.Printf( wxString(wxT("VLC media player " PACKAGE_VERSION)) +
765 wxU(_(" (wxWidgets interface)\n\n")) +
766 wxU(_("(c) 1996-2005 - the VideoLAN Team\n\n")) +
767 wxU(_("Compiled by "))+ wxU(VLC_CompileBy())+ wxU("@") +
768 wxU(VLC_CompileHost())+ wxT(".")+ wxU(VLC_CompileDomain())+ wxT(".\n") +
769 wxU(_("Compiler: "))+ wxU(VLC_Compiler())+wxT( ".\n") +
770 wxU(_("Based on SVN revision: "))+wxU(VLC_Changeset())+wxT(".\n\n") +
772 wxU( vlc_wraptext(LICENSE_MSG,WRAPCOUNT,VLC_TRUE) ) + wxT("\n\n") +
774 wxU( LICENSE_MSG ) + wxT("\n\n") +
776 wxU(_("The VideoLAN team <videolan@videolan.org>\n"
777 "http://www.videolan.org/\n\n")) );
779 wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
780 wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
783 void Interface::OnShowDialog( wxCommandEvent& event )
785 if( p_intf->p_sys->pf_show_dialog )
789 switch( event.GetId() )
791 case OpenFileSimple_Event:
792 i_id = INTF_DIALOG_FILE_SIMPLE;
795 i_id = INTF_DIALOG_FILE;
798 i_id = INTF_DIALOG_FILE;
801 i_id = INTF_DIALOG_DIRECTORY;
804 i_id = INTF_DIALOG_DISC;
807 i_id = INTF_DIALOG_NET;
809 case OpenCapture_Event:
810 i_id = INTF_DIALOG_CAPTURE;
813 i_id = INTF_DIALOG_SAT;
816 i_id = INTF_DIALOG_PLAYLIST;
819 i_id = INTF_DIALOG_MESSAGES;
822 i_id = INTF_DIALOG_FILEINFO;
825 i_id = INTF_DIALOG_PREFS;
828 i_id = INTF_DIALOG_WIZARD;
830 case Bookmarks_Event:
831 i_id = INTF_DIALOG_BOOKMARKS;
833 case UpdateVLC_Event:
834 i_id = INTF_DIALOG_UPDATEVLC;
837 i_id = INTF_DIALOG_VLM;
840 i_id = INTF_DIALOG_FILE;
844 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
848 void Interface::OnExtended( wxCommandEvent& WXUNUSED(event) )
850 UpdateVideoWindow( p_intf, video_window );
854 /* Create the extra panel */
855 extra_frame = new ExtraPanel( p_intf, main_panel );
856 panel_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
857 ext_min_size = extra_frame->GetBestSize();
861 panel_sizer->Show( extra_frame, b_extra );
864 main_sizer->Layout();
865 main_sizer->Fit( this );
868 void Interface::OnSmallPlaylist( wxCommandEvent& WXUNUSED(event) )
870 UpdateVideoWindow( p_intf, video_window );
872 if( !playlist_manager )
874 /* Create the extra panel */
875 playlist_manager = new PlaylistManager( p_intf, splitter );
876 playlist_min_size = playlist_manager->GetBestSize();
879 b_playlist_manager = !b_playlist_manager;
881 if( b_playlist_manager )
882 splitter->SplitHorizontally( main_panel, playlist_manager,
883 -playlist_min_size.GetHeight() );
885 splitter->Unsplit( playlist_manager );
888 main_sizer->Layout();
889 main_sizer->Fit( this );
892 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
897 void Interface::PlayStream()
899 wxCommandEvent dummy;
900 playlist_t *p_playlist =
901 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
903 if( p_playlist == NULL ) return;
905 if( p_playlist->i_size && p_playlist->i_enabled )
909 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
912 if( p_input == NULL )
914 /* No stream was playing, start one */
915 playlist_Play( p_playlist );
916 vlc_object_release( p_playlist );
917 input_manager->Update();
921 var_Get( p_input, "state", &state );
922 if( state.i_int != PAUSE_S )
924 /* A stream is being played, pause it */
925 state.i_int = PAUSE_S;
929 /* Stream is paused, resume it */
930 state.i_int = PLAYING_S;
932 var_Set( p_input, "state", state );
934 vlc_object_release( p_input );
935 vlc_object_release( p_playlist );
936 input_manager->Update();
940 /* If the playlist is empty, open a file requester instead */
941 vlc_object_release( p_playlist );
942 OnShowDialog( dummy );
946 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
950 void Interface::StopStream()
952 playlist_t * p_playlist =
953 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
955 if( p_playlist == NULL )
960 playlist_Stop( p_playlist );
961 vlc_object_release( p_playlist );
962 input_manager->Update();
965 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
970 void Interface::PrevStream()
972 playlist_t * p_playlist =
973 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
975 if( p_playlist == NULL )
980 playlist_Prev( p_playlist );
981 vlc_object_release( p_playlist );
984 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
989 void Interface::NextStream()
991 playlist_t * p_playlist =
992 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
994 if( p_playlist == NULL )
998 playlist_Next( p_playlist );
999 vlc_object_release( p_playlist );
1002 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1004 input_thread_t *p_input =
1005 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1009 vlc_value_t val; val.b_bool = VLC_TRUE;
1011 var_Set( p_input, "rate-slower", val );
1012 vlc_object_release( p_input );
1016 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1018 input_thread_t *p_input =
1019 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1023 vlc_value_t val; val.b_bool = VLC_TRUE;
1025 var_Set( p_input, "rate-faster", val );
1026 vlc_object_release( p_input );
1030 void Interface::TogglePlayButton( int i_playing_status )
1032 wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
1033 GetToolBar()->GetToolClientData( PlayStream_Event );
1034 if( !p_tool ) return;
1036 if( i_playing_status == PLAYING_S )
1038 p_tool->SetNormalBitmap( wxBitmap( pause_xpm ) );
1039 p_tool->SetLabel( wxU(_("Pause")) );
1040 p_tool->SetShortHelp( wxU(_(HELP_PAUSE)) );
1044 p_tool->SetNormalBitmap( wxBitmap( play_xpm ) );
1045 p_tool->SetLabel( wxU(_("Play")) );
1046 p_tool->SetShortHelp( wxU(_(HELP_PLAY)) );
1049 GetToolBar()->Realize();
1051 #if defined( __WXMSW__ )
1052 /* Needed to work around a bug in wxToolBar::Realize() */
1053 GetToolBar()->SetSize( GetSize().GetWidth(),
1054 GetToolBar()->GetSize().GetHeight() );
1055 GetToolBar()->Update();
1058 GetToolBar()->ToggleTool( PlayStream_Event, true );
1059 GetToolBar()->ToggleTool( PlayStream_Event, false );
1062 #if wxUSE_DRAG_AND_DROP
1063 /*****************************************************************************
1064 * Definition of DragAndDrop class.
1065 *****************************************************************************/
1066 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
1069 b_enqueue = _b_enqueue;
1072 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1073 const wxArrayString& filenames )
1075 /* Add dropped files to the playlist */
1077 playlist_t *p_playlist =
1078 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1080 if( p_playlist == NULL )
1085 for( size_t i = 0; i < filenames.GetCount(); i++ )
1087 char *psz_utf8 = wxFromLocale( filenames[i] );
1089 playlist_Add( p_playlist, psz_utf8, psz_utf8,
1090 PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
1092 wxLocaleFree( psz_utf8 );
1095 vlc_object_release( p_playlist );
1101 /*****************************************************************************
1102 * Definition of VolCtrl class.
1103 *****************************************************************************/
1104 class wxVolCtrl: public wxGauge
1108 wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1109 wxPoint = wxDefaultPosition, wxSize = wxSize( 20, -1 ) );
1110 virtual ~wxVolCtrl() {};
1112 void UpdateVolume();
1115 void OnChange( wxMouseEvent& event );
1118 intf_thread_t *p_intf;
1120 DECLARE_EVENT_TABLE();
1123 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
1125 EVT_LEFT_DOWN(wxVolCtrl::OnChange)
1126 EVT_MOTION(wxVolCtrl::OnChange)
1129 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1130 wxPoint point, wxSize size )
1131 : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
1137 void wxVolCtrl::OnChange( wxMouseEvent& event )
1139 if( !event.LeftDown() && !event.LeftIsDown() ) return;
1141 int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
1142 aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1146 void wxVolCtrl::UpdateVolume()
1148 audio_volume_t i_volume;
1149 aout_VolumeGet( p_intf, &i_volume );
1151 int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
1152 if( i_gauge_volume == GetValue() ) return;
1154 SetValue( i_gauge_volume );
1155 SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
1156 i_gauge_volume / 2 ) );
1159 #if defined(__WXGTK__)
1160 #define VLCVOL_HEIGHT p_parent->GetSize().GetHeight()
1162 #define VLCVOL_HEIGHT TOOLBAR_BMP_HEIGHT
1164 VLCVolCtrl::VLCVolCtrl( intf_thread_t *_p_intf, wxWindow *p_parent )
1165 :wxControl( p_parent, -1, wxDefaultPosition, wxSize(64, VLCVOL_HEIGHT ),
1167 i_y_offset((VLCVOL_HEIGHT - TOOLBAR_BMP_HEIGHT) / 2),
1168 b_mute(0), p_intf(_p_intf)
1170 gauge = new wxVolCtrl( p_intf, this, -1, wxPoint( 18, i_y_offset ),
1171 wxSize( 44, TOOLBAR_BMP_HEIGHT ) );
1174 void VLCVolCtrl::OnPaint( wxPaintEvent &evt )
1176 wxPaintDC dc( this );
1177 wxBitmap mPlayBitmap( b_mute ? speaker_mute_xpm : speaker_xpm );
1178 dc.DrawBitmap( mPlayBitmap, 0, i_y_offset, TRUE );
1181 void VLCVolCtrl::OnChange( wxMouseEvent& event )
1183 if( event.GetX() < TOOLBAR_BMP_WIDTH )
1186 aout_VolumeMute( p_intf, (audio_volume_t *)&i_volume );
1193 void VLCVolCtrl::UpdateVolume()
1195 gauge->UpdateVolume();
1197 int i_volume = gauge->GetValue();
1198 if( !!i_volume == !b_mute ) return;
1203 /*****************************************************************************
1205 *****************************************************************************/
1207 #ifdef wxHAS_TASK_BAR_ICON
1209 BEGIN_EVENT_TABLE(Systray, wxTaskBarIcon)
1212 EVT_TASKBAR_LEFT_DCLICK(Systray::OnLeftClick)
1214 EVT_TASKBAR_LEFT_DOWN(Systray::OnLeftClick)
1217 EVT_MENU(Iconize_Event, Systray::OnMenuIconize)
1218 EVT_MENU(Exit_Event, Systray::OnExit)
1219 EVT_MENU(PlayStream_Event, Systray::OnPlayStream)
1220 EVT_MENU(NextStream_Event, Systray::OnNextStream)
1221 EVT_MENU(PrevStream_Event, Systray::OnPrevStream)
1222 EVT_MENU(StopStream_Event, Systray::OnStopStream)
1225 Systray::Systray( Interface *_p_main_interface, intf_thread_t *_p_intf )
1227 p_main_interface = _p_main_interface;
1230 SetIcon( wxIcon( vlc16x16_xpm ), wxT("VLC media player") );
1231 if( !IsOk() || !IsIconInstalled() )
1233 msg_Warn(p_intf, "cannot set systray icon, weird things may happen");
1237 /* Event handlers */
1238 void Systray::OnMenuIconize( wxCommandEvent& event )
1240 p_main_interface->Show( ! p_main_interface->IsShown() );
1241 if ( p_main_interface->IsShown() ) p_main_interface->Raise();
1244 void Systray::OnLeftClick( wxTaskBarIconEvent& event )
1246 wxCommandEvent cevent;
1247 OnMenuIconize(cevent);
1250 void Systray::OnExit( wxCommandEvent& event )
1252 p_main_interface->Close(TRUE);
1255 void Systray::OnPrevStream( wxCommandEvent& event )
1257 p_main_interface->PrevStream();
1260 void Systray::OnNextStream( wxCommandEvent& event )
1262 p_main_interface->NextStream();
1265 void Systray::OnPlayStream( wxCommandEvent& event )
1267 p_main_interface->PlayStream();
1270 void Systray::OnStopStream( wxCommandEvent& event )
1272 p_main_interface->StopStream();
1275 /* Systray popup menu */
1276 wxMenu* Systray::CreatePopupMenu()
1278 int minimal = config_GetInt( p_intf, "wx-minimal" );
1280 wxMenu* systray_menu = new wxMenu;
1281 systray_menu->Append( Exit_Event, wxU(_("Quit VLC")) );
1282 systray_menu->AppendSeparator();
1283 systray_menu->Append( PlayStream_Event, wxU(_("Play/Pause")) );
1287 systray_menu->Append( PrevStream_Event, wxU(_("Previous")) );
1288 systray_menu->Append( NextStream_Event, wxU(_("Next")) );
1289 systray_menu->Append( StopStream_Event, wxU(_("Stop")) );
1291 systray_menu->AppendSeparator();
1292 systray_menu->Append( Iconize_Event, wxU(_("Show/Hide interface")) );
1293 return systray_menu;
1296 void Systray::UpdateTooltip( const wxChar* tooltip )
1298 SetIcon( wxIcon( vlc16x16_xpm ), tooltip );