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 );
634 msg_Dbg( p_intf, "accelerator table loaded" );
640 /*****************************************************************************
642 *****************************************************************************/
644 void Interface::OnMenuOpen(wxMenuEvent& event)
646 #if defined( __WXMSW__ )
647 # define GetEventObject GetMenu
650 if( event.GetEventObject() == p_settings_menu )
652 p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );
654 /* Add static items */
655 p_settings_menu->AppendCheckItem( Extended_Event,
656 wxU(_("&Extended GUI") ) );
657 if( b_extra ) p_settings_menu->Check( Extended_Event, TRUE );
659 p_settings_menu->AppendCheckItem( Undock_Event,
660 wxU(_("&Undock Ext. GUI") ) );
661 if( b_undock ) p_settings_menu->Check( Undock_Event, TRUE );
663 p_settings_menu->Append( Bookmarks_Event, wxU(_("&Bookmarks...") ) );
664 p_settings_menu->Append( Prefs_Event, wxU(_("&Preferences...")) );
667 else if( event.GetEventObject() == p_audio_menu )
669 p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
672 else if( event.GetEventObject() == p_video_menu )
674 p_video_menu = VideoMenu( p_intf, this, p_video_menu );
677 else if( event.GetEventObject() == p_navig_menu )
679 p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
682 #if defined( __WXMSW__ )
683 # undef GetEventObject
687 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
688 void Interface::OnContextMenu2(wxContextMenuEvent& event)
690 /* Only show the context menu for the main interface */
691 if( GetId() != event.GetId() )
697 if( p_intf->p_sys->pf_show_dialog )
698 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
701 void Interface::OnContextMenu(wxMouseEvent& event)
703 if( p_intf->p_sys->pf_show_dialog )
704 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
707 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
709 /* TRUE is to force the frame to close. */
713 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
716 msg.Printf( wxString(wxT("VLC media player " PACKAGE_VERSION)) +
717 wxU(_(" (wxWindows interface)\n\n")) +
718 wxU(_("(c) 1996-2005 - the VideoLAN Team\n\n")) +
719 wxU( vlc_wraptext(INTF_ABOUT_MSG,WRAPCOUNT,ISUTF8) ) + wxT("\n\n") +
720 wxU(_("The VideoLAN team <videolan@videolan.org>\n"
721 "http://www.videolan.org/\n\n")) );
723 wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
724 wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
727 void Interface::OnShowDialog( wxCommandEvent& event )
729 if( p_intf->p_sys->pf_show_dialog )
733 switch( event.GetId() )
735 case OpenFileSimple_Event:
736 i_id = INTF_DIALOG_FILE_SIMPLE;
739 i_id = INTF_DIALOG_FILE;
741 i_id = INTF_DIALOG_FILE;
744 i_id = INTF_DIALOG_DISC;
747 i_id = INTF_DIALOG_NET;
749 case OpenCapture_Event:
750 i_id = INTF_DIALOG_CAPTURE;
753 i_id = INTF_DIALOG_SAT;
756 i_id = INTF_DIALOG_PLAYLIST;
759 i_id = INTF_DIALOG_MESSAGES;
762 i_id = INTF_DIALOG_FILEINFO;
765 i_id = INTF_DIALOG_PREFS;
768 i_id = INTF_DIALOG_WIZARD;
770 case Bookmarks_Event:
771 i_id = INTF_DIALOG_BOOKMARKS;
774 i_id = INTF_DIALOG_FILE;
778 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
782 void Interface::OnExtended(wxCommandEvent& event)
784 b_extra = (b_extra == VLC_TRUE ? VLC_FALSE : VLC_TRUE );
786 if( b_extra == VLC_FALSE )
789 frame_sizer->Hide( extra_frame );
794 frame_sizer->Show( extra_frame );
796 frame_sizer->Layout();
797 frame_sizer->Fit(this);
801 if( b_undock == VLC_TRUE )
803 fprintf(stderr,"Deleting window\n");
813 frame_sizer->Hide( extra_frame );
814 frame_sizer->Layout();
815 frame_sizer->Fit(this);
820 if( b_undock == VLC_TRUE )
822 fprintf(stderr,"Creating window\n");
824 frame_sizer->Hide( extra_frame );
825 frame_sizer->Detach( extra_frame );
826 frame_sizer->Layout();
827 frame_sizer->Fit(this);
828 extra_window = new ExtraWindow( p_intf, this, extra_frame );
832 fprintf(stderr,"Deleting window\n");
838 frame_sizer->Show( extra_frame );
839 frame_sizer->Layout();
840 frame_sizer->Fit(this);
845 void Interface::OnUndock(wxCommandEvent& event)
847 b_undock = (b_undock == VLC_TRUE ? VLC_FALSE : VLC_TRUE );
849 if( b_extra == VLC_TRUE )
851 if( b_undock == VLC_FALSE )
853 fprintf(stderr,"Deleting window\n");
860 frame_sizer->Show( extra_frame );
861 frame_sizer->Layout();
862 frame_sizer->Fit(this);
866 fprintf(stderr,"Creating window\n");
868 frame_sizer->Hide( extra_frame );
869 frame_sizer->Detach( extra_frame );
870 frame_sizer->Layout();
871 frame_sizer->Fit(this);
872 extra_window = new ExtraWindow( p_intf, this, extra_frame );
878 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
880 wxCommandEvent dummy;
881 playlist_t *p_playlist =
882 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
884 if( p_playlist == NULL ) return;
886 if( p_playlist->i_size && p_playlist->i_enabled )
890 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
893 if( p_input == NULL )
895 /* No stream was playing, start one */
896 playlist_Play( p_playlist );
897 TogglePlayButton( PLAYING_S );
898 vlc_object_release( p_playlist );
902 var_Get( p_input, "state", &state );
904 if( state.i_int != PAUSE_S )
906 /* A stream is being played, pause it */
907 state.i_int = PAUSE_S;
911 /* Stream is paused, resume it */
912 state.i_int = PLAYING_S;
914 var_Set( p_input, "state", state );
916 TogglePlayButton( state.i_int );
917 vlc_object_release( p_input );
918 vlc_object_release( p_playlist );
922 /* If the playlist is empty, open a file requester instead */
923 vlc_object_release( p_playlist );
924 OnShowDialog( dummy );
928 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
930 playlist_t * p_playlist =
931 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
933 if( p_playlist == NULL )
938 playlist_Stop( p_playlist );
939 TogglePlayButton( PAUSE_S );
940 vlc_object_release( p_playlist );
943 void Interface::OnSliderUpdate( wxScrollEvent& event )
945 vlc_mutex_lock( &p_intf->change_lock );
948 if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
949 || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
952 if( p_intf->p_sys->i_slider_pos != event.GetPosition()
953 && p_intf->p_sys->p_input )
956 pos.f_float = (float)event.GetPosition() / (float)SLIDER_MAX_POS;
958 var_Set( p_intf->p_sys->p_input, "position", pos );
962 p_intf->p_sys->b_slider_free = VLC_TRUE;
966 p_intf->p_sys->b_slider_free = VLC_FALSE;
968 if( p_intf->p_sys->p_input )
970 /* Update stream date */
971 char psz_time[ MSTRTIME_MAX_SIZE ], psz_total[ MSTRTIME_MAX_SIZE ];
974 i_seconds = var_GetTime( p_intf->p_sys->p_input, "length" ) /
976 secstotimestr( psz_total, i_seconds );
978 i_seconds = var_GetTime( p_intf->p_sys->p_input, "time" ) /
980 secstotimestr( psz_time, i_seconds );
982 statusbar->SetStatusText( wxU(psz_time) + wxString(wxT(" / ") ) +
989 vlc_mutex_unlock( &p_intf->change_lock );
992 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
994 playlist_t * p_playlist =
995 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
997 if( p_playlist == NULL )
1002 /* FIXME --fenrir */
1004 if( p_playlist->p_input != NULL )
1006 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1007 if( p_playlist->p_input->stream.p_selected_area->i_id > 1 )
1009 vlc_value_t val; val.b_bool = VLC_TRUE;
1010 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1011 var_Set( p_playlist->p_input, "prev-title", val );
1013 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1015 vlc_mutex_unlock( &p_playlist->object_lock );
1018 playlist_Prev( p_playlist );
1019 vlc_object_release( p_playlist );
1022 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1024 playlist_t * p_playlist =
1025 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1027 if( p_playlist == NULL )
1032 /* FIXME --fenrir */
1034 var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
1035 vlc_mutex_lock( &p_playlist->object_lock );
1036 if( p_playlist->p_input != NULL )
1038 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1039 if( p_playlist->p_input->stream.i_area_nb > 1 &&
1040 p_playlist->p_input->stream.p_selected_area->i_id <
1041 p_playlist->p_input->stream.i_area_nb - 1 )
1043 vlc_value_t val; val.b_bool = VLC_TRUE;
1044 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1045 var_Set( p_playlist->p_input, "next-title", val );
1047 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1049 vlc_mutex_unlock( &p_playlist->object_lock );
1051 playlist_Next( p_playlist );
1052 vlc_object_release( p_playlist );
1055 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1057 input_thread_t *p_input =
1058 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1062 vlc_value_t val; val.b_bool = VLC_TRUE;
1064 var_Set( p_input, "rate-slower", val );
1065 vlc_object_release( p_input );
1069 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1071 input_thread_t *p_input =
1072 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1076 vlc_value_t val; val.b_bool = VLC_TRUE;
1078 var_Set( p_input, "rate-faster", val );
1079 vlc_object_release( p_input );
1083 void Interface::TogglePlayButton( int i_playing_status )
1085 if( i_playing_status == i_old_playing_status )
1088 wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
1089 GetToolBar()->GetToolClientData( PlayStream_Event );
1090 if( !p_tool ) return;
1092 if( i_playing_status == PLAYING_S )
1094 p_tool->SetNormalBitmap( wxBitmap( pause_xpm ) );
1095 p_tool->SetLabel( wxU(_("Pause")) );
1096 p_tool->SetShortHelp( wxU(_(HELP_PAUSE)) );
1100 p_tool->SetNormalBitmap( wxBitmap( play_xpm ) );
1101 p_tool->SetLabel( wxU(_("Play")) );
1102 p_tool->SetShortHelp( wxU(_(HELP_PLAY)) );
1105 GetToolBar()->Realize();
1107 i_old_playing_status = i_playing_status;
1110 void Interface::OnDiscMenu( wxCommandEvent& WXUNUSED(event) )
1112 input_thread_t *p_input =
1113 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1117 vlc_value_t val; val.i_int = 2;
1119 var_Set( p_input, "title 0", val);
1120 vlc_object_release( p_input );
1124 void Interface::OnDiscPrev( wxCommandEvent& WXUNUSED(event) )
1126 input_thread_t *p_input =
1127 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1131 int i_type = var_Type( p_input, "prev-chapter" );
1132 vlc_value_t val; val.b_bool = VLC_TRUE;
1134 var_Set( p_input, ( i_type & VLC_VAR_TYPE ) != 0 ?
1135 "prev-chapter" : "prev-title", val );
1137 vlc_object_release( p_input );
1141 void Interface::OnDiscNext( wxCommandEvent& WXUNUSED(event) )
1143 input_thread_t *p_input =
1144 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1148 int i_type = var_Type( p_input, "next-chapter" );
1149 vlc_value_t val; val.b_bool = VLC_TRUE;
1151 var_Set( p_input, ( i_type & VLC_VAR_TYPE ) != 0 ?
1152 "next-chapter" : "next-title", val );
1154 vlc_object_release( p_input );
1158 #if wxUSE_DRAG_AND_DROP
1159 /*****************************************************************************
1160 * Definition of DragAndDrop class.
1161 *****************************************************************************/
1162 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
1165 b_enqueue = _b_enqueue;
1168 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1169 const wxArrayString& filenames )
1171 /* Add dropped files to the playlist */
1173 playlist_t *p_playlist =
1174 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1176 if( p_playlist == NULL )
1181 for( size_t i = 0; i < filenames.GetCount(); i++ )
1182 playlist_Add( p_playlist, (const char *)filenames[i].mb_str(),
1183 (const char *)filenames[i].mb_str(),
1184 PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
1187 vlc_object_release( p_playlist );
1193 /*****************************************************************************
1194 * Definition of VolCtrl class.
1195 *****************************************************************************/
1196 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1197 wxPoint point, wxSize size )
1198 : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
1204 void wxVolCtrl::OnChange( wxMouseEvent& event )
1206 if( !event.LeftDown() && !event.LeftIsDown() ) return;
1208 int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
1209 aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1213 void wxVolCtrl::UpdateVolume()
1215 audio_volume_t i_volume;
1216 aout_VolumeGet( p_intf, &i_volume );
1218 int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
1219 if( i_gauge_volume == GetValue() ) return;
1221 SetValue( i_gauge_volume );
1222 SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
1223 i_gauge_volume / 2 ) );