1 /*****************************************************************************
2 * interface.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001,2003 VideoLAN
5 * $Id: interface.cpp,v 1.73 2003/12/03 00:24:16 rocky Exp $
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
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 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <errno.h> /* ENOMEM */
29 #include <string.h> /* strerror() */
36 #include "stream_control.h"
38 #include "wxwindows.h"
40 /* include the toolbar graphics */
41 #include "bitmaps/file.xpm"
43 #include "bitmaps/disc.xpm"
44 #include "bitmaps/net.xpm"
46 #include "bitmaps/sat.xpm"
48 #include "bitmaps/play.xpm"
49 #include "bitmaps/pause.xpm"
50 #include "bitmaps/stop.xpm"
51 #include "bitmaps/previous.xpm"
52 #include "bitmaps/next.xpm"
53 #include "bitmaps/playlist.xpm"
54 #include "bitmaps/fast.xpm"
55 #include "bitmaps/slow.xpm"
57 #include <wx/listctrl.h>
59 #define TOOLBAR_BMP_WIDTH 36
60 #define TOOLBAR_BMP_HEIGHT 36
62 /* include the icon graphic */
63 #include "../../../share/vlc32x32.xpm"
65 /*****************************************************************************
66 * Local class declarations.
67 *****************************************************************************/
68 class wxMenuExt: public wxMenu
72 wxMenuExt( wxMenu* parentMenu, int id, const wxString& text,
73 const wxString& helpString, wxItemKind kind,
74 char *_psz_var, int _i_object_id, vlc_value_t _val,
77 virtual ~wxMenuExt() {};
88 class wxVolCtrl: public wxGauge
92 wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id );
93 virtual ~wxVolCtrl() {};
95 void Change( int i_volume );
97 void OnChange( wxMouseEvent& event );
100 intf_thread_t *p_intf;
102 DECLARE_EVENT_TABLE();
105 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
107 EVT_LEFT_DOWN(wxVolCtrl::OnChange)
108 EVT_MOTION(wxVolCtrl::OnChange)
111 /*****************************************************************************
113 *****************************************************************************/
115 /* IDs for the controls and the menu commands */
119 MenuDummy_Event = wxID_HIGHEST + 1000,
120 Exit_Event = wxID_HIGHEST,
121 OpenFileSimple_Event,
157 /* it is important for the id corresponding to the "About" command to have
158 * this standard value as otherwise it won't be handled properly under Mac
159 * (where it is special and put into the "Apple" menu) */
160 About_Event = wxID_ABOUT
163 BEGIN_EVENT_TABLE(Interface, wxFrame)
165 EVT_MENU(Exit_Event, Interface::OnExit)
166 EVT_MENU(About_Event, Interface::OnAbout)
168 EVT_MENU(Playlist_Event, Interface::OnShowDialog)
169 EVT_MENU(Logs_Event, Interface::OnShowDialog)
170 EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
171 EVT_MENU(Prefs_Event, Interface::OnShowDialog)
173 EVT_MENU_OPEN(Interface::OnMenuOpen)
175 EVT_MENU( Extra_Event, Interface::OnExtra)
176 EVT_CHECKBOX( Adjust_Event, Interface::OnEnableAdjust)
178 EVT_COMBOBOX( Ratio_Event, Interface::OnRatio)
179 EVT_CHECKBOX( Visual_Event, Interface::OnEnableVisual)
181 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
182 EVT_CONTEXT_MENU(Interface::OnContextMenu2)
184 EVT_RIGHT_UP(Interface::OnContextMenu)
187 EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
188 EVT_MENU(OpenAdv_Event, Interface::OnShowDialog)
189 EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
190 EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
191 EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
192 EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
193 EVT_MENU(Stream_Event, Interface::OnStream)
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::OnHueUpdate)
205 EVT_COMMAND_SCROLL(Contrast_Event, Interface::OnContrastUpdate)
206 EVT_COMMAND_SCROLL(Brightness_Event, Interface::OnBrightnessUpdate)
207 EVT_COMMAND_SCROLL(Saturation_Event, Interface::OnSaturationUpdate)
211 /*****************************************************************************
213 *****************************************************************************/
214 Interface::Interface( intf_thread_t *_p_intf ):
215 wxFrame( NULL, -1, wxT("VLC media player"),
216 wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE )
218 /* Initializations */
220 i_old_playing_status = PAUSE_S;
223 /* Give our interface a nice little icon */
224 SetIcon( wxIcon( vlc_xpm ) );
226 /* Create a sizer for the main frame */
227 frame_sizer = new wxBoxSizer( wxVERTICAL );
228 SetSizer( frame_sizer );
230 /* Create a dummy widget that can get the keyboard focus */
231 wxWindow *p_dummy = new wxWindow( this, 0, wxDefaultPosition,
234 frame_sizer->Add( p_dummy );
236 /* Creation of the menu bar */
239 /* Creation of the tool bar */
242 /* Creation of the slider sub-window */
244 frame_sizer->Add( slider_frame, 0, wxEXPAND , 0 );
245 frame_sizer->Hide( slider_frame );
247 /* Create the extra panel */
248 CreateOurExtraPanel();
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 );
260 /* Make sure we've got the right background colour */
261 SetBackgroundColour( slider_frame->GetBackgroundColour() );
263 /* Layout everything */
264 SetAutoLayout( TRUE );
265 frame_sizer->Layout();
266 frame_sizer->Fit(this);
268 #if !defined(__WXX11__)
269 /* Associate drop targets with the main interface */
270 SetDropTarget( new DragAndDrop( p_intf ) );
273 UpdateAcceleratorTable();
276 timer = new Timer( p_intf, this );
279 Interface::~Interface()
281 if( p_intf->p_sys->p_wxwindow )
283 delete p_intf->p_sys->p_wxwindow;
290 /*****************************************************************************
292 *****************************************************************************/
293 void Interface::CreateOurMenuBar()
295 #define HELP_SIMPLE N_("Quick file open")
296 #define HELP_ADV N_("Advanced open")
297 #define HELP_FILE N_("Open a file")
298 #define HELP_DISC N_("Open a DVD or (S)VCD")
299 #define HELP_NET N_("Open a network stream")
300 #define HELP_SAT N_("Open a satellite stream")
301 #define HELP_EJECT N_("Eject the DVD/CD")
302 #define HELP_EXIT N_("Exit this program")
304 #define HELP_STREAMWIZARD N_("Open the streaming wizard")
305 #define HELP_OTHER N_("Open other types of inputs")
307 #define HELP_PLAYLIST N_("Open the playlist")
308 #define HELP_LOGS N_("Show the program logs")
309 #define HELP_FILEINFO N_("Show information about the file being played")
311 #define HELP_PREFS N_("Go to the preferences menu")
312 #define EXTRA_PREFS N_("Shows the extended GUI")
314 #define HELP_ABOUT N_("About this program")
316 /* Create the "File" menu */
317 wxMenu *file_menu = new wxMenu;
318 file_menu->Append( OpenFileSimple_Event, wxU(_("Quick &Open ...")),
319 wxU(_(HELP_SIMPLE)) );
321 file_menu->AppendSeparator();
322 file_menu->Append( OpenFile_Event, wxU(_("Open &File...")),
324 file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...")),
326 file_menu->Append( OpenNet_Event, wxU(_("Open &Network Stream...")),
330 file_menu->Append( OpenSat_Event, wxU(_("Open &Satellite Stream...")),
333 file_menu->AppendSeparator();
334 file_menu->Append( Stream_Event, wxU(_("Streaming Wizard...")),
335 wxU(_(HELP_STREAMWIZARD)) );
336 file_menu->AppendSeparator();
337 file_menu->Append( Exit_Event, wxU(_("E&xit")), wxU(_(HELP_EXIT)) );
339 /* Create the "View" menu */
340 wxMenu *view_menu = new wxMenu;
341 view_menu->Append( Playlist_Event, wxU(_("&Playlist...")),
342 wxU(_(HELP_PLAYLIST)) );
343 view_menu->Append( Logs_Event, wxU(_("&Messages...")), wxU(_(HELP_LOGS)) );
344 view_menu->Append( FileInfo_Event, wxU(_("&Stream and Media info...")),
345 wxU(_(HELP_FILEINFO)) );
347 /* Create the "Settings" menu */
348 p_settings_menu = new wxMenu;
351 /* Create the "Audio" menu */
352 p_audio_menu = new wxMenu;
355 /* Create the "Video" menu */
356 p_video_menu = new wxMenu;
359 /* Create the "Navigation" menu */
360 p_navig_menu = new wxMenu;
363 /* Create the "Help" menu */
364 wxMenu *help_menu = new wxMenu;
365 help_menu->Append( About_Event, wxU(_("&About...")), wxU(_(HELP_ABOUT)) );
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 /* Intercept all menu events in our custom event handler */
381 PushEventHandler( new MenuEvtHandler( p_intf, this ) );
383 #if !defined(__WXX11__)
384 /* Associate drop targets with the menubar */
385 menubar->SetDropTarget( new DragAndDrop( p_intf ) );
389 void Interface::CreateOurToolBar()
391 #define HELP_STOP N_("Stop current playlist item")
393 #define HELP_PLAY N_("Play current playlist item")
394 #define HELP_PAUSE N_("Pause current playlist item")
395 #define HELP_PLO N_("Open playlist")
396 #define HELP_PLP N_("Previous playlist item")
397 #define HELP_PLN N_("Next playlist item")
398 #define HELP_SLOW N_("Play slower")
399 #define HELP_FAST N_("Play faster")
401 wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
402 * version because we don't include wx.rc */
404 wxToolBar *toolbar = CreateToolBar(
405 wxTB_HORIZONTAL | wxTB_FLAT | wxTB_DOCKABLE );
407 toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
409 toolbar->AddTool( OpenFileSimple_Event, wxU(_("Quick")),
410 wxBitmap( file_xpm ), wxU(_(HELP_SIMPLE)) );
412 toolbar->AddSeparator();
414 toolbar->AddTool( OpenFile_Event, wxU(_("File")), wxBitmap( file_xpm ),
416 toolbar->AddTool( OpenDisc_Event, wxU(_("Disc")), wxBitmap( disc_xpm ),
418 toolbar->AddTool( OpenNet_Event, wxU(_("Net")), wxBitmap( net_xpm ),
421 toolbar->AddTool( OpenSat_Event, wxU(_("Sat")), wxBitmap( sat_xpm ),
424 toolbar->AddSeparator();
426 toolbar->AddTool( StopStream_Event, wxU(_("Stop")), wxBitmap( stop_xpm ),
428 toolbar->AddTool( PlayStream_Event, wxU(_("Play")), wxBitmap( play_xpm ),
430 toolbar->AddSeparator();
431 toolbar->AddTool( Playlist_Event, wxU(_("Playlist")),
432 wxBitmap( playlist_xpm ), wxU(_(HELP_PLO)) );
433 toolbar->AddTool( PrevStream_Event, wxU(_("Prev")),
434 wxBitmap( previous_xpm ), wxU(_(HELP_PLP)) );
435 toolbar->AddTool( NextStream_Event, wxU(_("Next")), wxBitmap( next_xpm ),
437 toolbar->AddTool( SlowStream_Event, wxU(_("Slower")), wxBitmap( slow_xpm ),
439 toolbar->AddTool( FastStream_Event, wxU(_("Faster")), wxBitmap( fast_xpm ),
444 /* Place the toolbar in a sizer, so we can calculate the width of the
445 * toolbar and set this as the minimum for the main frame size. */
446 wxBoxSizer *toolbar_sizer = new wxBoxSizer( wxHORIZONTAL );
447 toolbar_sizer->Add( toolbar, 0, 0, 0 );
449 toolbar_sizer->Layout();
452 frame_sizer->SetMinSize( toolbar_sizer->GetMinSize().GetWidth(), -1 );
454 frame_sizer->SetMinSize( toolbar->GetToolSize().GetWidth() *
455 toolbar->GetToolsCount(), -1 );
458 #if !defined(__WXX11__)
459 /* Associate drop targets with the toolbar */
460 toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
464 void Interface::CreateOurSlider()
466 /* Create a new frame and sizer containing the slider */
467 slider_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
468 slider_frame->SetAutoLayout( TRUE );
469 wxBoxSizer *frame_sizer =
470 new wxBoxSizer( wxHORIZONTAL );
472 /* Create static box to surround the slider */
473 slider_box = new wxStaticBox( slider_frame, -1, wxT("") );
475 /* Create sizer for slider frame */
476 wxStaticBoxSizer *slider_sizer =
477 new wxStaticBoxSizer( slider_box, wxHORIZONTAL );
478 slider_sizer->SetMinSize( -1, 50 );
481 slider = new wxSlider( slider_frame, SliderScroll_Event, 0, 0,
482 SLIDER_MAX_POS, wxDefaultPosition, wxDefaultSize );
483 slider_sizer->Add( slider, 1, wxEXPAND | wxALL, 5 );
486 volctrl = new wxVolCtrl( p_intf, slider_frame, -1 );
488 /* Add everything to the frame */
489 frame_sizer->Add( slider_sizer, 1, wxEXPAND | wxBOTTOM, 5 );
490 frame_sizer->Add( volctrl, 0, wxEXPAND | wxALL, 5 );
491 slider_frame->SetSizer( frame_sizer );
492 frame_sizer->Layout();
493 frame_sizer->SetSizeHints(slider_frame);
495 /* Hide the slider by default */
496 slider_frame->Hide();
500 void Interface::CreateOurExtraPanel()
504 extra_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
505 extra_frame->SetAutoLayout( TRUE );
506 wxBoxSizer *extra_sizer = new wxBoxSizer( wxHORIZONTAL );
508 /* Create static box to surround the adjust controls */
509 wxStaticBox *adjust_box =
510 new wxStaticBox( extra_frame, -1, wxU(_("Image adjust")) );
512 /* Create the size for the frame */
513 wxStaticBoxSizer *adjust_sizer =
514 new wxStaticBoxSizer( adjust_box, wxVERTICAL );
515 adjust_sizer->SetMinSize( -1, 50 );
517 /* Create every controls */
519 /* Create the adjust button */
520 wxCheckBox * adjust_check = new wxCheckBox( extra_frame, Adjust_Event,
524 wxBoxSizer *hue_sizer = new wxBoxSizer( wxHORIZONTAL );
525 wxStaticText *hue_text = new wxStaticText( extra_frame, -1,
527 hue_slider = new wxSlider ( extra_frame, Hue_Event, 0, 0,
528 360, wxDefaultPosition, wxDefaultSize );
530 hue_sizer->Add(hue_text,1, 0 ,0);
531 hue_sizer->Add(hue_slider,1, 0 ,0);
534 wxBoxSizer *contrast_sizer = new wxBoxSizer( wxHORIZONTAL );
535 wxStaticText *contrast_text = new wxStaticText( extra_frame, -1,
536 wxU(_("Contrast")) );
537 contrast_slider = new wxSlider ( extra_frame, Contrast_Event, 0, 0,
538 200, wxDefaultPosition, wxDefaultSize);
539 contrast_sizer->Add(contrast_text,1, 0 ,0);
540 contrast_sizer->Add(contrast_slider,1, 0 ,0);
541 contrast_sizer->Layout();
543 wxBoxSizer *brightness_sizer = new wxBoxSizer( wxHORIZONTAL );
544 wxStaticText *brightness_text = new wxStaticText( extra_frame, -1,
545 wxU(_("Brightness")) );
546 brightness_slider = new wxSlider ( extra_frame, Brightness_Event, 0, 0,
547 200, wxDefaultPosition, wxDefaultSize) ;
548 brightness_sizer->Add(brightness_text,1,0,0);
549 brightness_sizer->Add(brightness_slider,1,0,0);
550 brightness_sizer->Layout();
552 wxBoxSizer *saturation_sizer = new wxBoxSizer( wxHORIZONTAL );
553 wxStaticText *saturation_text = new wxStaticText( extra_frame, -1,
554 wxU(_("Saturation")) );
555 saturation_slider = new wxSlider ( extra_frame, Saturation_Event, 0, 0,
556 300, wxDefaultPosition, wxDefaultSize );
557 saturation_sizer->Add(saturation_text,1,0,0);
558 saturation_sizer->Add(saturation_slider,1,0,0);
559 saturation_sizer->Layout();
561 adjust_sizer->Add(adjust_check, 1, wxEXPAND, 0);
562 adjust_sizer->Add(hue_sizer, 1, wxEXPAND, 0);
563 adjust_sizer->Add(contrast_sizer, 1, wxEXPAND, 0);
564 adjust_sizer->Add(brightness_sizer, 1, wxEXPAND, 0);
565 adjust_sizer->Add(saturation_sizer, 1, wxEXPAND, 0);
567 extra_sizer->Add(adjust_sizer,1,wxBOTTOM,5);
570 /* Create sizer to surround the other controls */
571 wxBoxSizer *other_sizer = new wxBoxSizer( wxVERTICAL );
574 wxStaticBox *video_box =
575 new wxStaticBox( extra_frame, -1, wxU(_("Video Options")) );
576 /* Create the sizer for the frame */
577 wxStaticBoxSizer *video_sizer =
578 new wxStaticBoxSizer( video_box, wxVERTICAL );
579 video_sizer->SetMinSize( -1, 50 );
581 static const wxString ratio_array[] =
587 wxBoxSizer *ratio_sizer = new wxBoxSizer( wxHORIZONTAL );
588 wxStaticText *ratio_text = new wxStaticText( extra_frame, -1,
591 ratio_combo = new wxComboBox( extra_frame, Ratio_Event, wxT(""),
592 wxDefaultPosition, wxSize(120,-1),
593 WXSIZEOF(ratio_array), ratio_array,
596 ratio_sizer->Add( ratio_text, 0, wxALL, 2 );
597 ratio_sizer->Add( ratio_combo, 0, wxALL, 2 );
598 ratio_sizer->Layout();
600 video_sizer->Add( ratio_sizer , 0 , wxALL , 0 );
601 video_sizer->Layout();
603 wxBoxSizer *visual_sizer = new wxBoxSizer( wxHORIZONTAL );
605 wxCheckBox *visual_checkbox = new wxCheckBox( extra_frame, Visual_Event,
606 wxU(_("Visualisation")) );
608 visual_sizer->Add( visual_checkbox, 0, wxEXPAND, 0);
609 visual_sizer->Layout();
611 wxStaticBox *audio_box =
612 new wxStaticBox( extra_frame, -1, wxU(_("Audio Options")) );
613 /* Create the sizer for the frame */
614 wxStaticBoxSizer *audio_sizer =
615 new wxStaticBoxSizer( audio_box, wxVERTICAL );
616 audio_sizer->SetMinSize( -1, 50 );
618 audio_sizer->Add( visual_sizer, 0, wxALL, 0);
619 audio_sizer->Layout();
621 other_sizer->Add( video_sizer, 0, wxALL | wxEXPAND , 0);
622 other_sizer->Add( audio_sizer , 0 , wxALL | wxEXPAND , 0 );
623 other_sizer->Layout();
625 extra_sizer->Add(other_sizer,0,wxBOTTOM,5);
627 extra_frame->SetSizer( extra_sizer );
629 /* Layout the whole panel */
630 extra_sizer->Layout();
632 extra_sizer->SetSizeHints(extra_frame);
634 /* Write down initial values */
635 psz_filters = config_GetPsz( p_intf, "audio-filter" );
636 if( psz_filters && strstr( psz_filters, "visual" ) )
638 visual_checkbox->SetValue(1);
640 if( psz_filters ) free( psz_filters );
642 psz_filters = config_GetPsz( p_intf, "filter" );
643 if( psz_filters && strstr( psz_filters, "adjust" ) )
645 adjust_check->SetValue( 1 );
646 saturation_slider->Enable();
647 contrast_slider->Enable();
648 brightness_slider->Enable();
649 hue_slider->Enable();
653 adjust_check->SetValue( 0 );
654 saturation_slider->Disable();
655 contrast_slider->Disable();
656 brightness_slider->Disable();
657 hue_slider->Disable();
659 if( psz_filters ) free( psz_filters );
661 int i_value = config_GetInt( p_intf, "hue" );
662 if( i_value > 0 && i_value < 360 )
663 hue_slider->SetValue( i_value );
666 f_value = config_GetFloat( p_intf, "saturation" );
667 if( f_value > 0 && f_value < 5 )
668 saturation_slider->SetValue( (int)(100 * f_value) );
669 f_value = config_GetFloat( p_intf, "contrast" );
670 if( f_value > 0 && f_value < 4 )
671 contrast_slider->SetValue( (int)(100 * f_value) );
672 f_value = config_GetFloat( p_intf, "brightness" );
673 if( f_value > 0 && f_value < 2 )
674 brightness_slider->SetValue( (int)(100 * f_value) );
679 void Interface::UpdateAcceleratorTable()
681 /* Set some hotkeys */
682 wxAcceleratorEntry entries[7];
686 var_Get( p_intf->p_vlc, "key-quit", &val );
687 entries[i++].Set( ConvertHotkeyModifiers( val.i_int ),
688 ConvertHotkey( val.i_int ), Exit_Event );
689 var_Get( p_intf->p_vlc, "key-stop", &val );
690 entries[i++].Set( ConvertHotkeyModifiers( val.i_int ),
691 ConvertHotkey( val.i_int ), StopStream_Event );
692 var_Get( p_intf->p_vlc, "key-play-pause", &val );
693 entries[i++].Set( ConvertHotkeyModifiers( val.i_int ),
694 ConvertHotkey( val.i_int ), PlayStream_Event );
695 var_Get( p_intf->p_vlc, "key-next", &val );
696 entries[i++].Set( ConvertHotkeyModifiers( val.i_int ),
697 ConvertHotkey( val.i_int ), NextStream_Event );
698 var_Get( p_intf->p_vlc, "key-prev", &val );
699 entries[i++].Set( ConvertHotkeyModifiers( val.i_int ),
700 ConvertHotkey( val.i_int ), PrevStream_Event );
701 var_Get( p_intf->p_vlc, "key-faster", &val );
702 entries[i++].Set( ConvertHotkeyModifiers( val.i_int ),
703 ConvertHotkey( val.i_int ), FastStream_Event );
704 var_Get( p_intf->p_vlc, "key-slower", &val );
705 entries[i++].Set( ConvertHotkeyModifiers( val.i_int ),
706 ConvertHotkey( val.i_int ), SlowStream_Event );
708 wxAcceleratorTable accel( 7, entries );
711 msg_Err( p_intf, "invalid accelerator table" );
713 SetAcceleratorTable( accel );
714 msg_Dbg( p_intf, "accelerator table loaded" );
718 /*****************************************************************************
720 *****************************************************************************/
721 /* Work-around helper for buggy wxGTK */
722 void RecursiveDestroy( wxMenu *menu )
724 wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
727 wxMenuItem *item = node->GetData();
728 node = node->GetNext();
730 /* Delete the submenus */
731 wxMenu *submenu = item->GetSubMenu();
734 RecursiveDestroy( submenu );
736 menu->Delete( item );
740 void Interface::OnMenuOpen(wxMenuEvent& event)
742 #if !defined( __WXMSW__ )
743 if( event.GetEventObject() == p_settings_menu )
745 if( b_settings_menu )
747 p_settings_menu = SettingsMenu( p_intf, this );
749 /* Add static items */
750 p_settings_menu->AppendCheckItem( Extra_Event,
751 wxU(_("&Extended GUI") ), wxU(_(EXTRA_PREFS)) );
752 p_settings_menu->Append( Prefs_Event, wxU(_("&Preferences...")),
753 wxU(_(HELP_PREFS)) );
755 /* Work-around for buggy wxGTK */
756 wxMenu *menu = GetMenuBar()->GetMenu( 2 );
757 RecursiveDestroy( menu );
758 /* End work-around */
760 menu = GetMenuBar()->Replace( 2, p_settings_menu,
761 wxU(_("&Settings")));
762 if( menu ) delete menu;
766 else b_settings_menu = 1;
768 else if( event.GetEventObject() == p_audio_menu )
772 p_audio_menu = AudioMenu( p_intf, this );
774 /* Work-around for buggy wxGTK */
775 wxMenu *menu = GetMenuBar()->GetMenu( 3 );
776 RecursiveDestroy( menu );
777 /* End work-around */
780 GetMenuBar()->Replace( 3, p_audio_menu, wxU(_("&Audio")) );
781 if( menu ) delete menu;
785 else b_audio_menu = 1;
787 else if( event.GetEventObject() == p_video_menu )
791 p_video_menu = VideoMenu( p_intf, this );
793 /* Work-around for buggy wxGTK */
794 wxMenu *menu = GetMenuBar()->GetMenu( 4 );
795 RecursiveDestroy( menu );
796 /* End work-around */
799 GetMenuBar()->Replace( 4, p_video_menu, wxU(_("&Video")) );
800 if( menu ) delete menu;
804 else b_video_menu = 1;
806 else if( event.GetEventObject() == p_navig_menu )
810 p_navig_menu = NavigMenu( p_intf, this );
812 /* Work-around for buggy wxGTK */
813 wxMenu *menu = GetMenuBar()->GetMenu( 5 );
814 RecursiveDestroy( menu );
815 /* End work-around */
818 GetMenuBar()->Replace( 5, p_navig_menu, wxU(_("&Navigation")));
819 if( menu ) delete menu;
823 else b_navig_menu = 1;
827 p_settings_menu = SettingsMenu( p_intf, this );
828 /* Add static items */
829 p_settings_menu->AppendCheckItem( Extra_Event, wxU(_("&Extended GUI") ),
830 wxU(_(EXTRA_PREFS)) );
831 p_settings_menu->Append( Prefs_Event, wxU(_("&Preferences...")),
832 wxU(_(HELP_PREFS)) );
834 GetMenuBar()->Replace( 2, p_settings_menu, wxU(_("&Settings")) );
835 if( menu ) delete menu;
837 p_audio_menu = AudioMenu( p_intf, this );
838 menu = GetMenuBar()->Replace( 3, p_audio_menu, wxU(_("&Audio")) );
839 if( menu ) delete menu;
841 p_video_menu = VideoMenu( p_intf, this );
842 menu = GetMenuBar()->Replace( 4, p_video_menu, wxU(_("&Video")) );
843 if( menu ) delete menu;
845 p_navig_menu = NavigMenu( p_intf, this );
846 menu = GetMenuBar()->Replace( 5, p_navig_menu, wxU(_("&Navigation")) );
847 if( menu ) delete menu;
852 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
853 void Interface::OnContextMenu2(wxContextMenuEvent& event)
855 /* Only show the context menu for the main interface */
856 if( GetId() != event.GetId() )
862 if( p_intf->p_sys->pf_show_dialog )
863 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
866 void Interface::OnContextMenu(wxMouseEvent& event)
868 if( p_intf->p_sys->pf_show_dialog )
869 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
872 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
874 /* TRUE is to force the frame to close. */
878 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
881 msg.Printf( wxString(wxT("VLC media player " VERSION)) +
882 wxU(_(" (wxWindows interface)\n\n")) +
883 wxU(_("(C) 1996-2003 - the VideoLAN Team\n\n")) +
884 wxU( vlc_wraptext(INTF_ABOUT_MSG,WRAPCOUNT,ISUTF8) ) + wxT("\n\n") +
885 wxU(_("The VideoLAN team <videolan@videolan.org>\n"
886 "http://www.videolan.org/\n\n")) );
888 wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
889 wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
892 void Interface::OnShowDialog( wxCommandEvent& event )
894 if( p_intf->p_sys->pf_show_dialog )
898 switch( event.GetId() )
900 case OpenFileSimple_Event:
901 i_id = INTF_DIALOG_FILE_SIMPLE;
904 i_id = INTF_DIALOG_FILE;
906 i_id = INTF_DIALOG_FILE;
909 i_id = INTF_DIALOG_DISC;
912 i_id = INTF_DIALOG_NET;
915 i_id = INTF_DIALOG_SAT;
918 i_id = INTF_DIALOG_PLAYLIST;
921 i_id = INTF_DIALOG_MESSAGES;
924 i_id = INTF_DIALOG_FILEINFO;
927 i_id = INTF_DIALOG_PREFS;
930 i_id = INTF_DIALOG_FILE;
935 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
940 void Interface::OnStream( wxCommandEvent& event )
942 StreamDialog *p_stream_dialog = new StreamDialog(p_intf,this);
943 p_stream_dialog->Show();
947 void Interface::OnExtra(wxCommandEvent& event)
949 if( b_extra == VLC_FALSE)
952 frame_sizer->Show( extra_frame );
958 frame_sizer->Hide( extra_frame );
961 frame_sizer->Layout();
962 frame_sizer->Fit(this);
965 void Interface::OnEnableAdjust(wxCommandEvent& event)
967 char *psz_filters=config_GetPsz( p_intf, "filter");
968 char *psz_new = NULL;
969 if( event.IsChecked() )
971 if(psz_filters == NULL)
973 psz_new = strdup( "adjust" );
977 psz_new= (char *) malloc(strlen(psz_filters) + 8 );
978 sprintf( psz_new, "%s:adjust", psz_filters);
980 config_PutPsz( p_intf, "filter", psz_new );
982 vout_thread_t *p_vout =
983 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
987 val.psz_string = strdup( psz_new );
988 var_Set( p_vout, "filter", val);
989 vlc_object_release( p_vout );
991 if( val.psz_string ) free( val.psz_string );
992 brightness_slider->Enable();
993 saturation_slider->Enable();
994 contrast_slider->Enable();
995 hue_slider->Enable();
999 if( psz_filters != NULL )
1004 for( i = 0; i< strlen(psz_filters ); i++)
1006 if ( !strncasecmp( &psz_filters[i],"adjust",6 ))
1009 if( psz_filters[i-1] == ':' ) i--;
1010 psz_current = strchr( &psz_filters[i+1] , ':' );
1012 psz_filters[i] = '\0';
1015 memmove( &psz_filters[i] , psz_current,
1016 &psz_filters[strlen(psz_filters)]-psz_current
1021 config_PutPsz( p_intf, "filter", psz_filters);
1023 val.psz_string = strdup( psz_filters );
1024 vout_thread_t *p_vout =
1025 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1027 if( p_vout != NULL )
1029 var_Set( p_vout, "filter", val);
1030 vlc_object_release( p_vout );
1032 if( val.psz_string ) free( val.psz_string );
1034 brightness_slider->Disable();
1035 saturation_slider->Disable();
1036 contrast_slider->Disable();
1037 hue_slider->Disable();
1039 if(psz_filters) free(psz_filters);
1040 if(psz_new) free(psz_new);
1043 void Interface::OnHueUpdate( wxScrollEvent& event)
1045 config_PutInt( p_intf , "hue" , event.GetPosition() );
1048 void Interface::OnSaturationUpdate( wxScrollEvent& event)
1050 config_PutFloat( p_intf , "saturation" , (float)event.GetPosition()/100 );
1053 void Interface::OnBrightnessUpdate( wxScrollEvent& event)
1055 config_PutFloat( p_intf , "brightness", (float)event.GetPosition()/100 );
1058 void Interface::OnContrastUpdate(wxScrollEvent& event)
1060 config_PutFloat( p_intf , "contrast" , (float)event.GetPosition()/100 );
1064 void Interface::OnRatio( wxCommandEvent& event )
1066 config_PutPsz( p_intf, "aspect-ratio", ratio_combo->GetValue().mb_str() );
1069 void Interface::OnEnableVisual(wxCommandEvent& event)
1071 if( event.IsChecked() )
1073 config_PutPsz( p_intf, "audio-filter", "visual" );
1077 config_PutPsz( p_intf, "audio-filter", "" );
1081 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
1083 wxCommandEvent dummy;
1084 playlist_t *p_playlist =
1085 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1087 if( p_playlist == NULL ) return;
1089 if( p_playlist->i_size && p_playlist->i_enabled )
1093 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
1096 if( p_input == NULL )
1098 /* No stream was playing, start one */
1099 playlist_Play( p_playlist );
1100 TogglePlayButton( PLAYING_S );
1101 vlc_object_release( p_playlist );
1105 var_Get( p_input, "state", &state );
1107 if( state.i_int != PAUSE_S )
1109 /* A stream is being played, pause it */
1110 state.i_int = PAUSE_S;
1114 /* Stream is paused, resume it */
1115 state.i_int = PLAYING_S;
1117 var_Set( p_input, "state", state );
1119 TogglePlayButton( state.i_int );
1120 vlc_object_release( p_input );
1121 vlc_object_release( p_playlist );
1125 /* If the playlist is empty, open a file requester instead */
1126 vlc_object_release( p_playlist );
1127 OnShowDialog( dummy );
1131 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
1133 playlist_t * p_playlist =
1134 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1136 if( p_playlist == NULL )
1141 playlist_Stop( p_playlist );
1142 TogglePlayButton( PAUSE_S );
1143 vlc_object_release( p_playlist );
1146 void Interface::OnSliderUpdate( wxScrollEvent& event )
1148 vlc_mutex_lock( &p_intf->change_lock );
1151 if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
1152 || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
1155 if( p_intf->p_sys->i_slider_pos != event.GetPosition()
1156 && p_intf->p_sys->p_input )
1159 pos.f_float = (float)event.GetPosition() / (float)SLIDER_MAX_POS;
1161 var_Set( p_intf->p_sys->p_input, "position", pos );
1165 p_intf->p_sys->b_slider_free = VLC_TRUE;
1169 p_intf->p_sys->b_slider_free = VLC_FALSE;
1171 if( p_intf->p_sys->p_input )
1173 /* Update stream date */
1174 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
1175 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
1177 slider_box->SetLabel(
1178 wxU(input_OffsetToTime( p_intf->p_sys->p_input,
1180 p_area->i_size * event.GetPosition()
1181 / SLIDER_MAX_POS )) );
1187 vlc_mutex_unlock( &p_intf->change_lock );
1190 void Interface::OnPrevStream( 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 vlc_mutex_lock( &p_playlist->object_lock );
1201 if( p_playlist->p_input != NULL )
1203 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1204 if( p_playlist->p_input->stream.p_selected_area->i_id > 1 )
1206 vlc_value_t val; val.b_bool = VLC_TRUE;
1207 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1208 var_Set( p_playlist->p_input, "prev-title", val );
1209 vlc_mutex_unlock( &p_playlist->object_lock );
1210 vlc_object_release( p_playlist );
1213 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1215 vlc_mutex_unlock( &p_playlist->object_lock );
1217 playlist_Prev( p_playlist );
1218 vlc_object_release( p_playlist );
1221 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1223 playlist_t * p_playlist =
1224 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1226 if( p_playlist == NULL )
1231 vlc_mutex_lock( &p_playlist->object_lock );
1232 if( p_playlist->p_input != NULL )
1234 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1235 if( p_playlist->p_input->stream.i_area_nb > 1 &&
1236 p_playlist->p_input->stream.p_selected_area->i_id <
1237 p_playlist->p_input->stream.i_area_nb - 1 )
1239 vlc_value_t val; val.b_bool = VLC_TRUE;
1240 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1241 var_Set( p_playlist->p_input, "next-title", val );
1242 vlc_mutex_unlock( &p_playlist->object_lock );
1243 vlc_object_release( p_playlist );
1246 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1248 vlc_mutex_unlock( &p_playlist->object_lock );
1250 playlist_Next( p_playlist );
1251 vlc_object_release( p_playlist );
1254 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1256 input_thread_t *p_input =
1257 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1261 vlc_value_t val; val.b_bool = VLC_TRUE;
1263 var_Set( p_input, "rate-slower", val );
1264 vlc_object_release( p_input );
1268 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1270 input_thread_t *p_input =
1271 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1275 vlc_value_t val; val.b_bool = VLC_TRUE;
1277 var_Set( p_input, "rate-faster", val );
1278 vlc_object_release( p_input );
1282 void Interface::TogglePlayButton( int i_playing_status )
1284 if( i_playing_status == i_old_playing_status )
1287 GetToolBar()->DeleteTool( PlayStream_Event );
1289 if( i_playing_status == PLAYING_S )
1291 GetToolBar()->InsertTool( 8, PlayStream_Event, wxU(_("Pause")),
1292 wxBitmap( pause_xpm ), wxNullBitmap,
1293 wxITEM_NORMAL, wxU(_(HELP_PAUSE)) );
1297 GetToolBar()->InsertTool( 8, PlayStream_Event, wxU(_("Play")),
1298 wxBitmap( play_xpm ), wxNullBitmap,
1299 wxITEM_NORMAL, wxU(_(HELP_PLAY)) );
1302 GetToolBar()->Realize();
1304 i_old_playing_status = i_playing_status;
1307 #if !defined(__WXX11__)
1308 /*****************************************************************************
1309 * Definition of DragAndDrop class.
1310 *****************************************************************************/
1311 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf, vlc_bool_t _b_enqueue )
1314 b_enqueue = _b_enqueue;
1317 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1318 const wxArrayString& filenames )
1320 /* Add dropped files to the playlist */
1322 playlist_t *p_playlist =
1323 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1325 if( p_playlist == NULL )
1330 for( size_t i = 0; i < filenames.GetCount(); i++ )
1331 playlist_Add( p_playlist, (const char *)filenames[i].mb_str(), 0, 0,
1332 PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
1335 vlc_object_release( p_playlist );
1341 /*****************************************************************************
1342 * Definition of wxVolCtrl class.
1343 *****************************************************************************/
1344 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id )
1345 : wxGauge( parent, id, 200, wxDefaultPosition, wxDefaultSize,
1346 wxGA_VERTICAL | wxGA_SMOOTH )
1351 void wxVolCtrl::OnChange( wxMouseEvent& event )
1353 if( !event.LeftDown() && !event.LeftIsDown() ) return;
1355 int i_volume = (GetClientSize().GetHeight() - event.GetY()) * 200 /
1356 GetClientSize().GetHeight();
1360 void wxVolCtrl::Change( int i_volume )
1362 aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1363 SetValue( i_volume );
1364 SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),