1 /*****************************************************************************
2 * interface.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2005 VideoLAN
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 *****************************************************************************/
30 #include <vlc/input.h>
33 #include "wxwindows.h"
35 /* include the toolbar graphics */
36 #include "bitmaps/play.xpm"
37 #include "bitmaps/pause.xpm"
38 #include "bitmaps/stop.xpm"
39 #include "bitmaps/prev.xpm"
40 #include "bitmaps/next.xpm"
41 #include "bitmaps/eject.xpm"
42 #include "bitmaps/slow.xpm"
43 #include "bitmaps/fast.xpm"
44 #include "bitmaps/playlist.xpm"
45 #include "bitmaps/speaker.xpm"
47 #define TOOLBAR_BMP_WIDTH 16
48 #define TOOLBAR_BMP_HEIGHT 16
50 /* include the icon graphic */
51 #include "../../../share/vlc32x32.xpm"
53 /*****************************************************************************
54 * Local class declarations.
55 *****************************************************************************/
56 class wxMenuExt: public wxMenu
60 wxMenuExt( wxMenu* parentMenu, int id, const wxString& text,
61 const wxString& helpString, wxItemKind kind,
62 char *_psz_var, int _i_object_id, vlc_value_t _val,
65 virtual ~wxMenuExt() {};
76 class wxVolCtrl: public wxGauge
80 wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
81 wxPoint = wxDefaultPosition, wxSize = wxSize( 20, -1 ) );
82 virtual ~wxVolCtrl() {};
86 void OnChange( wxMouseEvent& event );
89 intf_thread_t *p_intf;
91 DECLARE_EVENT_TABLE();
94 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
96 EVT_LEFT_DOWN(wxVolCtrl::OnChange)
97 EVT_MOTION(wxVolCtrl::OnChange)
100 /*****************************************************************************
102 *****************************************************************************/
104 DEFINE_LOCAL_EVENT_TYPE( wxEVT_INTF );
106 /* IDs for the controls and the menu commands */
110 MenuDummy_Event = wxID_HIGHEST + 1000,
111 Exit_Event = wxID_HIGHEST,
112 OpenFileSimple_Event,
146 /* it is important for the id corresponding to the "About" command to have
147 * this standard value as otherwise it won't be handled properly under Mac
148 * (where it is special and put into the "Apple" menu) */
149 About_Event = wxID_ABOUT
152 BEGIN_EVENT_TABLE(Interface, wxFrame)
154 EVT_MENU(Exit_Event, Interface::OnExit)
155 EVT_MENU(About_Event, Interface::OnAbout)
157 EVT_MENU(Playlist_Event, Interface::OnShowDialog)
158 EVT_MENU(Logs_Event, Interface::OnShowDialog)
159 EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
160 EVT_MENU(Prefs_Event, Interface::OnShowDialog)
162 EVT_MENU_OPEN(Interface::OnMenuOpen)
164 EVT_MENU( Extended_Event, Interface::OnExtended )
165 // EVT_MENU( Undock_Event, Interface::OnUndock )
167 EVT_MENU( Bookmarks_Event, Interface::OnShowDialog)
169 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
170 EVT_CONTEXT_MENU(Interface::OnContextMenu2)
172 EVT_RIGHT_UP(Interface::OnContextMenu)
175 EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
176 EVT_MENU(OpenAdv_Event, Interface::OnShowDialog)
177 EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
178 EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
179 EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
180 EVT_MENU(OpenCapture_Event, Interface::OnShowDialog)
181 EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
182 EVT_MENU(Wizard_Event, Interface::OnShowDialog)
183 EVT_MENU(StopStream_Event, Interface::OnStopStream)
184 EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
185 EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
186 EVT_MENU(NextStream_Event, Interface::OnNextStream)
187 EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
188 EVT_MENU(FastStream_Event, Interface::OnFastStream)
190 /* Disc Buttons events */
191 EVT_BUTTON(DiscMenu_Event, Interface::OnDiscMenu)
192 EVT_BUTTON(DiscPrev_Event, Interface::OnDiscPrev)
193 EVT_BUTTON(DiscNext_Event, Interface::OnDiscNext)
196 EVT_COMMAND_SCROLL(SliderScroll_Event, Interface::OnSliderUpdate)
199 EVT_COMMAND(0, wxEVT_INTF, Interface::OnControlEvent)
200 EVT_COMMAND(1, wxEVT_INTF, Interface::OnControlEvent)
204 /*****************************************************************************
206 *****************************************************************************/
207 Interface::Interface( intf_thread_t *_p_intf ):
208 wxFrame( NULL, -1, wxT("VLC media player"),
209 wxDefaultPosition, wxSize(700,100), wxDEFAULT_FRAME_STYLE )
211 /* Initializations */
213 i_old_playing_status = PAUSE_S;
215 // b_undock = VLC_FALSE;
219 /* Give our interface a nice little icon */
220 SetIcon( wxIcon( vlc_xpm ) );
222 /* Create a sizer for the main frame */
223 frame_sizer = new wxBoxSizer( wxVERTICAL );
224 SetSizer( frame_sizer );
226 /* Create a dummy widget that can get the keyboard focus */
227 wxWindow *p_dummy = new wxWindow( this, 0, wxDefaultPosition,
230 frame_sizer->Add( p_dummy, 0, 0 );
232 /* Creation of the menu bar */
235 /* Creation of the tool bar */
238 /* Create the extra panel */
239 extra_frame = new ExtraPanel( p_intf, this );
240 frame_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
241 frame_sizer->Hide( extra_frame );
243 /* Creation of the status bar
244 * Helptext for menu items and toolbar tools will automatically get
246 int i_status_width[3] = {-6, -2, -9};
247 statusbar = CreateStatusBar( 3 ); /* 2 fields */
248 statusbar->SetStatusWidths( 3, i_status_width );
249 statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
252 if( config_GetInt( p_intf, "wxwin-embed" ) )
254 CreateVideoWindow( p_intf, this );
255 frame_sizer->Add( p_intf->p_sys->p_video_sizer, 1, wxEXPAND , 0 );
258 /* Creation of the slider sub-window */
260 frame_sizer->Add( slider_frame, 0, wxEXPAND , 0 );
261 frame_sizer->Hide( slider_frame );
263 /* Make sure we've got the right background colour */
264 SetBackgroundColour( slider_frame->GetBackgroundColour() );
266 /* Layout everything */
267 frame_sizer->Layout();
268 frame_sizer->Fit(this);
270 #if wxUSE_DRAG_AND_DROP
271 /* Associate drop targets with the main interface */
272 SetDropTarget( new DragAndDrop( p_intf ) );
278 timer = new Timer( p_intf, this );
281 Interface::~Interface()
283 if( p_intf->p_sys->p_wxwindow )
285 delete p_intf->p_sys->p_wxwindow;
292 void Interface::Init()
298 void Interface::Update()
301 ((wxVolCtrl *)volctrl)->UpdateVolume();
304 void Interface::OnControlEvent( wxCommandEvent& event )
306 switch( event.GetId() )
309 frame_sizer->Layout();
310 frame_sizer->Fit(this);
314 long i_style = GetWindowStyle();
315 if( event.GetInt() ) i_style |= wxSTAY_ON_TOP;
316 else i_style &= ~wxSTAY_ON_TOP;
317 SetWindowStyle( i_style );
322 /*****************************************************************************
324 *****************************************************************************/
325 void Interface::CreateOurMenuBar()
327 /* Create the "File" menu */
328 wxMenu *file_menu = new wxMenu;
329 file_menu->Append( OpenFileSimple_Event,
330 wxU(_("Quick &Open File...\tCtrl-O")) );
332 file_menu->AppendSeparator();
333 file_menu->Append( OpenFile_Event, wxU(_("Open &File...\tCtrl-F")) );
334 file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...\tCtrl-D")) );
335 file_menu->Append( OpenNet_Event,
336 wxU(_("Open &Network Stream...\tCtrl-N")) );
337 file_menu->Append( OpenCapture_Event,
338 wxU(_("Open &Capture Device...\tCtrl-C")) );
340 file_menu->AppendSeparator();
341 file_menu->Append( Wizard_Event, wxU(_("&Wizard...\tCtrl-W")) );
342 file_menu->AppendSeparator();
343 file_menu->Append( Exit_Event, wxU(_("E&xit\tCtrl-X")) );
345 /* Create the "View" menu */
346 wxMenu *view_menu = new wxMenu;
347 view_menu->Append( Playlist_Event, wxU(_("&Playlist...\tCtrl-P")) );
348 view_menu->Append( Logs_Event, wxU(_("&Messages...\tCtrl-M")) );
349 view_menu->Append( FileInfo_Event,
350 wxU(_("Stream and Media &info...\tCtrl-I")) );
352 /* Create the "Auto-generated" menus */
353 p_settings_menu = SettingsMenu( p_intf, this );
354 p_audio_menu = AudioMenu( p_intf, this );
355 p_video_menu = VideoMenu( p_intf, this );
356 p_navig_menu = NavigMenu( p_intf, this );
358 /* Create the "Help" menu */
359 wxMenu *help_menu = new wxMenu;
360 help_menu->Append( About_Event, wxU(_("About VLC media player")) );
362 /* Append the freshly created menus to the menu bar... */
363 wxMenuBar *menubar = new wxMenuBar();
364 menubar->Append( file_menu, wxU(_("&File")) );
365 menubar->Append( view_menu, wxU(_("&View")) );
366 menubar->Append( p_settings_menu, wxU(_("&Settings")) );
367 menubar->Append( p_audio_menu, wxU(_("&Audio")) );
368 menubar->Append( p_video_menu, wxU(_("&Video")) );
369 menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
370 menubar->Append( help_menu, wxU(_("&Help")) );
372 /* Attach the menu bar to the frame */
373 SetMenuBar( menubar );
375 /* Find out size of menu bar */
377 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
379 int i_width, i_height;
380 menubar->GetTextExtent( menubar->GetLabelTop(i), &i_width, &i_height );
382 #if defined(__WXGTK__)
383 22 /* approximate margin */;
385 #if (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 5) && (wxRELEASE_NUMBER < 3)
386 4 /* approximate margin */;
388 18 /* approximate margin */;
392 frame_sizer->SetMinSize( i_size, -1 );
394 /* Intercept all menu events in our custom event handler */
395 PushEventHandler( new MenuEvtHandler( p_intf, this ) );
397 #if wxUSE_DRAG_AND_DROP
398 /* Associate drop targets with the menubar */
399 menubar->SetDropTarget( new DragAndDrop( p_intf ) );
403 class VLCVolCtrl : public wxControl
406 VLCVolCtrl( intf_thread_t *p_intf, wxWindow *p_parent, wxGauge ** );
407 virtual ~VLCVolCtrl() {};
409 virtual void OnPaint( wxPaintEvent &event );
412 DECLARE_EVENT_TABLE()
416 BEGIN_EVENT_TABLE(VLCVolCtrl, wxControl)
417 EVT_PAINT(VLCVolCtrl::OnPaint)
420 #if defined(__WXGTK__)
421 #define VLCVOL_HEIGHT p_parent->GetSize().GetHeight()
423 #define VLCVOL_HEIGHT TOOLBAR_BMP_HEIGHT
425 VLCVolCtrl::VLCVolCtrl( intf_thread_t *p_intf, wxWindow *p_parent,
426 wxGauge **pp_volctrl )
427 :wxControl( p_parent, -1, wxDefaultPosition, wxSize(64, VLCVOL_HEIGHT ),
429 i_y_offset((VLCVOL_HEIGHT - TOOLBAR_BMP_HEIGHT) / 2)
431 *pp_volctrl = new wxVolCtrl( p_intf, this, -1, wxPoint( 18, i_y_offset ),
432 wxSize( 44, TOOLBAR_BMP_HEIGHT ) );
435 void VLCVolCtrl::OnPaint( wxPaintEvent &evt )
437 wxPaintDC dc( this );
438 wxBitmap mPlayBitmap( speaker_xpm );
439 dc.DrawBitmap( mPlayBitmap, 0, i_y_offset, TRUE );
442 void Interface::CreateOurToolBar()
444 #define HELP_OPEN N_("Open")
445 #define HELP_STOP N_("Stop")
446 #define HELP_PLAY N_("Play")
447 #define HELP_PAUSE N_("Pause")
448 #define HELP_PLO N_("Playlist")
449 #define HELP_PLP N_("Previous playlist item")
450 #define HELP_PLN N_("Next playlist item")
451 #define HELP_SLOW N_("Play slower")
452 #define HELP_FAST N_("Play faster")
454 wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
455 * version because we don't include wx.rc */
458 CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
460 toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
462 toolbar->AddTool( OpenFile_Event, wxT(""),
463 wxBitmap( eject_xpm ), wxU(_(HELP_OPEN)) );
464 toolbar->AddSeparator();
466 wxToolBarToolBase *p_tool = toolbar->AddTool( PlayStream_Event, wxT(""),
467 wxBitmap( play_xpm ), wxU(_(HELP_PLAY)) );
468 p_tool->SetClientData( p_tool );
470 toolbar->AddTool( StopStream_Event, wxT(""), wxBitmap( stop_xpm ),
472 toolbar->AddSeparator();
473 toolbar->AddTool( PrevStream_Event, wxT(""),
474 wxBitmap( prev_xpm ), wxU(_(HELP_PLP)) );
475 toolbar->AddTool( SlowStream_Event, wxT(""),
476 wxBitmap( slow_xpm ), wxU(_(HELP_SLOW)) );
477 toolbar->AddTool( FastStream_Event, wxT(""),
478 wxBitmap( fast_xpm ), wxU(_(HELP_FAST)) );
479 toolbar->AddTool( NextStream_Event, wxT(""), wxBitmap( next_xpm ),
481 toolbar->AddSeparator();
482 toolbar->AddTool( Playlist_Event, wxT(""), wxBitmap( playlist_xpm ),
485 wxControl *p_dummy_ctrl =
486 new wxControl( toolbar, -1, wxDefaultPosition,
487 wxSize(35, 16 ), wxBORDER_NONE );
489 toolbar->AddControl( p_dummy_ctrl );
491 VLCVolCtrl *sound_control = new VLCVolCtrl( p_intf, toolbar, &volctrl );
492 toolbar->AddControl( sound_control );
496 #if wxUSE_DRAG_AND_DROP
497 /* Associate drop targets with the toolbar */
498 toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
502 void Interface::CreateOurSlider()
504 /* Create a new frame and sizer containing the slider */
505 slider_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
506 slider_frame->SetAutoLayout( TRUE );
507 slider_sizer = new wxBoxSizer( wxHORIZONTAL );
508 //slider_sizer->SetMinSize( -1, 50 );
511 slider = new wxSlider( slider_frame, SliderScroll_Event, 0, 0,
512 SLIDER_MAX_POS, wxDefaultPosition, wxDefaultSize );
514 /* Add Disc Buttons */
515 disc_frame = new wxPanel( slider_frame, -1, wxDefaultPosition,
517 disc_frame->SetAutoLayout( TRUE );
518 disc_sizer = new wxBoxSizer( wxHORIZONTAL );
520 disc_menu_button = new wxBitmapButton( disc_frame, DiscMenu_Event,
521 wxBitmap( playlist_xpm ) );
522 disc_prev_button = new wxBitmapButton( disc_frame, DiscPrev_Event,
523 wxBitmap( prev_xpm ) );
524 disc_next_button = new wxBitmapButton( disc_frame, DiscNext_Event,
525 wxBitmap( next_xpm ) );
527 disc_sizer->Add( disc_menu_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
528 disc_sizer->Add( disc_prev_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
529 disc_sizer->Add( disc_next_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
531 disc_frame->SetSizer( disc_sizer );
532 disc_sizer->Layout();
534 /* Add everything to the frame */
535 slider_sizer->Add( slider, 1, wxEXPAND | wxALL, 5 );
536 slider_sizer->Add( disc_frame, 0, wxALL, 2 );
537 slider_frame->SetSizer( slider_sizer );
540 slider_sizer->Hide( disc_frame );
542 slider_sizer->Layout();
543 slider_sizer->Fit( slider_frame );
545 /* Hide the slider by default */
546 slider_frame->Hide();
549 static int ConvertHotkeyModifiers( int i_hotkey )
551 int i_accel_flags = 0;
552 if( i_hotkey & KEY_MODIFIER_ALT ) i_accel_flags |= wxACCEL_ALT;
553 if( i_hotkey & KEY_MODIFIER_CTRL ) i_accel_flags |= wxACCEL_CTRL;
554 if( i_hotkey & KEY_MODIFIER_SHIFT ) i_accel_flags |= wxACCEL_SHIFT;
555 if( !i_accel_flags ) i_accel_flags = wxACCEL_NORMAL;
556 return i_accel_flags;
559 static int ConvertHotkey( int i_hotkey )
561 int i_key = i_hotkey & ~KEY_MODIFIER;
562 if( i_key & KEY_ASCII ) return i_key & KEY_ASCII;
563 else if( i_key & KEY_SPECIAL )
567 case KEY_LEFT: return WXK_LEFT;
568 case KEY_RIGHT: return WXK_RIGHT;
569 case KEY_UP: return WXK_UP;
570 case KEY_DOWN: return WXK_DOWN;
571 case KEY_SPACE: return WXK_SPACE;
572 case KEY_ENTER: return WXK_RETURN;
573 case KEY_F1: return WXK_F1;
574 case KEY_F2: return WXK_F2;
575 case KEY_F3: return WXK_F3;
576 case KEY_F4: return WXK_F4;
577 case KEY_F5: return WXK_F5;
578 case KEY_F6: return WXK_F6;
579 case KEY_F7: return WXK_F7;
580 case KEY_F8: return WXK_F8;
581 case KEY_F9: return WXK_F9;
582 case KEY_F10: return WXK_F10;
583 case KEY_F11: return WXK_F11;
584 case KEY_F12: return WXK_F12;
585 case KEY_HOME: return WXK_HOME;
586 case KEY_END: return WXK_HOME;
587 case KEY_MENU: return WXK_MENU;
588 case KEY_ESC: return WXK_ESCAPE;
589 case KEY_PAGEUP: return WXK_PRIOR;
590 case KEY_PAGEDOWN: return WXK_NEXT;
591 case KEY_TAB: return WXK_TAB;
592 case KEY_BACKSPACE: return WXK_BACK;
598 void Interface::SetupHotkeys()
600 struct vlc_t::hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
603 /* Count number of hoteys */
604 for( i_hotkeys = 0; p_hotkeys[i_hotkeys].psz_action != NULL; i_hotkeys++ );
606 p_intf->p_sys->i_first_hotkey_event = wxID_HIGHEST + 7000;
607 p_intf->p_sys->i_hotkeys = i_hotkeys;
609 wxAcceleratorEntry *p_entries = new wxAcceleratorEntry[i_hotkeys];
611 /* Setup the hotkeys as accelerators */
612 for( int i = 0; i < i_hotkeys; i++ )
614 int i_mod = ConvertHotkeyModifiers( p_hotkeys[i].i_key );
615 int i_key = ConvertHotkey( p_hotkeys[i].i_key );
618 if( i_mod ) i_key = toupper(i_key);
621 p_entries[i].Set( i_mod, i_key,
622 p_intf->p_sys->i_first_hotkey_event + i );
625 wxAcceleratorTable accel( i_hotkeys, p_entries );
629 msg_Err( p_intf, "invalid accelerator table" );
633 SetAcceleratorTable( accel );
639 /*****************************************************************************
641 *****************************************************************************/
643 void Interface::OnMenuOpen(wxMenuEvent& event)
645 #if defined( __WXMSW__ )
646 # define GetEventObject GetMenu
649 if( event.GetEventObject() == p_settings_menu )
651 p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );
653 /* Add static items */
654 p_settings_menu->AppendCheckItem( Extended_Event,
655 wxU(_("&Extended GUI") ) );
656 if( b_extra ) p_settings_menu->Check( Extended_Event, TRUE );
658 p_settings_menu->AppendCheckItem( Undock_Event,
659 wxU(_("&Undock Ext. GUI") ) );
660 if( b_undock ) p_settings_menu->Check( Undock_Event, TRUE );
662 p_settings_menu->Append( Bookmarks_Event, wxU(_("&Bookmarks...") ) );
663 p_settings_menu->Append( Prefs_Event, wxU(_("&Preferences...")) );
666 else if( event.GetEventObject() == p_audio_menu )
668 p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
671 else if( event.GetEventObject() == p_video_menu )
673 p_video_menu = VideoMenu( p_intf, this, p_video_menu );
676 else if( event.GetEventObject() == p_navig_menu )
678 p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
681 #if defined( __WXMSW__ )
682 # undef GetEventObject
686 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
687 void Interface::OnContextMenu2(wxContextMenuEvent& event)
689 /* Only show the context menu for the main interface */
690 if( GetId() != event.GetId() )
696 if( p_intf->p_sys->pf_show_dialog )
697 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
700 void Interface::OnContextMenu(wxMouseEvent& event)
702 if( p_intf->p_sys->pf_show_dialog )
703 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
706 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
708 /* TRUE is to force the frame to close. */
712 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
715 msg.Printf( wxString(wxT("VLC media player " PACKAGE_VERSION)) +
716 wxU(_(" (wxWindows interface)\n\n")) +
717 wxU(_("(c) 1996-2005 - the VideoLAN Team\n\n")) +
718 wxU( vlc_wraptext(INTF_ABOUT_MSG,WRAPCOUNT,ISUTF8) ) + wxT("\n\n") +
719 wxU(_("The VideoLAN team <videolan@videolan.org>\n"
720 "http://www.videolan.org/\n\n")) );
722 wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
723 wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
726 void Interface::OnShowDialog( wxCommandEvent& event )
728 if( p_intf->p_sys->pf_show_dialog )
732 switch( event.GetId() )
734 case OpenFileSimple_Event:
735 i_id = INTF_DIALOG_FILE_SIMPLE;
738 i_id = INTF_DIALOG_FILE;
740 i_id = INTF_DIALOG_FILE;
743 i_id = INTF_DIALOG_DISC;
746 i_id = INTF_DIALOG_NET;
748 case OpenCapture_Event:
749 i_id = INTF_DIALOG_CAPTURE;
752 i_id = INTF_DIALOG_SAT;
755 i_id = INTF_DIALOG_PLAYLIST;
758 i_id = INTF_DIALOG_MESSAGES;
761 i_id = INTF_DIALOG_FILEINFO;
764 i_id = INTF_DIALOG_PREFS;
767 i_id = INTF_DIALOG_WIZARD;
769 case Bookmarks_Event:
770 i_id = INTF_DIALOG_BOOKMARKS;
773 i_id = INTF_DIALOG_FILE;
777 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
781 void Interface::OnExtended(wxCommandEvent& event)
783 b_extra = (b_extra == VLC_TRUE ? VLC_FALSE : VLC_TRUE );
785 if( b_extra == VLC_FALSE )
788 frame_sizer->Hide( extra_frame );
793 frame_sizer->Show( extra_frame );
795 frame_sizer->Layout();
796 frame_sizer->Fit(this);
800 if( b_undock == VLC_TRUE )
802 fprintf(stderr,"Deleting window\n");
812 frame_sizer->Hide( extra_frame );
813 frame_sizer->Layout();
814 frame_sizer->Fit(this);
819 if( b_undock == VLC_TRUE )
821 fprintf(stderr,"Creating window\n");
823 frame_sizer->Hide( extra_frame );
824 frame_sizer->Detach( extra_frame );
825 frame_sizer->Layout();
826 frame_sizer->Fit(this);
827 extra_window = new ExtraWindow( p_intf, this, extra_frame );
831 fprintf(stderr,"Deleting window\n");
837 frame_sizer->Show( extra_frame );
838 frame_sizer->Layout();
839 frame_sizer->Fit(this);
844 void Interface::OnUndock(wxCommandEvent& event)
846 b_undock = (b_undock == VLC_TRUE ? VLC_FALSE : VLC_TRUE );
848 if( b_extra == VLC_TRUE )
850 if( b_undock == VLC_FALSE )
852 fprintf(stderr,"Deleting window\n");
859 frame_sizer->Show( extra_frame );
860 frame_sizer->Layout();
861 frame_sizer->Fit(this);
865 fprintf(stderr,"Creating window\n");
867 frame_sizer->Hide( extra_frame );
868 frame_sizer->Detach( extra_frame );
869 frame_sizer->Layout();
870 frame_sizer->Fit(this);
871 extra_window = new ExtraWindow( p_intf, this, extra_frame );
877 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
879 wxCommandEvent dummy;
880 playlist_t *p_playlist =
881 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
883 if( p_playlist == NULL ) return;
885 if( p_playlist->i_size && p_playlist->i_enabled )
889 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
892 if( p_input == NULL )
894 /* No stream was playing, start one */
895 playlist_Play( p_playlist );
896 TogglePlayButton( PLAYING_S );
897 vlc_object_release( p_playlist );
901 var_Get( p_input, "state", &state );
903 if( state.i_int != PAUSE_S )
905 /* A stream is being played, pause it */
906 state.i_int = PAUSE_S;
910 /* Stream is paused, resume it */
911 state.i_int = PLAYING_S;
913 var_Set( p_input, "state", state );
915 TogglePlayButton( state.i_int );
916 vlc_object_release( p_input );
917 vlc_object_release( p_playlist );
921 /* If the playlist is empty, open a file requester instead */
922 vlc_object_release( p_playlist );
923 OnShowDialog( dummy );
927 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
929 playlist_t * p_playlist =
930 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
932 if( p_playlist == NULL )
937 playlist_Stop( p_playlist );
938 TogglePlayButton( PAUSE_S );
939 vlc_object_release( p_playlist );
942 void Interface::OnSliderUpdate( wxScrollEvent& event )
944 vlc_mutex_lock( &p_intf->change_lock );
947 if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
948 || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
951 if( p_intf->p_sys->i_slider_pos != event.GetPosition()
952 && p_intf->p_sys->p_input )
955 pos.f_float = (float)event.GetPosition() / (float)SLIDER_MAX_POS;
957 var_Set( p_intf->p_sys->p_input, "position", pos );
961 p_intf->p_sys->b_slider_free = VLC_TRUE;
965 p_intf->p_sys->b_slider_free = VLC_FALSE;
967 if( p_intf->p_sys->p_input )
969 /* Update stream date */
970 char psz_time[ MSTRTIME_MAX_SIZE ], psz_total[ MSTRTIME_MAX_SIZE ];
973 i_seconds = var_GetTime( p_intf->p_sys->p_input, "length" ) /
975 secstotimestr( psz_total, i_seconds );
977 i_seconds = var_GetTime( p_intf->p_sys->p_input, "time" ) /
979 secstotimestr( psz_time, i_seconds );
981 statusbar->SetStatusText( wxU(psz_time) + wxString(wxT(" / ") ) +
988 vlc_mutex_unlock( &p_intf->change_lock );
991 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
993 playlist_t * p_playlist =
994 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
996 if( p_playlist == NULL )
1001 /* FIXME --fenrir */
1003 if( p_playlist->p_input != NULL )
1005 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1006 if( p_playlist->p_input->stream.p_selected_area->i_id > 1 )
1008 vlc_value_t val; val.b_bool = VLC_TRUE;
1009 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1010 var_Set( p_playlist->p_input, "prev-title", val );
1012 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1014 vlc_mutex_unlock( &p_playlist->object_lock );
1017 playlist_Prev( p_playlist );
1018 vlc_object_release( p_playlist );
1021 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1023 playlist_t * p_playlist =
1024 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1026 if( p_playlist == NULL )
1031 /* FIXME --fenrir */
1033 var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
1034 vlc_mutex_lock( &p_playlist->object_lock );
1035 if( p_playlist->p_input != NULL )
1037 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1038 if( p_playlist->p_input->stream.i_area_nb > 1 &&
1039 p_playlist->p_input->stream.p_selected_area->i_id <
1040 p_playlist->p_input->stream.i_area_nb - 1 )
1042 vlc_value_t val; val.b_bool = VLC_TRUE;
1043 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1044 var_Set( p_playlist->p_input, "next-title", val );
1046 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1048 vlc_mutex_unlock( &p_playlist->object_lock );
1050 playlist_Next( p_playlist );
1051 vlc_object_release( p_playlist );
1054 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1056 input_thread_t *p_input =
1057 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1061 vlc_value_t val; val.b_bool = VLC_TRUE;
1063 var_Set( p_input, "rate-slower", val );
1064 vlc_object_release( p_input );
1068 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1070 input_thread_t *p_input =
1071 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1075 vlc_value_t val; val.b_bool = VLC_TRUE;
1077 var_Set( p_input, "rate-faster", val );
1078 vlc_object_release( p_input );
1082 void Interface::TogglePlayButton( int i_playing_status )
1084 if( i_playing_status == i_old_playing_status )
1087 wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
1088 GetToolBar()->GetToolClientData( PlayStream_Event );
1089 if( !p_tool ) return;
1091 if( i_playing_status == PLAYING_S )
1093 p_tool->SetNormalBitmap( wxBitmap( pause_xpm ) );
1094 p_tool->SetLabel( wxU(_("Pause")) );
1095 p_tool->SetShortHelp( wxU(_(HELP_PAUSE)) );
1099 p_tool->SetNormalBitmap( wxBitmap( play_xpm ) );
1100 p_tool->SetLabel( wxU(_("Play")) );
1101 p_tool->SetShortHelp( wxU(_(HELP_PLAY)) );
1104 GetToolBar()->Realize();
1106 i_old_playing_status = i_playing_status;
1109 void Interface::OnDiscMenu( wxCommandEvent& WXUNUSED(event) )
1111 input_thread_t *p_input =
1112 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1116 vlc_value_t val; val.i_int = 2;
1118 var_Set( p_input, "title 0", val);
1119 vlc_object_release( p_input );
1123 void Interface::OnDiscPrev( wxCommandEvent& WXUNUSED(event) )
1125 input_thread_t *p_input =
1126 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1130 int i_type = var_Type( p_input, "prev-chapter" );
1131 vlc_value_t val; val.b_bool = VLC_TRUE;
1133 var_Set( p_input, ( i_type & VLC_VAR_TYPE ) != 0 ?
1134 "prev-chapter" : "prev-title", val );
1136 vlc_object_release( p_input );
1140 void Interface::OnDiscNext( wxCommandEvent& WXUNUSED(event) )
1142 input_thread_t *p_input =
1143 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1147 int i_type = var_Type( p_input, "next-chapter" );
1148 vlc_value_t val; val.b_bool = VLC_TRUE;
1150 var_Set( p_input, ( i_type & VLC_VAR_TYPE ) != 0 ?
1151 "next-chapter" : "next-title", val );
1153 vlc_object_release( p_input );
1157 #if wxUSE_DRAG_AND_DROP
1158 /*****************************************************************************
1159 * Definition of DragAndDrop class.
1160 *****************************************************************************/
1161 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
1164 b_enqueue = _b_enqueue;
1167 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1168 const wxArrayString& filenames )
1170 /* Add dropped files to the playlist */
1172 playlist_t *p_playlist =
1173 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1175 if( p_playlist == NULL )
1180 for( size_t i = 0; i < filenames.GetCount(); i++ )
1181 playlist_Add( p_playlist, (const char *)filenames[i].mb_str(),
1182 (const char *)filenames[i].mb_str(),
1183 PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
1186 vlc_object_release( p_playlist );
1192 /*****************************************************************************
1193 * Definition of VolCtrl class.
1194 *****************************************************************************/
1195 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1196 wxPoint point, wxSize size )
1197 : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
1203 void wxVolCtrl::OnChange( wxMouseEvent& event )
1205 if( !event.LeftDown() && !event.LeftIsDown() ) return;
1207 int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
1208 aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1212 void wxVolCtrl::UpdateVolume()
1214 audio_volume_t i_volume;
1215 aout_VolumeGet( p_intf, &i_volume );
1217 int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
1218 if( i_gauge_volume == GetValue() ) return;
1220 SetValue( i_gauge_volume );
1221 SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
1222 i_gauge_volume / 2 ) );