1 /*****************************************************************************
2 * interface.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004, 2003 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 *****************************************************************************/
31 #include "stream_control.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/speaker.xpm"
46 #define TOOLBAR_BMP_WIDTH 16
47 #define TOOLBAR_BMP_HEIGHT 16
49 /* include the icon graphic */
50 #include "../../../share/vlc32x32.xpm"
52 /*****************************************************************************
53 * Local class declarations.
54 *****************************************************************************/
55 class wxMenuExt: public wxMenu
59 wxMenuExt( wxMenu* parentMenu, int id, const wxString& text,
60 const wxString& helpString, wxItemKind kind,
61 char *_psz_var, int _i_object_id, vlc_value_t _val,
64 virtual ~wxMenuExt() {};
75 class wxVolCtrl: public wxGauge
79 wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
80 wxPoint = wxDefaultPosition, wxSize = wxSize( 20, -1 ) );
81 virtual ~wxVolCtrl() {};
83 void Change( int i_volume );
85 void OnChange( wxMouseEvent& event );
88 intf_thread_t *p_intf;
90 DECLARE_EVENT_TABLE();
93 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
95 EVT_LEFT_DOWN(wxVolCtrl::OnChange)
96 EVT_MOTION(wxVolCtrl::OnChange)
99 /*****************************************************************************
101 *****************************************************************************/
103 DEFINE_LOCAL_EVENT_TYPE( wxEVT_INTF );
105 /* IDs for the controls and the menu commands */
109 MenuDummy_Event = wxID_HIGHEST + 1000,
110 Exit_Event = wxID_HIGHEST,
111 OpenFileSimple_Event,
142 RestoreDefaults_Event,
152 /* it is important for the id corresponding to the "About" command to have
153 * this standard value as otherwise it won't be handled properly under Mac
154 * (where it is special and put into the "Apple" menu) */
155 About_Event = wxID_ABOUT
158 BEGIN_EVENT_TABLE(Interface, wxFrame)
160 EVT_MENU(Exit_Event, Interface::OnExit)
161 EVT_MENU(About_Event, Interface::OnAbout)
163 EVT_MENU(Playlist_Event, Interface::OnShowDialog)
164 EVT_MENU(Logs_Event, Interface::OnShowDialog)
165 EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
166 EVT_MENU(Prefs_Event, Interface::OnShowDialog)
168 EVT_MENU_OPEN(Interface::OnMenuOpen)
170 EVT_MENU( Extended_Event, Interface::OnExtended)
171 EVT_MENU( Bookmarks_Event, Interface::OnShowDialog)
173 EVT_CHECKBOX( Adjust_Event, Interface::OnEnableAdjust)
174 EVT_BUTTON( RestoreDefaults_Event, Interface::OnRestoreDefaults)
175 EVT_TEXT( Ratio_Event, Interface::OnRatio)
176 EVT_CHECKBOX( Visual_Event, Interface::OnEnableVisual)
178 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
179 EVT_CONTEXT_MENU(Interface::OnContextMenu2)
181 EVT_RIGHT_UP(Interface::OnContextMenu)
184 EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
185 EVT_MENU(OpenAdv_Event, Interface::OnShowDialog)
186 EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
187 EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
188 EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
189 EVT_MENU(OpenCapture_Event, Interface::OnShowDialog)
190 EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
191 EVT_MENU(StreamWizard_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)
201 EVT_COMMAND_SCROLL(SliderScroll_Event, Interface::OnSliderUpdate)
203 EVT_COMMAND_SCROLL(Hue_Event, Interface::OnAdjustUpdate)
204 EVT_COMMAND_SCROLL(Contrast_Event, Interface::OnAdjustUpdate)
205 EVT_COMMAND_SCROLL(Brightness_Event, Interface::OnAdjustUpdate)
206 EVT_COMMAND_SCROLL(Saturation_Event, Interface::OnAdjustUpdate)
207 EVT_COMMAND_SCROLL(Gamma_Event, Interface::OnAdjustUpdate)
210 EVT_COMMAND(0, wxEVT_INTF, Interface::OnControlEvent)
211 EVT_COMMAND(1, wxEVT_INTF, Interface::OnControlEvent)
215 /*****************************************************************************
217 *****************************************************************************/
218 Interface::Interface( intf_thread_t *_p_intf ):
219 wxFrame( NULL, -1, wxT("VLC media player"),
220 wxDefaultPosition, wxSize(700,100), wxDEFAULT_FRAME_STYLE )
222 /* Initializations */
224 i_old_playing_status = PAUSE_S;
227 /* Give our interface a nice little icon */
228 SetIcon( wxIcon( vlc_xpm ) );
230 /* Create a sizer for the main frame */
231 frame_sizer = new wxBoxSizer( wxVERTICAL );
232 SetSizer( frame_sizer );
234 /* Create a dummy widget that can get the keyboard focus */
235 wxWindow *p_dummy = new wxWindow( this, 0, wxDefaultPosition,
238 frame_sizer->Add( p_dummy, 0, wxEXPAND );
240 /* Creation of the menu bar */
243 /* Creation of the tool bar */
246 /* Create the extra panel */
247 CreateOurExtendedPanel();
248 frame_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
249 frame_sizer->Hide( extra_frame );
251 /* Creation of the status bar
252 * Helptext for menu items and toolbar tools will automatically get
254 int i_status_width[3] = {-6, -2, -9};
255 statusbar = CreateStatusBar( 3 ); /* 2 fields */
256 statusbar->SetStatusWidths( 3, i_status_width );
257 statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
260 if( config_GetInt( p_intf, "wxwin-embed" ) )
262 VideoWindow( p_intf, this );
263 frame_sizer->Add( p_intf->p_sys->p_video_sizer, 1, wxEXPAND , 0 );
266 /* Creation of the slider sub-window */
268 frame_sizer->Add( slider_frame, 0, wxEXPAND , 0 );
269 frame_sizer->Hide( slider_frame );
271 /* Make sure we've got the right background colour */
272 SetBackgroundColour( slider_frame->GetBackgroundColour() );
274 /* Layout everything */
275 frame_sizer->Layout();
276 frame_sizer->Fit(this);
278 #if !defined(__WXX11__)
279 /* Associate drop targets with the main interface */
280 SetDropTarget( new DragAndDrop( p_intf ) );
283 UpdateAcceleratorTable();
286 timer = new Timer( p_intf, this );
289 Interface::~Interface()
291 if( p_intf->p_sys->p_wxwindow )
293 delete p_intf->p_sys->p_wxwindow;
300 void Interface::OnControlEvent( wxCommandEvent& event )
302 switch( event.GetId() )
305 frame_sizer->Layout();
306 frame_sizer->Fit(this);
310 long i_style = GetWindowStyle();
311 if( event.GetInt() ) i_style |= wxSTAY_ON_TOP;
312 else i_style &= ~wxSTAY_ON_TOP;
313 SetWindowStyle( i_style );
318 /*****************************************************************************
320 *****************************************************************************/
321 void Interface::CreateOurMenuBar()
323 /* Create the "File" menu */
324 wxMenu *file_menu = new wxMenu;
325 file_menu->Append( OpenFileSimple_Event,
326 wxU(_("Quick &Open File...\tCtrl-O")) );
328 file_menu->AppendSeparator();
329 file_menu->Append( OpenFile_Event, wxU(_("Open &File...\tCtrl-F")) );
330 file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...\tCtrl-D")) );
331 file_menu->Append( OpenNet_Event,
332 wxU(_("Open &Network Stream...\tCtrl-N")) );
333 file_menu->Append( OpenCapture_Event,
334 wxU(_("Open &Capture Device...\tCtrl-C")) );
336 file_menu->AppendSeparator();
337 file_menu->Append( StreamWizard_Event,
338 wxU(_("Streaming &Wizard...\tCtrl-W")) );
339 file_menu->Append( Wizard_Event, wxU(_("New Wizard...")) );
340 file_menu->AppendSeparator();
341 file_menu->Append( Exit_Event, wxU(_("E&xit\tCtrl-X")) );
343 /* Create the "View" menu */
344 wxMenu *view_menu = new wxMenu;
345 view_menu->Append( Playlist_Event, wxU(_("&Playlist...\tCtrl-P")) );
346 view_menu->Append( Logs_Event, wxU(_("&Messages...\tCtrl-M")) );
347 view_menu->Append( FileInfo_Event,
348 wxU(_("Stream and Media &info...\tCtrl-I")) );
350 /* Create the "Auto-generated" menus */
351 p_settings_menu = SettingsMenu( p_intf, this );
352 p_audio_menu = AudioMenu( p_intf, this );
353 p_video_menu = VideoMenu( p_intf, this );
354 p_navig_menu = NavigMenu( p_intf, this );
356 /* Create the "Help" menu */
357 wxMenu *help_menu = new wxMenu;
358 help_menu->Append( About_Event, wxU(_("About VLC media player")) );
360 /* Append the freshly created menus to the menu bar... */
361 wxMenuBar *menubar = new wxMenuBar( wxMB_DOCKABLE );
362 menubar->Append( file_menu, wxU(_("&File")) );
363 menubar->Append( view_menu, wxU(_("&View")) );
364 menubar->Append( p_settings_menu, wxU(_("&Settings")) );
365 menubar->Append( p_audio_menu, wxU(_("&Audio")) );
366 menubar->Append( p_video_menu, wxU(_("&Video")) );
367 menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
368 menubar->Append( help_menu, wxU(_("&Help")) );
370 /* Attach the menu bar to the frame */
371 SetMenuBar( menubar );
373 /* Find out size of menu bar */
375 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
377 int i_width, i_height;
378 menubar->GetTextExtent( menubar->GetLabelTop(i), &i_width, &i_height );
380 #if defined(__WXGTK__)
381 20 /* approximate margin */;
383 4 /* approximate margin */;
386 frame_sizer->SetMinSize( i_size, -1 );
388 /* Intercept all menu events in our custom event handler */
389 PushEventHandler( new MenuEvtHandler( p_intf, this ) );
391 #if !defined(__WXX11__)
392 /* Associate drop targets with the menubar */
393 menubar->SetDropTarget( new DragAndDrop( p_intf ) );
397 class VLCVolCtrl : public wxControl
400 VLCVolCtrl( intf_thread_t *p_intf, wxWindow *p_parent, wxGauge ** );
401 virtual ~VLCVolCtrl() {};
403 virtual void OnPaint( wxPaintEvent &event );
406 DECLARE_EVENT_TABLE()
409 BEGIN_EVENT_TABLE(VLCVolCtrl, wxControl)
410 EVT_PAINT(VLCVolCtrl::OnPaint)
413 VLCVolCtrl::VLCVolCtrl( intf_thread_t *p_intf, wxWindow *p_parent,
414 wxGauge **pp_volctrl )
415 :wxControl( p_parent, -1, wxDefaultPosition, wxSize(64, 16 ), wxBORDER_NONE )
417 *pp_volctrl = new wxVolCtrl( p_intf, this, -1, wxPoint(18,0),
421 void VLCVolCtrl::OnPaint( wxPaintEvent &evt )
423 wxPaintDC dc( this );
424 wxBitmap mPlayBitmap( speaker_xpm );
425 dc.DrawBitmap( mPlayBitmap, 1, 0, TRUE );
428 void Interface::CreateOurToolBar()
430 #define HELP_STOP N_("Stop")
431 #define HELP_PLAY N_("Play")
432 #define HELP_PAUSE N_("Pause")
433 #define HELP_PLO N_("Playlist")
434 #define HELP_PLP N_("Previous playlist item")
435 #define HELP_PLN N_("Next playlist item")
436 #define HELP_SLOW N_("Play slower")
437 #define HELP_FAST N_("Play faster")
439 wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
440 * version because we don't include wx.rc */
443 CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT | wxTB_DOCKABLE );
445 toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
447 toolbar->AddTool( PlayStream_Event, wxT(""), wxBitmap( play_xpm ),
450 toolbar->AddTool( PlayStream_Event, wxT(""), wxBitmap( pause_xpm ),
451 wxU(_(HELP_PAUSE)) );
453 toolbar->AddTool( StopStream_Event, wxT(""), wxBitmap( stop_xpm ),
455 toolbar->AddSeparator();
456 toolbar->AddTool( PrevStream_Event, wxT(""),
457 wxBitmap( prev_xpm ), wxU(_(HELP_PLP)) );
458 toolbar->AddTool( SlowStream_Event, wxT(""),
459 wxBitmap( slow_xpm ), wxU(_(HELP_SLOW)) );
460 toolbar->AddTool( FastStream_Event, wxT(""),
461 wxBitmap( fast_xpm ), wxU(_(HELP_FAST)) );
462 toolbar->AddTool( NextStream_Event, wxT(""), wxBitmap( next_xpm ),
464 toolbar->AddSeparator();
465 toolbar->AddTool( Playlist_Event, wxT(""), wxBitmap( eject_xpm ),
468 wxControl *p_dummy_ctrl =
469 new wxControl( toolbar, -1, wxDefaultPosition,
470 wxSize(64, 16 ), wxBORDER_NONE );
472 toolbar->AddControl( p_dummy_ctrl );
474 VLCVolCtrl *sound_control = new VLCVolCtrl( p_intf, toolbar, &volctrl );
475 toolbar->AddControl( sound_control );
479 #if !defined(__WXX11__)
480 /* Associate drop targets with the toolbar */
481 toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
485 void Interface::CreateOurSlider()
487 /* Create a new frame and sizer containing the slider */
488 slider_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
489 slider_frame->SetAutoLayout( TRUE );
490 wxBoxSizer *frame_sizer = new wxBoxSizer( wxHORIZONTAL );
491 //frame_sizer->SetMinSize( -1, 50 );
494 slider = new wxSlider( slider_frame, SliderScroll_Event, 0, 0,
495 SLIDER_MAX_POS, wxDefaultPosition, wxDefaultSize );
497 /* Add everything to the frame */
498 frame_sizer->Add( slider, 1, wxEXPAND | wxALL, 5 );
499 slider_frame->SetSizer( frame_sizer );
500 frame_sizer->Layout();
501 frame_sizer->SetSizeHints(slider_frame);
503 /* Hide the slider by default */
504 slider_frame->Hide();
508 void Interface::CreateOurExtendedPanel()
512 extra_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
513 extra_frame->SetAutoLayout( TRUE );
514 wxBoxSizer *extra_sizer = new wxBoxSizer( wxHORIZONTAL );
516 /* Create static box to surround the adjust controls */
517 wxStaticBox *adjust_box =
518 new wxStaticBox( extra_frame, -1, wxU(_("Adjust Image")) );
520 /* Create the size for the frame */
521 wxStaticBoxSizer *adjust_sizer =
522 new wxStaticBoxSizer( adjust_box, wxVERTICAL );
523 adjust_sizer->SetMinSize( -1, 50 );
525 /* Create flex grid */
526 wxFlexGridSizer *adjust_gridsizer =
527 new wxFlexGridSizer( 6, 2, 0, 0);
528 adjust_gridsizer->AddGrowableCol(1);
530 /* Create every controls */
532 /* Create the adjust button */
533 wxCheckBox * adjust_check = new wxCheckBox( extra_frame, Adjust_Event,
536 /* Create the restore to defaults button */
537 restoredefaults_button =
538 new wxButton( extra_frame, RestoreDefaults_Event,
539 wxU(_("Restore Defaults")), wxDefaultPosition);
541 wxStaticText *hue_text = new wxStaticText( extra_frame, -1,
543 hue_slider = new wxSlider ( extra_frame, Hue_Event, 0, 0,
544 360, wxDefaultPosition, wxDefaultSize );
547 wxStaticText *contrast_text = new wxStaticText( extra_frame, -1,
548 wxU(_("Contrast")) );
549 contrast_slider = new wxSlider ( extra_frame, Contrast_Event, 0, 0,
550 200, wxDefaultPosition, wxDefaultSize);
552 wxStaticText *brightness_text = new wxStaticText( extra_frame, -1,
553 wxU(_("Brightness")) );
554 brightness_slider = new wxSlider ( extra_frame, Brightness_Event, 0, 0,
555 200, wxDefaultPosition, wxDefaultSize) ;
557 wxStaticText *saturation_text = new wxStaticText( extra_frame, -1,
558 wxU(_("Saturation")) );
559 saturation_slider = new wxSlider ( extra_frame, Saturation_Event, 0, 0,
560 300, wxDefaultPosition, wxDefaultSize );
562 wxStaticText *gamma_text = new wxStaticText( extra_frame, -1,
564 gamma_slider = new wxSlider ( extra_frame, Gamma_Event, 0, 0,
565 100, wxDefaultPosition, wxDefaultSize );
567 adjust_gridsizer->Add(adjust_check, 1, wxEXPAND, 0);
568 adjust_gridsizer->Add(restoredefaults_button, 1, wxEXPAND, 0);
569 adjust_gridsizer->Add(hue_text, 1, wxEXPAND, 0);
570 adjust_gridsizer->Add(hue_slider, 1, wxEXPAND, 0);
571 adjust_gridsizer->Add(contrast_text, 1, wxEXPAND, 0);
572 adjust_gridsizer->Add(contrast_slider, 1, wxEXPAND, 0);
573 adjust_gridsizer->Add(brightness_text, 1, wxEXPAND, 0);
574 adjust_gridsizer->Add(brightness_slider, 1, wxEXPAND, 0);
575 adjust_gridsizer->Add(saturation_text, 1, wxEXPAND, 0);
576 adjust_gridsizer->Add(saturation_slider, 1, wxEXPAND, 0);
577 adjust_gridsizer->Add(gamma_text, 1, wxEXPAND, 0);
578 adjust_gridsizer->Add(gamma_slider, 1, wxEXPAND, 0);
580 adjust_sizer->Add(adjust_gridsizer,1,wxEXPAND, 0);
582 extra_sizer->Add(adjust_sizer,1,wxBOTTOM,5);
584 /* Create sizer to surround the other controls */
585 wxBoxSizer *other_sizer = new wxBoxSizer( wxVERTICAL );
588 wxStaticBox *video_box =
589 new wxStaticBox( extra_frame, -1, wxU(_("Video Options")) );
590 /* Create the sizer for the frame */
591 wxStaticBoxSizer *video_sizer =
592 new wxStaticBoxSizer( video_box, wxVERTICAL );
593 video_sizer->SetMinSize( -1, 50 );
595 static const wxString ratio_array[] =
601 wxBoxSizer *ratio_sizer = new wxBoxSizer( wxHORIZONTAL );
602 wxStaticText *ratio_text = new wxStaticText( extra_frame, -1,
603 wxU(_("Aspect Ratio")) );
605 ratio_combo = new wxComboBox( extra_frame, Ratio_Event, wxT(""),
606 wxDefaultPosition, wxSize(120,-1),
607 WXSIZEOF(ratio_array), ratio_array,
610 ratio_sizer->Add( ratio_text, 0, wxALL, 2 );
611 ratio_sizer->Add( ratio_combo, 0, wxALL, 2 );
612 ratio_sizer->Layout();
614 video_sizer->Add( ratio_sizer , 0 , wxALL , 0 );
615 video_sizer->Layout();
618 wxBoxSizer *visual_sizer = new wxBoxSizer( wxHORIZONTAL );
620 wxCheckBox *visual_checkbox = new wxCheckBox( extra_frame, Visual_Event,
621 wxU(_("Visualisations")) );
623 visual_sizer->Add( visual_checkbox, 0, wxEXPAND, 0);
624 visual_sizer->Layout();
626 wxStaticBox *audio_box =
627 new wxStaticBox( extra_frame, -1, wxU(_("Audio Options")) );
628 /* Create the sizer for the frame */
629 wxStaticBoxSizer *audio_sizer =
630 new wxStaticBoxSizer( audio_box, wxVERTICAL );
631 audio_sizer->SetMinSize( -1, 50 );
633 audio_sizer->Add( visual_sizer, 0, wxALL, 0);
634 audio_sizer->Layout();
636 other_sizer->Add( audio_sizer , 0 , wxALL | wxEXPAND , 0 );
638 other_sizer->Add( video_sizer, 0, wxALL | wxEXPAND , 0);
639 other_sizer->Layout();
641 extra_sizer->Add(other_sizer,0,wxBOTTOM,5);
643 extra_frame->SetSizer( extra_sizer );
645 /* Layout the whole panel */
646 extra_sizer->Layout();
648 extra_sizer->SetSizeHints(extra_frame);
650 /* Write down initial values */
652 psz_filters = config_GetPsz( p_intf, "audio-filter" );
653 if( psz_filters && strstr( psz_filters, "visual" ) )
655 visual_checkbox->SetValue(1);
657 if( psz_filters ) free( psz_filters );
659 psz_filters = config_GetPsz( p_intf, "filter" );
660 if( psz_filters && strstr( psz_filters, "adjust" ) )
662 adjust_check->SetValue( 1 );
663 restoredefaults_button->Enable();
664 saturation_slider->Enable();
665 contrast_slider->Enable();
666 brightness_slider->Enable();
667 hue_slider->Enable();
668 gamma_slider->Enable();
672 adjust_check->SetValue( 0 );
673 restoredefaults_button->Disable();
674 saturation_slider->Disable();
675 contrast_slider->Disable();
676 brightness_slider->Disable();
677 hue_slider->Disable();
678 gamma_slider->Disable();
680 if( psz_filters ) free( psz_filters );
682 int i_value = config_GetInt( p_intf, "hue" );
683 if( i_value > 0 && i_value < 360 )
684 hue_slider->SetValue( i_value );
687 f_value = config_GetFloat( p_intf, "saturation" );
688 if( f_value > 0 && f_value < 5 )
689 saturation_slider->SetValue( (int)(100 * f_value) );
690 f_value = config_GetFloat( p_intf, "contrast" );
691 if( f_value > 0 && f_value < 4 )
692 contrast_slider->SetValue( (int)(100 * f_value) );
693 f_value = config_GetFloat( p_intf, "brightness" );
694 if( f_value > 0 && f_value < 2 )
695 brightness_slider->SetValue( (int)(100 * f_value) );
696 f_value = config_GetFloat( p_intf, "gamma" );
697 if( f_value > 0 && f_value < 10 )
698 gamma_slider->SetValue( (int)(10 * f_value) );
703 void Interface::UpdateAcceleratorTable()
705 /* Set some hotkeys */
706 wxAcceleratorEntry entries[7];
710 var_Get( p_intf->p_vlc, "key-quit", &val );
711 entries[i++].Set( ConvertHotkeyModifiers( val.i_int ),
712 ConvertHotkey( val.i_int ), Exit_Event );
713 var_Get( p_intf->p_vlc, "key-stop", &val );
714 entries[i++].Set( ConvertHotkeyModifiers( val.i_int ),
715 ConvertHotkey( val.i_int ), StopStream_Event );
716 var_Get( p_intf->p_vlc, "key-play-pause", &val );
717 entries[i++].Set( ConvertHotkeyModifiers( val.i_int ),
718 ConvertHotkey( val.i_int ), PlayStream_Event );
719 var_Get( p_intf->p_vlc, "key-next", &val );
720 entries[i++].Set( ConvertHotkeyModifiers( val.i_int ),
721 ConvertHotkey( val.i_int ), NextStream_Event );
722 var_Get( p_intf->p_vlc, "key-prev", &val );
723 entries[i++].Set( ConvertHotkeyModifiers( val.i_int ),
724 ConvertHotkey( val.i_int ), PrevStream_Event );
725 var_Get( p_intf->p_vlc, "key-faster", &val );
726 entries[i++].Set( ConvertHotkeyModifiers( val.i_int ),
727 ConvertHotkey( val.i_int ), FastStream_Event );
728 var_Get( p_intf->p_vlc, "key-slower", &val );
729 entries[i++].Set( ConvertHotkeyModifiers( val.i_int ),
730 ConvertHotkey( val.i_int ), SlowStream_Event );
732 wxAcceleratorTable accel( 7, entries );
735 msg_Err( p_intf, "invalid accelerator table" );
737 SetAcceleratorTable( accel );
738 msg_Dbg( p_intf, "accelerator table loaded" );
742 /*****************************************************************************
744 *****************************************************************************/
746 void Interface::OnMenuOpen(wxMenuEvent& event)
748 #if defined( __WXMSW__ )
749 # define GetEventObject GetMenu
752 if( event.GetEventObject() == p_settings_menu )
754 p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );
756 /* Add static items */
757 p_settings_menu->AppendCheckItem( Extended_Event,
758 wxU(_("&Extended GUI") ) );
759 p_settings_menu->AppendCheckItem( Bookmarks_Event,
760 wxU(_("&Bookmarks...") ) );
761 p_settings_menu->Append( Prefs_Event, wxU(_("&Preferences...")) );
764 else if( event.GetEventObject() == p_audio_menu )
766 p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
769 else if( event.GetEventObject() == p_video_menu )
771 p_video_menu = VideoMenu( p_intf, this, p_video_menu );
774 else if( event.GetEventObject() == p_navig_menu )
776 p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
779 #if defined( __WXMSW__ )
780 # undef GetEventObject
784 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
785 void Interface::OnContextMenu2(wxContextMenuEvent& event)
787 /* Only show the context menu for the main interface */
788 if( GetId() != event.GetId() )
794 if( p_intf->p_sys->pf_show_dialog )
795 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
798 void Interface::OnContextMenu(wxMouseEvent& event)
800 if( p_intf->p_sys->pf_show_dialog )
801 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
804 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
806 /* TRUE is to force the frame to close. */
810 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
813 msg.Printf( wxString(wxT("VLC media player " VERSION)) +
814 wxU(_(" (wxWindows interface)\n\n")) +
815 wxU(_("(c) 1996-2004 - the VideoLAN Team\n\n")) +
816 wxU( vlc_wraptext(INTF_ABOUT_MSG,WRAPCOUNT,ISUTF8) ) + wxT("\n\n") +
817 wxU(_("The VideoLAN team <videolan@videolan.org>\n"
818 "http://www.videolan.org/\n\n")) );
820 wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
821 wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
824 void Interface::OnShowDialog( wxCommandEvent& event )
826 if( p_intf->p_sys->pf_show_dialog )
830 switch( event.GetId() )
832 case OpenFileSimple_Event:
833 i_id = INTF_DIALOG_FILE_SIMPLE;
836 i_id = INTF_DIALOG_FILE;
838 i_id = INTF_DIALOG_FILE;
841 i_id = INTF_DIALOG_DISC;
844 i_id = INTF_DIALOG_NET;
846 case OpenCapture_Event:
847 i_id = INTF_DIALOG_CAPTURE;
850 i_id = INTF_DIALOG_SAT;
853 i_id = INTF_DIALOG_PLAYLIST;
856 i_id = INTF_DIALOG_MESSAGES;
859 i_id = INTF_DIALOG_FILEINFO;
862 i_id = INTF_DIALOG_PREFS;
864 case StreamWizard_Event:
865 i_id = INTF_DIALOG_STREAMWIZARD;
868 i_id = INTF_DIALOG_WIZARD;
870 case Bookmarks_Event:
871 i_id = INTF_DIALOG_BOOKMARKS;
874 i_id = INTF_DIALOG_FILE;
878 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
882 void Interface::OnExtended(wxCommandEvent& event)
884 if( b_extra == VLC_FALSE)
887 frame_sizer->Show( extra_frame );
893 frame_sizer->Hide( extra_frame );
896 frame_sizer->Layout();
897 frame_sizer->Fit(this);
900 void Interface::OnEnableAdjust(wxCommandEvent& event)
902 char *psz_filters=config_GetPsz( p_intf, "filter");
903 char *psz_new = NULL;
904 if( event.IsChecked() )
906 if(psz_filters == NULL)
908 psz_new = strdup( "adjust" );
912 psz_new= (char *) malloc(strlen(psz_filters) + 8 );
913 sprintf( psz_new, "%s:adjust", psz_filters);
915 config_PutPsz( p_intf, "filter", psz_new );
917 vout_thread_t *p_vout =
918 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
922 val.psz_string = strdup( psz_new );
923 var_Set( p_vout, "filter", val);
924 vlc_object_release( p_vout );
926 if( val.psz_string ) free( val.psz_string );
927 restoredefaults_button->Enable();
928 brightness_slider->Enable();
929 saturation_slider->Enable();
930 contrast_slider->Enable();
931 hue_slider->Enable();
932 gamma_slider->Enable();
936 if( psz_filters != NULL )
941 for( i = 0; i< strlen(psz_filters ); i++)
943 if ( !strncasecmp( &psz_filters[i],"adjust",6 ))
946 if( psz_filters[i-1] == ':' ) i--;
947 psz_current = strchr( &psz_filters[i+1] , ':' );
949 psz_filters[i] = '\0';
952 memmove( &psz_filters[i] , psz_current,
953 &psz_filters[strlen(psz_filters)]-psz_current
958 config_PutPsz( p_intf, "filter", psz_filters);
960 val.psz_string = strdup( psz_filters );
961 vout_thread_t *p_vout =
962 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
966 var_Set( p_vout, "filter", val);
967 vlc_object_release( p_vout );
969 if( val.psz_string ) free( val.psz_string );
971 restoredefaults_button->Disable();
972 brightness_slider->Disable();
973 saturation_slider->Disable();
974 contrast_slider->Disable();
975 hue_slider->Disable();
976 gamma_slider->Disable();
978 if(psz_filters) free(psz_filters);
979 if(psz_new) free(psz_new);
982 void Interface::OnRestoreDefaults( wxCommandEvent &event)
984 hue_slider->SetValue(0);
985 saturation_slider->SetValue(100);
986 brightness_slider->SetValue(100);
987 contrast_slider->SetValue(100),
988 gamma_slider->SetValue(10);
990 wxScrollEvent *hscroll_event = new wxScrollEvent(0, Hue_Event, 0);
991 OnAdjustUpdate(*hscroll_event);
993 wxScrollEvent *sscroll_event = new wxScrollEvent(0, Saturation_Event, 100);
994 OnAdjustUpdate(*sscroll_event);
996 wxScrollEvent *bscroll_event = new wxScrollEvent(0, Brightness_Event, 100);
997 OnAdjustUpdate(*bscroll_event);
999 wxScrollEvent *cscroll_event = new wxScrollEvent(0, Contrast_Event, 100);
1000 OnAdjustUpdate(*cscroll_event);
1002 wxScrollEvent *gscroll_event = new wxScrollEvent(0, Gamma_Event, 10);
1003 OnAdjustUpdate(*gscroll_event);
1007 void Interface::OnAdjustUpdate( wxScrollEvent &event)
1009 vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find(p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE);
1011 switch(event.GetId())
1014 config_PutInt( p_intf , "hue" , event.GetPosition() );
1017 case Saturation_Event:
1018 config_PutFloat( p_intf , "saturation" , (float)event.GetPosition()/100 );
1021 case Brightness_Event:
1022 config_PutFloat( p_intf , "brightness" , (float)event.GetPosition()/100 );
1025 case Contrast_Event:
1026 config_PutFloat( p_intf , "contrast" , (float)event.GetPosition()/100 );
1030 config_PutFloat( p_intf , "gamma" , (float)event.GetPosition()/10 );
1036 switch(event.GetId())
1039 val.i_int = event.GetPosition();
1040 var_Set(p_vout, "hue", val);
1043 case Saturation_Event:
1044 val.f_float = (float)event.GetPosition()/100;
1045 var_Set(p_vout, "saturation", val);
1048 case Brightness_Event:
1049 val.f_float = (float)event.GetPosition()/100;
1050 var_Set(p_vout, "brightness", val);
1053 case Contrast_Event:
1054 val.f_float = (float)event.GetPosition()/100;
1055 var_Set(p_vout, "contrast", val);
1059 val.f_float = (float)event.GetPosition()/10;
1060 var_Set(p_vout, "gamma", val);
1063 vlc_object_release(p_vout);
1067 void Interface::OnRatio( wxCommandEvent& event )
1069 config_PutPsz( p_intf, "aspect-ratio", ratio_combo->GetValue().mb_str() );
1072 void Interface::OnEnableVisual(wxCommandEvent& event)
1074 if( event.IsChecked() )
1076 config_PutPsz( p_intf, "audio-filter", "visual" );
1080 config_PutPsz( p_intf, "audio-filter", "" );
1084 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
1086 wxCommandEvent dummy;
1087 playlist_t *p_playlist =
1088 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1090 if( p_playlist == NULL ) return;
1092 if( p_playlist->i_size && p_playlist->i_enabled )
1096 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
1099 if( p_input == NULL )
1101 /* No stream was playing, start one */
1102 playlist_Play( p_playlist );
1103 TogglePlayButton( PLAYING_S );
1104 vlc_object_release( p_playlist );
1108 var_Get( p_input, "state", &state );
1110 if( state.i_int != PAUSE_S )
1112 /* A stream is being played, pause it */
1113 state.i_int = PAUSE_S;
1117 /* Stream is paused, resume it */
1118 state.i_int = PLAYING_S;
1120 var_Set( p_input, "state", state );
1122 TogglePlayButton( state.i_int );
1123 vlc_object_release( p_input );
1124 vlc_object_release( p_playlist );
1128 /* If the playlist is empty, open a file requester instead */
1129 vlc_object_release( p_playlist );
1130 OnShowDialog( dummy );
1134 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
1136 playlist_t * p_playlist =
1137 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1139 if( p_playlist == NULL )
1144 playlist_Stop( p_playlist );
1145 TogglePlayButton( PAUSE_S );
1146 vlc_object_release( p_playlist );
1149 void Interface::OnSliderUpdate( wxScrollEvent& event )
1151 vlc_mutex_lock( &p_intf->change_lock );
1154 if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
1155 || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
1158 if( p_intf->p_sys->i_slider_pos != event.GetPosition()
1159 && p_intf->p_sys->p_input )
1162 pos.f_float = (float)event.GetPosition() / (float)SLIDER_MAX_POS;
1164 var_Set( p_intf->p_sys->p_input, "position", pos );
1168 p_intf->p_sys->b_slider_free = VLC_TRUE;
1172 p_intf->p_sys->b_slider_free = VLC_FALSE;
1174 if( p_intf->p_sys->p_input )
1176 /* Update stream date */
1177 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
1178 char psz_time[ MSTRTIME_MAX_SIZE ], psz_total[ MSTRTIME_MAX_SIZE ];
1182 var_Get( p_intf->p_sys->p_input, "length", &val );
1183 i_seconds = val.i_time / 1000000;
1184 secstotimestr ( psz_total, i_seconds );
1186 statusbar->SetStatusText(
1187 wxU(input_OffsetToTime( p_intf->p_sys->p_input,
1188 psz_time, p_area->i_size * event.GetPosition()
1189 / SLIDER_MAX_POS )) + wxString(wxT(" / ")) +
1190 wxU(psz_total), 0 );
1197 vlc_mutex_unlock( &p_intf->change_lock );
1200 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
1202 playlist_t * p_playlist =
1203 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1205 if( p_playlist == NULL )
1210 vlc_mutex_lock( &p_playlist->object_lock );
1211 if( p_playlist->p_input != NULL )
1213 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1214 if( p_playlist->p_input->stream.p_selected_area->i_id > 1 )
1216 vlc_value_t val; val.b_bool = VLC_TRUE;
1217 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1218 var_Set( p_playlist->p_input, "prev-title", val );
1220 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1222 vlc_mutex_unlock( &p_playlist->object_lock );
1224 playlist_Prev( p_playlist );
1225 vlc_object_release( p_playlist );
1228 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1230 playlist_t * p_playlist =
1231 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1233 if( p_playlist == NULL )
1238 vlc_mutex_lock( &p_playlist->object_lock );
1239 if( p_playlist->p_input != NULL )
1241 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1242 if( p_playlist->p_input->stream.i_area_nb > 1 &&
1243 p_playlist->p_input->stream.p_selected_area->i_id <
1244 p_playlist->p_input->stream.i_area_nb - 1 )
1246 vlc_value_t val; val.b_bool = VLC_TRUE;
1247 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1248 var_Set( p_playlist->p_input, "next-title", val );
1250 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1252 vlc_mutex_unlock( &p_playlist->object_lock );
1254 playlist_Next( p_playlist );
1255 vlc_object_release( p_playlist );
1258 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1260 input_thread_t *p_input =
1261 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1265 vlc_value_t val; val.b_bool = VLC_TRUE;
1267 var_Set( p_input, "rate-slower", val );
1268 vlc_object_release( p_input );
1272 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1274 input_thread_t *p_input =
1275 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1279 vlc_value_t val; val.b_bool = VLC_TRUE;
1281 var_Set( p_input, "rate-faster", val );
1282 vlc_object_release( p_input );
1286 void Interface::TogglePlayButton( int i_playing_status )
1288 if( i_playing_status == i_old_playing_status )
1291 GetToolBar()->DeleteTool( PlayStream_Event );
1293 if( i_playing_status == PLAYING_S )
1295 GetToolBar()->InsertTool( 0, PlayStream_Event, wxU(_("Pause")),
1296 wxBitmap( pause_xpm ), wxNullBitmap,
1297 wxITEM_NORMAL, wxU(_(HELP_PAUSE)) );
1301 GetToolBar()->InsertTool( 0, PlayStream_Event, wxU(_("Play")),
1302 wxBitmap( play_xpm ), wxNullBitmap,
1303 wxITEM_NORMAL, wxU(_(HELP_PLAY)) );
1306 GetToolBar()->Realize();
1308 i_old_playing_status = i_playing_status;
1311 #if !defined(__WXX11__)
1312 /*****************************************************************************
1313 * Definition of DragAndDrop class.
1314 *****************************************************************************/
1315 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
1318 b_enqueue = _b_enqueue;
1321 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1322 const wxArrayString& filenames )
1324 /* Add dropped files to the playlist */
1326 playlist_t *p_playlist =
1327 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1329 if( p_playlist == NULL )
1334 for( size_t i = 0; i < filenames.GetCount(); i++ )
1335 playlist_Add( p_playlist, (const char *)filenames[i].mb_str(),
1336 (const char *)filenames[i].mb_str(),
1337 PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
1340 vlc_object_release( p_playlist );
1346 /*****************************************************************************
1347 * Definition of wxVolCtrl class.
1348 *****************************************************************************/
1349 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1350 wxPoint point, wxSize size )
1351 : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
1355 audio_volume_t i_volume;
1356 aout_VolumeGet( p_intf, &i_volume );
1357 i_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
1358 SetValue( i_volume );
1359 SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
1363 void wxVolCtrl::OnChange( wxMouseEvent& event )
1365 if( !event.LeftDown() && !event.LeftIsDown() ) return;
1367 int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
1371 void wxVolCtrl::Change( int i_volume )
1373 aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1374 SetValue( i_volume );
1375 SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),