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/playlist.xpm"
45 #include "bitmaps/speaker.xpm"
47 #define TOOLBAR_BMP_WIDTH 16
48 #define TOOLBAR_BMP_HEIGHT 16
50 /* include the icon graphic */
51 #include "../../../share/vlc32x32.xpm"
53 /*****************************************************************************
54 * Local class declarations.
55 *****************************************************************************/
56 class wxMenuExt: public wxMenu
60 wxMenuExt( wxMenu* parentMenu, int id, const wxString& text,
61 const wxString& helpString, wxItemKind kind,
62 char *_psz_var, int _i_object_id, vlc_value_t _val,
65 virtual ~wxMenuExt() {};
76 class wxVolCtrl: public wxGauge
80 wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
81 wxPoint = wxDefaultPosition, wxSize = wxSize( 20, -1 ) );
82 virtual ~wxVolCtrl() {};
86 void OnChange( wxMouseEvent& event );
89 intf_thread_t *p_intf;
91 DECLARE_EVENT_TABLE();
94 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
96 EVT_LEFT_DOWN(wxVolCtrl::OnChange)
97 EVT_MOTION(wxVolCtrl::OnChange)
100 /*****************************************************************************
102 *****************************************************************************/
104 DEFINE_LOCAL_EVENT_TYPE( wxEVT_INTF );
106 /* IDs for the controls and the menu commands */
110 MenuDummy_Event = wxID_HIGHEST + 1000,
111 Exit_Event = wxID_HIGHEST,
112 OpenFileSimple_Event,
143 RestoreDefaults_Event,
153 /* it is important for the id corresponding to the "About" command to have
154 * this standard value as otherwise it won't be handled properly under Mac
155 * (where it is special and put into the "Apple" menu) */
156 About_Event = wxID_ABOUT
159 BEGIN_EVENT_TABLE(Interface, wxFrame)
161 EVT_MENU(Exit_Event, Interface::OnExit)
162 EVT_MENU(About_Event, Interface::OnAbout)
164 EVT_MENU(Playlist_Event, Interface::OnShowDialog)
165 EVT_MENU(Logs_Event, Interface::OnShowDialog)
166 EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
167 EVT_MENU(Prefs_Event, Interface::OnShowDialog)
169 EVT_MENU_OPEN(Interface::OnMenuOpen)
171 EVT_MENU( Extended_Event, Interface::OnExtended)
172 EVT_MENU( Bookmarks_Event, Interface::OnShowDialog)
174 EVT_CHECKBOX( Adjust_Event, Interface::OnEnableAdjust)
175 EVT_BUTTON( RestoreDefaults_Event, Interface::OnRestoreDefaults)
176 EVT_TEXT( Ratio_Event, Interface::OnRatio)
177 EVT_CHECKBOX( Visual_Event, Interface::OnEnableVisual)
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(StreamWizard_Event, Interface::OnShowDialog)
193 EVT_MENU(Wizard_Event, Interface::OnShowDialog)
194 EVT_MENU(StopStream_Event, Interface::OnStopStream)
195 EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
196 EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
197 EVT_MENU(NextStream_Event, Interface::OnNextStream)
198 EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
199 EVT_MENU(FastStream_Event, Interface::OnFastStream)
202 EVT_COMMAND_SCROLL(SliderScroll_Event, Interface::OnSliderUpdate)
204 EVT_COMMAND_SCROLL(Hue_Event, Interface::OnAdjustUpdate)
205 EVT_COMMAND_SCROLL(Contrast_Event, Interface::OnAdjustUpdate)
206 EVT_COMMAND_SCROLL(Brightness_Event, Interface::OnAdjustUpdate)
207 EVT_COMMAND_SCROLL(Saturation_Event, Interface::OnAdjustUpdate)
208 EVT_COMMAND_SCROLL(Gamma_Event, Interface::OnAdjustUpdate)
211 EVT_COMMAND(0, wxEVT_INTF, Interface::OnControlEvent)
212 EVT_COMMAND(1, wxEVT_INTF, Interface::OnControlEvent)
216 /*****************************************************************************
218 *****************************************************************************/
219 Interface::Interface( intf_thread_t *_p_intf ):
220 wxFrame( NULL, -1, wxT("VLC media player"),
221 wxDefaultPosition, wxSize(700,100), wxDEFAULT_FRAME_STYLE )
223 /* Initializations */
225 i_old_playing_status = PAUSE_S;
228 /* Give our interface a nice little icon */
229 SetIcon( wxIcon( vlc_xpm ) );
231 /* Create a sizer for the main frame */
232 frame_sizer = new wxBoxSizer( wxVERTICAL );
233 SetSizer( frame_sizer );
235 /* Create a dummy widget that can get the keyboard focus */
236 wxWindow *p_dummy = new wxWindow( this, 0, wxDefaultPosition,
239 frame_sizer->Add( p_dummy, 0, wxEXPAND );
241 /* Creation of the menu bar */
244 /* Creation of the tool bar */
247 /* Create the extra panel */
248 CreateOurExtendedPanel();
249 frame_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
250 frame_sizer->Hide( extra_frame );
252 /* Creation of the status bar
253 * Helptext for menu items and toolbar tools will automatically get
255 int i_status_width[3] = {-6, -2, -9};
256 statusbar = CreateStatusBar( 3 ); /* 2 fields */
257 statusbar->SetStatusWidths( 3, i_status_width );
258 statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
261 if( config_GetInt( p_intf, "wxwin-embed" ) )
263 VideoWindow( p_intf, this );
264 frame_sizer->Add( p_intf->p_sys->p_video_sizer, 1, wxEXPAND , 0 );
267 /* Creation of the slider sub-window */
269 frame_sizer->Add( slider_frame, 0, wxEXPAND , 0 );
270 frame_sizer->Hide( slider_frame );
272 /* Make sure we've got the right background colour */
273 SetBackgroundColour( slider_frame->GetBackgroundColour() );
275 /* Layout everything */
276 frame_sizer->Layout();
277 frame_sizer->Fit(this);
279 #if wxUSE_DRAG_AND_DROP
280 /* Associate drop targets with the main interface */
281 SetDropTarget( new DragAndDrop( p_intf ) );
287 timer = new Timer( p_intf, this );
290 Interface::~Interface()
292 if( p_intf->p_sys->p_wxwindow )
294 delete p_intf->p_sys->p_wxwindow;
301 void Interface::Update()
304 ((wxVolCtrl *)volctrl)->UpdateVolume();
307 void Interface::OnControlEvent( wxCommandEvent& event )
309 switch( event.GetId() )
312 frame_sizer->Layout();
313 frame_sizer->Fit(this);
317 long i_style = GetWindowStyle();
318 if( event.GetInt() ) i_style |= wxSTAY_ON_TOP;
319 else i_style &= ~wxSTAY_ON_TOP;
320 SetWindowStyle( i_style );
325 /*****************************************************************************
327 *****************************************************************************/
328 void Interface::CreateOurMenuBar()
330 /* Create the "File" menu */
331 wxMenu *file_menu = new wxMenu;
332 file_menu->Append( OpenFileSimple_Event,
333 wxU(_("Quick &Open File...\tCtrl-O")) );
335 file_menu->AppendSeparator();
336 file_menu->Append( OpenFile_Event, wxU(_("Open &File...\tCtrl-F")) );
337 file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...\tCtrl-D")) );
338 file_menu->Append( OpenNet_Event,
339 wxU(_("Open &Network Stream...\tCtrl-N")) );
340 file_menu->Append( OpenCapture_Event,
341 wxU(_("Open &Capture Device...\tCtrl-C")) );
343 file_menu->AppendSeparator();
344 file_menu->Append( Wizard_Event, wxU(_("&Wizard...\tCtrl-W")) );
345 file_menu->Append( StreamWizard_Event,
346 wxU(_("Old streaming Wizard...")) );
347 file_menu->AppendSeparator();
348 file_menu->Append( Exit_Event, wxU(_("E&xit\tCtrl-X")) );
350 /* Create the "View" menu */
351 wxMenu *view_menu = new wxMenu;
352 view_menu->Append( Playlist_Event, wxU(_("&Playlist...\tCtrl-P")) );
353 view_menu->Append( Logs_Event, wxU(_("&Messages...\tCtrl-M")) );
354 view_menu->Append( FileInfo_Event,
355 wxU(_("Stream and Media &info...\tCtrl-I")) );
357 /* Create the "Auto-generated" menus */
358 p_settings_menu = SettingsMenu( p_intf, this );
359 p_audio_menu = AudioMenu( p_intf, this );
360 p_video_menu = VideoMenu( p_intf, this );
361 p_navig_menu = NavigMenu( p_intf, this );
363 /* Create the "Help" menu */
364 wxMenu *help_menu = new wxMenu;
365 help_menu->Append( About_Event, wxU(_("About VLC media player")) );
367 /* Append the freshly created menus to the menu bar... */
368 wxMenuBar *menubar = new wxMenuBar( wxMB_DOCKABLE );
369 menubar->Append( file_menu, wxU(_("&File")) );
370 menubar->Append( view_menu, wxU(_("&View")) );
371 menubar->Append( p_settings_menu, wxU(_("&Settings")) );
372 menubar->Append( p_audio_menu, wxU(_("&Audio")) );
373 menubar->Append( p_video_menu, wxU(_("&Video")) );
374 menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
375 menubar->Append( help_menu, wxU(_("&Help")) );
377 /* Attach the menu bar to the frame */
378 SetMenuBar( menubar );
380 /* Find out size of menu bar */
382 for( unsigned int i = 0; i < menubar->GetMenuCount(); i++ )
384 int i_width, i_height;
385 menubar->GetTextExtent( menubar->GetLabelTop(i), &i_width, &i_height );
387 #if defined(__WXGTK__)
388 20 /* approximate margin */;
390 4 /* approximate margin */;
393 frame_sizer->SetMinSize( i_size, -1 );
395 /* Intercept all menu events in our custom event handler */
396 PushEventHandler( new MenuEvtHandler( p_intf, this ) );
398 #if wxUSE_DRAG_AND_DROP
399 /* Associate drop targets with the menubar */
400 menubar->SetDropTarget( new DragAndDrop( p_intf ) );
404 class VLCVolCtrl : public wxControl
407 VLCVolCtrl( intf_thread_t *p_intf, wxWindow *p_parent, wxGauge ** );
408 virtual ~VLCVolCtrl() {};
410 virtual void OnPaint( wxPaintEvent &event );
413 DECLARE_EVENT_TABLE()
416 BEGIN_EVENT_TABLE(VLCVolCtrl, wxControl)
417 EVT_PAINT(VLCVolCtrl::OnPaint)
420 VLCVolCtrl::VLCVolCtrl( intf_thread_t *p_intf, wxWindow *p_parent,
421 wxGauge **pp_volctrl )
422 :wxControl( p_parent, -1, wxDefaultPosition, wxSize(64, 16), wxBORDER_NONE )
424 *pp_volctrl = new wxVolCtrl( p_intf, this, -1, wxPoint( 18, 0 ),
428 void VLCVolCtrl::OnPaint( wxPaintEvent &evt )
430 wxPaintDC dc( this );
431 wxBitmap mPlayBitmap( speaker_xpm );
432 dc.DrawBitmap( mPlayBitmap, 1, 0, TRUE );
435 void Interface::CreateOurToolBar()
437 #define HELP_OPEN N_("Open")
438 #define HELP_STOP N_("Stop")
439 #define HELP_PLAY N_("Play")
440 #define HELP_PAUSE N_("Pause")
441 #define HELP_PLO N_("Playlist")
442 #define HELP_PLP N_("Previous playlist item")
443 #define HELP_PLN N_("Next playlist item")
444 #define HELP_SLOW N_("Play slower")
445 #define HELP_FAST N_("Play faster")
447 wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
448 * version because we don't include wx.rc */
451 CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT | wxTB_DOCKABLE );
453 toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
455 toolbar->AddTool( OpenFile_Event, wxT(""),
456 wxBitmap( eject_xpm ), wxU(_(HELP_OPEN)) );
457 toolbar->AddSeparator();
458 toolbar->AddTool( PlayStream_Event, wxT(""), wxBitmap( play_xpm ),
461 toolbar->AddTool( PlayStream_Event, wxT(""), wxBitmap( pause_xpm ),
462 wxU(_(HELP_PAUSE)) );
464 toolbar->AddTool( StopStream_Event, wxT(""), wxBitmap( stop_xpm ),
466 toolbar->AddSeparator();
467 toolbar->AddTool( PrevStream_Event, wxT(""),
468 wxBitmap( prev_xpm ), wxU(_(HELP_PLP)) );
469 toolbar->AddTool( SlowStream_Event, wxT(""),
470 wxBitmap( slow_xpm ), wxU(_(HELP_SLOW)) );
471 toolbar->AddTool( FastStream_Event, wxT(""),
472 wxBitmap( fast_xpm ), wxU(_(HELP_FAST)) );
473 toolbar->AddTool( NextStream_Event, wxT(""), wxBitmap( next_xpm ),
475 toolbar->AddSeparator();
476 toolbar->AddTool( Playlist_Event, wxT(""), wxBitmap( playlist_xpm ),
479 wxControl *p_dummy_ctrl =
480 new wxControl( toolbar, -1, wxDefaultPosition,
481 wxSize(35, 16 ), wxBORDER_NONE );
483 toolbar->AddControl( p_dummy_ctrl );
485 VLCVolCtrl *sound_control = new VLCVolCtrl( p_intf, toolbar, &volctrl );
486 toolbar->AddControl( sound_control );
490 #if wxUSE_DRAG_AND_DROP
491 /* Associate drop targets with the toolbar */
492 toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
496 void Interface::CreateOurSlider()
498 /* Create a new frame and sizer containing the slider */
499 slider_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
500 slider_frame->SetAutoLayout( TRUE );
501 wxBoxSizer *frame_sizer = new wxBoxSizer( wxHORIZONTAL );
502 //frame_sizer->SetMinSize( -1, 50 );
505 slider = new wxSlider( slider_frame, SliderScroll_Event, 0, 0,
506 SLIDER_MAX_POS, wxDefaultPosition, wxDefaultSize );
508 /* Add everything to the frame */
509 frame_sizer->Add( slider, 1, wxEXPAND | wxALL, 5 );
510 slider_frame->SetSizer( frame_sizer );
511 frame_sizer->Layout();
512 frame_sizer->SetSizeHints(slider_frame);
514 /* Hide the slider by default */
515 slider_frame->Hide();
519 void Interface::CreateOurExtendedPanel()
523 extra_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
524 extra_frame->SetAutoLayout( TRUE );
525 wxBoxSizer *extra_sizer = new wxBoxSizer( wxHORIZONTAL );
527 /* Create static box to surround the adjust controls */
528 wxStaticBox *adjust_box =
529 new wxStaticBox( extra_frame, -1, wxU(_("Adjust Image")) );
531 /* Create the size for the frame */
532 wxStaticBoxSizer *adjust_sizer =
533 new wxStaticBoxSizer( adjust_box, wxVERTICAL );
534 adjust_sizer->SetMinSize( -1, 50 );
536 /* Create flex grid */
537 wxFlexGridSizer *adjust_gridsizer =
538 new wxFlexGridSizer( 6, 2, 0, 0);
539 adjust_gridsizer->AddGrowableCol(1);
541 /* Create every controls */
543 /* Create the adjust button */
544 wxCheckBox * adjust_check = new wxCheckBox( extra_frame, Adjust_Event,
547 /* Create the restore to defaults button */
548 restoredefaults_button =
549 new wxButton( extra_frame, RestoreDefaults_Event,
550 wxU(_("Restore Defaults")), wxDefaultPosition);
552 wxStaticText *hue_text = new wxStaticText( extra_frame, -1,
554 hue_slider = new wxSlider ( extra_frame, Hue_Event, 0, 0,
555 360, wxDefaultPosition, wxDefaultSize );
558 wxStaticText *contrast_text = new wxStaticText( extra_frame, -1,
559 wxU(_("Contrast")) );
560 contrast_slider = new wxSlider ( extra_frame, Contrast_Event, 0, 0,
561 200, wxDefaultPosition, wxDefaultSize);
563 wxStaticText *brightness_text = new wxStaticText( extra_frame, -1,
564 wxU(_("Brightness")) );
565 brightness_slider = new wxSlider ( extra_frame, Brightness_Event, 0, 0,
566 200, wxDefaultPosition, wxDefaultSize) ;
568 wxStaticText *saturation_text = new wxStaticText( extra_frame, -1,
569 wxU(_("Saturation")) );
570 saturation_slider = new wxSlider ( extra_frame, Saturation_Event, 0, 0,
571 300, wxDefaultPosition, wxDefaultSize );
573 wxStaticText *gamma_text = new wxStaticText( extra_frame, -1,
575 gamma_slider = new wxSlider ( extra_frame, Gamma_Event, 0, 0,
576 100, wxDefaultPosition, wxDefaultSize );
578 adjust_gridsizer->Add(adjust_check, 1, wxEXPAND, 0);
579 adjust_gridsizer->Add(restoredefaults_button, 1, wxEXPAND, 0);
580 adjust_gridsizer->Add(hue_text, 1, wxEXPAND, 0);
581 adjust_gridsizer->Add(hue_slider, 1, wxEXPAND, 0);
582 adjust_gridsizer->Add(contrast_text, 1, wxEXPAND, 0);
583 adjust_gridsizer->Add(contrast_slider, 1, wxEXPAND, 0);
584 adjust_gridsizer->Add(brightness_text, 1, wxEXPAND, 0);
585 adjust_gridsizer->Add(brightness_slider, 1, wxEXPAND, 0);
586 adjust_gridsizer->Add(saturation_text, 1, wxEXPAND, 0);
587 adjust_gridsizer->Add(saturation_slider, 1, wxEXPAND, 0);
588 adjust_gridsizer->Add(gamma_text, 1, wxEXPAND, 0);
589 adjust_gridsizer->Add(gamma_slider, 1, wxEXPAND, 0);
591 adjust_sizer->Add(adjust_gridsizer,1,wxEXPAND, 0);
593 extra_sizer->Add(adjust_sizer,1,wxBOTTOM,5);
595 /* Create sizer to surround the other controls */
596 wxBoxSizer *other_sizer = new wxBoxSizer( wxVERTICAL );
599 wxStaticBox *video_box =
600 new wxStaticBox( extra_frame, -1, wxU(_("Video Options")) );
601 /* Create the sizer for the frame */
602 wxStaticBoxSizer *video_sizer =
603 new wxStaticBoxSizer( video_box, wxVERTICAL );
604 video_sizer->SetMinSize( -1, 50 );
606 static const wxString ratio_array[] =
612 wxBoxSizer *ratio_sizer = new wxBoxSizer( wxHORIZONTAL );
613 wxStaticText *ratio_text = new wxStaticText( extra_frame, -1,
614 wxU(_("Aspect Ratio")) );
616 ratio_combo = new wxComboBox( extra_frame, Ratio_Event, wxT(""),
617 wxDefaultPosition, wxSize(120,-1),
618 WXSIZEOF(ratio_array), ratio_array,
621 ratio_sizer->Add( ratio_text, 0, wxALL, 2 );
622 ratio_sizer->Add( ratio_combo, 0, wxALL, 2 );
623 ratio_sizer->Layout();
625 video_sizer->Add( ratio_sizer , 0 , wxALL , 0 );
626 video_sizer->Layout();
629 wxBoxSizer *visual_sizer = new wxBoxSizer( wxHORIZONTAL );
631 wxCheckBox *visual_checkbox = new wxCheckBox( extra_frame, Visual_Event,
632 wxU(_("Visualizations")) );
634 visual_sizer->Add( visual_checkbox, 0, wxEXPAND, 0);
635 visual_sizer->Layout();
637 wxStaticBox *audio_box =
638 new wxStaticBox( extra_frame, -1, wxU(_("Audio Options")) );
639 /* Create the sizer for the frame */
640 wxStaticBoxSizer *audio_sizer =
641 new wxStaticBoxSizer( audio_box, wxVERTICAL );
642 audio_sizer->SetMinSize( -1, 50 );
644 audio_sizer->Add( visual_sizer, 0, wxALL, 0);
645 audio_sizer->Layout();
647 other_sizer->Add( audio_sizer , 0 , wxALL | wxEXPAND , 0 );
649 other_sizer->Add( video_sizer, 0, wxALL | wxEXPAND , 0);
650 other_sizer->Layout();
652 extra_sizer->Add(other_sizer,0,wxBOTTOM,5);
654 extra_frame->SetSizer( extra_sizer );
656 /* Layout the whole panel */
657 extra_sizer->Layout();
659 extra_sizer->SetSizeHints(extra_frame);
661 /* Write down initial values */
663 psz_filters = config_GetPsz( p_intf, "audio-filter" );
664 if( psz_filters && strstr( psz_filters, "visual" ) )
666 visual_checkbox->SetValue(1);
668 if( psz_filters ) free( psz_filters );
670 psz_filters = config_GetPsz( p_intf, "filter" );
671 if( psz_filters && strstr( psz_filters, "adjust" ) )
673 adjust_check->SetValue( 1 );
674 restoredefaults_button->Enable();
675 saturation_slider->Enable();
676 contrast_slider->Enable();
677 brightness_slider->Enable();
678 hue_slider->Enable();
679 gamma_slider->Enable();
683 adjust_check->SetValue( 0 );
684 restoredefaults_button->Disable();
685 saturation_slider->Disable();
686 contrast_slider->Disable();
687 brightness_slider->Disable();
688 hue_slider->Disable();
689 gamma_slider->Disable();
691 if( psz_filters ) free( psz_filters );
693 int i_value = config_GetInt( p_intf, "hue" );
694 if( i_value > 0 && i_value < 360 )
695 hue_slider->SetValue( i_value );
698 f_value = config_GetFloat( p_intf, "saturation" );
699 if( f_value > 0 && f_value < 5 )
700 saturation_slider->SetValue( (int)(100 * f_value) );
701 f_value = config_GetFloat( p_intf, "contrast" );
702 if( f_value > 0 && f_value < 4 )
703 contrast_slider->SetValue( (int)(100 * f_value) );
704 f_value = config_GetFloat( p_intf, "brightness" );
705 if( f_value > 0 && f_value < 2 )
706 brightness_slider->SetValue( (int)(100 * f_value) );
707 f_value = config_GetFloat( p_intf, "gamma" );
708 if( f_value > 0 && f_value < 10 )
709 gamma_slider->SetValue( (int)(10 * f_value) );
714 static int ConvertHotkeyModifiers( int i_hotkey )
716 int i_accel_flags = 0;
717 if( i_hotkey & KEY_MODIFIER_ALT ) i_accel_flags |= wxACCEL_ALT;
718 if( i_hotkey & KEY_MODIFIER_CTRL ) i_accel_flags |= wxACCEL_CTRL;
719 if( i_hotkey & KEY_MODIFIER_SHIFT ) i_accel_flags |= wxACCEL_SHIFT;
720 if( !i_accel_flags ) i_accel_flags = wxACCEL_NORMAL;
721 return i_accel_flags;
724 static int ConvertHotkey( int i_hotkey )
726 int i_key = i_hotkey & ~KEY_MODIFIER;
727 if( i_key & KEY_ASCII ) return i_key & KEY_ASCII;
728 else if( i_key & KEY_SPECIAL )
732 case KEY_LEFT: return WXK_LEFT;
733 case KEY_RIGHT: return WXK_RIGHT;
734 case KEY_UP: return WXK_UP;
735 case KEY_DOWN: return WXK_DOWN;
736 case KEY_SPACE: return WXK_SPACE;
737 case KEY_ENTER: return WXK_RETURN;
738 case KEY_F1: return WXK_F1;
739 case KEY_F2: return WXK_F2;
740 case KEY_F3: return WXK_F3;
741 case KEY_F4: return WXK_F4;
742 case KEY_F5: return WXK_F5;
743 case KEY_F6: return WXK_F6;
744 case KEY_F7: return WXK_F7;
745 case KEY_F8: return WXK_F8;
746 case KEY_F9: return WXK_F9;
747 case KEY_F10: return WXK_F10;
748 case KEY_F11: return WXK_F11;
749 case KEY_F12: return WXK_F12;
750 case KEY_HOME: return WXK_HOME;
751 case KEY_END: return WXK_HOME;
752 case KEY_MENU: return WXK_MENU;
753 case KEY_ESC: return WXK_ESCAPE;
754 case KEY_PAGEUP: return WXK_PRIOR;
755 case KEY_PAGEDOWN: return WXK_NEXT;
756 case KEY_TAB: return WXK_TAB;
757 case KEY_BACKSPACE: return WXK_BACK;
763 void Interface::SetupHotkeys()
765 struct vlc_t::hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
768 /* Count number of hoteys */
769 for( i_hotkeys = 0; p_hotkeys[i_hotkeys].psz_action != NULL; i_hotkeys++ );
771 p_intf->p_sys->i_first_hotkey_event = wxID_HIGHEST + 7000;
772 p_intf->p_sys->i_hotkeys = i_hotkeys;
774 wxAcceleratorEntry p_entries[i_hotkeys];
776 /* Setup the hotkeys as accelerators */
777 for( int i = 0; i < i_hotkeys; i++ )
779 p_entries[i].Set( ConvertHotkeyModifiers( p_hotkeys[i].i_key ),
780 ConvertHotkey( p_hotkeys[i].i_key ),
781 p_intf->p_sys->i_first_hotkey_event + i );
784 wxAcceleratorTable accel( i_hotkeys, p_entries );
788 msg_Err( p_intf, "invalid accelerator table" );
792 SetAcceleratorTable( accel );
793 msg_Dbg( p_intf, "accelerator table loaded" );
797 /*****************************************************************************
799 *****************************************************************************/
801 void Interface::OnMenuOpen(wxMenuEvent& event)
803 #if defined( __WXMSW__ )
804 # define GetEventObject GetMenu
807 if( event.GetEventObject() == p_settings_menu )
809 p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );
811 /* Add static items */
812 p_settings_menu->AppendCheckItem( Extended_Event,
813 wxU(_("&Extended GUI") ) );
814 if( b_extra ) p_settings_menu->Check( Extended_Event, TRUE );
815 p_settings_menu->AppendCheckItem( Bookmarks_Event,
816 wxU(_("&Bookmarks...") ) );
817 p_settings_menu->Append( Prefs_Event, wxU(_("&Preferences...")) );
820 else if( event.GetEventObject() == p_audio_menu )
822 p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
825 else if( event.GetEventObject() == p_video_menu )
827 p_video_menu = VideoMenu( p_intf, this, p_video_menu );
830 else if( event.GetEventObject() == p_navig_menu )
832 p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
835 #if defined( __WXMSW__ )
836 # undef GetEventObject
840 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
841 void Interface::OnContextMenu2(wxContextMenuEvent& event)
843 /* Only show the context menu for the main interface */
844 if( GetId() != event.GetId() )
850 if( p_intf->p_sys->pf_show_dialog )
851 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
854 void Interface::OnContextMenu(wxMouseEvent& event)
856 if( p_intf->p_sys->pf_show_dialog )
857 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
860 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
862 /* TRUE is to force the frame to close. */
866 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
869 msg.Printf( wxString(wxT("VLC media player " VERSION)) +
870 wxU(_(" (wxWindows interface)\n\n")) +
871 wxU(_("(c) 1996-2004 - the VideoLAN Team\n\n")) +
872 wxU( vlc_wraptext(INTF_ABOUT_MSG,WRAPCOUNT,ISUTF8) ) + wxT("\n\n") +
873 wxU(_("The VideoLAN team <videolan@videolan.org>\n"
874 "http://www.videolan.org/\n\n")) );
876 wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
877 wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
880 void Interface::OnShowDialog( wxCommandEvent& event )
882 if( p_intf->p_sys->pf_show_dialog )
886 switch( event.GetId() )
888 case OpenFileSimple_Event:
889 i_id = INTF_DIALOG_FILE_SIMPLE;
892 i_id = INTF_DIALOG_FILE;
894 i_id = INTF_DIALOG_FILE;
897 i_id = INTF_DIALOG_DISC;
900 i_id = INTF_DIALOG_NET;
902 case OpenCapture_Event:
903 i_id = INTF_DIALOG_CAPTURE;
906 i_id = INTF_DIALOG_SAT;
909 i_id = INTF_DIALOG_PLAYLIST;
912 i_id = INTF_DIALOG_MESSAGES;
915 i_id = INTF_DIALOG_FILEINFO;
918 i_id = INTF_DIALOG_PREFS;
920 case StreamWizard_Event:
921 i_id = INTF_DIALOG_STREAMWIZARD;
924 i_id = INTF_DIALOG_WIZARD;
926 case Bookmarks_Event:
927 i_id = INTF_DIALOG_BOOKMARKS;
930 i_id = INTF_DIALOG_FILE;
934 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
938 void Interface::OnExtended(wxCommandEvent& event)
940 if( b_extra == VLC_FALSE)
943 frame_sizer->Show( extra_frame );
949 frame_sizer->Hide( extra_frame );
952 frame_sizer->Layout();
953 frame_sizer->Fit(this);
956 void Interface::OnEnableAdjust(wxCommandEvent& event)
958 char *psz_filters=config_GetPsz( p_intf, "filter");
959 char *psz_new = NULL;
960 if( event.IsChecked() )
962 if(psz_filters == NULL)
964 psz_new = strdup( "adjust" );
968 psz_new= (char *) malloc(strlen(psz_filters) + 8 );
969 sprintf( psz_new, "%s:adjust", psz_filters);
971 config_PutPsz( p_intf, "filter", psz_new );
973 vout_thread_t *p_vout =
974 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
978 val.psz_string = strdup( psz_new );
979 var_Set( p_vout, "filter", val);
980 vlc_object_release( p_vout );
982 if( val.psz_string ) free( val.psz_string );
983 restoredefaults_button->Enable();
984 brightness_slider->Enable();
985 saturation_slider->Enable();
986 contrast_slider->Enable();
987 hue_slider->Enable();
988 gamma_slider->Enable();
992 if( psz_filters != NULL )
997 for( i = 0; i< strlen(psz_filters ); i++)
999 if ( !strncasecmp( &psz_filters[i],"adjust",6 ))
1002 if( psz_filters[i-1] == ':' ) i--;
1003 psz_current = strchr( &psz_filters[i+1] , ':' );
1005 psz_filters[i] = '\0';
1008 memmove( &psz_filters[i] , psz_current,
1009 &psz_filters[strlen(psz_filters)]-psz_current
1014 config_PutPsz( p_intf, "filter", psz_filters);
1016 val.psz_string = strdup( psz_filters );
1017 vout_thread_t *p_vout =
1018 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1020 if( p_vout != NULL )
1022 var_Set( p_vout, "filter", val);
1023 vlc_object_release( p_vout );
1025 if( val.psz_string ) free( val.psz_string );
1027 restoredefaults_button->Disable();
1028 brightness_slider->Disable();
1029 saturation_slider->Disable();
1030 contrast_slider->Disable();
1031 hue_slider->Disable();
1032 gamma_slider->Disable();
1034 if(psz_filters) free(psz_filters);
1035 if(psz_new) free(psz_new);
1038 void Interface::OnRestoreDefaults( wxCommandEvent &event)
1040 hue_slider->SetValue(0);
1041 saturation_slider->SetValue(100);
1042 brightness_slider->SetValue(100);
1043 contrast_slider->SetValue(100),
1044 gamma_slider->SetValue(10);
1046 wxScrollEvent *hscroll_event = new wxScrollEvent(0, Hue_Event, 0);
1047 OnAdjustUpdate(*hscroll_event);
1049 wxScrollEvent *sscroll_event = new wxScrollEvent(0, Saturation_Event, 100);
1050 OnAdjustUpdate(*sscroll_event);
1052 wxScrollEvent *bscroll_event = new wxScrollEvent(0, Brightness_Event, 100);
1053 OnAdjustUpdate(*bscroll_event);
1055 wxScrollEvent *cscroll_event = new wxScrollEvent(0, Contrast_Event, 100);
1056 OnAdjustUpdate(*cscroll_event);
1058 wxScrollEvent *gscroll_event = new wxScrollEvent(0, Gamma_Event, 10);
1059 OnAdjustUpdate(*gscroll_event);
1063 void Interface::OnAdjustUpdate( wxScrollEvent &event)
1065 vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find(p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE);
1067 switch(event.GetId())
1070 config_PutInt( p_intf , "hue" , event.GetPosition() );
1073 case Saturation_Event:
1074 config_PutFloat( p_intf , "saturation" , (float)event.GetPosition()/100 );
1077 case Brightness_Event:
1078 config_PutFloat( p_intf , "brightness" , (float)event.GetPosition()/100 );
1081 case Contrast_Event:
1082 config_PutFloat( p_intf , "contrast" , (float)event.GetPosition()/100 );
1086 config_PutFloat( p_intf , "gamma" , (float)event.GetPosition()/10 );
1092 switch(event.GetId())
1095 val.i_int = event.GetPosition();
1096 var_Set(p_vout, "hue", val);
1099 case Saturation_Event:
1100 val.f_float = (float)event.GetPosition()/100;
1101 var_Set(p_vout, "saturation", val);
1104 case Brightness_Event:
1105 val.f_float = (float)event.GetPosition()/100;
1106 var_Set(p_vout, "brightness", val);
1109 case Contrast_Event:
1110 val.f_float = (float)event.GetPosition()/100;
1111 var_Set(p_vout, "contrast", val);
1115 val.f_float = (float)event.GetPosition()/10;
1116 var_Set(p_vout, "gamma", val);
1119 vlc_object_release(p_vout);
1123 void Interface::OnRatio( wxCommandEvent& event )
1125 config_PutPsz( p_intf, "aspect-ratio", ratio_combo->GetValue().mb_str() );
1128 void Interface::OnEnableVisual(wxCommandEvent& event)
1130 if( event.IsChecked() )
1132 config_PutPsz( p_intf, "audio-filter", "visual" );
1136 config_PutPsz( p_intf, "audio-filter", "" );
1140 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
1142 wxCommandEvent dummy;
1143 playlist_t *p_playlist =
1144 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1146 if( p_playlist == NULL ) return;
1148 if( p_playlist->i_size && p_playlist->i_enabled )
1152 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
1155 if( p_input == NULL )
1157 /* No stream was playing, start one */
1158 playlist_Play( p_playlist );
1159 TogglePlayButton( PLAYING_S );
1160 vlc_object_release( p_playlist );
1164 var_Get( p_input, "state", &state );
1166 if( state.i_int != PAUSE_S )
1168 /* A stream is being played, pause it */
1169 state.i_int = PAUSE_S;
1173 /* Stream is paused, resume it */
1174 state.i_int = PLAYING_S;
1176 var_Set( p_input, "state", state );
1178 TogglePlayButton( state.i_int );
1179 vlc_object_release( p_input );
1180 vlc_object_release( p_playlist );
1184 /* If the playlist is empty, open a file requester instead */
1185 vlc_object_release( p_playlist );
1186 OnShowDialog( dummy );
1190 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
1192 playlist_t * p_playlist =
1193 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1195 if( p_playlist == NULL )
1200 playlist_Stop( p_playlist );
1201 TogglePlayButton( PAUSE_S );
1202 vlc_object_release( p_playlist );
1205 void Interface::OnSliderUpdate( wxScrollEvent& event )
1207 vlc_mutex_lock( &p_intf->change_lock );
1210 if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
1211 || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
1214 if( p_intf->p_sys->i_slider_pos != event.GetPosition()
1215 && p_intf->p_sys->p_input )
1218 pos.f_float = (float)event.GetPosition() / (float)SLIDER_MAX_POS;
1220 var_Set( p_intf->p_sys->p_input, "position", pos );
1224 p_intf->p_sys->b_slider_free = VLC_TRUE;
1228 p_intf->p_sys->b_slider_free = VLC_FALSE;
1230 if( p_intf->p_sys->p_input )
1232 /* Update stream date */
1233 char psz_time[ MSTRTIME_MAX_SIZE ], psz_total[ MSTRTIME_MAX_SIZE ];
1237 i_seconds = var_GetTime( p_intf->p_sys->p_input, "length" ) / I64C(1000000 );
1238 secstotimestr( psz_total, i_seconds );
1240 i_seconds = var_GetTime( p_intf->p_sys->p_input, "time" ) / I64C(1000000 );
1241 secstotimestr( psz_time, i_seconds );
1243 statusbar->SetStatusText( wxU(psz_time)+ wxString(wxT(" / ")) + wxU(psz_total), 0 );
1249 vlc_mutex_unlock( &p_intf->change_lock );
1252 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
1254 playlist_t * p_playlist =
1255 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1257 if( p_playlist == NULL )
1262 vlc_mutex_lock( &p_playlist->object_lock );
1263 if( p_playlist->p_input != NULL )
1265 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1266 if( p_playlist->p_input->stream.p_selected_area->i_id > 1 )
1268 vlc_value_t val; val.b_bool = VLC_TRUE;
1269 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1270 var_Set( p_playlist->p_input, "prev-title", val );
1272 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1274 vlc_mutex_unlock( &p_playlist->object_lock );
1276 playlist_Prev( p_playlist );
1277 vlc_object_release( p_playlist );
1280 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1282 playlist_t * p_playlist =
1283 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1285 if( p_playlist == NULL )
1290 vlc_mutex_lock( &p_playlist->object_lock );
1291 if( p_playlist->p_input != NULL )
1293 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1294 if( p_playlist->p_input->stream.i_area_nb > 1 &&
1295 p_playlist->p_input->stream.p_selected_area->i_id <
1296 p_playlist->p_input->stream.i_area_nb - 1 )
1298 vlc_value_t val; val.b_bool = VLC_TRUE;
1299 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1300 var_Set( p_playlist->p_input, "next-title", val );
1302 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1304 vlc_mutex_unlock( &p_playlist->object_lock );
1306 playlist_Next( p_playlist );
1307 vlc_object_release( p_playlist );
1310 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1312 input_thread_t *p_input =
1313 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1317 vlc_value_t val; val.b_bool = VLC_TRUE;
1319 var_Set( p_input, "rate-slower", val );
1320 vlc_object_release( p_input );
1324 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1326 input_thread_t *p_input =
1327 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1331 vlc_value_t val; val.b_bool = VLC_TRUE;
1333 var_Set( p_input, "rate-faster", val );
1334 vlc_object_release( p_input );
1338 void Interface::TogglePlayButton( int i_playing_status )
1340 if( i_playing_status == i_old_playing_status )
1343 GetToolBar()->DeleteTool( PlayStream_Event );
1345 if( i_playing_status == PLAYING_S )
1347 GetToolBar()->InsertTool( 2, PlayStream_Event, wxU(_("Pause")),
1348 wxBitmap( pause_xpm ), wxNullBitmap,
1349 wxITEM_NORMAL, wxU(_(HELP_PAUSE)) );
1353 GetToolBar()->InsertTool( 2, PlayStream_Event, wxU(_("Play")),
1354 wxBitmap( play_xpm ), wxNullBitmap,
1355 wxITEM_NORMAL, wxU(_(HELP_PLAY)) );
1358 GetToolBar()->Realize();
1360 i_old_playing_status = i_playing_status;
1363 #if wxUSE_DRAG_AND_DROP
1364 /*****************************************************************************
1365 * Definition of DragAndDrop class.
1366 *****************************************************************************/
1367 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
1370 b_enqueue = _b_enqueue;
1373 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1374 const wxArrayString& filenames )
1376 /* Add dropped files to the playlist */
1378 playlist_t *p_playlist =
1379 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1381 if( p_playlist == NULL )
1386 for( size_t i = 0; i < filenames.GetCount(); i++ )
1387 playlist_Add( p_playlist, (const char *)filenames[i].mb_str(),
1388 (const char *)filenames[i].mb_str(),
1389 PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
1392 vlc_object_release( p_playlist );
1398 /*****************************************************************************
1399 * Definition of VolCtrl class.
1400 *****************************************************************************/
1401 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id,
1402 wxPoint point, wxSize size )
1403 : wxGauge( parent, id, 200, point, size, wxGA_HORIZONTAL | wxGA_SMOOTH )
1409 void wxVolCtrl::OnChange( wxMouseEvent& event )
1411 if( !event.LeftDown() && !event.LeftIsDown() ) return;
1413 int i_volume = event.GetX() * 200 / GetClientSize().GetWidth();
1414 aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1418 void wxVolCtrl::UpdateVolume()
1420 audio_volume_t i_volume;
1421 aout_VolumeGet( p_intf, &i_volume );
1423 int i_gauge_volume = i_volume * 200 * 2 / AOUT_VOLUME_MAX;
1424 if( i_gauge_volume == GetValue() ) return;
1426 SetValue( i_gauge_volume );
1427 SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),
1428 i_gauge_volume / 2 ) );