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), i_width(-1)
126 virtual ~Splitter() {};
128 virtual bool Split( wxWindow* window1, wxWindow* window2 )
132 wxSize size = wxSize( i_width, i_sash_position - GetSashSize() );
133 if( window2->GetSizer() ) window2->GetSizer()->SetMinSize( size );
135 return wxSplitterWindow::SplitHorizontally( window1, window2,
139 virtual bool Unsplit( wxWindow* window )
142 return wxSplitterWindow::Unsplit( window );
146 DECLARE_EVENT_TABLE()
148 void OnSize( wxSizeEvent &event )
150 /* If we display video, then resize the video window */
152 p_intf->p_sys->p_video_window && p_intf->p_sys->p_video_sizer &&
153 p_intf->p_sys->p_video_sizer->GetMinSize() != wxSize(0,0) )
155 SetSashPosition( event.GetSize().GetHeight() - i_sash_position );
157 else if( GetWindow2() && GetWindow1() && GetWindow1()->GetSizer() )
159 wxSize size = GetWindow1()->GetSizer()->GetMinSize();
161 if( event.GetSize().GetHeight() - size.GetHeight() )
163 SetSashPosition( size.GetHeight() ? size.GetHeight() : 1 );
164 i_sash_position = event.GetSize().GetHeight() -
166 i_width = event.GetSize().GetWidth();
168 size = wxSize( i_width, i_sash_position - GetSashSize() );
169 if( GetWindow2()->GetSizer() )
170 GetWindow2()->GetSizer()->SetMinSize( size );
177 void OnSashPosChanged( wxSplitterEvent &event )
179 if( !GetSize().GetHeight() ){ event.Skip(); return; }
180 i_sash_position = GetSize().GetHeight() - event.GetSashPosition();
184 intf_thread_t *p_intf;
189 BEGIN_EVENT_TABLE(Splitter, wxSplitterWindow)
190 EVT_SIZE( Splitter::OnSize )
191 EVT_SPLITTER_SASH_POS_CHANGED(-1, Splitter::OnSashPosChanged)
194 /*****************************************************************************
196 *****************************************************************************/
198 DEFINE_LOCAL_EVENT_TYPE( wxEVT_INTF );
200 /* IDs for the controls and the menu commands */
204 MenuDummy_Event = wxID_HIGHEST + 1000,
205 Exit_Event = wxID_HIGHEST,
206 OpenFileSimple_Event,
236 /* it is important for the id corresponding to the "About" command to have
237 * this standard value as otherwise it won't be handled properly under Mac
238 * (where it is special and put into the "Apple" menu) */
239 About_Event = wxID_ABOUT,
246 BEGIN_EVENT_TABLE(Interface, wxFrame)
248 EVT_MENU(Exit_Event, Interface::OnExit)
249 EVT_MENU(About_Event, Interface::OnAbout)
250 EVT_MENU(UpdateVLC_Event, Interface::OnShowDialog)
251 EVT_MENU(VLM_Event, Interface::OnShowDialog)
253 EVT_MENU(Playlist_Event, Interface::OnShowDialog)
254 EVT_MENU(PlaylistSmall_Event, Interface::OnSmallPlaylist)
255 EVT_MENU(Logs_Event, Interface::OnShowDialog)
256 EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
257 EVT_MENU(Prefs_Event, Interface::OnShowDialog)
259 EVT_MENU_OPEN(Interface::OnMenuOpen)
261 EVT_MENU( Extended_Event, Interface::OnExtended )
263 EVT_MENU( Bookmarks_Event, Interface::OnShowDialog)
265 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
266 EVT_CONTEXT_MENU(Interface::OnContextMenu2)
268 EVT_RIGHT_UP(Interface::OnContextMenu)
271 EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
272 EVT_MENU(OpenAdv_Event, Interface::OnShowDialog)
273 EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
274 EVT_MENU(OpenDir_Event, Interface::OnShowDialog)
275 EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
276 EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
277 EVT_MENU(OpenCapture_Event, Interface::OnShowDialog)
278 EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
279 EVT_MENU(Wizard_Event, Interface::OnShowDialog)
280 EVT_MENU(StopStream_Event, Interface::OnStopStream)
281 EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
282 EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
283 EVT_MENU(NextStream_Event, Interface::OnNextStream)
284 EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
285 EVT_MENU(FastStream_Event, Interface::OnFastStream)
288 EVT_COMMAND(0, wxEVT_INTF, Interface::OnControlEvent)
289 EVT_COMMAND(1, wxEVT_INTF, Interface::OnControlEvent)
292 /*****************************************************************************
294 *****************************************************************************/
295 Interface::Interface( intf_thread_t *_p_intf, long style ):
296 wxFrame( NULL, -1, wxT("VLC media player"),
297 wxDefaultPosition, wxSize(700,100), style )
299 /* Initializations */
303 playlist_manager = 0;
305 /* Give our interface a nice little icon */
306 SetIcon( wxIcon( vlc_xpm ) );
308 /* Create a splitter window that will fill in the interface window.
309 * We need a splitter bar in order to make the embedded playlist
311 splitter = new Splitter( this, p_intf );
312 main_sizer = new wxBoxSizer( wxVERTICAL );
313 main_sizer->Add( splitter, 1, wxEXPAND );
314 SetSizer( main_sizer );
316 /* Create a main panel that will fill in the interface window */
317 main_panel = new wxPanel( splitter, -1, wxPoint(0,0), wxSize(0,0),
319 main_panel->SetFocus();
321 #if defined(__WXGTK20__) && wxCHECK_VERSION(2,5,6)
322 /* As ugly as your butt! Please remove when wxWidgets 2.6 fixed their
323 * Accelerators bug. */
324 main_panel->m_imData = 0;
328 /* Create a sizer for the main frame */
329 panel_sizer = new wxBoxSizer( wxVERTICAL );
330 main_panel->SetSizer( panel_sizer );
332 /* Put this in the splitter */
333 splitter->Initialize( main_panel );
335 #ifdef wxHAS_TASK_BAR_ICON
336 /* Systray integration */
338 if( config_GetInt( p_intf, "wx-systray" ) )
340 p_systray = new Systray( this, p_intf );
344 /* Creation of the menu bar */
347 /* Creation of the tool bar */
350 /* Creation of the status bar
351 * Helptext for menu items and toolbar tools will automatically get
353 int i_status_width[3] = {100, 40, -1};
354 statusbar = CreateStatusBar( 3 ); /* 2 fields */
355 statusbar->SetStatusWidths( 3, i_status_width );
356 statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
358 /* Get minimum window size to prevent user from glitching it */
359 splitter->SetSizeHints( -1, 0 );
360 panel_sizer->Layout(); panel_sizer->Fit( main_panel );
361 main_sizer->Layout(); main_sizer->Fit( this );
362 main_min_size = GetSize();
363 splitter->SetSizeHints( -1, -1 );
367 if( config_GetInt( p_intf, "wx-embed" ) )
369 video_window = CreateVideoWindow( p_intf, main_panel );
370 panel_sizer->Add( p_intf->p_sys->p_video_sizer, 1, wxEXPAND, 0 );
373 /* Creation of the input manager panel */
374 input_manager = new InputManager( p_intf, this, main_panel );
375 panel_sizer->Add( input_manager, 0, wxEXPAND , 0 );
377 /* Layout everything */
378 splitter->SetSizeHints( -1, 0 );
379 panel_sizer->Layout(); panel_sizer->Fit( main_panel );
380 main_sizer->Layout(); main_sizer->Fit( this );
381 splitter->SetSizeHints( -1, -1 );
383 #if wxUSE_DRAG_AND_DROP
384 /* Associate drop targets with the main interface */
385 SetDropTarget( new DragAndDrop( p_intf ) );
391 timer = new Timer( p_intf, this );
393 /* Restore previous position / settings */
394 WindowSettings *ws = p_intf->p_sys->p_window_settings;
399 ws->SetScreen( wxSystemSettings::GetMetric( wxSYS_SCREEN_X ),
400 wxSystemSettings::GetMetric( wxSYS_SCREEN_Y ) );
402 if( ws->GetSettings( WindowSettings::ID_MAIN, b_shown, p, s ) ) Move( p );
404 /* Show extended GUI if requested */
405 wxCommandEvent dummy;
406 if( config_GetInt( p_intf, "wx-extended" ) ) OnExtended( dummy );
411 Interface::~Interface()
413 WindowSettings *ws = p_intf->p_sys->p_window_settings;
417 ws->SetSettings( WindowSettings::ID_MAIN, true,
418 GetPosition(), GetSize() );
421 PopEventHandler(true);
423 if( video_window ) delete video_window;
425 #ifdef wxHAS_TASK_BAR_ICON
426 if( p_systray ) delete p_systray;
429 if( p_intf->p_sys->p_wxwindow ) delete p_intf->p_sys->p_wxwindow;
435 void Interface::Init()
441 void Interface::Update()
444 ((VLCVolCtrl *)volctrl)->UpdateVolume();
446 if( playlist_manager ) playlist_manager->Update();
449 void Interface::OnControlEvent( wxCommandEvent& event )
451 switch( event.GetId() )
454 main_sizer->Layout();
455 main_sizer->Fit( this );
459 long i_style = GetWindowStyle();
460 if( event.GetInt() ) i_style |= wxSTAY_ON_TOP;
461 else i_style &= ~wxSTAY_ON_TOP;
462 SetWindowStyle( i_style );
467 /*****************************************************************************
469 *****************************************************************************/
470 void Interface::CreateOurMenuBar()
472 int minimal = config_GetInt( p_intf, "wx-minimal" );
474 /* Create the "File" menu */
475 wxMenu *file_menu = new wxMenu;
479 file_menu->Append( OpenFileSimple_Event,
480 wxU(_("Quick &Open File...\tCtrl-O")) );
482 file_menu->AppendSeparator();
483 file_menu->Append( OpenFile_Event, wxU(_("Open &File...\tCtrl-F")) );
484 file_menu->Append( OpenDir_Event, wxU(_("Open Dir&ectory...\tCtrl-E")) );
485 file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...\tCtrl-D")) );
486 file_menu->Append( OpenNet_Event,
487 wxU(_("Open &Network Stream...\tCtrl-N")) );
488 file_menu->Append( OpenCapture_Event,
489 wxU(_("Open C&apture Device...\tCtrl-A")) );
491 file_menu->AppendSeparator();
492 file_menu->Append( Wizard_Event, wxU(_("&Wizard...\tCtrl-W")) );
493 file_menu->AppendSeparator();
495 file_menu->Append( Exit_Event, wxU(_("E&xit\tCtrl-X")) );
497 /* Create the "View" menu */
498 wxMenu *view_menu = new wxMenu;
501 view_menu->Append( Playlist_Event, wxU(_("&Playlist...\tCtrl-P")) );
503 view_menu->Append( Logs_Event, wxU(_("&Messages...\tCtrl-M")) );
504 view_menu->Append( FileInfo_Event,
505 wxU(_("Stream and Media &info...\tCtrl-I")) );
506 view_menu->Append( VLM_Event,
507 wxU(_("VLM Control...\tCtrl-V")) );
509 /* Create the "Auto-generated" menus */
510 p_settings_menu = SettingsMenu( p_intf, this );
511 p_audio_menu = AudioMenu( p_intf, this );
512 p_video_menu = VideoMenu( p_intf, this );
513 p_navig_menu = NavigMenu( p_intf, this );
515 /* Create the "Help" menu */
516 wxMenu *help_menu = new wxMenu;
517 help_menu->Append( About_Event, wxU(_("About VLC media player")) );
518 help_menu->AppendSeparator();
519 help_menu->Append( UpdateVLC_Event, wxU(_("Check for updates ...")) );
521 /* Append the freshly created menus to the menu bar... */
522 wxMenuBar *menubar = new wxMenuBar();
523 menubar->Append( file_menu, wxU(_("&File")) );
524 menubar->Append( view_menu, wxU(_("&View")) );
525 menubar->Append( p_settings_menu, wxU(_("&Settings")) );
526 menubar->Append( p_audio_menu, wxU(_("&Audio")) );
527 menubar->Append( p_video_menu, wxU(_("&Video")) );
528 menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
529 menubar->Append( help_menu, wxU(_("&Help")) );
531 /* Attach the menu bar to the frame */
532 SetMenuBar( menubar );
534 /* Find out size of menu bar */
536 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
538 int i_width, i_height;
539 menubar->GetTextExtent( menubar->GetLabelTop(i), &i_width, &i_height );
541 #if defined(__WXGTK__)
542 22 /* approximate margin */;
544 #if (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 5) && (wxRELEASE_NUMBER < 3)
545 4 /* approximate margin */;
547 18 /* approximate margin */;
552 /* Patch by zcot for menu wrapping */
554 /* Find out size of msw menu bar */
557 HDC hdc = GetDC( NULL );
558 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
560 GetTextExtentPoint32( hdc, menubar->GetLabelTop(i).c_str(),
561 menubar->GetLabelTop(i).Length(), &sizing );
563 // [ SM_CXDLGFRAME + pixels + textextent + pixels + SM_CXDLGFRAME ]
564 i_size += sizing.cx + 2 + GetSystemMetrics( SM_CXDLGFRAME ) * 2;
566 ReleaseDC( NULL, hdc );
567 i_size += GetSystemMetrics( SM_CXSIZEFRAME ) * 2 + 4;
569 /* End patch by zcot */
571 panel_sizer->SetMinSize( i_size, -1 );
573 /* Intercept all menu events in our custom event handler */
574 PushEventHandler( new MenuEvtHandler( p_intf, this ) );
576 #if wxUSE_DRAG_AND_DROP
577 /* Associate drop targets with the menubar */
578 menubar->SetDropTarget( new DragAndDrop( p_intf ) );
582 void Interface::CreateOurToolBar()
584 #define HELP_OPEN N_("Open")
585 #define HELP_STOP N_("Stop")
586 #define HELP_PLAY N_("Play")
587 #define HELP_PAUSE N_("Pause")
588 #define HELP_PLO N_("Playlist")
589 #define HELP_SPLO N_("Small playlist")
590 #define HELP_PLP N_("Previous playlist item")
591 #define HELP_PLN N_("Next playlist item")
592 #define HELP_SLOW N_("Play slower")
593 #define HELP_FAST N_("Play faster")
595 int minimal = config_GetInt( p_intf, "wx-minimal" );
597 wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
598 * version because we don't include wx.rc */
601 CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
603 toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
607 toolbar->AddTool( OpenFile_Event, wxT(""),
608 wxBitmap( eject_xpm ), wxU(_(HELP_OPEN)) );
609 toolbar->AddSeparator();
612 wxToolBarToolBase *p_tool = toolbar->AddTool( PlayStream_Event, wxT(""),
613 wxBitmap( play_xpm ), wxU(_(HELP_PLAY)), wxITEM_CHECK );
614 p_tool->SetClientData( p_tool );
618 toolbar->AddTool( StopStream_Event, wxT(""), wxBitmap( stop_xpm ),
620 toolbar->AddSeparator();
622 toolbar->AddTool( PrevStream_Event, wxT(""),
623 wxBitmap( prev_xpm ), wxU(_(HELP_PLP)) );
624 toolbar->AddTool( SlowStream_Event, wxT(""),
625 wxBitmap( slow_xpm ), wxU(_(HELP_SLOW)) );
626 toolbar->AddTool( FastStream_Event, wxT(""),
627 wxBitmap( fast_xpm ), wxU(_(HELP_FAST)) );
628 toolbar->AddTool( NextStream_Event, wxT(""), wxBitmap( next_xpm ),
630 toolbar->AddSeparator();
631 toolbar->AddTool( Playlist_Event, wxT(""), wxBitmap( playlist_xpm ),
633 toolbar->AddTool( PlaylistSmall_Event, wxT(""),
634 wxBitmap( playlist_small_xpm ), wxU(_(HELP_SPLO)) );
637 wxControl *p_dummy_ctrl =
638 new wxControl( toolbar, -1, wxDefaultPosition,
639 wxSize(16, 16 ), wxBORDER_NONE );
641 toolbar->AddControl( p_dummy_ctrl );
643 volctrl = new VLCVolCtrl( p_intf, toolbar );
644 toolbar->AddControl( volctrl );
648 #if wxUSE_DRAG_AND_DROP
649 /* Associate drop targets with the toolbar */
650 toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
654 static int ConvertHotkeyModifiers( int i_hotkey )
656 int i_accel_flags = 0;
657 if( i_hotkey & KEY_MODIFIER_ALT ) i_accel_flags |= wxACCEL_ALT;
658 if( i_hotkey & KEY_MODIFIER_CTRL ) i_accel_flags |= wxACCEL_CTRL;
659 if( i_hotkey & KEY_MODIFIER_SHIFT ) i_accel_flags |= wxACCEL_SHIFT;
660 if( !i_accel_flags ) i_accel_flags = wxACCEL_NORMAL;
661 return i_accel_flags;
664 static int ConvertHotkey( int i_hotkey )
666 int i_key = i_hotkey & ~KEY_MODIFIER;
667 if( i_key & KEY_ASCII ) return i_key & KEY_ASCII;
668 else if( i_key & KEY_SPECIAL )
672 case KEY_LEFT: return WXK_LEFT;
673 case KEY_RIGHT: return WXK_RIGHT;
674 case KEY_UP: return WXK_UP;
675 case KEY_DOWN: return WXK_DOWN;
676 case KEY_SPACE: return WXK_SPACE;
677 case KEY_ENTER: return WXK_RETURN;
678 case KEY_F1: return WXK_F1;
679 case KEY_F2: return WXK_F2;
680 case KEY_F3: return WXK_F3;
681 case KEY_F4: return WXK_F4;
682 case KEY_F5: return WXK_F5;
683 case KEY_F6: return WXK_F6;
684 case KEY_F7: return WXK_F7;
685 case KEY_F8: return WXK_F8;
686 case KEY_F9: return WXK_F9;
687 case KEY_F10: return WXK_F10;
688 case KEY_F11: return WXK_F11;
689 case KEY_F12: return WXK_F12;
690 case KEY_HOME: return WXK_HOME;
691 case KEY_END: return WXK_END;
692 case KEY_INSERT: return WXK_INSERT;
693 case KEY_DELETE: return WXK_DELETE;
694 case KEY_MENU: return WXK_MENU;
695 case KEY_ESC: return WXK_ESCAPE;
696 case KEY_PAGEUP: return WXK_PRIOR;
697 case KEY_PAGEDOWN: return WXK_NEXT;
698 case KEY_TAB: return WXK_TAB;
699 case KEY_BACKSPACE: return WXK_BACK;
705 void Interface::SetupHotkeys()
707 struct vlc_t::hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
710 /* Count number of hoteys */
711 for( i_hotkeys = 0; p_hotkeys[i_hotkeys].psz_action != NULL; i_hotkeys++ );
713 p_intf->p_sys->i_first_hotkey_event = wxID_HIGHEST + 7000;
714 p_intf->p_sys->i_hotkeys = i_hotkeys;
716 wxAcceleratorEntry *p_entries = new wxAcceleratorEntry[i_hotkeys];
718 /* Setup the hotkeys as accelerators */
719 for( int i = 0; i < i_hotkeys; i++ )
721 int i_mod = ConvertHotkeyModifiers( p_hotkeys[i].i_key );
722 int i_key = ConvertHotkey( p_hotkeys[i].i_key );
725 if( !(p_hotkeys[i].i_key & KEY_SPECIAL) && i_mod )
726 i_key = toupper(i_key);
729 p_entries[i].Set( i_mod, i_key,
730 p_intf->p_sys->i_first_hotkey_event + i );
733 wxAcceleratorTable accel( i_hotkeys, p_entries );
737 msg_Err( p_intf, "invalid accelerator table" );
741 SetAcceleratorTable( accel );
747 void Interface::SetIntfMinSize()
749 wxSize ms = main_min_size;
751 if( extra_frame && extra_frame->IsShown() )
753 ms.SetHeight( ms.GetHeight() + ext_min_size.GetHeight() );
754 if( ext_min_size.GetWidth() > ms.GetWidth() )
755 ms.SetWidth( ext_min_size.GetWidth() );
758 SetSizeHints( ms.GetWidth(), ms.GetHeight() );
761 /*****************************************************************************
763 *****************************************************************************/
764 void Interface::OnMenuOpen( wxMenuEvent& event )
766 #if defined( __WXMSW__ )
767 # define GetEventObject GetMenu
770 if( event.GetEventObject() == p_settings_menu )
772 p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );
774 /* Add static items */
775 p_settings_menu->AppendCheckItem( Extended_Event,
776 wxU(_("Extended &GUI\tCtrl-G") ) );
777 if( b_extra ) p_settings_menu->Check( Extended_Event, TRUE );
778 p_settings_menu->Append( Bookmarks_Event,
779 wxU(_("&Bookmarks...\tCtrl-B") ) );
780 p_settings_menu->Append( Prefs_Event,
781 wxU(_("Preference&s...\tCtrl-S")) );
784 else if( event.GetEventObject() == p_audio_menu )
786 p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
789 else if( event.GetEventObject() == p_video_menu )
791 p_video_menu = VideoMenu( p_intf, this, p_video_menu );
794 else if( event.GetEventObject() == p_navig_menu )
796 p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
799 #if defined( __WXMSW__ )
800 # undef GetEventObject
804 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
805 void Interface::OnContextMenu2(wxContextMenuEvent& event)
807 /* Only show the context menu for the main interface */
808 if( GetId() != event.GetId() )
814 if( p_intf->p_sys->pf_show_dialog )
815 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
818 void Interface::OnContextMenu(wxMouseEvent& event)
820 if( p_intf->p_sys->pf_show_dialog )
821 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
824 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
826 /* TRUE is to force the frame to close. */
830 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
833 msg.Printf( wxString(wxT("VLC media player " PACKAGE_VERSION)) +
834 wxU(_(" (wxWidgets interface)\n\n")) +
835 wxU(_("(c) 1996-2005 - the VideoLAN Team\n\n")) +
836 wxU(_("Compiled by "))+ wxU(VLC_CompileBy())+ wxU("@") +
837 wxU(VLC_CompileHost())+ wxT(".")+ wxU(VLC_CompileDomain())+ wxT(".\n") +
838 wxU(_("Compiler: "))+ wxU(VLC_Compiler())+wxT( ".\n") +
839 wxU(_("Based on SVN revision: "))+wxU(VLC_Changeset())+wxT(".\n\n") +
841 wxU( vlc_wraptext(LICENSE_MSG,WRAPCOUNT,VLC_TRUE) ) + wxT("\n\n") +
843 wxU( LICENSE_MSG ) + wxT("\n\n") +
845 wxU(_("The VideoLAN team <videolan@videolan.org>\n"
846 "http://www.videolan.org/\n\n")) );
848 wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
849 wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
852 void Interface::OnShowDialog( wxCommandEvent& event )
854 if( p_intf->p_sys->pf_show_dialog )
858 switch( event.GetId() )
860 case OpenFileSimple_Event:
861 i_id = INTF_DIALOG_FILE_SIMPLE;
864 i_id = INTF_DIALOG_FILE;
867 i_id = INTF_DIALOG_FILE;
870 i_id = INTF_DIALOG_DIRECTORY;
873 i_id = INTF_DIALOG_DISC;
876 i_id = INTF_DIALOG_NET;
878 case OpenCapture_Event:
879 i_id = INTF_DIALOG_CAPTURE;
882 i_id = INTF_DIALOG_SAT;
885 i_id = INTF_DIALOG_PLAYLIST;
888 i_id = INTF_DIALOG_MESSAGES;
891 i_id = INTF_DIALOG_FILEINFO;
894 i_id = INTF_DIALOG_PREFS;
897 i_id = INTF_DIALOG_WIZARD;
899 case Bookmarks_Event:
900 i_id = INTF_DIALOG_BOOKMARKS;
902 case UpdateVLC_Event:
903 i_id = INTF_DIALOG_UPDATEVLC;
906 i_id = INTF_DIALOG_VLM;
909 i_id = INTF_DIALOG_FILE;
913 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
917 void Interface::OnExtended( wxCommandEvent& WXUNUSED(event) )
919 UpdateVideoWindow( p_intf, video_window );
923 /* Create the extra panel */
924 extra_frame = new ExtraPanel( p_intf, main_panel );
925 panel_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
926 ext_min_size = extra_frame->GetBestSize();
930 panel_sizer->Show( extra_frame, b_extra );
933 main_sizer->Layout();
934 main_sizer->Fit( this );
937 void Interface::OnSmallPlaylist( wxCommandEvent& WXUNUSED(event) )
939 UpdateVideoWindow( p_intf, video_window );
941 if( !playlist_manager )
943 /* Create the extra panel */
944 playlist_manager = new PlaylistManager( p_intf, splitter );
947 if( !splitter->IsSplit() ) splitter->Split( main_panel, playlist_manager );
948 else splitter->Unsplit( playlist_manager );
951 main_sizer->Layout();
952 main_sizer->Fit( this );
955 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
960 void Interface::PlayStream()
962 wxCommandEvent dummy;
963 playlist_t *p_playlist =
964 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
966 if( p_playlist == NULL ) return;
968 if( p_playlist->i_size && p_playlist->i_enabled )
972 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
975 if( p_input == NULL )
977 /* No stream was playing, start one */
978 playlist_Play( p_playlist );
979 vlc_object_release( p_playlist );
980 input_manager->Update();
984 var_Get( p_input, "state", &state );
985 if( state.i_int != PAUSE_S )
987 /* A stream is being played, pause it */
988 state.i_int = PAUSE_S;
992 /* Stream is paused, resume it */
993 state.i_int = PLAYING_S;
995 var_Set( p_input, "state", state );
997 vlc_object_release( p_input );
998 vlc_object_release( p_playlist );
999 input_manager->Update();
1003 /* If the playlist is empty, open a file requester instead */
1004 vlc_object_release( p_playlist );
1005 OnShowDialog( dummy );
1009 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
1013 void Interface::StopStream()
1015 playlist_t * p_playlist =
1016 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1018 if( p_playlist == NULL )
1023 playlist_Stop( p_playlist );
1024 vlc_object_release( p_playlist );
1025 input_manager->Update();
1028 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
1033 void Interface::PrevStream()
1035 playlist_t * p_playlist =
1036 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1038 if( p_playlist == NULL )
1043 playlist_Prev( p_playlist );
1044 vlc_object_release( p_playlist );
1047 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1052 void Interface::NextStream()
1054 playlist_t * p_playlist =
1055 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1057 if( p_playlist == NULL )
1061 playlist_Next( p_playlist );
1062 vlc_object_release( p_playlist );
1065 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1067 input_thread_t *p_input =
1068 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1072 vlc_value_t val; val.b_bool = VLC_TRUE;
1074 var_Set( p_input, "rate-slower", val );
1075 vlc_object_release( p_input );
1079 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1081 input_thread_t *p_input =
1082 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1086 vlc_value_t val; val.b_bool = VLC_TRUE;
1088 var_Set( p_input, "rate-faster", val );
1089 vlc_object_release( p_input );
1093 void Interface::TogglePlayButton( int i_playing_status )
1095 wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
1096 GetToolBar()->GetToolClientData( PlayStream_Event );
1097 if( !p_tool ) return;
1099 if( i_playing_status == PLAYING_S )
1101 p_tool->SetNormalBitmap( wxBitmap( pause_xpm ) );
1102 p_tool->SetLabel( wxU(_("Pause")) );
1103 p_tool->SetShortHelp( wxU(_(HELP_PAUSE)) );
1107 p_tool->SetNormalBitmap( wxBitmap( play_xpm ) );
1108 p_tool->SetLabel( wxU(_("Play")) );
1109 p_tool->SetShortHelp( wxU(_(HELP_PLAY)) );
1112 GetToolBar()->Realize();
1114 #if defined( __WXMSW__ )
1115 /* Needed to work around a bug in wxToolBar::Realize() */
1116 GetToolBar()->SetSize( GetSize().GetWidth(),
1117 GetToolBar()->GetSize().GetHeight() );
1118 GetToolBar()->Update();
1121 GetToolBar()->ToggleTool( PlayStream_Event, true );
1122 GetToolBar()->ToggleTool( PlayStream_Event, false );
1125 #if wxUSE_DRAG_AND_DROP
1126 /*****************************************************************************
1127 * Definition of DragAndDrop class.
1128 *****************************************************************************/
1129 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
1132 b_enqueue = _b_enqueue;
1135 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1136 const wxArrayString& filenames )
1138 /* Add dropped files to the playlist */
1140 playlist_t *p_playlist =
1141 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1143 if( p_playlist == NULL )
1148 for( size_t i = 0; i < filenames.GetCount(); i++ )
1150 char *psz_utf8 = wxFromLocale( filenames[i] );
1152 playlist_Add( p_playlist, psz_utf8, psz_utf8,
1153 PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
1155 wxLocaleFree( psz_utf8 );
1158 vlc_object_release( p_playlist );
1164 /*****************************************************************************
1165 * Definition of VolCtrl class.
1166 *****************************************************************************/
1167 class wxVolCtrl: public wxGauge
1171 wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1172 wxPoint = wxDefaultPosition, wxSize = wxSize( 20, -1 ) );
1173 virtual ~wxVolCtrl() {};
1175 void UpdateVolume();
1178 void OnChange( wxMouseEvent& event );
1181 intf_thread_t *p_intf;
1183 DECLARE_EVENT_TABLE();
1186 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
1188 EVT_LEFT_DOWN(wxVolCtrl::OnChange)
1189 EVT_MOTION(wxVolCtrl::OnChange)
1192 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1193 wxPoint point, wxSize size )
1194 : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
1200 void wxVolCtrl::OnChange( wxMouseEvent& event )
1202 if( !event.LeftDown() && !event.LeftIsDown() ) return;
1204 int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
1205 aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1209 void wxVolCtrl::UpdateVolume()
1211 audio_volume_t i_volume;
1212 aout_VolumeGet( p_intf, &i_volume );
1214 int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
1215 if( i_gauge_volume == GetValue() ) return;
1217 SetValue( i_gauge_volume );
1218 SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
1219 i_gauge_volume / 2 ) );
1222 #if defined(__WXGTK__)
1223 #define VLCVOL_HEIGHT p_parent->GetSize().GetHeight()
1225 #define VLCVOL_HEIGHT TOOLBAR_BMP_HEIGHT
1227 VLCVolCtrl::VLCVolCtrl( intf_thread_t *_p_intf, wxWindow *p_parent )
1228 :wxControl( p_parent, -1, wxDefaultPosition, wxSize(64, VLCVOL_HEIGHT ),
1230 i_y_offset((VLCVOL_HEIGHT - TOOLBAR_BMP_HEIGHT) / 2),
1231 b_mute(0), p_intf(_p_intf)
1233 gauge = new wxVolCtrl( p_intf, this, -1, wxPoint( 18, i_y_offset ),
1234 wxSize( 44, TOOLBAR_BMP_HEIGHT ) );
1237 void VLCVolCtrl::OnPaint( wxPaintEvent &evt )
1239 wxPaintDC dc( this );
1240 wxBitmap mPlayBitmap( b_mute ? speaker_mute_xpm : speaker_xpm );
1241 dc.DrawBitmap( mPlayBitmap, 0, i_y_offset, TRUE );
1244 void VLCVolCtrl::OnChange( wxMouseEvent& event )
1246 if( event.GetX() < TOOLBAR_BMP_WIDTH )
1249 aout_VolumeMute( p_intf, (audio_volume_t *)&i_volume );
1256 void VLCVolCtrl::UpdateVolume()
1258 gauge->UpdateVolume();
1260 int i_volume = gauge->GetValue();
1261 if( !!i_volume == !b_mute ) return;
1266 /*****************************************************************************
1268 *****************************************************************************/
1270 #ifdef wxHAS_TASK_BAR_ICON
1272 BEGIN_EVENT_TABLE(Systray, wxTaskBarIcon)
1275 EVT_TASKBAR_LEFT_DCLICK(Systray::OnLeftClick)
1277 EVT_TASKBAR_LEFT_DOWN(Systray::OnLeftClick)
1280 EVT_MENU(Iconize_Event, Systray::OnMenuIconize)
1281 EVT_MENU(Exit_Event, Systray::OnExit)
1282 EVT_MENU(PlayStream_Event, Systray::OnPlayStream)
1283 EVT_MENU(NextStream_Event, Systray::OnNextStream)
1284 EVT_MENU(PrevStream_Event, Systray::OnPrevStream)
1285 EVT_MENU(StopStream_Event, Systray::OnStopStream)
1288 Systray::Systray( Interface *_p_main_interface, intf_thread_t *_p_intf )
1290 p_main_interface = _p_main_interface;
1293 SetIcon( wxIcon( vlc16x16_xpm ), wxT("VLC media player") );
1294 if( !IsOk() || !IsIconInstalled() )
1296 msg_Warn(p_intf, "cannot set systray icon, weird things may happen");
1300 /* Event handlers */
1301 void Systray::OnMenuIconize( wxCommandEvent& event )
1303 p_main_interface->Show( ! p_main_interface->IsShown() );
1304 if ( p_main_interface->IsShown() ) p_main_interface->Raise();
1307 void Systray::OnLeftClick( wxTaskBarIconEvent& event )
1309 wxCommandEvent cevent;
1310 OnMenuIconize(cevent);
1313 void Systray::OnExit( wxCommandEvent& event )
1315 p_main_interface->Close(TRUE);
1318 void Systray::OnPrevStream( wxCommandEvent& event )
1320 p_main_interface->PrevStream();
1323 void Systray::OnNextStream( wxCommandEvent& event )
1325 p_main_interface->NextStream();
1328 void Systray::OnPlayStream( wxCommandEvent& event )
1330 p_main_interface->PlayStream();
1333 void Systray::OnStopStream( wxCommandEvent& event )
1335 p_main_interface->StopStream();
1338 /* Systray popup menu */
1339 wxMenu* Systray::CreatePopupMenu()
1341 int minimal = config_GetInt( p_intf, "wx-minimal" );
1343 wxMenu* systray_menu = new wxMenu;
1344 systray_menu->Append( Exit_Event, wxU(_("Quit VLC")) );
1345 systray_menu->AppendSeparator();
1346 systray_menu->Append( PlayStream_Event, wxU(_("Play/Pause")) );
1350 systray_menu->Append( PrevStream_Event, wxU(_("Previous")) );
1351 systray_menu->Append( NextStream_Event, wxU(_("Next")) );
1352 systray_menu->Append( StopStream_Event, wxU(_("Stop")) );
1354 systray_menu->AppendSeparator();
1355 systray_menu->Append( Iconize_Event, wxU(_("Show/Hide interface")) );
1356 return systray_menu;
1359 void Systray::UpdateTooltip( const wxChar* tooltip )
1361 SetIcon( wxIcon( vlc16x16_xpm ), tooltip );