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"
46 #include "bitmaps/speaker_mute.xpm"
48 #define TOOLBAR_BMP_WIDTH 16
49 #define TOOLBAR_BMP_HEIGHT 16
51 /* include the icon graphic */
52 #include "../../../share/vlc32x32.xpm"
53 /* include a small icon graphic for the systray icon */
54 #ifdef wxHAS_TASK_BAR_ICON
55 #include "../../../share/vlc16x16.xpm"
58 /*****************************************************************************
59 * Local class declarations.
60 *****************************************************************************/
61 class wxMenuExt: public wxMenu
65 wxMenuExt( wxMenu* parentMenu, int id, const wxString& text,
66 const wxString& helpString, wxItemKind kind,
67 char *_psz_var, int _i_object_id, vlc_value_t _val,
70 virtual ~wxMenuExt() {};
82 class VLCVolCtrl : public wxControl
85 VLCVolCtrl( intf_thread_t *p_intf, wxWindow *p_parent );
86 virtual ~VLCVolCtrl() {};
88 virtual void OnPaint( wxPaintEvent &event );
89 void OnChange( wxMouseEvent& event );
98 intf_thread_t *p_intf;
101 BEGIN_EVENT_TABLE(VLCVolCtrl, wxControl)
102 EVT_PAINT(VLCVolCtrl::OnPaint)
105 EVT_LEFT_UP(VLCVolCtrl::OnChange)
108 /*****************************************************************************
110 *****************************************************************************/
112 DEFINE_LOCAL_EVENT_TYPE( wxEVT_INTF );
114 /* IDs for the controls and the menu commands */
118 MenuDummy_Event = wxID_HIGHEST + 1000,
119 Exit_Event = wxID_HIGHEST,
120 OpenFileSimple_Event,
155 /* it is important for the id corresponding to the "About" command to have
156 * this standard value as otherwise it won't be handled properly under Mac
157 * (where it is special and put into the "Apple" menu) */
158 About_Event = wxID_ABOUT,
163 BEGIN_EVENT_TABLE(Interface, wxFrame)
165 EVT_MENU(Exit_Event, Interface::OnExit)
166 EVT_MENU(About_Event, Interface::OnAbout)
168 EVT_MENU(Playlist_Event, Interface::OnShowDialog)
169 EVT_MENU(Logs_Event, Interface::OnShowDialog)
170 EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
171 EVT_MENU(Prefs_Event, Interface::OnShowDialog)
173 EVT_MENU_OPEN(Interface::OnMenuOpen)
175 EVT_MENU( Extended_Event, Interface::OnExtended )
176 // EVT_MENU( Undock_Event, Interface::OnUndock )
178 EVT_MENU( Bookmarks_Event, Interface::OnShowDialog)
180 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
181 EVT_CONTEXT_MENU(Interface::OnContextMenu2)
183 EVT_RIGHT_UP(Interface::OnContextMenu)
186 EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
187 EVT_MENU(OpenAdv_Event, Interface::OnShowDialog)
188 EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
189 EVT_MENU(OpenDir_Event, Interface::OnShowDialog)
190 EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
191 EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
192 EVT_MENU(OpenCapture_Event, Interface::OnShowDialog)
193 EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
194 EVT_MENU(Wizard_Event, Interface::OnShowDialog)
195 EVT_MENU(StopStream_Event, Interface::OnStopStream)
196 EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
197 EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
198 EVT_MENU(NextStream_Event, Interface::OnNextStream)
199 EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
200 EVT_MENU(FastStream_Event, Interface::OnFastStream)
202 /* Disc Buttons events */
203 EVT_BUTTON(DiscMenu_Event, Interface::OnDiscMenu)
204 EVT_BUTTON(DiscPrev_Event, Interface::OnDiscPrev)
205 EVT_BUTTON(DiscNext_Event, Interface::OnDiscNext)
208 EVT_COMMAND_SCROLL(SliderScroll_Event, Interface::OnSliderUpdate)
211 EVT_COMMAND(0, wxEVT_INTF, Interface::OnControlEvent)
212 EVT_COMMAND(1, wxEVT_INTF, Interface::OnControlEvent)
214 EVT_TIMER(ID_CONTROLS_TIMER, Interface::OnControlsTimer)
215 EVT_TIMER(ID_SLIDER_TIMER, Interface::OnSliderTimer)
218 /*****************************************************************************
220 *****************************************************************************/
221 Interface::Interface( intf_thread_t *_p_intf, long style ):
222 wxFrame( NULL, -1, wxT("VLC media player"),
223 wxDefaultPosition, wxSize(700,100), style )
225 /* Initializations */
227 i_old_playing_status = PAUSE_S;
229 // b_undock = VLC_FALSE;
234 /* Give our interface a nice little icon */
235 SetIcon( wxIcon( vlc_xpm ) );
237 /* Create a sizer for the main frame */
238 frame_sizer = new wxBoxSizer( wxVERTICAL );
239 SetSizer( frame_sizer );
241 /* Create a dummy widget that can get the keyboard focus */
242 wxWindow *p_dummy = new wxWindow( this, 0, wxDefaultPosition,
245 frame_sizer->Add( p_dummy, 0, 0 );
247 #ifdef wxHAS_TASK_BAR_ICON
248 /* Systray integration */
250 if ( config_GetInt( p_intf, "wxwin-systray" ) )
252 p_systray = new Systray(this, p_intf);
253 p_systray->SetIcon( wxIcon( vlc16x16_xpm ), wxT("VLC media player") );
254 if ( (! p_systray->IsOk()) || (! p_systray->IsIconInstalled()) )
256 msg_Warn(p_intf, "Cannot set systray icon, weird things may happen");
261 /* Creation of the menu bar */
264 /* Creation of the tool bar */
267 /* Create the extra panel */
268 extra_frame = new ExtraPanel( p_intf, this );
269 frame_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
270 frame_sizer->Hide( extra_frame );
272 /* Creation of the status bar
273 * Helptext for menu items and toolbar tools will automatically get
275 int i_status_width[3] = {-6, -2, -9};
276 statusbar = CreateStatusBar( 3 ); /* 2 fields */
277 statusbar->SetStatusWidths( 3, i_status_width );
278 statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
282 if( config_GetInt( p_intf, "wxwin-embed" ) )
284 video_window = CreateVideoWindow( p_intf, this );
285 frame_sizer->Add( p_intf->p_sys->p_video_sizer, 1, wxEXPAND, 0 );
288 /* Creation of the slider sub-window */
290 frame_sizer->Add( slider_frame, 0, wxEXPAND , 0 );
291 frame_sizer->Hide( slider_frame );
293 /* Make sure we've got the right background colour */
294 SetBackgroundColour( slider_frame->GetBackgroundColour() );
296 /* Layout everything */
297 frame_sizer->Layout();
298 frame_sizer->Fit(this);
300 #if wxUSE_DRAG_AND_DROP
301 /* Associate drop targets with the main interface */
302 SetDropTarget( new DragAndDrop( p_intf ) );
307 m_controls_timer.SetOwner(this, ID_CONTROLS_TIMER);
308 m_slider_timer.SetOwner(this, ID_SLIDER_TIMER);
311 timer = new Timer( p_intf, this );
314 WindowSettings *ws = p_intf->p_sys->p_window_settings;
319 ws->SetScreen( wxSystemSettings::GetMetric( wxSYS_SCREEN_X ),
320 wxSystemSettings::GetMetric( wxSYS_SCREEN_Y ) );
322 if( ws->GetSettings( WindowSettings::ID_MAIN, b_shown, p, s ) )
326 Interface::~Interface()
328 WindowSettings *ws = p_intf->p_sys->p_window_settings;
330 ws->SetSettings( WindowSettings::ID_MAIN, true,
331 GetPosition(), GetSize() );
333 if( video_window ) delete video_window;
335 #ifdef wxHAS_TASK_BAR_ICON
336 if( p_systray ) delete p_systray;
339 if( p_intf->p_sys->p_wxwindow ) delete p_intf->p_sys->p_wxwindow;
345 void Interface::Init()
351 void Interface::Update()
354 ((VLCVolCtrl *)volctrl)->UpdateVolume();
357 void Interface::OnControlEvent( wxCommandEvent& event )
359 switch( event.GetId() )
363 if( p_intf->p_sys->b_video_autosize )
365 frame_sizer->Layout();
366 frame_sizer->Fit(this);
372 long i_style = GetWindowStyle();
373 if( event.GetInt() ) i_style |= wxSTAY_ON_TOP;
374 else i_style &= ~wxSTAY_ON_TOP;
375 SetWindowStyle( i_style );
380 /*****************************************************************************
382 *****************************************************************************/
383 void Interface::CreateOurMenuBar()
385 int minimal = config_GetInt( p_intf, "wxwin-minimal" );
387 /* Create the "File" menu */
388 wxMenu *file_menu = new wxMenu;
392 file_menu->Append( OpenFileSimple_Event,
393 wxU(_("Quick &Open File...\tCtrl-O")) );
395 file_menu->AppendSeparator();
396 file_menu->Append( OpenFile_Event, wxU(_("Open &File...\tCtrl-F")) );
397 file_menu->Append( OpenDir_Event, wxU(_("Open D&irectory...\tCtrl-I")) );
398 file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...\tCtrl-D")) );
399 file_menu->Append( OpenNet_Event,
400 wxU(_("Open &Network Stream...\tCtrl-N")) );
401 file_menu->Append( OpenCapture_Event,
402 wxU(_("Open &Capture Device...\tCtrl-C")) );
404 file_menu->AppendSeparator();
405 file_menu->Append( Wizard_Event, wxU(_("&Wizard...\tCtrl-W")) );
406 file_menu->AppendSeparator();
408 file_menu->Append( Exit_Event, wxU(_("E&xit\tCtrl-X")) );
410 /* Create the "View" menu */
411 wxMenu *view_menu = new wxMenu;
414 view_menu->Append( Playlist_Event, wxU(_("&Playlist...\tCtrl-P")) );
416 view_menu->Append( Logs_Event, wxU(_("&Messages...\tCtrl-M")) );
417 view_menu->Append( FileInfo_Event,
418 wxU(_("Stream and Media &info...\tCtrl-I")) );
420 /* Create the "Auto-generated" menus */
421 p_settings_menu = SettingsMenu( p_intf, this );
422 p_audio_menu = AudioMenu( p_intf, this );
423 p_video_menu = VideoMenu( p_intf, this );
424 p_navig_menu = NavigMenu( p_intf, this );
426 /* Create the "Help" menu */
427 wxMenu *help_menu = new wxMenu;
428 help_menu->Append( About_Event, wxU(_("About VLC media player")) );
430 /* Append the freshly created menus to the menu bar... */
431 wxMenuBar *menubar = new wxMenuBar();
432 menubar->Append( file_menu, wxU(_("&File")) );
433 menubar->Append( view_menu, wxU(_("&View")) );
434 menubar->Append( p_settings_menu, wxU(_("&Settings")) );
435 menubar->Append( p_audio_menu, wxU(_("&Audio")) );
436 menubar->Append( p_video_menu, wxU(_("&Video")) );
437 menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
438 menubar->Append( help_menu, wxU(_("&Help")) );
440 /* Attach the menu bar to the frame */
441 SetMenuBar( menubar );
443 /* Find out size of menu bar */
445 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
447 int i_width, i_height;
448 menubar->GetTextExtent( menubar->GetLabelTop(i), &i_width, &i_height );
450 #if defined(__WXGTK__)
451 22 /* approximate margin */;
453 #if (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 5) && (wxRELEASE_NUMBER < 3)
454 4 /* approximate margin */;
456 18 /* approximate margin */;
460 frame_sizer->SetMinSize( i_size, -1 );
462 /* Intercept all menu events in our custom event handler */
463 PushEventHandler( new MenuEvtHandler( p_intf, this ) );
465 #if wxUSE_DRAG_AND_DROP
466 /* Associate drop targets with the menubar */
467 menubar->SetDropTarget( new DragAndDrop( p_intf ) );
471 void Interface::CreateOurToolBar()
473 #define HELP_OPEN N_("Open")
474 #define HELP_STOP N_("Stop")
475 #define HELP_PLAY N_("Play")
476 #define HELP_PAUSE N_("Pause")
477 #define HELP_PLO N_("Playlist")
478 #define HELP_PLP N_("Previous playlist item")
479 #define HELP_PLN N_("Next playlist item")
480 #define HELP_SLOW N_("Play slower")
481 #define HELP_FAST N_("Play faster")
483 int minimal = config_GetInt( p_intf, "wxwin-minimal" );
485 wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
486 * version because we don't include wx.rc */
489 CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
491 toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
495 toolbar->AddTool( OpenFile_Event, wxT(""),
496 wxBitmap( eject_xpm ), wxU(_(HELP_OPEN)) );
497 toolbar->AddSeparator();
500 wxToolBarToolBase *p_tool = toolbar->AddTool( PlayStream_Event, wxT(""),
501 wxBitmap( play_xpm ), wxU(_(HELP_PLAY)) );
502 p_tool->SetClientData( p_tool );
506 toolbar->AddTool( StopStream_Event, wxT(""), wxBitmap( stop_xpm ),
508 toolbar->AddSeparator();
510 toolbar->AddTool( PrevStream_Event, wxT(""),
511 wxBitmap( prev_xpm ), wxU(_(HELP_PLP)) );
512 toolbar->AddTool( SlowStream_Event, wxT(""),
513 wxBitmap( slow_xpm ), wxU(_(HELP_SLOW)) );
514 toolbar->AddTool( FastStream_Event, wxT(""),
515 wxBitmap( fast_xpm ), wxU(_(HELP_FAST)) );
516 toolbar->AddTool( NextStream_Event, wxT(""), wxBitmap( next_xpm ),
518 toolbar->AddSeparator();
519 toolbar->AddTool( Playlist_Event, wxT(""), wxBitmap( playlist_xpm ),
523 wxControl *p_dummy_ctrl =
524 new wxControl( toolbar, -1, wxDefaultPosition,
525 wxSize(35, 16 ), wxBORDER_NONE );
527 toolbar->AddControl( p_dummy_ctrl );
529 volctrl = new VLCVolCtrl( p_intf, toolbar );
530 toolbar->AddControl( volctrl );
534 #if wxUSE_DRAG_AND_DROP
535 /* Associate drop targets with the toolbar */
536 toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
540 void Interface::CreateOurSlider()
542 /* Create a new frame and sizer containing the slider */
543 slider_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
544 slider_frame->SetAutoLayout( TRUE );
545 slider_sizer = new wxBoxSizer( wxHORIZONTAL );
546 //slider_sizer->SetMinSize( -1, 50 );
549 slider = new wxSlider( slider_frame, SliderScroll_Event, 0, 0,
550 SLIDER_MAX_POS, wxDefaultPosition, wxDefaultSize );
552 /* Add Disc Buttons */
553 disc_frame = new wxPanel( slider_frame, -1, wxDefaultPosition,
555 disc_frame->SetAutoLayout( TRUE );
556 disc_sizer = new wxBoxSizer( wxHORIZONTAL );
558 disc_menu_button = new wxBitmapButton( disc_frame, DiscMenu_Event,
559 wxBitmap( playlist_xpm ) );
560 disc_prev_button = new wxBitmapButton( disc_frame, DiscPrev_Event,
561 wxBitmap( prev_xpm ) );
562 disc_next_button = new wxBitmapButton( disc_frame, DiscNext_Event,
563 wxBitmap( next_xpm ) );
565 disc_sizer->Add( disc_menu_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
566 disc_sizer->Add( disc_prev_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
567 disc_sizer->Add( disc_next_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
569 disc_frame->SetSizer( disc_sizer );
570 disc_sizer->Layout();
572 /* Add everything to the frame */
573 slider_sizer->Add( slider, 1, wxEXPAND | wxALL, 5 );
574 slider_sizer->Add( disc_frame, 0, wxALL, 2 );
575 slider_frame->SetSizer( slider_sizer );
578 slider_sizer->Hide( disc_frame );
580 slider_sizer->Layout();
581 slider_sizer->Fit( slider_frame );
583 /* Hide the slider by default */
584 slider_frame->Hide();
587 static int ConvertHotkeyModifiers( int i_hotkey )
589 int i_accel_flags = 0;
590 if( i_hotkey & KEY_MODIFIER_ALT ) i_accel_flags |= wxACCEL_ALT;
591 if( i_hotkey & KEY_MODIFIER_CTRL ) i_accel_flags |= wxACCEL_CTRL;
592 if( i_hotkey & KEY_MODIFIER_SHIFT ) i_accel_flags |= wxACCEL_SHIFT;
593 if( !i_accel_flags ) i_accel_flags = wxACCEL_NORMAL;
594 return i_accel_flags;
597 static int ConvertHotkey( int i_hotkey )
599 int i_key = i_hotkey & ~KEY_MODIFIER;
600 if( i_key & KEY_ASCII ) return i_key & KEY_ASCII;
601 else if( i_key & KEY_SPECIAL )
605 case KEY_LEFT: return WXK_LEFT;
606 case KEY_RIGHT: return WXK_RIGHT;
607 case KEY_UP: return WXK_UP;
608 case KEY_DOWN: return WXK_DOWN;
609 case KEY_SPACE: return WXK_SPACE;
610 case KEY_ENTER: return WXK_RETURN;
611 case KEY_F1: return WXK_F1;
612 case KEY_F2: return WXK_F2;
613 case KEY_F3: return WXK_F3;
614 case KEY_F4: return WXK_F4;
615 case KEY_F5: return WXK_F5;
616 case KEY_F6: return WXK_F6;
617 case KEY_F7: return WXK_F7;
618 case KEY_F8: return WXK_F8;
619 case KEY_F9: return WXK_F9;
620 case KEY_F10: return WXK_F10;
621 case KEY_F11: return WXK_F11;
622 case KEY_F12: return WXK_F12;
623 case KEY_HOME: return WXK_HOME;
624 case KEY_END: return WXK_HOME;
625 case KEY_MENU: return WXK_MENU;
626 case KEY_ESC: return WXK_ESCAPE;
627 case KEY_PAGEUP: return WXK_PRIOR;
628 case KEY_PAGEDOWN: return WXK_NEXT;
629 case KEY_TAB: return WXK_TAB;
630 case KEY_BACKSPACE: return WXK_BACK;
636 void Interface::SetupHotkeys()
638 struct vlc_t::hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
641 /* Count number of hoteys */
642 for( i_hotkeys = 0; p_hotkeys[i_hotkeys].psz_action != NULL; i_hotkeys++ );
644 p_intf->p_sys->i_first_hotkey_event = wxID_HIGHEST + 7000;
645 p_intf->p_sys->i_hotkeys = i_hotkeys;
647 wxAcceleratorEntry *p_entries = new wxAcceleratorEntry[i_hotkeys];
649 /* Setup the hotkeys as accelerators */
650 for( int i = 0; i < i_hotkeys; i++ )
652 int i_mod = ConvertHotkeyModifiers( p_hotkeys[i].i_key );
653 int i_key = ConvertHotkey( p_hotkeys[i].i_key );
656 if( !(p_hotkeys[i].i_key & KEY_SPECIAL) && i_mod )
657 i_key = toupper(i_key);
660 p_entries[i].Set( i_mod, i_key,
661 p_intf->p_sys->i_first_hotkey_event + i );
664 wxAcceleratorTable accel( i_hotkeys, p_entries );
668 msg_Err( p_intf, "invalid accelerator table" );
672 SetAcceleratorTable( accel );
678 void Interface::HideSlider( bool layout )
680 ShowSlider( false, layout );
683 void Interface::ShowSlider( bool show, bool layout )
687 //prevent the hide timers from hiding it now
688 m_slider_timer.Stop();
689 m_controls_timer.Stop();
691 //prevent continuous layout
692 if( slider_frame->IsShown() ) return;
694 slider_frame->Show();
695 frame_sizer->Show( slider_frame );
699 //prevent continuous layout
700 if( !slider_frame->IsShown() ) return;
702 slider_frame->Hide();
703 frame_sizer->Hide( slider_frame );
708 frame_sizer->Layout();
709 if( p_intf->p_sys->b_video_autosize )
711 UpdateVideoWindow( p_intf, video_window );
712 frame_sizer->Fit( this );
717 void Interface::HideDiscFrame( bool layout )
719 ShowDiscFrame( false, layout );
722 void Interface::ShowDiscFrame( bool show, bool layout )
726 //prevent the hide timer from hiding it now
727 m_controls_timer.Stop();
729 //prevent continuous layout
730 if( disc_frame->IsShown() ) return;
733 slider_sizer->Show( disc_frame );
737 //prevent continuous layout
738 if( !disc_frame->IsShown() ) return;
741 slider_sizer->Hide( disc_frame );
746 slider_sizer->Layout();
747 if( p_intf->p_sys->b_video_autosize )
749 UpdateVideoWindow( p_intf, video_window );
750 slider_sizer->Fit( slider_frame );
755 /*****************************************************************************
757 *****************************************************************************/
758 void Interface::OnControlsTimer( wxTimerEvent& WXUNUSED(event) )
760 /* Hide slider and Disc Buttons */
761 //postpone layout, we'll do it ourselves
762 HideDiscFrame( false );
765 slider_sizer->Layout();
766 if( p_intf->p_sys->b_video_autosize )
768 slider_sizer->Fit( slider_frame );
769 UpdateVideoWindow( p_intf, video_window );
770 frame_sizer->Fit( this );
774 void Interface::OnSliderTimer( wxTimerEvent& WXUNUSED(event) )
779 void Interface::OnMenuOpen( wxMenuEvent& event )
781 #if defined( __WXMSW__ )
782 # define GetEventObject GetMenu
785 if( event.GetEventObject() == p_settings_menu )
787 p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );
789 /* Add static items */
790 p_settings_menu->AppendCheckItem( Extended_Event,
791 wxU(_("&Extended GUI") ) );
792 if( b_extra ) p_settings_menu->Check( Extended_Event, TRUE );
794 p_settings_menu->AppendCheckItem( Undock_Event,
795 wxU(_("&Undock Ext. GUI") ) );
796 if( b_undock ) p_settings_menu->Check( Undock_Event, TRUE );
798 p_settings_menu->Append( Bookmarks_Event, wxU(_("&Bookmarks...") ) );
799 p_settings_menu->Append( Prefs_Event, wxU(_("&Preferences...")) );
802 else if( event.GetEventObject() == p_audio_menu )
804 p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
807 else if( event.GetEventObject() == p_video_menu )
809 p_video_menu = VideoMenu( p_intf, this, p_video_menu );
812 else if( event.GetEventObject() == p_navig_menu )
814 p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
817 #if defined( __WXMSW__ )
818 # undef GetEventObject
822 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
823 void Interface::OnContextMenu2(wxContextMenuEvent& event)
825 /* Only show the context menu for the main interface */
826 if( GetId() != event.GetId() )
832 if( p_intf->p_sys->pf_show_dialog )
833 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
836 void Interface::OnContextMenu(wxMouseEvent& event)
838 if( p_intf->p_sys->pf_show_dialog )
839 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
842 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
844 /* TRUE is to force the frame to close. */
848 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
851 msg.Printf( wxString(wxT("VLC media player " PACKAGE_VERSION)) +
852 wxU(_(" (wxWindows interface)\n\n")) +
853 wxU(_("(c) 1996-2005 - the VideoLAN Team\n\n")) +
854 wxU( vlc_wraptext(INTF_ABOUT_MSG,WRAPCOUNT,ISUTF8) ) + wxT("\n\n") +
855 wxU(_("The VideoLAN team <videolan@videolan.org>\n"
856 "http://www.videolan.org/\n\n")) );
858 wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
859 wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
862 void Interface::OnShowDialog( wxCommandEvent& event )
864 if( p_intf->p_sys->pf_show_dialog )
868 switch( event.GetId() )
870 case OpenFileSimple_Event:
871 i_id = INTF_DIALOG_FILE_SIMPLE;
874 i_id = INTF_DIALOG_FILE;
876 i_id = INTF_DIALOG_FILE;
879 i_id = INTF_DIALOG_DIRECTORY;
882 i_id = INTF_DIALOG_DISC;
885 i_id = INTF_DIALOG_NET;
887 case OpenCapture_Event:
888 i_id = INTF_DIALOG_CAPTURE;
891 i_id = INTF_DIALOG_SAT;
894 i_id = INTF_DIALOG_PLAYLIST;
897 i_id = INTF_DIALOG_MESSAGES;
900 i_id = INTF_DIALOG_FILEINFO;
903 i_id = INTF_DIALOG_PREFS;
906 i_id = INTF_DIALOG_WIZARD;
908 case Bookmarks_Event:
909 i_id = INTF_DIALOG_BOOKMARKS;
912 i_id = INTF_DIALOG_FILE;
916 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
920 void Interface::OnExtended(wxCommandEvent& event)
922 b_extra = (b_extra == VLC_TRUE ? VLC_FALSE : VLC_TRUE );
924 if( b_extra == VLC_FALSE )
927 frame_sizer->Hide( extra_frame );
932 frame_sizer->Show( extra_frame );
934 frame_sizer->Layout();
935 frame_sizer->Fit(this);
939 if( b_undock == VLC_TRUE )
941 fprintf(stderr,"Deleting window\n");
951 frame_sizer->Hide( extra_frame );
952 frame_sizer->Layout();
953 frame_sizer->Fit(this);
958 if( b_undock == VLC_TRUE )
960 fprintf(stderr,"Creating window\n");
962 frame_sizer->Hide( extra_frame );
963 #if (wxCHECK_VERSION(2,5,0))
964 frame_sizer->Detach( extra_frame );
966 frame_sizer->Remove( extra_frame );
968 frame_sizer->Layout();
969 frame_sizer->Fit(this);
970 extra_window = new ExtraWindow( p_intf, this, extra_frame );
974 fprintf(stderr,"Deleting window\n");
980 frame_sizer->Show( extra_frame );
981 frame_sizer->Layout();
982 frame_sizer->Fit(this);
987 void Interface::OnUndock(wxCommandEvent& event)
989 b_undock = (b_undock == VLC_TRUE ? VLC_FALSE : VLC_TRUE );
991 if( b_extra == VLC_TRUE )
993 if( b_undock == VLC_FALSE )
995 fprintf(stderr,"Deleting window\n");
1001 extra_frame->Show();
1002 frame_sizer->Show( extra_frame );
1003 frame_sizer->Layout();
1004 frame_sizer->Fit(this);
1008 fprintf(stderr,"Creating window\n");
1009 extra_frame->Hide();
1010 frame_sizer->Hide( extra_frame );
1011 #if (wxCHECK_VERSION(2,5,0))
1012 frame_sizer->Detach( extra_frame );
1014 frame_sizer->Remove( extra_frame );
1016 frame_sizer->Layout();
1017 frame_sizer->Fit(this);
1018 extra_window = new ExtraWindow( p_intf, this, extra_frame );
1025 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
1030 void Interface::PlayStream()
1032 wxCommandEvent dummy;
1033 playlist_t *p_playlist =
1034 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1036 if( p_playlist == NULL ) return;
1038 if( p_playlist->i_size && p_playlist->i_enabled )
1042 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
1045 if( p_input == NULL )
1047 /* No stream was playing, start one */
1048 playlist_Play( p_playlist );
1049 TogglePlayButton( PLAYING_S );
1050 vlc_object_release( p_playlist );
1054 var_Get( p_input, "state", &state );
1056 if( state.i_int != PAUSE_S )
1058 /* A stream is being played, pause it */
1059 state.i_int = PAUSE_S;
1063 /* Stream is paused, resume it */
1064 state.i_int = PLAYING_S;
1066 var_Set( p_input, "state", state );
1068 TogglePlayButton( state.i_int );
1069 vlc_object_release( p_input );
1070 vlc_object_release( p_playlist );
1074 /* If the playlist is empty, open a file requester instead */
1075 vlc_object_release( p_playlist );
1076 OnShowDialog( dummy );
1080 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
1084 void Interface::StopStream()
1086 playlist_t * p_playlist =
1087 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1089 if( p_playlist == NULL )
1094 playlist_Stop( p_playlist );
1095 TogglePlayButton( PAUSE_S );
1096 vlc_object_release( p_playlist );
1099 void Interface::OnSliderUpdate( wxScrollEvent& event )
1101 vlc_mutex_lock( &p_intf->change_lock );
1104 if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
1105 || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
1108 if( p_intf->p_sys->i_slider_pos != event.GetPosition()
1109 && p_intf->p_sys->p_input )
1112 pos.f_float = (float)event.GetPosition() / (float)SLIDER_MAX_POS;
1114 var_Set( p_intf->p_sys->p_input, "position", pos );
1118 p_intf->p_sys->b_slider_free = VLC_TRUE;
1122 p_intf->p_sys->b_slider_free = VLC_FALSE;
1124 if( p_intf->p_sys->p_input )
1126 /* Update stream date */
1127 char psz_time[ MSTRTIME_MAX_SIZE ], psz_total[ MSTRTIME_MAX_SIZE ];
1130 i_seconds = var_GetTime( p_intf->p_sys->p_input, "length" ) /
1132 secstotimestr( psz_total, i_seconds );
1134 i_seconds = var_GetTime( p_intf->p_sys->p_input, "time" ) /
1136 secstotimestr( psz_time, i_seconds );
1138 statusbar->SetStatusText( wxU(psz_time) + wxString(wxT(" / ") ) +
1139 wxU(psz_total), 0 );
1145 vlc_mutex_unlock( &p_intf->change_lock );
1148 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
1153 void Interface::PrevStream()
1155 playlist_t * p_playlist =
1156 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1158 if( p_playlist == NULL )
1163 /* FIXME --fenrir */
1165 if( p_playlist->p_input != NULL )
1167 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1168 if( p_playlist->p_input->stream.p_selected_area->i_id > 1 )
1170 vlc_value_t val; val.b_bool = VLC_TRUE;
1171 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1172 var_Set( p_playlist->p_input, "prev-title", val );
1174 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1176 vlc_mutex_unlock( &p_playlist->object_lock );
1179 playlist_Prev( p_playlist );
1180 vlc_object_release( p_playlist );
1183 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1188 void Interface::NextStream()
1190 playlist_t * p_playlist =
1191 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1193 if( p_playlist == NULL )
1198 /* FIXME --fenrir */
1200 var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
1201 vlc_mutex_lock( &p_playlist->object_lock );
1202 if( p_playlist->p_input != NULL )
1204 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1205 if( p_playlist->p_input->stream.i_area_nb > 1 &&
1206 p_playlist->p_input->stream.p_selected_area->i_id <
1207 p_playlist->p_input->stream.i_area_nb - 1 )
1209 vlc_value_t val; val.b_bool = VLC_TRUE;
1210 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1211 var_Set( p_playlist->p_input, "next-title", val );
1213 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1215 vlc_mutex_unlock( &p_playlist->object_lock );
1217 playlist_Next( p_playlist );
1218 vlc_object_release( p_playlist );
1221 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1223 input_thread_t *p_input =
1224 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1228 vlc_value_t val; val.b_bool = VLC_TRUE;
1230 var_Set( p_input, "rate-slower", val );
1231 vlc_object_release( p_input );
1235 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1237 input_thread_t *p_input =
1238 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1242 vlc_value_t val; val.b_bool = VLC_TRUE;
1244 var_Set( p_input, "rate-faster", val );
1245 vlc_object_release( p_input );
1249 void Interface::TogglePlayButton( int i_playing_status )
1251 if( i_playing_status == i_old_playing_status )
1254 wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
1255 GetToolBar()->GetToolClientData( PlayStream_Event );
1256 if( !p_tool ) return;
1258 if( i_playing_status == PLAYING_S )
1260 p_tool->SetNormalBitmap( wxBitmap( pause_xpm ) );
1261 p_tool->SetLabel( wxU(_("Pause")) );
1262 p_tool->SetShortHelp( wxU(_(HELP_PAUSE)) );
1266 p_tool->SetNormalBitmap( wxBitmap( play_xpm ) );
1267 p_tool->SetLabel( wxU(_("Play")) );
1268 p_tool->SetShortHelp( wxU(_(HELP_PLAY)) );
1271 GetToolBar()->Realize();
1273 i_old_playing_status = i_playing_status;
1276 void Interface::OnDiscMenu( wxCommandEvent& WXUNUSED(event) )
1278 input_thread_t *p_input =
1279 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1283 vlc_value_t val; val.i_int = 2;
1285 var_Set( p_input, "title 0", val);
1286 vlc_object_release( p_input );
1290 void Interface::OnDiscPrev( wxCommandEvent& WXUNUSED(event) )
1292 input_thread_t *p_input =
1293 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1297 int i_type = var_Type( p_input, "prev-chapter" );
1298 vlc_value_t val; val.b_bool = VLC_TRUE;
1300 var_Set( p_input, ( i_type & VLC_VAR_TYPE ) != 0 ?
1301 "prev-chapter" : "prev-title", val );
1303 vlc_object_release( p_input );
1307 void Interface::OnDiscNext( wxCommandEvent& WXUNUSED(event) )
1309 input_thread_t *p_input =
1310 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1314 int i_type = var_Type( p_input, "next-chapter" );
1315 vlc_value_t val; val.b_bool = VLC_TRUE;
1317 var_Set( p_input, ( i_type & VLC_VAR_TYPE ) != 0 ?
1318 "next-chapter" : "next-title", val );
1320 vlc_object_release( p_input );
1324 #if wxUSE_DRAG_AND_DROP
1325 /*****************************************************************************
1326 * Definition of DragAndDrop class.
1327 *****************************************************************************/
1328 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
1331 b_enqueue = _b_enqueue;
1334 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1335 const wxArrayString& filenames )
1337 /* Add dropped files to the playlist */
1339 playlist_t *p_playlist =
1340 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1342 if( p_playlist == NULL )
1347 for( size_t i = 0; i < filenames.GetCount(); i++ )
1348 playlist_Add( p_playlist, (const char *)filenames[i].mb_str(),
1349 (const char *)filenames[i].mb_str(),
1350 PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
1353 vlc_object_release( p_playlist );
1359 /*****************************************************************************
1360 * Definition of VolCtrl class.
1361 *****************************************************************************/
1362 class wxVolCtrl: public wxGauge
1366 wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1367 wxPoint = wxDefaultPosition, wxSize = wxSize( 20, -1 ) );
1368 virtual ~wxVolCtrl() {};
1370 void UpdateVolume();
1372 void OnChange( wxMouseEvent& event );
1375 intf_thread_t *p_intf;
1377 DECLARE_EVENT_TABLE();
1380 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
1382 EVT_LEFT_DOWN(wxVolCtrl::OnChange)
1383 EVT_MOTION(wxVolCtrl::OnChange)
1386 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1387 wxPoint point, wxSize size )
1388 : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
1394 void wxVolCtrl::OnChange( wxMouseEvent& event )
1396 if( !event.LeftDown() && !event.LeftIsDown() ) return;
1398 int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
1399 aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1403 void wxVolCtrl::UpdateVolume()
1405 audio_volume_t i_volume;
1406 aout_VolumeGet( p_intf, &i_volume );
1408 int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
1409 if( i_gauge_volume == GetValue() ) return;
1411 SetValue( i_gauge_volume );
1412 SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
1413 i_gauge_volume / 2 ) );
1416 #if defined(__WXGTK__)
1417 #define VLCVOL_HEIGHT p_parent->GetSize().GetHeight()
1419 #define VLCVOL_HEIGHT TOOLBAR_BMP_HEIGHT
1421 VLCVolCtrl::VLCVolCtrl( intf_thread_t *_p_intf, wxWindow *p_parent )
1422 :wxControl( p_parent, -1, wxDefaultPosition, wxSize(64, VLCVOL_HEIGHT ),
1424 i_y_offset((VLCVOL_HEIGHT - TOOLBAR_BMP_HEIGHT) / 2),
1425 b_mute(0), p_intf(_p_intf)
1427 gauge = new wxVolCtrl( p_intf, this, -1, wxPoint( 18, i_y_offset ),
1428 wxSize( 44, TOOLBAR_BMP_HEIGHT ) );
1431 void VLCVolCtrl::OnPaint( wxPaintEvent &evt )
1433 wxPaintDC dc( this );
1434 wxBitmap mPlayBitmap( b_mute ? speaker_mute_xpm : speaker_xpm );
1435 dc.DrawBitmap( mPlayBitmap, 0, i_y_offset, TRUE );
1438 void VLCVolCtrl::OnChange( wxMouseEvent& event )
1440 if( event.GetX() < TOOLBAR_BMP_WIDTH )
1443 aout_VolumeMute( p_intf, (audio_volume_t *)&i_volume );
1450 void VLCVolCtrl::UpdateVolume()
1452 gauge->UpdateVolume();
1455 /*****************************************************************************
1457 *****************************************************************************/
1459 #ifdef wxHAS_TASK_BAR_ICON
1461 BEGIN_EVENT_TABLE(Systray, wxTaskBarIcon)
1464 EVT_TASKBAR_LEFT_DCLICK(Systray::OnLeftClick)
1466 EVT_TASKBAR_LEFT_DOWN(Systray::OnLeftClick)
1469 EVT_MENU(Iconize_Event, Systray::OnMenuIconize)
1470 EVT_MENU(Exit_Event, Systray::OnExit)
1471 EVT_MENU(PlayStream_Event, Systray::OnPlayStream)
1472 EVT_MENU(NextStream_Event, Systray::OnNextStream)
1473 EVT_MENU(PrevStream_Event, Systray::OnPrevStream)
1474 EVT_MENU(StopStream_Event, Systray::OnStopStream)
1477 Systray::Systray( Interface *_p_main_interface, intf_thread_t *_p_intf )
1479 p_main_interface = _p_main_interface;
1483 /* Event handlers */
1484 void Systray::OnMenuIconize( wxCommandEvent& event )
1486 p_main_interface->Show( ! p_main_interface->IsShown() );
1487 if ( p_main_interface->IsShown() ) p_main_interface->Raise();
1490 void Systray::OnLeftClick( wxTaskBarIconEvent& event )
1492 wxCommandEvent cevent;
1493 OnMenuIconize(cevent);
1496 void Systray::OnExit( wxCommandEvent& event )
1498 p_main_interface->Close(TRUE);
1501 void Systray::OnPrevStream( wxCommandEvent& event )
1503 p_main_interface->PrevStream();
1506 void Systray::OnNextStream( wxCommandEvent& event )
1508 p_main_interface->NextStream();
1511 void Systray::OnPlayStream( wxCommandEvent& event )
1513 p_main_interface->PlayStream();
1516 void Systray::OnStopStream( wxCommandEvent& event )
1518 p_main_interface->StopStream();
1521 /* Systray popup menu */
1522 wxMenu* Systray::CreatePopupMenu()
1524 int minimal = config_GetInt( p_intf, "wxwin-minimal" );
1526 wxMenu* systray_menu = new wxMenu;
1527 systray_menu->Append( Exit_Event, wxU(_("Quit VLC")) );
1528 systray_menu->AppendSeparator();
1529 systray_menu->Append( PlayStream_Event, wxU(_("Play/Pause")) );
1533 systray_menu->Append( PrevStream_Event, wxU(_("Previous")) );
1534 systray_menu->Append( NextStream_Event, wxU(_("Next")) );
1535 systray_menu->Append( StopStream_Event, wxU(_("Stop")) );
1537 systray_menu->AppendSeparator();
1538 systray_menu->Append( Iconize_Event, wxU(_("Show/Hide interface")) );
1539 return systray_menu;
1542 void Systray::UpdateTooltip( const wxChar* tooltip )
1544 SetIcon( wxIcon( vlc16x16_xpm ), tooltip );