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 #if defined( __WXMSW__ )
123 wxCLIP_CHILDREN | wxSP_3DSASH ),
125 p_intf(_p_intf), i_sash_position(150), i_width(-1)
130 virtual ~Splitter() {};
132 virtual bool Split( wxWindow* window1, wxWindow* window2 )
135 wxSize size = wxSize( i_width, i_sash_position );
136 if( window2->GetSizer() ) window2->GetSizer()->SetMinSize( size );
138 return wxSplitterWindow::SplitHorizontally( window1, window2,
142 virtual bool Unsplit( wxWindow* window )
145 return wxSplitterWindow::Unsplit( window );
149 DECLARE_EVENT_TABLE()
151 void OnSize( wxSizeEvent &event )
153 /* If we display video, then resize the video window */
155 p_intf->p_sys->p_video_window && p_intf->p_sys->p_video_sizer &&
156 p_intf->p_sys->p_video_sizer->GetMinSize() != wxSize(0,0) )
160 #if defined( __WXMSW__ )
161 SetSashPosition( event.GetSize().GetHeight() - i_sash_position );
163 SetSashPosition( event.GetSize().GetHeight() -
164 i_sash_position - GetSashSize() );
167 else if( GetWindow2() && GetWindow1() && GetWindow1()->GetSizer() )
169 wxSize size = GetWindow1()->GetSizer()->GetMinSize();
171 if( event.GetSize().GetHeight() - size.GetHeight() )
175 SetSashPosition( size.GetHeight() ? size.GetHeight() : 1 );
176 i_sash_position = event.GetSize().GetHeight() -
178 i_width = event.GetSize().GetWidth();
180 size = wxSize( i_width, i_sash_position );
181 if( GetWindow2()->GetSizer() )
182 GetWindow2()->GetSizer()->SetMinSize( size );
189 void OnSashPosChanged( wxSplitterEvent &event )
191 if( !GetSize().GetHeight() ){ event.Skip(); return; }
192 i_sash_position = GetSize().GetHeight() - event.GetSashPosition();
196 intf_thread_t *p_intf;
201 BEGIN_EVENT_TABLE(Splitter, wxSplitterWindow)
202 EVT_SIZE( Splitter::OnSize )
203 EVT_SPLITTER_SASH_POS_CHANGED(-1, Splitter::OnSashPosChanged)
206 /*****************************************************************************
208 *****************************************************************************/
210 DEFINE_LOCAL_EVENT_TYPE( wxEVT_INTF );
212 /* IDs for the controls and the menu commands */
216 MenuDummy_Event = wxID_HIGHEST + 1000,
217 Exit_Event = wxID_HIGHEST,
218 OpenFileSimple_Event,
248 /* it is important for the id corresponding to the "About" command to have
249 * this standard value as otherwise it won't be handled properly under Mac
250 * (where it is special and put into the "Apple" menu) */
251 About_Event = wxID_ABOUT,
258 BEGIN_EVENT_TABLE(Interface, wxFrame)
260 EVT_MENU(Exit_Event, Interface::OnExit)
261 EVT_MENU(About_Event, Interface::OnAbout)
262 EVT_MENU(UpdateVLC_Event, Interface::OnShowDialog)
263 EVT_MENU(VLM_Event, Interface::OnShowDialog)
265 EVT_MENU(Playlist_Event, Interface::OnShowDialog)
266 EVT_MENU(PlaylistSmall_Event, Interface::OnSmallPlaylist)
267 EVT_MENU(Logs_Event, Interface::OnShowDialog)
268 EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
269 EVT_MENU(Prefs_Event, Interface::OnShowDialog)
271 EVT_MENU_OPEN(Interface::OnMenuOpen)
273 EVT_MENU( Extended_Event, Interface::OnExtended )
275 EVT_MENU( Bookmarks_Event, Interface::OnShowDialog)
277 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
278 EVT_CONTEXT_MENU(Interface::OnContextMenu2)
280 EVT_RIGHT_UP(Interface::OnContextMenu)
283 EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
284 EVT_MENU(OpenAdv_Event, Interface::OnShowDialog)
285 EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
286 EVT_MENU(OpenDir_Event, Interface::OnShowDialog)
287 EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
288 EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
289 EVT_MENU(OpenCapture_Event, Interface::OnShowDialog)
290 EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
291 EVT_MENU(Wizard_Event, Interface::OnShowDialog)
292 EVT_MENU(StopStream_Event, Interface::OnStopStream)
293 EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
294 EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
295 EVT_MENU(NextStream_Event, Interface::OnNextStream)
296 EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
297 EVT_MENU(FastStream_Event, Interface::OnFastStream)
300 EVT_COMMAND(0, wxEVT_INTF, Interface::OnControlEvent)
301 EVT_COMMAND(1, wxEVT_INTF, Interface::OnControlEvent)
304 /*****************************************************************************
306 *****************************************************************************/
307 Interface::Interface( intf_thread_t *_p_intf, long style ):
308 wxFrame( NULL, -1, wxT("VLC media player"),
309 wxDefaultPosition, wxSize(700,100), style )
311 /* Initializations */
315 playlist_manager = 0;
317 /* Give our interface a nice little icon */
318 SetIcon( wxIcon( vlc_xpm ) );
320 /* Create a splitter window that will fill in the interface window.
321 * We need a splitter bar in order to make the embedded playlist
323 splitter = new Splitter( this, p_intf );
324 main_sizer = new wxBoxSizer( wxVERTICAL );
325 main_sizer->Add( splitter, 1, wxEXPAND );
326 SetSizer( main_sizer );
328 /* Create a main panel that will fill in the interface window */
329 main_panel = new wxPanel( splitter, -1, wxPoint(0,0), wxSize(0,0),
331 main_panel->SetFocus();
333 #if defined(__WXGTK20__) && wxCHECK_VERSION(2,5,6)
334 /* As ugly as your butt! Please remove when wxWidgets 2.6 fixed their
335 * Accelerators bug. */
336 main_panel->m_imData = 0;
340 /* Create a sizer for the main frame */
341 panel_sizer = new wxBoxSizer( wxVERTICAL );
342 main_panel->SetSizer( panel_sizer );
344 /* Put this in the splitter */
345 splitter->Initialize( main_panel );
347 #ifdef wxHAS_TASK_BAR_ICON
348 /* Systray integration */
350 if( config_GetInt( p_intf, "wx-systray" ) )
352 p_systray = new Systray( this, p_intf );
356 /* Creation of the menu bar */
359 /* Creation of the tool bar */
362 /* Creation of the status bar
363 * Helptext for menu items and toolbar tools will automatically get
365 int i_status_width[3] = {100, 40, -1};
366 statusbar = CreateStatusBar( 3 ); /* 2 fields */
367 statusbar->SetStatusWidths( 3, i_status_width );
368 statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
370 /* Get minimum window size to prevent user from glitching it */
371 splitter->SetSizeHints( -1, 0 );
372 panel_sizer->Layout(); panel_sizer->Fit( main_panel );
373 main_sizer->Layout(); main_sizer->Fit( this );
374 main_min_size = GetSize();
375 splitter->SetSizeHints( -1, -1 );
379 if( config_GetInt( p_intf, "wx-embed" ) )
381 video_window = CreateVideoWindow( p_intf, main_panel );
382 panel_sizer->Add( p_intf->p_sys->p_video_sizer, 1, wxEXPAND, 0 );
385 /* Creation of the input manager panel */
386 input_manager = new InputManager( p_intf, this, main_panel );
387 panel_sizer->Add( input_manager, 0, wxEXPAND , 0 );
389 /* Layout everything */
390 splitter->SetSizeHints( -1, 0 );
391 panel_sizer->Layout(); panel_sizer->Fit( main_panel );
392 main_sizer->Layout(); main_sizer->Fit( this );
393 splitter->SetSizeHints( -1, -1 );
395 #if wxUSE_DRAG_AND_DROP
396 /* Associate drop targets with the main interface */
397 SetDropTarget( new DragAndDrop( p_intf ) );
403 timer = new Timer( p_intf, this );
405 /* Restore previous position / settings */
406 WindowSettings *ws = p_intf->p_sys->p_window_settings;
411 ws->SetScreen( wxSystemSettings::GetMetric( wxSYS_SCREEN_X ),
412 wxSystemSettings::GetMetric( wxSYS_SCREEN_Y ) );
414 if( ws->GetSettings( WindowSettings::ID_MAIN, b_shown, p, s ) ) Move( p );
416 /* Show extended GUI if requested */
417 wxCommandEvent dummy;
418 if( config_GetInt( p_intf, "wx-extended" ) ) OnExtended( dummy );
423 Interface::~Interface()
425 WindowSettings *ws = p_intf->p_sys->p_window_settings;
429 ws->SetSettings( WindowSettings::ID_MAIN, true,
430 GetPosition(), GetSize() );
433 PopEventHandler(true);
435 if( video_window ) delete video_window;
437 #ifdef wxHAS_TASK_BAR_ICON
438 if( p_systray ) delete p_systray;
441 if( p_intf->p_sys->p_wxwindow ) delete p_intf->p_sys->p_wxwindow;
447 void Interface::Init()
453 void Interface::Update()
456 ((VLCVolCtrl *)volctrl)->UpdateVolume();
458 if( playlist_manager ) playlist_manager->Update();
461 void Interface::OnControlEvent( wxCommandEvent& event )
463 switch( event.GetId() )
466 main_sizer->Layout();
467 main_sizer->Fit( this );
471 long i_style = GetWindowStyle();
472 if( event.GetInt() ) i_style |= wxSTAY_ON_TOP;
473 else i_style &= ~wxSTAY_ON_TOP;
474 SetWindowStyle( i_style );
479 /*****************************************************************************
481 *****************************************************************************/
482 void Interface::CreateOurMenuBar()
484 int minimal = config_GetInt( p_intf, "wx-minimal" );
486 /* Create the "File" menu */
487 wxMenu *file_menu = new wxMenu;
491 file_menu->Append( OpenFileSimple_Event,
492 wxU(_("Quick &Open File...\tCtrl-O")) );
494 file_menu->AppendSeparator();
495 file_menu->Append( OpenFile_Event, wxU(_("Open &File...\tCtrl-F")) );
496 file_menu->Append( OpenDir_Event, wxU(_("Open Dir&ectory...\tCtrl-E")) );
497 file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...\tCtrl-D")) );
498 file_menu->Append( OpenNet_Event,
499 wxU(_("Open &Network Stream...\tCtrl-N")) );
500 file_menu->Append( OpenCapture_Event,
501 wxU(_("Open C&apture Device...\tCtrl-A")) );
503 file_menu->AppendSeparator();
504 file_menu->Append( Wizard_Event, wxU(_("&Wizard...\tCtrl-W")) );
505 file_menu->AppendSeparator();
507 file_menu->Append( Exit_Event, wxU(_("E&xit\tCtrl-X")) );
509 /* Create the "View" menu */
510 wxMenu *view_menu = new wxMenu;
513 view_menu->Append( Playlist_Event, wxU(_("&Playlist...\tCtrl-P")) );
515 view_menu->Append( Logs_Event, wxU(_("&Messages...\tCtrl-M")) );
516 view_menu->Append( FileInfo_Event,
517 wxU(_("Stream and Media &info...\tCtrl-I")) );
518 view_menu->Append( VLM_Event,
519 wxU(_("VLM Control...\tCtrl-V")) );
521 /* Create the "Auto-generated" menus */
522 p_settings_menu = SettingsMenu( p_intf, this );
523 p_audio_menu = AudioMenu( p_intf, this );
524 p_video_menu = VideoMenu( p_intf, this );
525 p_navig_menu = NavigMenu( p_intf, this );
527 /* Create the "Help" menu */
528 wxMenu *help_menu = new wxMenu;
529 help_menu->Append( About_Event, wxU(_("About VLC media player")) );
530 help_menu->AppendSeparator();
531 help_menu->Append( UpdateVLC_Event, wxU(_("Check for updates ...")) );
533 /* Append the freshly created menus to the menu bar... */
534 wxMenuBar *menubar = new wxMenuBar();
535 menubar->Append( file_menu, wxU(_("&File")) );
536 menubar->Append( view_menu, wxU(_("&View")) );
537 menubar->Append( p_settings_menu, wxU(_("&Settings")) );
538 menubar->Append( p_audio_menu, wxU(_("&Audio")) );
539 menubar->Append( p_video_menu, wxU(_("&Video")) );
540 menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
541 menubar->Append( help_menu, wxU(_("&Help")) );
543 /* Attach the menu bar to the frame */
544 SetMenuBar( menubar );
546 /* Find out size of menu bar */
548 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
550 int i_width, i_height;
551 menubar->GetTextExtent( menubar->GetLabelTop(i), &i_width, &i_height );
553 #if defined(__WXGTK__)
554 22 /* approximate margin */;
556 #if (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 5) && (wxRELEASE_NUMBER < 3)
557 4 /* approximate margin */;
559 18 /* approximate margin */;
564 /* Patch by zcot for menu wrapping */
566 /* Find out size of msw menu bar */
569 HDC hdc = GetDC( NULL );
570 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
572 GetTextExtentPoint32( hdc, menubar->GetLabelTop(i).c_str(),
573 menubar->GetLabelTop(i).Length(), &sizing );
575 // [ SM_CXDLGFRAME + pixels + textextent + pixels + SM_CXDLGFRAME ]
576 i_size += sizing.cx + 2 + GetSystemMetrics( SM_CXDLGFRAME ) * 2;
578 ReleaseDC( NULL, hdc );
579 i_size += GetSystemMetrics( SM_CXSIZEFRAME ) * 2 + 4;
581 /* End patch by zcot */
583 panel_sizer->SetMinSize( i_size, -1 );
585 /* Intercept all menu events in our custom event handler */
586 PushEventHandler( new MenuEvtHandler( p_intf, this ) );
588 #if wxUSE_DRAG_AND_DROP
589 /* Associate drop targets with the menubar */
590 menubar->SetDropTarget( new DragAndDrop( p_intf ) );
594 void Interface::CreateOurToolBar()
596 #define HELP_OPEN N_("Open")
597 #define HELP_STOP N_("Stop")
598 #define HELP_PLAY N_("Play")
599 #define HELP_PAUSE N_("Pause")
600 #define HELP_PLO N_("Playlist")
601 #define HELP_SPLO N_("Small playlist")
602 #define HELP_PLP N_("Previous playlist item")
603 #define HELP_PLN N_("Next playlist item")
604 #define HELP_SLOW N_("Play slower")
605 #define HELP_FAST N_("Play faster")
607 int minimal = config_GetInt( p_intf, "wx-minimal" );
609 wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
610 * version because we don't include wx.rc */
613 CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
615 toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
619 toolbar->AddTool( OpenFile_Event, wxT(""),
620 wxBitmap( eject_xpm ), wxU(_(HELP_OPEN)) );
621 toolbar->AddSeparator();
624 wxToolBarToolBase *p_tool = toolbar->AddTool( PlayStream_Event, wxT(""),
625 wxBitmap( play_xpm ), wxU(_(HELP_PLAY)), wxITEM_CHECK );
626 p_tool->SetClientData( p_tool );
630 toolbar->AddTool( StopStream_Event, wxT(""), wxBitmap( stop_xpm ),
632 toolbar->AddSeparator();
634 toolbar->AddTool( PrevStream_Event, wxT(""),
635 wxBitmap( prev_xpm ), wxU(_(HELP_PLP)) );
636 toolbar->AddTool( SlowStream_Event, wxT(""),
637 wxBitmap( slow_xpm ), wxU(_(HELP_SLOW)) );
638 toolbar->AddTool( FastStream_Event, wxT(""),
639 wxBitmap( fast_xpm ), wxU(_(HELP_FAST)) );
640 toolbar->AddTool( NextStream_Event, wxT(""), wxBitmap( next_xpm ),
642 toolbar->AddSeparator();
643 toolbar->AddTool( Playlist_Event, wxT(""), wxBitmap( playlist_xpm ),
645 toolbar->AddTool( PlaylistSmall_Event, wxT(""),
646 wxBitmap( playlist_small_xpm ), wxU(_(HELP_SPLO)) );
649 wxControl *p_dummy_ctrl =
650 new wxControl( toolbar, -1, wxDefaultPosition,
651 wxSize(16, 16 ), wxBORDER_NONE );
653 toolbar->AddControl( p_dummy_ctrl );
655 volctrl = new VLCVolCtrl( p_intf, toolbar );
656 toolbar->AddControl( volctrl );
660 #if wxUSE_DRAG_AND_DROP
661 /* Associate drop targets with the toolbar */
662 toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
666 static int ConvertHotkeyModifiers( int i_hotkey )
668 int i_accel_flags = 0;
669 if( i_hotkey & KEY_MODIFIER_ALT ) i_accel_flags |= wxACCEL_ALT;
670 if( i_hotkey & KEY_MODIFIER_CTRL ) i_accel_flags |= wxACCEL_CTRL;
671 if( i_hotkey & KEY_MODIFIER_SHIFT ) i_accel_flags |= wxACCEL_SHIFT;
672 if( !i_accel_flags ) i_accel_flags = wxACCEL_NORMAL;
673 return i_accel_flags;
676 static int ConvertHotkey( int i_hotkey )
678 int i_key = i_hotkey & ~KEY_MODIFIER;
679 if( i_key & KEY_ASCII ) return i_key & KEY_ASCII;
680 else if( i_key & KEY_SPECIAL )
684 case KEY_LEFT: return WXK_LEFT;
685 case KEY_RIGHT: return WXK_RIGHT;
686 case KEY_UP: return WXK_UP;
687 case KEY_DOWN: return WXK_DOWN;
688 case KEY_SPACE: return WXK_SPACE;
689 case KEY_ENTER: return WXK_RETURN;
690 case KEY_F1: return WXK_F1;
691 case KEY_F2: return WXK_F2;
692 case KEY_F3: return WXK_F3;
693 case KEY_F4: return WXK_F4;
694 case KEY_F5: return WXK_F5;
695 case KEY_F6: return WXK_F6;
696 case KEY_F7: return WXK_F7;
697 case KEY_F8: return WXK_F8;
698 case KEY_F9: return WXK_F9;
699 case KEY_F10: return WXK_F10;
700 case KEY_F11: return WXK_F11;
701 case KEY_F12: return WXK_F12;
702 case KEY_HOME: return WXK_HOME;
703 case KEY_END: return WXK_END;
704 case KEY_INSERT: return WXK_INSERT;
705 case KEY_DELETE: return WXK_DELETE;
706 case KEY_MENU: return WXK_MENU;
707 case KEY_ESC: return WXK_ESCAPE;
708 case KEY_PAGEUP: return WXK_PRIOR;
709 case KEY_PAGEDOWN: return WXK_NEXT;
710 case KEY_TAB: return WXK_TAB;
711 case KEY_BACKSPACE: return WXK_BACK;
717 void Interface::SetupHotkeys()
719 struct vlc_t::hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
722 /* Count number of hoteys */
723 for( i_hotkeys = 0; p_hotkeys[i_hotkeys].psz_action != NULL; i_hotkeys++ );
725 p_intf->p_sys->i_first_hotkey_event = wxID_HIGHEST + 7000;
726 p_intf->p_sys->i_hotkeys = i_hotkeys;
728 wxAcceleratorEntry *p_entries = new wxAcceleratorEntry[i_hotkeys];
730 /* Setup the hotkeys as accelerators */
731 for( int i = 0; i < i_hotkeys; i++ )
733 int i_mod = ConvertHotkeyModifiers( p_hotkeys[i].i_key );
734 int i_key = ConvertHotkey( p_hotkeys[i].i_key );
737 if( !(p_hotkeys[i].i_key & KEY_SPECIAL) && i_mod )
738 i_key = toupper(i_key);
741 p_entries[i].Set( i_mod, i_key,
742 p_intf->p_sys->i_first_hotkey_event + i );
745 wxAcceleratorTable accel( i_hotkeys, p_entries );
749 msg_Err( p_intf, "invalid accelerator table" );
753 SetAcceleratorTable( accel );
759 void Interface::SetIntfMinSize()
761 wxSize ms = main_min_size;
763 if( extra_frame && extra_frame->IsShown() )
765 ms.SetHeight( ms.GetHeight() + ext_min_size.GetHeight() );
766 if( ext_min_size.GetWidth() > ms.GetWidth() )
767 ms.SetWidth( ext_min_size.GetWidth() );
770 SetSizeHints( ms.GetWidth(), ms.GetHeight() );
773 /*****************************************************************************
775 *****************************************************************************/
776 void Interface::OnMenuOpen( wxMenuEvent& event )
778 #if defined( __WXMSW__ )
779 # define GetEventObject GetMenu
782 if( event.GetEventObject() == p_settings_menu )
784 p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );
786 /* Add static items */
787 p_settings_menu->AppendCheckItem( Extended_Event,
788 wxU(_("Extended &GUI\tCtrl-G") ) );
789 if( b_extra ) p_settings_menu->Check( Extended_Event, TRUE );
790 p_settings_menu->Append( Bookmarks_Event,
791 wxU(_("&Bookmarks...\tCtrl-B") ) );
792 p_settings_menu->Append( Prefs_Event,
793 wxU(_("Preference&s...\tCtrl-S")) );
796 else if( event.GetEventObject() == p_audio_menu )
798 p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
801 else if( event.GetEventObject() == p_video_menu )
803 p_video_menu = VideoMenu( p_intf, this, p_video_menu );
806 else if( event.GetEventObject() == p_navig_menu )
808 p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
811 #if defined( __WXMSW__ )
812 # undef GetEventObject
816 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
817 void Interface::OnContextMenu2(wxContextMenuEvent& event)
819 /* Only show the context menu for the main interface */
820 if( GetId() != event.GetId() )
826 if( p_intf->p_sys->pf_show_dialog )
827 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
830 void Interface::OnContextMenu(wxMouseEvent& event)
832 if( p_intf->p_sys->pf_show_dialog )
833 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
836 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
838 /* TRUE is to force the frame to close. */
842 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
845 msg.Printf( wxString(wxT("VLC media player " PACKAGE_VERSION)) +
846 wxU(_(" (wxWidgets interface)\n\n")) +
847 wxU(_("(c) 1996-2005 - the VideoLAN Team\n\n")) +
848 wxU(_("Compiled by "))+ wxU(VLC_CompileBy())+ wxU("@") +
849 wxU(VLC_CompileHost())+ wxT(".")+ wxU(VLC_CompileDomain())+ wxT(".\n") +
850 wxU(_("Compiler: "))+ wxU(VLC_Compiler())+wxT( ".\n") +
851 wxU(_("Based on SVN revision: "))+wxU(VLC_Changeset())+wxT(".\n\n") +
853 wxU( vlc_wraptext(LICENSE_MSG,WRAPCOUNT,VLC_TRUE) ) + wxT("\n\n") +
855 wxU( LICENSE_MSG ) + wxT("\n\n") +
857 wxU(_("The VideoLAN team <videolan@videolan.org>\n"
858 "http://www.videolan.org/\n\n")) );
860 wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
861 wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
864 void Interface::OnShowDialog( wxCommandEvent& event )
866 if( p_intf->p_sys->pf_show_dialog )
870 switch( event.GetId() )
872 case OpenFileSimple_Event:
873 i_id = INTF_DIALOG_FILE_SIMPLE;
876 i_id = INTF_DIALOG_FILE;
879 i_id = INTF_DIALOG_FILE;
882 i_id = INTF_DIALOG_DIRECTORY;
885 i_id = INTF_DIALOG_DISC;
888 i_id = INTF_DIALOG_NET;
890 case OpenCapture_Event:
891 i_id = INTF_DIALOG_CAPTURE;
894 i_id = INTF_DIALOG_SAT;
897 i_id = INTF_DIALOG_PLAYLIST;
900 i_id = INTF_DIALOG_MESSAGES;
903 i_id = INTF_DIALOG_FILEINFO;
906 i_id = INTF_DIALOG_PREFS;
909 i_id = INTF_DIALOG_WIZARD;
911 case Bookmarks_Event:
912 i_id = INTF_DIALOG_BOOKMARKS;
914 case UpdateVLC_Event:
915 i_id = INTF_DIALOG_UPDATEVLC;
918 i_id = INTF_DIALOG_VLM;
921 i_id = INTF_DIALOG_FILE;
925 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
929 void Interface::OnExtended( wxCommandEvent& WXUNUSED(event) )
931 UpdateVideoWindow( p_intf, video_window );
935 /* Create the extra panel */
936 extra_frame = new ExtraPanel( p_intf, main_panel );
937 panel_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
938 ext_min_size = extra_frame->GetBestSize();
942 panel_sizer->Show( extra_frame, b_extra );
945 main_sizer->Layout();
946 main_sizer->Fit( this );
949 void Interface::OnSmallPlaylist( wxCommandEvent& WXUNUSED(event) )
951 UpdateVideoWindow( p_intf, video_window );
953 if( !playlist_manager )
955 /* Create the extra panel */
956 playlist_manager = new PlaylistManager( p_intf, splitter );
959 if( !splitter->IsSplit() ) splitter->Split( main_panel, playlist_manager );
960 else splitter->Unsplit( playlist_manager );
963 main_sizer->Layout();
964 main_sizer->Fit( this );
967 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
972 void Interface::PlayStream()
974 wxCommandEvent dummy;
975 playlist_t *p_playlist =
976 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
978 if( p_playlist == NULL ) return;
980 if( p_playlist->i_size && p_playlist->i_enabled )
984 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
987 if( p_input == NULL )
989 /* No stream was playing, start one */
990 playlist_Play( p_playlist );
991 vlc_object_release( p_playlist );
992 input_manager->Update();
996 var_Get( p_input, "state", &state );
997 if( state.i_int != PAUSE_S )
999 /* A stream is being played, pause it */
1000 state.i_int = PAUSE_S;
1004 /* Stream is paused, resume it */
1005 state.i_int = PLAYING_S;
1007 var_Set( p_input, "state", state );
1009 vlc_object_release( p_input );
1010 vlc_object_release( p_playlist );
1011 input_manager->Update();
1015 /* If the playlist is empty, open a file requester instead */
1016 vlc_object_release( p_playlist );
1017 OnShowDialog( dummy );
1021 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
1025 void Interface::StopStream()
1027 playlist_t * p_playlist =
1028 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1030 if( p_playlist == NULL )
1035 playlist_Stop( p_playlist );
1036 vlc_object_release( p_playlist );
1037 input_manager->Update();
1040 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
1045 void Interface::PrevStream()
1047 playlist_t * p_playlist =
1048 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1050 if( p_playlist == NULL )
1055 playlist_Prev( p_playlist );
1056 vlc_object_release( p_playlist );
1059 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1064 void Interface::NextStream()
1066 playlist_t * p_playlist =
1067 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1069 if( p_playlist == NULL )
1073 playlist_Next( p_playlist );
1074 vlc_object_release( p_playlist );
1077 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1079 input_thread_t *p_input =
1080 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1084 vlc_value_t val; val.b_bool = VLC_TRUE;
1086 var_Set( p_input, "rate-slower", val );
1087 vlc_object_release( p_input );
1091 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1093 input_thread_t *p_input =
1094 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1098 vlc_value_t val; val.b_bool = VLC_TRUE;
1100 var_Set( p_input, "rate-faster", val );
1101 vlc_object_release( p_input );
1105 void Interface::TogglePlayButton( int i_playing_status )
1107 wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
1108 GetToolBar()->GetToolClientData( PlayStream_Event );
1109 if( !p_tool ) return;
1111 if( i_playing_status == PLAYING_S )
1113 p_tool->SetNormalBitmap( wxBitmap( pause_xpm ) );
1114 p_tool->SetLabel( wxU(_("Pause")) );
1115 p_tool->SetShortHelp( wxU(_(HELP_PAUSE)) );
1119 p_tool->SetNormalBitmap( wxBitmap( play_xpm ) );
1120 p_tool->SetLabel( wxU(_("Play")) );
1121 p_tool->SetShortHelp( wxU(_(HELP_PLAY)) );
1124 GetToolBar()->Realize();
1126 #if defined( __WXMSW__ )
1127 /* Needed to work around a bug in wxToolBar::Realize() */
1128 GetToolBar()->SetSize( GetSize().GetWidth(),
1129 GetToolBar()->GetSize().GetHeight() );
1130 GetToolBar()->Update();
1133 GetToolBar()->ToggleTool( PlayStream_Event, true );
1134 GetToolBar()->ToggleTool( PlayStream_Event, false );
1137 #if wxUSE_DRAG_AND_DROP
1138 /*****************************************************************************
1139 * Definition of DragAndDrop class.
1140 *****************************************************************************/
1141 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
1144 b_enqueue = _b_enqueue;
1147 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1148 const wxArrayString& filenames )
1150 /* Add dropped files to the playlist */
1152 playlist_t *p_playlist =
1153 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1155 if( p_playlist == NULL )
1160 for( size_t i = 0; i < filenames.GetCount(); i++ )
1162 char *psz_utf8 = wxFromLocale( filenames[i] );
1164 playlist_Add( p_playlist, psz_utf8, psz_utf8,
1165 PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
1167 wxLocaleFree( psz_utf8 );
1170 vlc_object_release( p_playlist );
1176 /*****************************************************************************
1177 * Definition of VolCtrl class.
1178 *****************************************************************************/
1179 class wxVolCtrl: public wxGauge
1183 wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1184 wxPoint = wxDefaultPosition, wxSize = wxSize( 20, -1 ) );
1185 virtual ~wxVolCtrl() {};
1187 void UpdateVolume();
1190 void OnChange( wxMouseEvent& event );
1193 intf_thread_t *p_intf;
1195 DECLARE_EVENT_TABLE();
1198 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
1200 EVT_LEFT_DOWN(wxVolCtrl::OnChange)
1201 EVT_MOTION(wxVolCtrl::OnChange)
1204 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1205 wxPoint point, wxSize size )
1206 : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
1212 void wxVolCtrl::OnChange( wxMouseEvent& event )
1214 if( !event.LeftDown() && !event.LeftIsDown() ) return;
1216 int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
1217 aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1221 void wxVolCtrl::UpdateVolume()
1223 audio_volume_t i_volume;
1224 aout_VolumeGet( p_intf, &i_volume );
1226 int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
1227 if( i_gauge_volume == GetValue() ) return;
1229 SetValue( i_gauge_volume );
1230 SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
1231 i_gauge_volume / 2 ) );
1234 #if defined(__WXGTK__)
1235 #define VLCVOL_HEIGHT p_parent->GetSize().GetHeight()
1237 #define VLCVOL_HEIGHT TOOLBAR_BMP_HEIGHT
1239 VLCVolCtrl::VLCVolCtrl( intf_thread_t *_p_intf, wxWindow *p_parent )
1240 :wxControl( p_parent, -1, wxDefaultPosition, wxSize(64, VLCVOL_HEIGHT ),
1242 i_y_offset((VLCVOL_HEIGHT - TOOLBAR_BMP_HEIGHT) / 2),
1243 b_mute(0), p_intf(_p_intf)
1245 gauge = new wxVolCtrl( p_intf, this, -1, wxPoint( 18, i_y_offset ),
1246 wxSize( 44, TOOLBAR_BMP_HEIGHT ) );
1249 void VLCVolCtrl::OnPaint( wxPaintEvent &evt )
1251 wxPaintDC dc( this );
1252 wxBitmap mPlayBitmap( b_mute ? speaker_mute_xpm : speaker_xpm );
1253 dc.DrawBitmap( mPlayBitmap, 0, i_y_offset, TRUE );
1256 void VLCVolCtrl::OnChange( wxMouseEvent& event )
1258 if( event.GetX() < TOOLBAR_BMP_WIDTH )
1261 aout_VolumeMute( p_intf, (audio_volume_t *)&i_volume );
1268 void VLCVolCtrl::UpdateVolume()
1270 gauge->UpdateVolume();
1272 int i_volume = gauge->GetValue();
1273 if( !!i_volume == !b_mute ) return;
1278 /*****************************************************************************
1280 *****************************************************************************/
1282 #ifdef wxHAS_TASK_BAR_ICON
1284 BEGIN_EVENT_TABLE(Systray, wxTaskBarIcon)
1287 EVT_TASKBAR_LEFT_DCLICK(Systray::OnLeftClick)
1289 EVT_TASKBAR_LEFT_DOWN(Systray::OnLeftClick)
1292 EVT_MENU(Iconize_Event, Systray::OnMenuIconize)
1293 EVT_MENU(Exit_Event, Systray::OnExit)
1294 EVT_MENU(PlayStream_Event, Systray::OnPlayStream)
1295 EVT_MENU(NextStream_Event, Systray::OnNextStream)
1296 EVT_MENU(PrevStream_Event, Systray::OnPrevStream)
1297 EVT_MENU(StopStream_Event, Systray::OnStopStream)
1300 Systray::Systray( Interface *_p_main_interface, intf_thread_t *_p_intf )
1302 p_main_interface = _p_main_interface;
1305 SetIcon( wxIcon( vlc16x16_xpm ), wxT("VLC media player") );
1306 if( !IsOk() || !IsIconInstalled() )
1308 msg_Warn(p_intf, "cannot set systray icon, weird things may happen");
1312 /* Event handlers */
1313 void Systray::OnMenuIconize( wxCommandEvent& event )
1315 p_main_interface->Show( ! p_main_interface->IsShown() );
1316 if ( p_main_interface->IsShown() ) p_main_interface->Raise();
1319 void Systray::OnLeftClick( wxTaskBarIconEvent& event )
1321 wxCommandEvent cevent;
1322 OnMenuIconize(cevent);
1325 void Systray::OnExit( wxCommandEvent& event )
1327 p_main_interface->Close(TRUE);
1330 void Systray::OnPrevStream( wxCommandEvent& event )
1332 p_main_interface->PrevStream();
1335 void Systray::OnNextStream( wxCommandEvent& event )
1337 p_main_interface->NextStream();
1340 void Systray::OnPlayStream( wxCommandEvent& event )
1342 p_main_interface->PlayStream();
1345 void Systray::OnStopStream( wxCommandEvent& event )
1347 p_main_interface->StopStream();
1350 /* Systray popup menu */
1351 wxMenu* Systray::CreatePopupMenu()
1353 int minimal = config_GetInt( p_intf, "wx-minimal" );
1355 wxMenu* systray_menu = new wxMenu;
1356 systray_menu->Append( Exit_Event, wxU(_("Quit VLC")) );
1357 systray_menu->AppendSeparator();
1358 systray_menu->Append( PlayStream_Event, wxU(_("Play/Pause")) );
1362 systray_menu->Append( PrevStream_Event, wxU(_("Previous")) );
1363 systray_menu->Append( NextStream_Event, wxU(_("Next")) );
1364 systray_menu->Append( StopStream_Event, wxU(_("Stop")) );
1366 systray_menu->AppendSeparator();
1367 systray_menu->Append( Iconize_Event, wxU(_("Show/Hide interface")) );
1368 return systray_menu;
1371 void Systray::UpdateTooltip( const wxChar* tooltip )
1373 SetIcon( wxIcon( vlc16x16_xpm ), tooltip );