1 /*****************************************************************************
2 * interface.cpp : wxWidgets plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2005 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include "interface.hpp"
28 #include "playlist_manager.hpp"
29 #include "extrapanel.hpp"
39 #include <wx/splitter.h>
41 /* include the toolbar graphics */
42 #include "bitmaps/play.xpm"
43 #include "bitmaps/pause.xpm"
44 #include "bitmaps/stop.xpm"
45 #include "bitmaps/prev.xpm"
46 #include "bitmaps/next.xpm"
47 #include "bitmaps/eject.xpm"
48 #include "bitmaps/slow.xpm"
49 #include "bitmaps/fast.xpm"
50 #include "bitmaps/playlist.xpm"
51 #include "bitmaps/playlist_small.xpm"
52 #include "bitmaps/speaker.xpm"
53 #include "bitmaps/speaker_mute.xpm"
55 #define TOOLBAR_BMP_WIDTH 16
56 #define TOOLBAR_BMP_HEIGHT 16
58 /* include the icon graphic */
59 #include "../../../share/vlc32x32.xpm"
60 /* include a small icon graphic for the systray icon */
61 #ifdef wxHAS_TASK_BAR_ICON
62 #include "../../../share/vlc16x16.xpm"
65 /*****************************************************************************
66 * Local class declarations.
67 *****************************************************************************/
68 class wxMenuExt: public wxMenu
72 wxMenuExt( wxMenu* parentMenu, int id, const wxString& text,
73 const wxString& helpString, wxItemKind kind,
74 char *_psz_var, int _i_object_id, vlc_value_t _val,
77 virtual ~wxMenuExt() {};
89 class VLCVolCtrl : public wxControl
92 VLCVolCtrl( intf_thread_t *p_intf, wxWindow *p_parent );
93 virtual ~VLCVolCtrl() {};
95 virtual void OnPaint( wxPaintEvent &event );
96 void OnChange( wxMouseEvent& event );
100 DECLARE_EVENT_TABLE()
105 intf_thread_t *p_intf;
108 BEGIN_EVENT_TABLE(VLCVolCtrl, wxControl)
109 EVT_PAINT(VLCVolCtrl::OnPaint)
112 EVT_LEFT_UP(VLCVolCtrl::OnChange)
115 class Splitter : public wxSplitterWindow
118 Splitter( wxWindow *p_parent, intf_thread_t *_p_intf )
119 : wxSplitterWindow( p_parent, -1, wxDefaultPosition, wxSize(0,0),
120 wxCLIP_CHILDREN|wxSP_3DSASH ),
121 p_intf(_p_intf), i_sash_position(150) {}
122 virtual ~Splitter() {};
124 virtual bool Split( wxWindow* window1, wxWindow* window2 )
126 return wxSplitterWindow::SplitHorizontally( window1, window2,
131 DECLARE_EVENT_TABLE()
133 void OnSize( wxSizeEvent &event )
135 SetSashPosition( event.GetSize().GetHeight() - i_sash_position );
139 void OnSashPosChanged( wxSplitterEvent &event )
141 if( !GetSize().GetHeight() ){ event.Skip(); return; }
142 i_sash_position = GetSize().GetHeight() - event.GetSashPosition();
146 intf_thread_t *p_intf;
150 BEGIN_EVENT_TABLE(Splitter, wxSplitterWindow)
151 EVT_SIZE( Splitter::OnSize )
152 EVT_SPLITTER_SASH_POS_CHANGED(-1, Splitter::OnSashPosChanged)
155 /*****************************************************************************
157 *****************************************************************************/
159 DEFINE_LOCAL_EVENT_TYPE( wxEVT_INTF );
161 /* IDs for the controls and the menu commands */
165 MenuDummy_Event = wxID_HIGHEST + 1000,
166 Exit_Event = wxID_HIGHEST,
167 OpenFileSimple_Event,
197 /* it is important for the id corresponding to the "About" command to have
198 * this standard value as otherwise it won't be handled properly under Mac
199 * (where it is special and put into the "Apple" menu) */
200 About_Event = wxID_ABOUT,
207 BEGIN_EVENT_TABLE(Interface, wxFrame)
209 EVT_MENU(Exit_Event, Interface::OnExit)
210 EVT_MENU(About_Event, Interface::OnAbout)
211 EVT_MENU(UpdateVLC_Event, Interface::OnShowDialog)
212 EVT_MENU(VLM_Event, Interface::OnShowDialog)
214 EVT_MENU(Playlist_Event, Interface::OnShowDialog)
215 EVT_MENU(PlaylistSmall_Event, Interface::OnSmallPlaylist)
216 EVT_MENU(Logs_Event, Interface::OnShowDialog)
217 EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
218 EVT_MENU(Prefs_Event, Interface::OnShowDialog)
220 EVT_MENU_OPEN(Interface::OnMenuOpen)
222 EVT_MENU( Extended_Event, Interface::OnExtended )
224 EVT_MENU( Bookmarks_Event, Interface::OnShowDialog)
226 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
227 EVT_CONTEXT_MENU(Interface::OnContextMenu2)
229 EVT_RIGHT_UP(Interface::OnContextMenu)
232 EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
233 EVT_MENU(OpenAdv_Event, Interface::OnShowDialog)
234 EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
235 EVT_MENU(OpenDir_Event, Interface::OnShowDialog)
236 EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
237 EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
238 EVT_MENU(OpenCapture_Event, Interface::OnShowDialog)
239 EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
240 EVT_MENU(Wizard_Event, Interface::OnShowDialog)
241 EVT_MENU(StopStream_Event, Interface::OnStopStream)
242 EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
243 EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
244 EVT_MENU(NextStream_Event, Interface::OnNextStream)
245 EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
246 EVT_MENU(FastStream_Event, Interface::OnFastStream)
249 EVT_COMMAND(0, wxEVT_INTF, Interface::OnControlEvent)
250 EVT_COMMAND(1, wxEVT_INTF, Interface::OnControlEvent)
253 /*****************************************************************************
255 *****************************************************************************/
256 Interface::Interface( intf_thread_t *_p_intf, long style ):
257 wxFrame( NULL, -1, wxT("VLC media player"),
258 wxDefaultPosition, wxSize(700,100), style )
260 /* Initializations */
264 b_playlist_manager = VLC_FALSE;
265 playlist_manager = 0;
267 /* Give our interface a nice little icon */
268 SetIcon( wxIcon( vlc_xpm ) );
270 /* Create a splitter window that will fill in the interface window.
271 * We need a splitter bar in order to make the embedded playlist
273 splitter = new Splitter( this, p_intf );
274 main_sizer = new wxBoxSizer( wxVERTICAL );
275 main_sizer->Add( splitter, 1, wxEXPAND );
276 SetSizer( main_sizer );
278 /* Create a main panel that will fill in the interface window */
279 main_panel = new wxPanel( splitter, -1, wxPoint(0,0), wxSize(0,0),
281 main_panel->SetFocus();
283 #if defined(__WXGTK20__) && wxCHECK_VERSION(2,5,6)
284 /* As ugly as your butt! Please remove when wxWidgets 2.6 fixed their
285 * Accelerators bug. */
286 main_panel->m_imData = 0;
290 /* Create a sizer for the main frame */
291 panel_sizer = new wxBoxSizer( wxVERTICAL );
292 main_panel->SetSizer( panel_sizer );
294 /* Put this in the splitter */
295 splitter->Initialize( main_panel );
297 #ifdef wxHAS_TASK_BAR_ICON
298 /* Systray integration */
300 if( config_GetInt( p_intf, "wx-systray" ) )
302 p_systray = new Systray( this, p_intf );
306 /* Creation of the menu bar */
309 /* Creation of the tool bar */
312 /* Creation of the status bar
313 * Helptext for menu items and toolbar tools will automatically get
315 int i_status_width[3] = {100, 40, -1};
316 statusbar = CreateStatusBar( 3 ); /* 2 fields */
317 statusbar->SetStatusWidths( 3, i_status_width );
318 statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
320 /* Get minimum window size to prevent user from glitching it */
321 splitter->SetSizeHints( -1, 0 );
322 panel_sizer->Layout(); panel_sizer->Fit( main_panel );
323 main_sizer->Layout(); main_sizer->Fit( this );
324 main_min_size = GetSize();
325 splitter->SetSizeHints( -1, -1 );
329 if( config_GetInt( p_intf, "wx-embed" ) )
331 video_window = CreateVideoWindow( p_intf, main_panel );
332 panel_sizer->Add( p_intf->p_sys->p_video_sizer, 1, wxEXPAND, 0 );
335 /* Creation of the input manager panel */
336 input_manager = new InputManager( p_intf, this, main_panel );
337 panel_sizer->Add( input_manager, 0, wxEXPAND , 0 );
339 /* Layout everything */
340 splitter->SetSizeHints( -1, 0 );
341 panel_sizer->Layout(); panel_sizer->Fit( main_panel );
342 main_sizer->Layout(); main_sizer->Fit( this );
343 splitter->SetSizeHints( -1, -1 );
345 #if wxUSE_DRAG_AND_DROP
346 /* Associate drop targets with the main interface */
347 SetDropTarget( new DragAndDrop( p_intf ) );
353 timer = new Timer( p_intf, this );
355 /* Restore previous position / settings */
356 WindowSettings *ws = p_intf->p_sys->p_window_settings;
361 ws->SetScreen( wxSystemSettings::GetMetric( wxSYS_SCREEN_X ),
362 wxSystemSettings::GetMetric( wxSYS_SCREEN_Y ) );
364 if( ws->GetSettings( WindowSettings::ID_MAIN, b_shown, p, s ) ) Move( p );
366 /* Show extended GUI if requested */
367 wxCommandEvent dummy;
368 if( config_GetInt( p_intf, "wx-extended" ) ) OnExtended( dummy );
373 Interface::~Interface()
375 WindowSettings *ws = p_intf->p_sys->p_window_settings;
379 ws->SetSettings( WindowSettings::ID_MAIN, true,
380 GetPosition(), GetSize() );
383 PopEventHandler(true);
385 if( video_window ) delete video_window;
387 #ifdef wxHAS_TASK_BAR_ICON
388 if( p_systray ) delete p_systray;
391 if( p_intf->p_sys->p_wxwindow ) delete p_intf->p_sys->p_wxwindow;
397 void Interface::Init()
403 void Interface::Update()
406 ((VLCVolCtrl *)volctrl)->UpdateVolume();
408 if( playlist_manager ) playlist_manager->Update();
411 void Interface::OnControlEvent( wxCommandEvent& event )
413 switch( event.GetId() )
416 main_sizer->Layout();
417 main_sizer->Fit( this );
421 long i_style = GetWindowStyle();
422 if( event.GetInt() ) i_style |= wxSTAY_ON_TOP;
423 else i_style &= ~wxSTAY_ON_TOP;
424 SetWindowStyle( i_style );
429 /*****************************************************************************
431 *****************************************************************************/
432 void Interface::CreateOurMenuBar()
434 int minimal = config_GetInt( p_intf, "wx-minimal" );
436 /* Create the "File" menu */
437 wxMenu *file_menu = new wxMenu;
441 file_menu->Append( OpenFileSimple_Event,
442 wxU(_("Quick &Open File...\tCtrl-O")) );
444 file_menu->AppendSeparator();
445 file_menu->Append( OpenFile_Event, wxU(_("Open &File...\tCtrl-F")) );
446 file_menu->Append( OpenDir_Event, wxU(_("Open Dir&ectory...\tCtrl-E")) );
447 file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...\tCtrl-D")) );
448 file_menu->Append( OpenNet_Event,
449 wxU(_("Open &Network Stream...\tCtrl-N")) );
450 file_menu->Append( OpenCapture_Event,
451 wxU(_("Open C&apture Device...\tCtrl-A")) );
453 file_menu->AppendSeparator();
454 file_menu->Append( Wizard_Event, wxU(_("&Wizard...\tCtrl-W")) );
455 file_menu->AppendSeparator();
457 file_menu->Append( Exit_Event, wxU(_("E&xit\tCtrl-X")) );
459 /* Create the "View" menu */
460 wxMenu *view_menu = new wxMenu;
463 view_menu->Append( Playlist_Event, wxU(_("&Playlist...\tCtrl-P")) );
465 view_menu->Append( Logs_Event, wxU(_("&Messages...\tCtrl-M")) );
466 view_menu->Append( FileInfo_Event,
467 wxU(_("Stream and Media &info...\tCtrl-I")) );
468 view_menu->Append( VLM_Event,
469 wxU(_("VLM Control...\tCtrl-V")) );
471 /* Create the "Auto-generated" menus */
472 p_settings_menu = SettingsMenu( p_intf, this );
473 p_audio_menu = AudioMenu( p_intf, this );
474 p_video_menu = VideoMenu( p_intf, this );
475 p_navig_menu = NavigMenu( p_intf, this );
477 /* Create the "Help" menu */
478 wxMenu *help_menu = new wxMenu;
479 help_menu->Append( About_Event, wxU(_("About VLC media player")) );
480 help_menu->AppendSeparator();
481 help_menu->Append( UpdateVLC_Event, wxU(_("Check for updates ...")) );
483 /* Append the freshly created menus to the menu bar... */
484 wxMenuBar *menubar = new wxMenuBar();
485 menubar->Append( file_menu, wxU(_("&File")) );
486 menubar->Append( view_menu, wxU(_("&View")) );
487 menubar->Append( p_settings_menu, wxU(_("&Settings")) );
488 menubar->Append( p_audio_menu, wxU(_("&Audio")) );
489 menubar->Append( p_video_menu, wxU(_("&Video")) );
490 menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
491 menubar->Append( help_menu, wxU(_("&Help")) );
493 /* Attach the menu bar to the frame */
494 SetMenuBar( menubar );
496 /* Find out size of menu bar */
498 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
500 int i_width, i_height;
501 menubar->GetTextExtent( menubar->GetLabelTop(i), &i_width, &i_height );
503 #if defined(__WXGTK__)
504 22 /* approximate margin */;
506 #if (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 5) && (wxRELEASE_NUMBER < 3)
507 4 /* approximate margin */;
509 18 /* approximate margin */;
514 /* Patch by zcot for menu wrapping */
516 /* Find out size of msw menu bar */
519 HDC hdc = GetDC( NULL );
520 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
522 GetTextExtentPoint32( hdc, menubar->GetLabelTop(i).c_str(),
523 menubar->GetLabelTop(i).Length(), &sizing );
525 // [ SM_CXDLGFRAME + pixels + textextent + pixels + SM_CXDLGFRAME ]
526 i_size += sizing.cx + 2 + GetSystemMetrics( SM_CXDLGFRAME ) * 2;
528 ReleaseDC( NULL, hdc );
529 i_size += GetSystemMetrics( SM_CXSIZEFRAME ) * 2 + 4;
531 /* End patch by zcot */
533 panel_sizer->SetMinSize( i_size, -1 );
535 /* Intercept all menu events in our custom event handler */
536 PushEventHandler( new MenuEvtHandler( p_intf, this ) );
538 #if wxUSE_DRAG_AND_DROP
539 /* Associate drop targets with the menubar */
540 menubar->SetDropTarget( new DragAndDrop( p_intf ) );
544 void Interface::CreateOurToolBar()
546 #define HELP_OPEN N_("Open")
547 #define HELP_STOP N_("Stop")
548 #define HELP_PLAY N_("Play")
549 #define HELP_PAUSE N_("Pause")
550 #define HELP_PLO N_("Playlist")
551 #define HELP_SPLO N_("Small playlist")
552 #define HELP_PLP N_("Previous playlist item")
553 #define HELP_PLN N_("Next playlist item")
554 #define HELP_SLOW N_("Play slower")
555 #define HELP_FAST N_("Play faster")
557 int minimal = config_GetInt( p_intf, "wx-minimal" );
559 wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
560 * version because we don't include wx.rc */
563 CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
565 toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
569 toolbar->AddTool( OpenFile_Event, wxT(""),
570 wxBitmap( eject_xpm ), wxU(_(HELP_OPEN)) );
571 toolbar->AddSeparator();
574 wxToolBarToolBase *p_tool = toolbar->AddTool( PlayStream_Event, wxT(""),
575 wxBitmap( play_xpm ), wxU(_(HELP_PLAY)), wxITEM_CHECK );
576 p_tool->SetClientData( p_tool );
580 toolbar->AddTool( StopStream_Event, wxT(""), wxBitmap( stop_xpm ),
582 toolbar->AddSeparator();
584 toolbar->AddTool( PrevStream_Event, wxT(""),
585 wxBitmap( prev_xpm ), wxU(_(HELP_PLP)) );
586 toolbar->AddTool( SlowStream_Event, wxT(""),
587 wxBitmap( slow_xpm ), wxU(_(HELP_SLOW)) );
588 toolbar->AddTool( FastStream_Event, wxT(""),
589 wxBitmap( fast_xpm ), wxU(_(HELP_FAST)) );
590 toolbar->AddTool( NextStream_Event, wxT(""), wxBitmap( next_xpm ),
592 toolbar->AddSeparator();
593 toolbar->AddTool( Playlist_Event, wxT(""), wxBitmap( playlist_xpm ),
595 toolbar->AddTool( PlaylistSmall_Event, wxT(""),
596 wxBitmap( playlist_small_xpm ), wxU(_(HELP_SPLO)) );
599 wxControl *p_dummy_ctrl =
600 new wxControl( toolbar, -1, wxDefaultPosition,
601 wxSize(16, 16 ), wxBORDER_NONE );
603 toolbar->AddControl( p_dummy_ctrl );
605 volctrl = new VLCVolCtrl( p_intf, toolbar );
606 toolbar->AddControl( volctrl );
610 #if wxUSE_DRAG_AND_DROP
611 /* Associate drop targets with the toolbar */
612 toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
616 static int ConvertHotkeyModifiers( int i_hotkey )
618 int i_accel_flags = 0;
619 if( i_hotkey & KEY_MODIFIER_ALT ) i_accel_flags |= wxACCEL_ALT;
620 if( i_hotkey & KEY_MODIFIER_CTRL ) i_accel_flags |= wxACCEL_CTRL;
621 if( i_hotkey & KEY_MODIFIER_SHIFT ) i_accel_flags |= wxACCEL_SHIFT;
622 if( !i_accel_flags ) i_accel_flags = wxACCEL_NORMAL;
623 return i_accel_flags;
626 static int ConvertHotkey( int i_hotkey )
628 int i_key = i_hotkey & ~KEY_MODIFIER;
629 if( i_key & KEY_ASCII ) return i_key & KEY_ASCII;
630 else if( i_key & KEY_SPECIAL )
634 case KEY_LEFT: return WXK_LEFT;
635 case KEY_RIGHT: return WXK_RIGHT;
636 case KEY_UP: return WXK_UP;
637 case KEY_DOWN: return WXK_DOWN;
638 case KEY_SPACE: return WXK_SPACE;
639 case KEY_ENTER: return WXK_RETURN;
640 case KEY_F1: return WXK_F1;
641 case KEY_F2: return WXK_F2;
642 case KEY_F3: return WXK_F3;
643 case KEY_F4: return WXK_F4;
644 case KEY_F5: return WXK_F5;
645 case KEY_F6: return WXK_F6;
646 case KEY_F7: return WXK_F7;
647 case KEY_F8: return WXK_F8;
648 case KEY_F9: return WXK_F9;
649 case KEY_F10: return WXK_F10;
650 case KEY_F11: return WXK_F11;
651 case KEY_F12: return WXK_F12;
652 case KEY_HOME: return WXK_HOME;
653 case KEY_END: return WXK_END;
654 case KEY_INSERT: return WXK_INSERT;
655 case KEY_DELETE: return WXK_DELETE;
656 case KEY_MENU: return WXK_MENU;
657 case KEY_ESC: return WXK_ESCAPE;
658 case KEY_PAGEUP: return WXK_PRIOR;
659 case KEY_PAGEDOWN: return WXK_NEXT;
660 case KEY_TAB: return WXK_TAB;
661 case KEY_BACKSPACE: return WXK_BACK;
667 void Interface::SetupHotkeys()
669 struct vlc_t::hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
672 /* Count number of hoteys */
673 for( i_hotkeys = 0; p_hotkeys[i_hotkeys].psz_action != NULL; i_hotkeys++ );
675 p_intf->p_sys->i_first_hotkey_event = wxID_HIGHEST + 7000;
676 p_intf->p_sys->i_hotkeys = i_hotkeys;
678 wxAcceleratorEntry *p_entries = new wxAcceleratorEntry[i_hotkeys];
680 /* Setup the hotkeys as accelerators */
681 for( int i = 0; i < i_hotkeys; i++ )
683 int i_mod = ConvertHotkeyModifiers( p_hotkeys[i].i_key );
684 int i_key = ConvertHotkey( p_hotkeys[i].i_key );
687 if( !(p_hotkeys[i].i_key & KEY_SPECIAL) && i_mod )
688 i_key = toupper(i_key);
691 p_entries[i].Set( i_mod, i_key,
692 p_intf->p_sys->i_first_hotkey_event + i );
695 wxAcceleratorTable accel( i_hotkeys, p_entries );
699 msg_Err( p_intf, "invalid accelerator table" );
703 SetAcceleratorTable( accel );
709 void Interface::SetIntfMinSize()
711 wxSize ms = main_min_size;
713 if( extra_frame && extra_frame->IsShown() )
715 ms.SetHeight( ms.GetHeight() + ext_min_size.GetHeight() );
716 if( ext_min_size.GetWidth() > ms.GetWidth() )
717 ms.SetWidth( ext_min_size.GetWidth() );
720 if( playlist_manager && playlist_manager->IsShown() )
722 ms.SetHeight( ms.GetHeight() + playlist_min_size.GetHeight() );
723 if( playlist_min_size.GetWidth() > ms.GetWidth() )
724 ms.SetWidth( playlist_min_size.GetWidth() );
727 SetSizeHints( ms.GetWidth(), ms.GetHeight() );
730 /*****************************************************************************
732 *****************************************************************************/
733 void Interface::OnMenuOpen( wxMenuEvent& event )
735 #if defined( __WXMSW__ )
736 # define GetEventObject GetMenu
739 if( event.GetEventObject() == p_settings_menu )
741 p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );
743 /* Add static items */
744 p_settings_menu->AppendCheckItem( Extended_Event,
745 wxU(_("Extended &GUI\tCtrl-G") ) );
746 if( b_extra ) p_settings_menu->Check( Extended_Event, TRUE );
747 p_settings_menu->Append( Bookmarks_Event,
748 wxU(_("&Bookmarks...\tCtrl-B") ) );
749 p_settings_menu->Append( Prefs_Event,
750 wxU(_("Preference&s...\tCtrl-S")) );
753 else if( event.GetEventObject() == p_audio_menu )
755 p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
758 else if( event.GetEventObject() == p_video_menu )
760 p_video_menu = VideoMenu( p_intf, this, p_video_menu );
763 else if( event.GetEventObject() == p_navig_menu )
765 p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
768 #if defined( __WXMSW__ )
769 # undef GetEventObject
773 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
774 void Interface::OnContextMenu2(wxContextMenuEvent& event)
776 /* Only show the context menu for the main interface */
777 if( GetId() != event.GetId() )
783 if( p_intf->p_sys->pf_show_dialog )
784 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
787 void Interface::OnContextMenu(wxMouseEvent& event)
789 if( p_intf->p_sys->pf_show_dialog )
790 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
793 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
795 /* TRUE is to force the frame to close. */
799 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
802 msg.Printf( wxString(wxT("VLC media player " PACKAGE_VERSION)) +
803 wxU(_(" (wxWidgets interface)\n\n")) +
804 wxU(_("(c) 1996-2005 - the VideoLAN Team\n\n")) +
805 wxU(_("Compiled by "))+ wxU(VLC_CompileBy())+ wxU("@") +
806 wxU(VLC_CompileHost())+ wxT(".")+ wxU(VLC_CompileDomain())+ wxT(".\n") +
807 wxU(_("Compiler: "))+ wxU(VLC_Compiler())+wxT( ".\n") +
808 wxU(_("Based on SVN revision: "))+wxU(VLC_Changeset())+wxT(".\n\n") +
810 wxU( vlc_wraptext(LICENSE_MSG,WRAPCOUNT,VLC_TRUE) ) + wxT("\n\n") +
812 wxU( LICENSE_MSG ) + wxT("\n\n") +
814 wxU(_("The VideoLAN team <videolan@videolan.org>\n"
815 "http://www.videolan.org/\n\n")) );
817 wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
818 wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
821 void Interface::OnShowDialog( wxCommandEvent& event )
823 if( p_intf->p_sys->pf_show_dialog )
827 switch( event.GetId() )
829 case OpenFileSimple_Event:
830 i_id = INTF_DIALOG_FILE_SIMPLE;
833 i_id = INTF_DIALOG_FILE;
836 i_id = INTF_DIALOG_FILE;
839 i_id = INTF_DIALOG_DIRECTORY;
842 i_id = INTF_DIALOG_DISC;
845 i_id = INTF_DIALOG_NET;
847 case OpenCapture_Event:
848 i_id = INTF_DIALOG_CAPTURE;
851 i_id = INTF_DIALOG_SAT;
854 i_id = INTF_DIALOG_PLAYLIST;
857 i_id = INTF_DIALOG_MESSAGES;
860 i_id = INTF_DIALOG_FILEINFO;
863 i_id = INTF_DIALOG_PREFS;
866 i_id = INTF_DIALOG_WIZARD;
868 case Bookmarks_Event:
869 i_id = INTF_DIALOG_BOOKMARKS;
871 case UpdateVLC_Event:
872 i_id = INTF_DIALOG_UPDATEVLC;
875 i_id = INTF_DIALOG_VLM;
878 i_id = INTF_DIALOG_FILE;
882 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
886 void Interface::OnExtended( wxCommandEvent& WXUNUSED(event) )
888 UpdateVideoWindow( p_intf, video_window );
892 /* Create the extra panel */
893 extra_frame = new ExtraPanel( p_intf, main_panel );
894 panel_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
895 ext_min_size = extra_frame->GetBestSize();
899 panel_sizer->Show( extra_frame, b_extra );
902 main_sizer->Layout();
903 main_sizer->Fit( this );
906 void Interface::OnSmallPlaylist( wxCommandEvent& WXUNUSED(event) )
908 UpdateVideoWindow( p_intf, video_window );
910 if( !playlist_manager )
912 /* Create the extra panel */
913 playlist_manager = new PlaylistManager( p_intf, splitter );
914 playlist_min_size = playlist_manager->GetBestSize();
917 b_playlist_manager = !b_playlist_manager;
919 if( b_playlist_manager ) splitter->Split( main_panel, playlist_manager );
920 else splitter->Unsplit( playlist_manager );
923 main_sizer->Layout();
924 main_sizer->Fit( this );
927 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
932 void Interface::PlayStream()
934 wxCommandEvent dummy;
935 playlist_t *p_playlist =
936 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
938 if( p_playlist == NULL ) return;
940 if( p_playlist->i_size && p_playlist->i_enabled )
944 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
947 if( p_input == NULL )
949 /* No stream was playing, start one */
950 playlist_Play( p_playlist );
951 vlc_object_release( p_playlist );
952 input_manager->Update();
956 var_Get( p_input, "state", &state );
957 if( state.i_int != PAUSE_S )
959 /* A stream is being played, pause it */
960 state.i_int = PAUSE_S;
964 /* Stream is paused, resume it */
965 state.i_int = PLAYING_S;
967 var_Set( p_input, "state", state );
969 vlc_object_release( p_input );
970 vlc_object_release( p_playlist );
971 input_manager->Update();
975 /* If the playlist is empty, open a file requester instead */
976 vlc_object_release( p_playlist );
977 OnShowDialog( dummy );
981 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
985 void Interface::StopStream()
987 playlist_t * p_playlist =
988 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
990 if( p_playlist == NULL )
995 playlist_Stop( p_playlist );
996 vlc_object_release( p_playlist );
997 input_manager->Update();
1000 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
1005 void Interface::PrevStream()
1007 playlist_t * p_playlist =
1008 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1010 if( p_playlist == NULL )
1015 playlist_Prev( p_playlist );
1016 vlc_object_release( p_playlist );
1019 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1024 void Interface::NextStream()
1026 playlist_t * p_playlist =
1027 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1029 if( p_playlist == NULL )
1033 playlist_Next( p_playlist );
1034 vlc_object_release( p_playlist );
1037 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1039 input_thread_t *p_input =
1040 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1044 vlc_value_t val; val.b_bool = VLC_TRUE;
1046 var_Set( p_input, "rate-slower", val );
1047 vlc_object_release( p_input );
1051 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1053 input_thread_t *p_input =
1054 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1058 vlc_value_t val; val.b_bool = VLC_TRUE;
1060 var_Set( p_input, "rate-faster", val );
1061 vlc_object_release( p_input );
1065 void Interface::TogglePlayButton( int i_playing_status )
1067 wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
1068 GetToolBar()->GetToolClientData( PlayStream_Event );
1069 if( !p_tool ) return;
1071 if( i_playing_status == PLAYING_S )
1073 p_tool->SetNormalBitmap( wxBitmap( pause_xpm ) );
1074 p_tool->SetLabel( wxU(_("Pause")) );
1075 p_tool->SetShortHelp( wxU(_(HELP_PAUSE)) );
1079 p_tool->SetNormalBitmap( wxBitmap( play_xpm ) );
1080 p_tool->SetLabel( wxU(_("Play")) );
1081 p_tool->SetShortHelp( wxU(_(HELP_PLAY)) );
1084 GetToolBar()->Realize();
1086 #if defined( __WXMSW__ )
1087 /* Needed to work around a bug in wxToolBar::Realize() */
1088 GetToolBar()->SetSize( GetSize().GetWidth(),
1089 GetToolBar()->GetSize().GetHeight() );
1090 GetToolBar()->Update();
1093 GetToolBar()->ToggleTool( PlayStream_Event, true );
1094 GetToolBar()->ToggleTool( PlayStream_Event, false );
1097 #if wxUSE_DRAG_AND_DROP
1098 /*****************************************************************************
1099 * Definition of DragAndDrop class.
1100 *****************************************************************************/
1101 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
1104 b_enqueue = _b_enqueue;
1107 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1108 const wxArrayString& filenames )
1110 /* Add dropped files to the playlist */
1112 playlist_t *p_playlist =
1113 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1115 if( p_playlist == NULL )
1120 for( size_t i = 0; i < filenames.GetCount(); i++ )
1122 char *psz_utf8 = wxFromLocale( filenames[i] );
1124 playlist_Add( p_playlist, psz_utf8, psz_utf8,
1125 PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
1127 wxLocaleFree( psz_utf8 );
1130 vlc_object_release( p_playlist );
1136 /*****************************************************************************
1137 * Definition of VolCtrl class.
1138 *****************************************************************************/
1139 class wxVolCtrl: public wxGauge
1143 wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1144 wxPoint = wxDefaultPosition, wxSize = wxSize( 20, -1 ) );
1145 virtual ~wxVolCtrl() {};
1147 void UpdateVolume();
1150 void OnChange( wxMouseEvent& event );
1153 intf_thread_t *p_intf;
1155 DECLARE_EVENT_TABLE();
1158 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
1160 EVT_LEFT_DOWN(wxVolCtrl::OnChange)
1161 EVT_MOTION(wxVolCtrl::OnChange)
1164 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1165 wxPoint point, wxSize size )
1166 : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
1172 void wxVolCtrl::OnChange( wxMouseEvent& event )
1174 if( !event.LeftDown() && !event.LeftIsDown() ) return;
1176 int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
1177 aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1181 void wxVolCtrl::UpdateVolume()
1183 audio_volume_t i_volume;
1184 aout_VolumeGet( p_intf, &i_volume );
1186 int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
1187 if( i_gauge_volume == GetValue() ) return;
1189 SetValue( i_gauge_volume );
1190 SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
1191 i_gauge_volume / 2 ) );
1194 #if defined(__WXGTK__)
1195 #define VLCVOL_HEIGHT p_parent->GetSize().GetHeight()
1197 #define VLCVOL_HEIGHT TOOLBAR_BMP_HEIGHT
1199 VLCVolCtrl::VLCVolCtrl( intf_thread_t *_p_intf, wxWindow *p_parent )
1200 :wxControl( p_parent, -1, wxDefaultPosition, wxSize(64, VLCVOL_HEIGHT ),
1202 i_y_offset((VLCVOL_HEIGHT - TOOLBAR_BMP_HEIGHT) / 2),
1203 b_mute(0), p_intf(_p_intf)
1205 gauge = new wxVolCtrl( p_intf, this, -1, wxPoint( 18, i_y_offset ),
1206 wxSize( 44, TOOLBAR_BMP_HEIGHT ) );
1209 void VLCVolCtrl::OnPaint( wxPaintEvent &evt )
1211 wxPaintDC dc( this );
1212 wxBitmap mPlayBitmap( b_mute ? speaker_mute_xpm : speaker_xpm );
1213 dc.DrawBitmap( mPlayBitmap, 0, i_y_offset, TRUE );
1216 void VLCVolCtrl::OnChange( wxMouseEvent& event )
1218 if( event.GetX() < TOOLBAR_BMP_WIDTH )
1221 aout_VolumeMute( p_intf, (audio_volume_t *)&i_volume );
1228 void VLCVolCtrl::UpdateVolume()
1230 gauge->UpdateVolume();
1232 int i_volume = gauge->GetValue();
1233 if( !!i_volume == !b_mute ) return;
1238 /*****************************************************************************
1240 *****************************************************************************/
1242 #ifdef wxHAS_TASK_BAR_ICON
1244 BEGIN_EVENT_TABLE(Systray, wxTaskBarIcon)
1247 EVT_TASKBAR_LEFT_DCLICK(Systray::OnLeftClick)
1249 EVT_TASKBAR_LEFT_DOWN(Systray::OnLeftClick)
1252 EVT_MENU(Iconize_Event, Systray::OnMenuIconize)
1253 EVT_MENU(Exit_Event, Systray::OnExit)
1254 EVT_MENU(PlayStream_Event, Systray::OnPlayStream)
1255 EVT_MENU(NextStream_Event, Systray::OnNextStream)
1256 EVT_MENU(PrevStream_Event, Systray::OnPrevStream)
1257 EVT_MENU(StopStream_Event, Systray::OnStopStream)
1260 Systray::Systray( Interface *_p_main_interface, intf_thread_t *_p_intf )
1262 p_main_interface = _p_main_interface;
1265 SetIcon( wxIcon( vlc16x16_xpm ), wxT("VLC media player") );
1266 if( !IsOk() || !IsIconInstalled() )
1268 msg_Warn(p_intf, "cannot set systray icon, weird things may happen");
1272 /* Event handlers */
1273 void Systray::OnMenuIconize( wxCommandEvent& event )
1275 p_main_interface->Show( ! p_main_interface->IsShown() );
1276 if ( p_main_interface->IsShown() ) p_main_interface->Raise();
1279 void Systray::OnLeftClick( wxTaskBarIconEvent& event )
1281 wxCommandEvent cevent;
1282 OnMenuIconize(cevent);
1285 void Systray::OnExit( wxCommandEvent& event )
1287 p_main_interface->Close(TRUE);
1290 void Systray::OnPrevStream( wxCommandEvent& event )
1292 p_main_interface->PrevStream();
1295 void Systray::OnNextStream( wxCommandEvent& event )
1297 p_main_interface->NextStream();
1300 void Systray::OnPlayStream( wxCommandEvent& event )
1302 p_main_interface->PlayStream();
1305 void Systray::OnStopStream( wxCommandEvent& event )
1307 p_main_interface->StopStream();
1310 /* Systray popup menu */
1311 wxMenu* Systray::CreatePopupMenu()
1313 int minimal = config_GetInt( p_intf, "wx-minimal" );
1315 wxMenu* systray_menu = new wxMenu;
1316 systray_menu->Append( Exit_Event, wxU(_("Quit VLC")) );
1317 systray_menu->AppendSeparator();
1318 systray_menu->Append( PlayStream_Event, wxU(_("Play/Pause")) );
1322 systray_menu->Append( PrevStream_Event, wxU(_("Previous")) );
1323 systray_menu->Append( NextStream_Event, wxU(_("Next")) );
1324 systray_menu->Append( StopStream_Event, wxU(_("Stop")) );
1326 systray_menu->AppendSeparator();
1327 systray_menu->Append( Iconize_Event, wxU(_("Show/Hide interface")) );
1328 return systray_menu;
1331 void Systray::UpdateTooltip( const wxChar* tooltip )
1333 SetIcon( wxIcon( vlc16x16_xpm ), tooltip );