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,
154 /* it is important for the id corresponding to the "About" command to have
155 * this standard value as otherwise it won't be handled properly under Mac
156 * (where it is special and put into the "Apple" menu) */
157 About_Event = wxID_ABOUT,
162 BEGIN_EVENT_TABLE(Interface, wxFrame)
164 EVT_MENU(Exit_Event, Interface::OnExit)
165 EVT_MENU(About_Event, Interface::OnAbout)
167 EVT_MENU(Playlist_Event, Interface::OnShowDialog)
168 EVT_MENU(Logs_Event, Interface::OnShowDialog)
169 EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
170 EVT_MENU(Prefs_Event, Interface::OnShowDialog)
172 EVT_MENU_OPEN(Interface::OnMenuOpen)
174 EVT_MENU( Extended_Event, Interface::OnExtended )
175 // EVT_MENU( Undock_Event, Interface::OnUndock )
177 EVT_MENU( Bookmarks_Event, Interface::OnShowDialog)
179 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
180 EVT_CONTEXT_MENU(Interface::OnContextMenu2)
182 EVT_RIGHT_UP(Interface::OnContextMenu)
185 EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
186 EVT_MENU(OpenAdv_Event, Interface::OnShowDialog)
187 EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
188 EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
189 EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
190 EVT_MENU(OpenCapture_Event, Interface::OnShowDialog)
191 EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
192 EVT_MENU(Wizard_Event, Interface::OnShowDialog)
193 EVT_MENU(StopStream_Event, Interface::OnStopStream)
194 EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
195 EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
196 EVT_MENU(NextStream_Event, Interface::OnNextStream)
197 EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
198 EVT_MENU(FastStream_Event, Interface::OnFastStream)
200 /* Disc Buttons events */
201 EVT_BUTTON(DiscMenu_Event, Interface::OnDiscMenu)
202 EVT_BUTTON(DiscPrev_Event, Interface::OnDiscPrev)
203 EVT_BUTTON(DiscNext_Event, Interface::OnDiscNext)
206 EVT_COMMAND_SCROLL(SliderScroll_Event, Interface::OnSliderUpdate)
209 EVT_COMMAND(0, wxEVT_INTF, Interface::OnControlEvent)
210 EVT_COMMAND(1, wxEVT_INTF, Interface::OnControlEvent)
214 /*****************************************************************************
216 *****************************************************************************/
217 Interface::Interface( intf_thread_t *_p_intf, long style ):
218 wxFrame( NULL, -1, wxT("VLC media player"),
219 wxDefaultPosition, wxSize(700,100), style )
221 /* Initializations */
223 i_old_playing_status = PAUSE_S;
225 // b_undock = VLC_FALSE;
229 /* Give our interface a nice little icon */
230 SetIcon( wxIcon( vlc_xpm ) );
232 /* Create a sizer for the main frame */
233 frame_sizer = new wxBoxSizer( wxVERTICAL );
234 SetSizer( frame_sizer );
236 /* Create a dummy widget that can get the keyboard focus */
237 wxWindow *p_dummy = new wxWindow( this, 0, wxDefaultPosition,
240 frame_sizer->Add( p_dummy, 0, 0 );
242 #ifdef wxHAS_TASK_BAR_ICON
243 /* Systray integration */
245 if ( config_GetInt( p_intf, "wxwin-systray" ) )
247 p_systray = new Systray(this);
248 p_systray->SetIcon( wxIcon( vlc16x16_xpm ), wxT("VLC media player") );
249 if ( (! p_systray->IsOk()) || (! p_systray->IsIconInstalled()) )
251 msg_Warn(p_intf, "Cannot set systray icon, weird things may happen");
256 /* Creation of the menu bar */
259 /* Creation of the tool bar */
262 /* Create the extra panel */
263 extra_frame = new ExtraPanel( p_intf, this );
264 frame_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
265 frame_sizer->Hide( extra_frame );
267 /* Creation of the status bar
268 * Helptext for menu items and toolbar tools will automatically get
270 int i_status_width[3] = {-6, -2, -9};
271 statusbar = CreateStatusBar( 3 ); /* 2 fields */
272 statusbar->SetStatusWidths( 3, i_status_width );
273 statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
276 if( config_GetInt( p_intf, "wxwin-embed" ) )
278 CreateVideoWindow( p_intf, this );
279 frame_sizer->Add( p_intf->p_sys->p_video_sizer, 1, wxEXPAND , 0 );
282 /* Creation of the slider sub-window */
284 frame_sizer->Add( slider_frame, 0, wxEXPAND , 0 );
285 frame_sizer->Hide( slider_frame );
287 /* Make sure we've got the right background colour */
288 SetBackgroundColour( slider_frame->GetBackgroundColour() );
290 /* Layout everything */
291 frame_sizer->Layout();
292 frame_sizer->Fit(this);
294 #if wxUSE_DRAG_AND_DROP
295 /* Associate drop targets with the main interface */
296 SetDropTarget( new DragAndDrop( p_intf ) );
302 timer = new Timer( p_intf, this );
305 Interface::~Interface()
307 #ifdef wxHAS_TASK_BAR_ICON
314 if( p_intf->p_sys->p_wxwindow )
316 delete p_intf->p_sys->p_wxwindow;
323 void Interface::Init()
329 void Interface::Update()
332 ((VLCVolCtrl *)volctrl)->UpdateVolume();
335 void Interface::OnControlEvent( wxCommandEvent& event )
337 switch( event.GetId() )
340 frame_sizer->Layout();
341 frame_sizer->Fit(this);
345 long i_style = GetWindowStyle();
346 if( event.GetInt() ) i_style |= wxSTAY_ON_TOP;
347 else i_style &= ~wxSTAY_ON_TOP;
348 SetWindowStyle( i_style );
353 /*****************************************************************************
355 *****************************************************************************/
356 void Interface::CreateOurMenuBar()
358 /* Create the "File" menu */
359 wxMenu *file_menu = new wxMenu;
360 file_menu->Append( OpenFileSimple_Event,
361 wxU(_("Quick &Open File...\tCtrl-O")) );
363 file_menu->AppendSeparator();
364 file_menu->Append( OpenFile_Event, wxU(_("Open &File...\tCtrl-F")) );
365 file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...\tCtrl-D")) );
366 file_menu->Append( OpenNet_Event,
367 wxU(_("Open &Network Stream...\tCtrl-N")) );
368 file_menu->Append( OpenCapture_Event,
369 wxU(_("Open &Capture Device...\tCtrl-C")) );
371 file_menu->AppendSeparator();
372 file_menu->Append( Wizard_Event, wxU(_("&Wizard...\tCtrl-W")) );
373 file_menu->AppendSeparator();
374 file_menu->Append( Exit_Event, wxU(_("E&xit\tCtrl-X")) );
376 /* Create the "View" menu */
377 wxMenu *view_menu = new wxMenu;
378 view_menu->Append( Playlist_Event, wxU(_("&Playlist...\tCtrl-P")) );
379 view_menu->Append( Logs_Event, wxU(_("&Messages...\tCtrl-M")) );
380 view_menu->Append( FileInfo_Event,
381 wxU(_("Stream and Media &info...\tCtrl-I")) );
383 /* Create the "Auto-generated" menus */
384 p_settings_menu = SettingsMenu( p_intf, this );
385 p_audio_menu = AudioMenu( p_intf, this );
386 p_video_menu = VideoMenu( p_intf, this );
387 p_navig_menu = NavigMenu( p_intf, this );
389 /* Create the "Help" menu */
390 wxMenu *help_menu = new wxMenu;
391 help_menu->Append( About_Event, wxU(_("About VLC media player")) );
393 /* Append the freshly created menus to the menu bar... */
394 wxMenuBar *menubar = new wxMenuBar();
395 menubar->Append( file_menu, wxU(_("&File")) );
396 menubar->Append( view_menu, wxU(_("&View")) );
397 menubar->Append( p_settings_menu, wxU(_("&Settings")) );
398 menubar->Append( p_audio_menu, wxU(_("&Audio")) );
399 menubar->Append( p_video_menu, wxU(_("&Video")) );
400 menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
401 menubar->Append( help_menu, wxU(_("&Help")) );
403 /* Attach the menu bar to the frame */
404 SetMenuBar( menubar );
406 /* Find out size of menu bar */
408 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
410 int i_width, i_height;
411 menubar->GetTextExtent( menubar->GetLabelTop(i), &i_width, &i_height );
413 #if defined(__WXGTK__)
414 22 /* approximate margin */;
416 #if (wxMAJOR_VERSION <= 2) && (wxMINOR_VERSION <= 5) && (wxRELEASE_NUMBER < 3)
417 4 /* approximate margin */;
419 18 /* approximate margin */;
423 frame_sizer->SetMinSize( i_size, -1 );
425 /* Intercept all menu events in our custom event handler */
426 PushEventHandler( new MenuEvtHandler( p_intf, this ) );
428 #if wxUSE_DRAG_AND_DROP
429 /* Associate drop targets with the menubar */
430 menubar->SetDropTarget( new DragAndDrop( p_intf ) );
434 void Interface::CreateOurToolBar()
436 #define HELP_OPEN N_("Open")
437 #define HELP_STOP N_("Stop")
438 #define HELP_PLAY N_("Play")
439 #define HELP_PAUSE N_("Pause")
440 #define HELP_PLO N_("Playlist")
441 #define HELP_PLP N_("Previous playlist item")
442 #define HELP_PLN N_("Next playlist item")
443 #define HELP_SLOW N_("Play slower")
444 #define HELP_FAST N_("Play faster")
446 wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
447 * version because we don't include wx.rc */
450 CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
452 toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
454 toolbar->AddTool( OpenFile_Event, wxT(""),
455 wxBitmap( eject_xpm ), wxU(_(HELP_OPEN)) );
456 toolbar->AddSeparator();
458 wxToolBarToolBase *p_tool = toolbar->AddTool( PlayStream_Event, wxT(""),
459 wxBitmap( play_xpm ), wxU(_(HELP_PLAY)) );
460 p_tool->SetClientData( p_tool );
462 toolbar->AddTool( StopStream_Event, wxT(""), wxBitmap( stop_xpm ),
464 toolbar->AddSeparator();
465 toolbar->AddTool( PrevStream_Event, wxT(""),
466 wxBitmap( prev_xpm ), wxU(_(HELP_PLP)) );
467 toolbar->AddTool( SlowStream_Event, wxT(""),
468 wxBitmap( slow_xpm ), wxU(_(HELP_SLOW)) );
469 toolbar->AddTool( FastStream_Event, wxT(""),
470 wxBitmap( fast_xpm ), wxU(_(HELP_FAST)) );
471 toolbar->AddTool( NextStream_Event, wxT(""), wxBitmap( next_xpm ),
473 toolbar->AddSeparator();
474 toolbar->AddTool( Playlist_Event, wxT(""), wxBitmap( playlist_xpm ),
477 wxControl *p_dummy_ctrl =
478 new wxControl( toolbar, -1, wxDefaultPosition,
479 wxSize(35, 16 ), wxBORDER_NONE );
481 toolbar->AddControl( p_dummy_ctrl );
483 volctrl = new VLCVolCtrl( p_intf, toolbar );
484 toolbar->AddControl( volctrl );
488 #if wxUSE_DRAG_AND_DROP
489 /* Associate drop targets with the toolbar */
490 toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
494 void Interface::CreateOurSlider()
496 /* Create a new frame and sizer containing the slider */
497 slider_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
498 slider_frame->SetAutoLayout( TRUE );
499 slider_sizer = new wxBoxSizer( wxHORIZONTAL );
500 //slider_sizer->SetMinSize( -1, 50 );
503 slider = new wxSlider( slider_frame, SliderScroll_Event, 0, 0,
504 SLIDER_MAX_POS, wxDefaultPosition, wxDefaultSize );
506 /* Add Disc Buttons */
507 disc_frame = new wxPanel( slider_frame, -1, wxDefaultPosition,
509 disc_frame->SetAutoLayout( TRUE );
510 disc_sizer = new wxBoxSizer( wxHORIZONTAL );
512 disc_menu_button = new wxBitmapButton( disc_frame, DiscMenu_Event,
513 wxBitmap( playlist_xpm ) );
514 disc_prev_button = new wxBitmapButton( disc_frame, DiscPrev_Event,
515 wxBitmap( prev_xpm ) );
516 disc_next_button = new wxBitmapButton( disc_frame, DiscNext_Event,
517 wxBitmap( next_xpm ) );
519 disc_sizer->Add( disc_menu_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
520 disc_sizer->Add( disc_prev_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
521 disc_sizer->Add( disc_next_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
523 disc_frame->SetSizer( disc_sizer );
524 disc_sizer->Layout();
526 /* Add everything to the frame */
527 slider_sizer->Add( slider, 1, wxEXPAND | wxALL, 5 );
528 slider_sizer->Add( disc_frame, 0, wxALL, 2 );
529 slider_frame->SetSizer( slider_sizer );
532 slider_sizer->Hide( disc_frame );
534 slider_sizer->Layout();
535 slider_sizer->Fit( slider_frame );
537 /* Hide the slider by default */
538 slider_frame->Hide();
541 static int ConvertHotkeyModifiers( int i_hotkey )
543 int i_accel_flags = 0;
544 if( i_hotkey & KEY_MODIFIER_ALT ) i_accel_flags |= wxACCEL_ALT;
545 if( i_hotkey & KEY_MODIFIER_CTRL ) i_accel_flags |= wxACCEL_CTRL;
546 if( i_hotkey & KEY_MODIFIER_SHIFT ) i_accel_flags |= wxACCEL_SHIFT;
547 if( !i_accel_flags ) i_accel_flags = wxACCEL_NORMAL;
548 return i_accel_flags;
551 static int ConvertHotkey( int i_hotkey )
553 int i_key = i_hotkey & ~KEY_MODIFIER;
554 if( i_key & KEY_ASCII ) return i_key & KEY_ASCII;
555 else if( i_key & KEY_SPECIAL )
559 case KEY_LEFT: return WXK_LEFT;
560 case KEY_RIGHT: return WXK_RIGHT;
561 case KEY_UP: return WXK_UP;
562 case KEY_DOWN: return WXK_DOWN;
563 case KEY_SPACE: return WXK_SPACE;
564 case KEY_ENTER: return WXK_RETURN;
565 case KEY_F1: return WXK_F1;
566 case KEY_F2: return WXK_F2;
567 case KEY_F3: return WXK_F3;
568 case KEY_F4: return WXK_F4;
569 case KEY_F5: return WXK_F5;
570 case KEY_F6: return WXK_F6;
571 case KEY_F7: return WXK_F7;
572 case KEY_F8: return WXK_F8;
573 case KEY_F9: return WXK_F9;
574 case KEY_F10: return WXK_F10;
575 case KEY_F11: return WXK_F11;
576 case KEY_F12: return WXK_F12;
577 case KEY_HOME: return WXK_HOME;
578 case KEY_END: return WXK_HOME;
579 case KEY_MENU: return WXK_MENU;
580 case KEY_ESC: return WXK_ESCAPE;
581 case KEY_PAGEUP: return WXK_PRIOR;
582 case KEY_PAGEDOWN: return WXK_NEXT;
583 case KEY_TAB: return WXK_TAB;
584 case KEY_BACKSPACE: return WXK_BACK;
590 void Interface::SetupHotkeys()
592 struct vlc_t::hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
595 /* Count number of hoteys */
596 for( i_hotkeys = 0; p_hotkeys[i_hotkeys].psz_action != NULL; i_hotkeys++ );
598 p_intf->p_sys->i_first_hotkey_event = wxID_HIGHEST + 7000;
599 p_intf->p_sys->i_hotkeys = i_hotkeys;
601 wxAcceleratorEntry *p_entries = new wxAcceleratorEntry[i_hotkeys];
603 /* Setup the hotkeys as accelerators */
604 for( int i = 0; i < i_hotkeys; i++ )
606 int i_mod = ConvertHotkeyModifiers( p_hotkeys[i].i_key );
607 int i_key = ConvertHotkey( p_hotkeys[i].i_key );
610 if( i_mod ) i_key = toupper(i_key);
613 p_entries[i].Set( i_mod, i_key,
614 p_intf->p_sys->i_first_hotkey_event + i );
617 wxAcceleratorTable accel( i_hotkeys, p_entries );
621 msg_Err( p_intf, "invalid accelerator table" );
625 SetAcceleratorTable( accel );
631 /*****************************************************************************
633 *****************************************************************************/
635 void Interface::OnMenuOpen(wxMenuEvent& event)
637 #if defined( __WXMSW__ )
638 # define GetEventObject GetMenu
641 if( event.GetEventObject() == p_settings_menu )
643 p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );
645 /* Add static items */
646 p_settings_menu->AppendCheckItem( Extended_Event,
647 wxU(_("&Extended GUI") ) );
648 if( b_extra ) p_settings_menu->Check( Extended_Event, TRUE );
650 p_settings_menu->AppendCheckItem( Undock_Event,
651 wxU(_("&Undock Ext. GUI") ) );
652 if( b_undock ) p_settings_menu->Check( Undock_Event, TRUE );
654 p_settings_menu->Append( Bookmarks_Event, wxU(_("&Bookmarks...") ) );
655 p_settings_menu->Append( Prefs_Event, wxU(_("&Preferences...")) );
658 else if( event.GetEventObject() == p_audio_menu )
660 p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
663 else if( event.GetEventObject() == p_video_menu )
665 p_video_menu = VideoMenu( p_intf, this, p_video_menu );
668 else if( event.GetEventObject() == p_navig_menu )
670 p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
673 #if defined( __WXMSW__ )
674 # undef GetEventObject
678 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
679 void Interface::OnContextMenu2(wxContextMenuEvent& event)
681 /* Only show the context menu for the main interface */
682 if( GetId() != event.GetId() )
688 if( p_intf->p_sys->pf_show_dialog )
689 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
692 void Interface::OnContextMenu(wxMouseEvent& event)
694 if( p_intf->p_sys->pf_show_dialog )
695 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
698 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
700 /* TRUE is to force the frame to close. */
704 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
707 msg.Printf( wxString(wxT("VLC media player " PACKAGE_VERSION)) +
708 wxU(_(" (wxWindows interface)\n\n")) +
709 wxU(_("(c) 1996-2005 - the VideoLAN Team\n\n")) +
710 wxU( vlc_wraptext(INTF_ABOUT_MSG,WRAPCOUNT,ISUTF8) ) + wxT("\n\n") +
711 wxU(_("The VideoLAN team <videolan@videolan.org>\n"
712 "http://www.videolan.org/\n\n")) );
714 wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
715 wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
718 void Interface::OnShowDialog( wxCommandEvent& event )
720 if( p_intf->p_sys->pf_show_dialog )
724 switch( event.GetId() )
726 case OpenFileSimple_Event:
727 i_id = INTF_DIALOG_FILE_SIMPLE;
730 i_id = INTF_DIALOG_FILE;
732 i_id = INTF_DIALOG_FILE;
735 i_id = INTF_DIALOG_DISC;
738 i_id = INTF_DIALOG_NET;
740 case OpenCapture_Event:
741 i_id = INTF_DIALOG_CAPTURE;
744 i_id = INTF_DIALOG_SAT;
747 i_id = INTF_DIALOG_PLAYLIST;
750 i_id = INTF_DIALOG_MESSAGES;
753 i_id = INTF_DIALOG_FILEINFO;
756 i_id = INTF_DIALOG_PREFS;
759 i_id = INTF_DIALOG_WIZARD;
761 case Bookmarks_Event:
762 i_id = INTF_DIALOG_BOOKMARKS;
765 i_id = INTF_DIALOG_FILE;
769 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
773 void Interface::OnExtended(wxCommandEvent& event)
775 b_extra = (b_extra == VLC_TRUE ? VLC_FALSE : VLC_TRUE );
777 if( b_extra == VLC_FALSE )
780 frame_sizer->Hide( extra_frame );
785 frame_sizer->Show( extra_frame );
787 frame_sizer->Layout();
788 frame_sizer->Fit(this);
792 if( b_undock == VLC_TRUE )
794 fprintf(stderr,"Deleting window\n");
804 frame_sizer->Hide( extra_frame );
805 frame_sizer->Layout();
806 frame_sizer->Fit(this);
811 if( b_undock == VLC_TRUE )
813 fprintf(stderr,"Creating window\n");
815 frame_sizer->Hide( extra_frame );
816 frame_sizer->Detach( extra_frame );
817 frame_sizer->Layout();
818 frame_sizer->Fit(this);
819 extra_window = new ExtraWindow( p_intf, this, extra_frame );
823 fprintf(stderr,"Deleting window\n");
829 frame_sizer->Show( extra_frame );
830 frame_sizer->Layout();
831 frame_sizer->Fit(this);
836 void Interface::OnUndock(wxCommandEvent& event)
838 b_undock = (b_undock == VLC_TRUE ? VLC_FALSE : VLC_TRUE );
840 if( b_extra == VLC_TRUE )
842 if( b_undock == VLC_FALSE )
844 fprintf(stderr,"Deleting window\n");
851 frame_sizer->Show( extra_frame );
852 frame_sizer->Layout();
853 frame_sizer->Fit(this);
857 fprintf(stderr,"Creating window\n");
859 frame_sizer->Hide( extra_frame );
860 frame_sizer->Detach( extra_frame );
861 frame_sizer->Layout();
862 frame_sizer->Fit(this);
863 extra_window = new ExtraWindow( p_intf, this, extra_frame );
870 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
875 void Interface::PlayStream()
877 wxCommandEvent dummy;
878 playlist_t *p_playlist =
879 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
881 if( p_playlist == NULL ) return;
883 if( p_playlist->i_size && p_playlist->i_enabled )
887 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
890 if( p_input == NULL )
892 /* No stream was playing, start one */
893 playlist_Play( p_playlist );
894 TogglePlayButton( PLAYING_S );
895 vlc_object_release( p_playlist );
899 var_Get( p_input, "state", &state );
901 if( state.i_int != PAUSE_S )
903 /* A stream is being played, pause it */
904 state.i_int = PAUSE_S;
908 /* Stream is paused, resume it */
909 state.i_int = PLAYING_S;
911 var_Set( p_input, "state", state );
913 TogglePlayButton( state.i_int );
914 vlc_object_release( p_input );
915 vlc_object_release( p_playlist );
919 /* If the playlist is empty, open a file requester instead */
920 vlc_object_release( p_playlist );
921 OnShowDialog( dummy );
925 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
929 void Interface::StopStream()
931 playlist_t * p_playlist =
932 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
934 if( p_playlist == NULL )
939 playlist_Stop( p_playlist );
940 TogglePlayButton( PAUSE_S );
941 vlc_object_release( p_playlist );
944 void Interface::OnSliderUpdate( wxScrollEvent& event )
946 vlc_mutex_lock( &p_intf->change_lock );
949 if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
950 || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
953 if( p_intf->p_sys->i_slider_pos != event.GetPosition()
954 && p_intf->p_sys->p_input )
957 pos.f_float = (float)event.GetPosition() / (float)SLIDER_MAX_POS;
959 var_Set( p_intf->p_sys->p_input, "position", pos );
963 p_intf->p_sys->b_slider_free = VLC_TRUE;
967 p_intf->p_sys->b_slider_free = VLC_FALSE;
969 if( p_intf->p_sys->p_input )
971 /* Update stream date */
972 char psz_time[ MSTRTIME_MAX_SIZE ], psz_total[ MSTRTIME_MAX_SIZE ];
975 i_seconds = var_GetTime( p_intf->p_sys->p_input, "length" ) /
977 secstotimestr( psz_total, i_seconds );
979 i_seconds = var_GetTime( p_intf->p_sys->p_input, "time" ) /
981 secstotimestr( psz_time, i_seconds );
983 statusbar->SetStatusText( wxU(psz_time) + wxString(wxT(" / ") ) +
990 vlc_mutex_unlock( &p_intf->change_lock );
993 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
998 void Interface::PrevStream()
1000 playlist_t * p_playlist =
1001 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1003 if( p_playlist == NULL )
1008 /* FIXME --fenrir */
1010 if( p_playlist->p_input != NULL )
1012 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1013 if( p_playlist->p_input->stream.p_selected_area->i_id > 1 )
1015 vlc_value_t val; val.b_bool = VLC_TRUE;
1016 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1017 var_Set( p_playlist->p_input, "prev-title", val );
1019 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1021 vlc_mutex_unlock( &p_playlist->object_lock );
1024 playlist_Prev( p_playlist );
1025 vlc_object_release( p_playlist );
1028 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1033 void Interface::NextStream()
1035 playlist_t * p_playlist =
1036 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1038 if( p_playlist == NULL )
1043 /* FIXME --fenrir */
1045 var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
1046 vlc_mutex_lock( &p_playlist->object_lock );
1047 if( p_playlist->p_input != NULL )
1049 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1050 if( p_playlist->p_input->stream.i_area_nb > 1 &&
1051 p_playlist->p_input->stream.p_selected_area->i_id <
1052 p_playlist->p_input->stream.i_area_nb - 1 )
1054 vlc_value_t val; val.b_bool = VLC_TRUE;
1055 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1056 var_Set( p_playlist->p_input, "next-title", val );
1058 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1060 vlc_mutex_unlock( &p_playlist->object_lock );
1062 playlist_Next( p_playlist );
1063 vlc_object_release( p_playlist );
1066 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1068 input_thread_t *p_input =
1069 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1073 vlc_value_t val; val.b_bool = VLC_TRUE;
1075 var_Set( p_input, "rate-slower", val );
1076 vlc_object_release( p_input );
1080 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1082 input_thread_t *p_input =
1083 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1087 vlc_value_t val; val.b_bool = VLC_TRUE;
1089 var_Set( p_input, "rate-faster", val );
1090 vlc_object_release( p_input );
1094 void Interface::TogglePlayButton( int i_playing_status )
1096 if( i_playing_status == i_old_playing_status )
1099 wxToolBarToolBase *p_tool = (wxToolBarToolBase *)
1100 GetToolBar()->GetToolClientData( PlayStream_Event );
1101 if( !p_tool ) return;
1103 if( i_playing_status == PLAYING_S )
1105 p_tool->SetNormalBitmap( wxBitmap( pause_xpm ) );
1106 p_tool->SetLabel( wxU(_("Pause")) );
1107 p_tool->SetShortHelp( wxU(_(HELP_PAUSE)) );
1111 p_tool->SetNormalBitmap( wxBitmap( play_xpm ) );
1112 p_tool->SetLabel( wxU(_("Play")) );
1113 p_tool->SetShortHelp( wxU(_(HELP_PLAY)) );
1116 GetToolBar()->Realize();
1118 i_old_playing_status = i_playing_status;
1121 void Interface::OnDiscMenu( wxCommandEvent& WXUNUSED(event) )
1123 input_thread_t *p_input =
1124 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1128 vlc_value_t val; val.i_int = 2;
1130 var_Set( p_input, "title 0", val);
1131 vlc_object_release( p_input );
1135 void Interface::OnDiscPrev( wxCommandEvent& WXUNUSED(event) )
1137 input_thread_t *p_input =
1138 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1142 int i_type = var_Type( p_input, "prev-chapter" );
1143 vlc_value_t val; val.b_bool = VLC_TRUE;
1145 var_Set( p_input, ( i_type & VLC_VAR_TYPE ) != 0 ?
1146 "prev-chapter" : "prev-title", val );
1148 vlc_object_release( p_input );
1152 void Interface::OnDiscNext( wxCommandEvent& WXUNUSED(event) )
1154 input_thread_t *p_input =
1155 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1159 int i_type = var_Type( p_input, "next-chapter" );
1160 vlc_value_t val; val.b_bool = VLC_TRUE;
1162 var_Set( p_input, ( i_type & VLC_VAR_TYPE ) != 0 ?
1163 "next-chapter" : "next-title", val );
1165 vlc_object_release( p_input );
1169 #if wxUSE_DRAG_AND_DROP
1170 /*****************************************************************************
1171 * Definition of DragAndDrop class.
1172 *****************************************************************************/
1173 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
1176 b_enqueue = _b_enqueue;
1179 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1180 const wxArrayString& filenames )
1182 /* Add dropped files to the playlist */
1184 playlist_t *p_playlist =
1185 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1187 if( p_playlist == NULL )
1192 for( size_t i = 0; i < filenames.GetCount(); i++ )
1193 playlist_Add( p_playlist, (const char *)filenames[i].mb_str(),
1194 (const char *)filenames[i].mb_str(),
1195 PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
1198 vlc_object_release( p_playlist );
1204 /*****************************************************************************
1205 * Definition of VolCtrl class.
1206 *****************************************************************************/
1207 class wxVolCtrl: public wxGauge
1211 wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1212 wxPoint = wxDefaultPosition, wxSize = wxSize( 20, -1 ) );
1213 virtual ~wxVolCtrl() {};
1215 void UpdateVolume();
1217 void OnChange( wxMouseEvent& event );
1220 intf_thread_t *p_intf;
1222 DECLARE_EVENT_TABLE();
1225 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
1227 EVT_LEFT_DOWN(wxVolCtrl::OnChange)
1228 EVT_MOTION(wxVolCtrl::OnChange)
1231 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1232 wxPoint point, wxSize size )
1233 : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
1239 void wxVolCtrl::OnChange( wxMouseEvent& event )
1241 if( !event.LeftDown() && !event.LeftIsDown() ) return;
1243 int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
1244 aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1248 void wxVolCtrl::UpdateVolume()
1250 audio_volume_t i_volume;
1251 aout_VolumeGet( p_intf, &i_volume );
1253 int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
1254 if( i_gauge_volume == GetValue() ) return;
1256 SetValue( i_gauge_volume );
1257 SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
1258 i_gauge_volume / 2 ) );
1261 #if defined(__WXGTK__)
1262 #define VLCVOL_HEIGHT p_parent->GetSize().GetHeight()
1264 #define VLCVOL_HEIGHT TOOLBAR_BMP_HEIGHT
1266 VLCVolCtrl::VLCVolCtrl( intf_thread_t *_p_intf, wxWindow *p_parent )
1267 :wxControl( p_parent, -1, wxDefaultPosition, wxSize(64, VLCVOL_HEIGHT ),
1269 i_y_offset((VLCVOL_HEIGHT - TOOLBAR_BMP_HEIGHT) / 2),
1270 b_mute(0), p_intf(_p_intf)
1272 gauge = new wxVolCtrl( p_intf, this, -1, wxPoint( 18, i_y_offset ),
1273 wxSize( 44, TOOLBAR_BMP_HEIGHT ) );
1276 void VLCVolCtrl::OnPaint( wxPaintEvent &evt )
1278 wxPaintDC dc( this );
1279 wxBitmap mPlayBitmap( b_mute ? speaker_mute_xpm : speaker_xpm );
1280 dc.DrawBitmap( mPlayBitmap, 0, i_y_offset, TRUE );
1283 void VLCVolCtrl::OnChange( wxMouseEvent& event )
1285 if( event.GetX() < TOOLBAR_BMP_WIDTH )
1288 aout_VolumeMute( p_intf, (audio_volume_t *)&i_volume );
1295 void VLCVolCtrl::UpdateVolume()
1297 gauge->UpdateVolume();
1300 /*****************************************************************************
1302 *****************************************************************************/
1304 #ifdef wxHAS_TASK_BAR_ICON
1306 BEGIN_EVENT_TABLE(Systray, wxTaskBarIcon)
1309 EVT_TASKBAR_LEFT_DCLICK(Systray::OnLeftClick)
1311 EVT_TASKBAR_LEFT_DOWN(Systray::OnLeftClick)
1314 EVT_MENU(Iconize_Event, Systray::OnLeftClick)
1315 EVT_MENU(Exit_Event, Systray::OnExit)
1316 EVT_MENU(PlayStream_Event, Systray::OnPlayStream)
1317 EVT_MENU(NextStream_Event, Systray::OnNextStream)
1318 EVT_MENU(PrevStream_Event, Systray::OnPrevStream)
1319 EVT_MENU(StopStream_Event, Systray::OnStopStream)
1322 Systray::Systray( Interface *_p_main_interface )
1324 p_main_interface = _p_main_interface;
1327 /* Event handlers */
1328 void Systray::OnLeftClick( wxTaskBarIconEvent& event )
1330 p_main_interface->Show( ! p_main_interface->IsShown() );
1331 if ( p_main_interface->IsShown() ) p_main_interface->Raise();
1334 void Systray::OnExit( wxCommandEvent& event )
1336 p_main_interface->Close(TRUE);
1339 void Systray::OnPrevStream( wxCommandEvent& event )
1341 p_main_interface->PrevStream();
1344 void Systray::OnNextStream( wxCommandEvent& event )
1346 p_main_interface->NextStream();
1349 void Systray::OnPlayStream( wxCommandEvent& event )
1351 p_main_interface->PlayStream();
1354 void Systray::OnStopStream( wxCommandEvent& event )
1356 p_main_interface->StopStream();
1359 /* Systray popup menu */
1360 wxMenu* Systray::CreatePopupMenu()
1362 wxMenu* systray_menu = new wxMenu;
1363 systray_menu->Append( Exit_Event, wxU(_("Quit VLC")) );
1364 systray_menu->AppendSeparator();
1365 systray_menu->Append( PlayStream_Event, wxU(_("Play/Pause")) );
1366 systray_menu->Append( PrevStream_Event, wxU(_("Previous")) );
1367 systray_menu->Append( NextStream_Event, wxU(_("Next")) );
1368 systray_menu->Append( StopStream_Event, wxU(_("Stop")) );
1369 systray_menu->AppendSeparator();
1370 systray_menu->Append( Iconize_Event, wxU(_("Show/Hide interface")) );
1371 return systray_menu;
1374 void Systray::UpdateTooltip( const wxChar* tooltip )
1376 SetIcon( wxIcon( vlc16x16_xpm ), tooltip );