1 /*****************************************************************************
2 * interface.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: interface.cpp,v 1.67 2003/10/19 22:52:11 sigmunau 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"
42 #include "bitmaps/disc.xpm"
43 #include "bitmaps/net.xpm"
45 #include "bitmaps/sat.xpm"
47 #include "bitmaps/play.xpm"
48 #include "bitmaps/pause.xpm"
49 #include "bitmaps/stop.xpm"
50 #include "bitmaps/previous.xpm"
51 #include "bitmaps/next.xpm"
52 #include "bitmaps/playlist.xpm"
53 #include "bitmaps/fast.xpm"
54 #include "bitmaps/slow.xpm"
56 #define TOOLBAR_BMP_WIDTH 36
57 #define TOOLBAR_BMP_HEIGHT 36
59 /* include the icon graphic */
60 #include "../../../share/vlc32x32.xpm"
62 /*****************************************************************************
63 * Local class declarations.
64 *****************************************************************************/
65 class wxMenuExt: public wxMenu
69 wxMenuExt( wxMenu* parentMenu, int id, const wxString& text,
70 const wxString& helpString, wxItemKind kind,
71 char *_psz_var, int _i_object_id, vlc_value_t _val,
74 virtual ~wxMenuExt() {};
85 class wxVolCtrl: public wxGauge
89 wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id );
90 virtual ~wxVolCtrl() {};
92 void Change( int i_volume );
94 void OnChange( wxMouseEvent& event );
97 intf_thread_t *p_intf;
99 DECLARE_EVENT_TABLE();
102 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
104 EVT_LEFT_DOWN(wxVolCtrl::OnChange)
105 EVT_MOTION(wxVolCtrl::OnChange)
108 /*****************************************************************************
110 *****************************************************************************/
112 /* IDs for the controls and the menu commands */
116 Exit_Event = wxID_HIGHEST,
117 OpenFileSimple_Event,
147 /* it is important for the id corresponding to the "About" command to have
148 * this standard value as otherwise it won't be handled properly under Mac
149 * (where it is special and put into the "Apple" menu) */
150 About_Event = wxID_ABOUT
153 BEGIN_EVENT_TABLE(Interface, wxFrame)
155 EVT_MENU(Exit_Event, Interface::OnExit)
156 EVT_MENU(About_Event, Interface::OnAbout)
158 EVT_MENU(Playlist_Event, Interface::OnShowDialog)
159 EVT_MENU(Logs_Event, Interface::OnShowDialog)
160 EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
161 EVT_MENU(Prefs_Event, Interface::OnShowDialog)
163 EVT_MENU_OPEN(Interface::OnMenuOpen)
165 EVT_MENU( Extra_Event, Interface::OnExtra)
166 EVT_CHECKBOX( Adjust_Event, Interface::OnEnableAdjust)
168 EVT_COMBOBOX( Ratio_Event, Interface::OnRatio)
170 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
171 EVT_CONTEXT_MENU(Interface::OnContextMenu2)
173 EVT_RIGHT_UP(Interface::OnContextMenu)
176 EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
177 EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
178 EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
179 EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
180 EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
181 EVT_MENU(StopStream_Event, Interface::OnStopStream)
182 EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
183 EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
184 EVT_MENU(NextStream_Event, Interface::OnNextStream)
185 EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
186 EVT_MENU(FastStream_Event, Interface::OnFastStream)
189 EVT_COMMAND_SCROLL(SliderScroll_Event, Interface::OnSliderUpdate)
191 EVT_COMMAND_SCROLL(Hue_Event, Interface::OnHueUpdate)
192 EVT_COMMAND_SCROLL(Contrast_Event, Interface::OnContrastUpdate)
193 EVT_COMMAND_SCROLL(Brightness_Event, Interface::OnBrightnessUpdate)
194 EVT_COMMAND_SCROLL(Saturation_Event, Interface::OnSaturationUpdate)
198 /*****************************************************************************
200 *****************************************************************************/
201 Interface::Interface( intf_thread_t *_p_intf ):
202 wxFrame( NULL, -1, wxT("VLC media player"),
203 wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE )
205 /* Initializations */
207 i_old_playing_status = PAUSE_S;
210 /* Give our interface a nice little icon */
211 SetIcon( wxIcon( vlc_xpm ) );
213 /* Create a sizer for the main frame */
214 //frame_sizer= new wxFlexGridSizer( 1, 0, 0);
215 frame_sizer = new wxBoxSizer( wxVERTICAL );
216 SetSizer( frame_sizer );
218 /* Create a dummy widget that can get the keyboard focus */
219 wxWindow *p_dummy = new wxWindow( this, 0, wxDefaultPosition,
222 frame_sizer->Add( p_dummy );
224 /* Creation of the menu bar */
227 /* Creation of the tool bar */
230 /* Creation of the slider sub-window */
232 frame_sizer->Add( slider_frame, 0, wxEXPAND , 0 );
233 frame_sizer->Hide( slider_frame );
235 /* Create the extra panel */
236 CreateOurExtraPanel();
237 frame_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
238 frame_sizer->Hide( extra_frame );
240 /* Creation of the status bar
241 * Helptext for menu items and toolbar tools will automatically get
243 int i_status_width[3] = {-6, -2, -9};
244 statusbar = CreateStatusBar( 3 ); /* 2 fields */
245 statusbar->SetStatusWidths( 3, i_status_width );
246 statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
248 /* Make sure we've got the right background colour */
249 SetBackgroundColour( slider_frame->GetBackgroundColour() );
251 /* Layout everything */
252 SetAutoLayout( TRUE );
253 frame_sizer->Layout();
254 frame_sizer->Fit(this);
256 #if !defined(__WXX11__)
257 /* Associate drop targets with the main interface */
258 SetDropTarget( new DragAndDrop( p_intf ) );
261 UpdateAcceleratorTable();
264 timer = new Timer( p_intf, this );
267 Interface::~Interface()
269 if( p_intf->p_sys->p_wxwindow )
271 delete p_intf->p_sys->p_wxwindow;
278 /*****************************************************************************
280 *****************************************************************************/
281 void Interface::CreateOurMenuBar()
283 #define HELP_FILE N_("Open a file")
284 #define HELP_DISC N_("Open a DVD or (S)VCD")
285 #define HELP_NET N_("Open a network stream")
286 #define HELP_SAT N_("Open a satellite stream")
287 #define HELP_EJECT N_("Eject the DVD/CD")
288 #define HELP_EXIT N_("Exit this program")
290 #define HELP_PLAYLIST N_("Open the playlist")
291 #define HELP_LOGS N_("Show the program logs")
292 #define HELP_FILEINFO N_("Show information about the file being played")
294 #define HELP_PREFS N_("Go to the preferences menu")
295 #define EXTRA_PREFS N_("Shows the extended GUI")
297 #define HELP_ABOUT N_("About this program")
299 /* Create the "File" menu */
300 wxMenu *file_menu = new wxMenu;
301 file_menu->Append( OpenFileSimple_Event, wxU(_("Simple &Open ...")),
303 file_menu->Append( OpenFile_Event, wxU(_("Open &File...")),
305 file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...")),
307 file_menu->Append( OpenNet_Event, wxU(_("Open &Network Stream...")),
310 file_menu->Append( OpenSat_Event, wxU(_("Open &Satellite Stream...")),
314 file_menu->AppendSeparator();
315 file_menu->Append( EjectDisc_Event, wxU(_("&Eject Disc")),
316 wxU(_(HELP_EJECT)) );
318 file_menu->AppendSeparator();
319 file_menu->Append( Exit_Event, wxU(_("E&xit")), wxU(_(HELP_EXIT)) );
321 /* Create the "View" menu */
322 wxMenu *view_menu = new wxMenu;
323 view_menu->Append( Playlist_Event, wxU(_("&Playlist...")),
324 wxU(_(HELP_PLAYLIST)) );
325 view_menu->Append( Logs_Event, wxU(_("&Messages...")), wxU(_(HELP_LOGS)) );
326 view_menu->Append( FileInfo_Event, wxU(_("&File info...")),
327 wxU(_(HELP_FILEINFO)) );
329 /* Create the "Settings" menu */
330 wxMenu *settings_menu = new wxMenu;
331 settings_menu->Append( Prefs_Event, wxU(_("&Preferences...")),
332 wxU(_(HELP_PREFS)) );
333 settings_menu->AppendCheckItem( Extra_Event, wxU(_("&Extended GUI") ),
334 wxU(_(EXTRA_PREFS)) );
336 /* Create the "Audio" menu */
337 p_audio_menu = new wxMenu;
340 /* Create the "Video" menu */
341 p_video_menu = new wxMenu;
344 /* Create the "Navigation" menu */
345 p_navig_menu = new wxMenu;
348 /* Create the "Miscellaneous" menu */
349 p_misc_menu = new wxMenu;
352 /* Create the "Help" menu */
353 wxMenu *help_menu = new wxMenu;
354 help_menu->Append( About_Event, wxU(_("&About...")), wxU(_(HELP_ABOUT)) );
356 /* Append the freshly created menus to the menu bar... */
357 wxMenuBar *menubar = new wxMenuBar( wxMB_DOCKABLE );
358 menubar->Append( file_menu, wxU(_("&File")) );
359 menubar->Append( view_menu, wxU(_("&View")) );
360 menubar->Append( settings_menu, wxU(_("&Settings")) );
361 menubar->Append( p_audio_menu, wxU(_("&Audio")) );
362 menubar->Append( p_video_menu, wxU(_("&Video")) );
363 menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
364 menubar->Append( p_misc_menu, wxU(_("&Miscellaneous")) );
365 menubar->Append( help_menu, wxU(_("&Help")) );
367 /* Attach the menu bar to the frame */
368 SetMenuBar( menubar );
370 /* Intercept all menu events in our custom event handler */
371 PushEventHandler( new MenuEvtHandler( p_intf, this ) );
373 #if !defined(__WXX11__)
374 /* Associate drop targets with the menubar */
375 menubar->SetDropTarget( new DragAndDrop( p_intf ) );
379 void Interface::CreateOurToolBar()
381 #define HELP_STOP N_("Stop current playlist item")
382 #define HELP_PLAY N_("Play current playlist item")
383 #define HELP_PAUSE N_("Pause current playlist item")
384 #define HELP_PLO N_("Open playlist")
385 #define HELP_PLP N_("Previous playlist item")
386 #define HELP_PLN N_("Next playlist item")
387 #define HELP_SLOW N_("Play slower")
388 #define HELP_FAST N_("Play faster")
390 wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
391 * version because we don't include wx.rc */
393 wxToolBar *toolbar = CreateToolBar(
394 wxTB_HORIZONTAL | wxTB_FLAT | wxTB_DOCKABLE );
396 toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
398 toolbar->AddTool( OpenFile_Event, wxU(_("File")), wxBitmap( file_xpm ),
400 toolbar->AddTool( OpenDisc_Event, wxU(_("Disc")), wxBitmap( disc_xpm ),
402 toolbar->AddTool( OpenNet_Event, wxU(_("Net")), wxBitmap( net_xpm ),
405 toolbar->AddTool( OpenSat_Event, wxU(_("Sat")), wxBitmap( sat_xpm ),
408 toolbar->AddSeparator();
409 toolbar->AddTool( StopStream_Event, wxU(_("Stop")), wxBitmap( stop_xpm ),
411 toolbar->AddTool( PlayStream_Event, wxU(_("Play")), wxBitmap( play_xpm ),
413 toolbar->AddSeparator();
414 toolbar->AddTool( Playlist_Event, wxU(_("Playlist")),
415 wxBitmap( playlist_xpm ), wxU(_(HELP_PLO)) );
416 toolbar->AddTool( PrevStream_Event, wxU(_("Prev")),
417 wxBitmap( previous_xpm ), wxU(_(HELP_PLP)) );
418 toolbar->AddTool( NextStream_Event, wxU(_("Next")), wxBitmap( next_xpm ),
420 toolbar->AddTool( SlowStream_Event, wxU(_("Slower")), wxBitmap( slow_xpm ),
422 toolbar->AddTool( FastStream_Event, wxU(_("Faster")), wxBitmap( fast_xpm ),
427 /* Place the toolbar in a sizer, so we can calculate the width of the
428 * toolbar and set this as the minimum for the main frame size. */
429 wxBoxSizer *toolbar_sizer = new wxBoxSizer( wxHORIZONTAL );
430 toolbar_sizer->Add( toolbar, 0, 0, 0 );
432 toolbar_sizer->Layout();
435 frame_sizer->SetMinSize( toolbar_sizer->GetMinSize().GetWidth(), -1 );
437 frame_sizer->SetMinSize( toolbar->GetToolSize().GetWidth() *
438 toolbar->GetToolsCount(), -1 );
441 #if !defined(__WXX11__)
442 /* Associate drop targets with the toolbar */
443 toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
447 void Interface::CreateOurSlider()
449 /* Create a new frame and sizer containing the slider */
450 slider_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
451 slider_frame->SetAutoLayout( TRUE );
452 wxBoxSizer *frame_sizer =
453 new wxBoxSizer( wxHORIZONTAL );
455 /* Create static box to surround the slider */
456 slider_box = new wxStaticBox( slider_frame, -1, wxT("") );
458 /* Create sizer for slider frame */
459 wxStaticBoxSizer *slider_sizer =
460 new wxStaticBoxSizer( slider_box, wxHORIZONTAL );
461 slider_sizer->SetMinSize( -1, 50 );
464 slider = new wxSlider( slider_frame, SliderScroll_Event, 0, 0,
465 SLIDER_MAX_POS, wxDefaultPosition, wxDefaultSize );
466 slider_sizer->Add( slider, 1, wxEXPAND | wxALL, 5 );
469 volctrl = new wxVolCtrl( p_intf, slider_frame, -1 );
471 /* Add everything to the frame */
472 frame_sizer->Add( slider_sizer, 1, wxEXPAND | wxBOTTOM, 5 );
473 frame_sizer->Add( volctrl, 0, wxEXPAND | wxALL, 5 );
474 slider_frame->SetSizer( frame_sizer );
475 frame_sizer->Layout();
476 frame_sizer->SetSizeHints(slider_frame);
478 /* Hide the slider by default */
479 slider_frame->Hide();
483 void Interface::CreateOurExtraPanel()
487 extra_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
488 extra_frame->SetAutoLayout( TRUE );
489 wxBoxSizer *extra_sizer = new wxBoxSizer( wxHORIZONTAL );
491 /* Create static box to surround the adjust controls */
492 adjust_box = new wxStaticBox( extra_frame, -1, wxU(_("Image adjust")) );
494 /* Create the size for the frame */
495 wxStaticBoxSizer *adjust_sizer =
496 new wxStaticBoxSizer( adjust_box, wxVERTICAL );
497 adjust_sizer->SetMinSize( -1, 50 );
499 /* Create every controls */
501 /* Create the adjust button */
502 wxCheckBox * adjust_check = new wxCheckBox( extra_frame, Adjust_Event,
506 wxBoxSizer *hue_sizer = new wxBoxSizer( wxHORIZONTAL );
507 wxStaticText *hue_text = new wxStaticText( extra_frame, -1,
509 hue_slider = new wxSlider ( extra_frame, Hue_Event, 0, 0,
510 360, wxDefaultPosition, wxDefaultSize );
512 hue_sizer->Add(hue_text,1, 0 ,0);
513 hue_sizer->Add(hue_slider,1, 0 ,0);
516 wxBoxSizer *contrast_sizer = new wxBoxSizer( wxHORIZONTAL );
517 wxStaticText *contrast_text = new wxStaticText( extra_frame, -1,
518 wxU(_("Contrast")) );
519 contrast_slider = new wxSlider ( extra_frame, Contrast_Event, 0, 0,
520 200, wxDefaultPosition, wxDefaultSize);
521 contrast_sizer->Add(contrast_text,1, 0 ,0);
522 contrast_sizer->Add(contrast_slider,1, 0 ,0);
523 contrast_sizer->Layout();
525 wxBoxSizer *brightness_sizer = new wxBoxSizer( wxHORIZONTAL );
526 wxStaticText *brightness_text = new wxStaticText( extra_frame, -1,
527 wxU(_("Brightness")) );
528 brightness_slider = new wxSlider ( extra_frame, Brightness_Event, 0, 0,
529 200, wxDefaultPosition, wxDefaultSize) ;
530 brightness_sizer->Add(brightness_text,1,0,0);
531 brightness_sizer->Add(brightness_slider,1,0,0);
532 brightness_sizer->Layout();
534 wxBoxSizer *saturation_sizer = new wxBoxSizer( wxHORIZONTAL );
535 wxStaticText *saturation_text = new wxStaticText( extra_frame, -1,
536 wxU(_("Saturation")) );
537 saturation_slider = new wxSlider ( extra_frame, Saturation_Event, 0, 0,
538 300, wxDefaultPosition, wxDefaultSize );
539 saturation_sizer->Add(saturation_text,1,0,0);
540 saturation_sizer->Add(saturation_slider,1,0,0);
541 saturation_sizer->Layout();
543 adjust_sizer->Add(adjust_check, 1, wxEXPAND, 0);
544 adjust_sizer->Add(hue_sizer, 1, wxEXPAND, 0);
545 adjust_sizer->Add(contrast_sizer, 1, wxEXPAND, 0);
546 adjust_sizer->Add(brightness_sizer, 1, wxEXPAND, 0);
547 adjust_sizer->Add(saturation_sizer, 1, wxEXPAND, 0);
549 extra_sizer->Add(adjust_sizer,1,wxBOTTOM,5);
552 /* Create static box to surround the other controls */
553 other_box = new wxStaticBox( extra_frame, -1, wxU(_("Video Options")) );
555 /* Create the sizer for the frame */
556 wxStaticBoxSizer *other_sizer =
557 new wxStaticBoxSizer( other_box, wxVERTICAL );
558 other_sizer->SetMinSize( -1, 50 );
560 static const wxString ratio_array[] =
566 wxBoxSizer *ratio_sizer = new wxBoxSizer( wxHORIZONTAL );
567 wxStaticText *ratio_text = new wxStaticText( extra_frame, -1,
570 ratio_combo = new wxComboBox( extra_frame, Ratio_Event, wxT(""),
571 wxDefaultPosition, wxSize(120,-1),
572 WXSIZEOF(ratio_array), ratio_array,
575 ratio_sizer->Add( ratio_text, 0, wxALL, 2 );
576 ratio_sizer->Add( ratio_combo, 0, wxALL, 2 );
577 ratio_sizer->Layout();
579 other_sizer->Add(ratio_sizer,0,wxALL,0 );
581 extra_sizer->Add(other_sizer,0,wxBOTTOM,5);
583 extra_frame->SetSizer( extra_sizer );
585 /* Layout the whole panel */
586 extra_sizer->Layout();
588 extra_sizer->SetSizeHints(extra_frame);
590 /* Write down initial values */
591 psz_filters = config_GetPsz( p_intf, "filter" );
593 if(psz_filters == NULL) psz_filters=strdup("");
595 if( strstr(psz_filters,"adjust") )
597 adjust_check->SetValue( 1 );
598 saturation_slider->Enable();
599 contrast_slider->Enable();
600 brightness_slider->Enable();
601 hue_slider->Enable();
605 adjust_check->SetValue( 0 );
606 saturation_slider->Disable();
607 contrast_slider->Disable();
608 brightness_slider->Disable();
609 hue_slider->Disable();
612 int i_value = config_GetInt( p_intf, "hue" );
613 if( i_value > 0 && i_value < 360 )
614 hue_slider->SetValue( i_value );
617 f_value = config_GetFloat( p_intf, "saturation" );
618 if( f_value > 0 && f_value < 5 )
619 saturation_slider->SetValue( (int)(100 * f_value) );
620 f_value = config_GetFloat( p_intf, "contrast" );
621 if( f_value > 0 && f_value < 4 )
622 contrast_slider->SetValue( (int)(100 * f_value) );
623 f_value = config_GetFloat( p_intf, "brightness" );
624 if( f_value > 0 && f_value < 2 )
625 brightness_slider->SetValue( (int)(100 * f_value) );
631 void Interface::UpdateAcceleratorTable()
633 /* Set some hotkeys */
634 wxAcceleratorEntry entries[7];
635 int i_key = config_GetInt( p_intf, "quit-key" );
637 entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
639 i_key = config_GetInt( p_intf, "stop-key" );
640 entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
642 i_key = config_GetInt( p_intf, "play-pause-key" );
643 entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
645 i_key = config_GetInt( p_intf, "next-key" );
646 entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
648 i_key = config_GetInt( p_intf, "prev-key" );
649 entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
651 i_key = config_GetInt( p_intf, "faster-key" );
652 entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
654 i_key = config_GetInt( p_intf, "slower-key" );
655 entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
658 wxAcceleratorTable accel( 7, entries );
661 msg_Err( p_intf, "invalid accelerator table" );
663 SetAcceleratorTable( accel );
664 msg_Dbg( p_intf, "accelerator table loaded" );
670 /*****************************************************************************
672 *****************************************************************************/
673 /* Work-around helper for buggy wxGTK */
674 void RecursiveDestroy( wxMenu *menu )
676 wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
679 wxMenuItem *item = node->GetData();
680 node = node->GetNext();
682 /* Delete the submenus */
683 wxMenu *submenu = item->GetSubMenu();
686 RecursiveDestroy( submenu );
688 menu->Delete( item );
692 void Interface::OnMenuOpen(wxMenuEvent& event)
694 #if !defined( __WXMSW__ )
695 if( event.GetEventObject() == p_audio_menu )
699 p_audio_menu = AudioMenu( p_intf, this );
701 /* Work-around for buggy wxGTK */
702 wxMenu *menu = GetMenuBar()->GetMenu( 3 );
703 RecursiveDestroy( menu );
704 /* End work-around */
707 GetMenuBar()->Replace( 3, p_audio_menu, wxU(_("&Audio")) );
708 if( menu ) delete menu;
712 else b_audio_menu = 1;
714 else if( event.GetEventObject() == p_video_menu )
718 p_video_menu = VideoMenu( p_intf, this );
720 /* Work-around for buggy wxGTK */
721 wxMenu *menu = GetMenuBar()->GetMenu( 4 );
722 RecursiveDestroy( menu );
723 /* End work-around */
726 GetMenuBar()->Replace( 4, p_video_menu, wxU(_("&Video")) );
727 if( menu ) delete menu;
731 else b_video_menu = 1;
733 else if( event.GetEventObject() == p_navig_menu )
737 p_navig_menu = NavigMenu( p_intf, this );
739 /* Work-around for buggy wxGTK */
740 wxMenu *menu = GetMenuBar()->GetMenu( 5 );
741 RecursiveDestroy( menu );
742 /* End work-around */
745 GetMenuBar()->Replace( 5, p_navig_menu, wxU(_("&Navigation")));
746 if( menu ) delete menu;
750 else b_navig_menu = 1;
752 else if( event.GetEventObject() == p_misc_menu )
756 p_misc_menu = MiscMenu( p_intf, this );
758 /* Work-around for buggy wxGTK */
759 wxMenu *menu = GetMenuBar()->GetMenu( 6 );
760 RecursiveDestroy( menu );
761 /* End work-around */
763 menu = GetMenuBar()->Replace( 6, p_misc_menu,
764 wxU(_("&Miscellaneous")));
765 if( menu ) delete menu;
769 else b_misc_menu = 1;
773 p_audio_menu = AudioMenu( p_intf, this );
774 wxMenu *menu = GetMenuBar()->Replace( 3, p_audio_menu, wxU(_("&Audio")) );
775 if( menu ) delete menu;
777 p_video_menu = VideoMenu( p_intf, this );
778 menu = GetMenuBar()->Replace( 4, p_video_menu, wxU(_("&Video")) );
779 if( menu ) delete menu;
781 p_navig_menu = NavigMenu( p_intf, this );
782 menu = GetMenuBar()->Replace( 5, p_navig_menu, wxU(_("&Navigation")) );
783 if( menu ) delete menu;
785 p_misc_menu = MiscMenu( p_intf, this );
786 menu = GetMenuBar()->Replace( 6, p_misc_menu, wxU(_("&Miscellaneous")) );
787 if( menu ) delete menu;
791 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
792 void Interface::OnContextMenu2(wxContextMenuEvent& event)
794 /* Only show the context menu for the main interface */
795 if( GetId() != event.GetId() )
801 if( p_intf->p_sys->pf_show_dialog )
802 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
805 void Interface::OnContextMenu(wxMouseEvent& event)
807 if( p_intf->p_sys->pf_show_dialog )
808 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
811 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
813 /* TRUE is to force the frame to close. */
817 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
820 msg.Printf( wxString(wxT("VLC media player " VERSION)) +
821 wxU(_(" (wxWindows interface)\n\n")) +
822 wxU(_("(C) 1996-2003 - the VideoLAN Team\n\n")) +
823 wxU( INTF_ABOUT_MSG ) + wxT("\n\n") +
824 wxU(_("The VideoLAN team <videolan@videolan.org>\n"
825 "http://www.videolan.org/\n\n")) );
827 wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
828 wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
831 void Interface::OnShowDialog( wxCommandEvent& event )
833 if( p_intf->p_sys->pf_show_dialog )
837 switch( event.GetId() )
839 case OpenFileSimple_Event:
840 i_id = INTF_DIALOG_FILE_SIMPLE;
843 i_id = INTF_DIALOG_FILE;
846 i_id = INTF_DIALOG_DISC;
849 i_id = INTF_DIALOG_NET;
852 i_id = INTF_DIALOG_SAT;
855 i_id = INTF_DIALOG_PLAYLIST;
858 i_id = INTF_DIALOG_MESSAGES;
861 i_id = INTF_DIALOG_FILEINFO;
864 i_id = INTF_DIALOG_PREFS;
867 i_id = INTF_DIALOG_FILE;
872 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
876 void Interface::OnExtra(wxCommandEvent& event)
878 if( b_extra == VLC_FALSE)
881 frame_sizer->Show( extra_frame );
887 frame_sizer->Hide( extra_frame );
890 frame_sizer->Layout();
891 frame_sizer->Fit(this);
894 void Interface::OnEnableAdjust(wxCommandEvent& event)
896 char *psz_filters=config_GetPsz( p_intf, "filter");
897 char *psz_new = NULL;
898 if( event.IsChecked() )
900 if(psz_filters == NULL)
902 psz_new = strdup( "adjust" );
906 psz_new= (char *) malloc(strlen(psz_filters) + 8 );
907 sprintf( psz_new, "%s:adjust", psz_filters);
909 config_PutPsz( p_intf, "filter", psz_new );
911 vout_thread_t *p_vout =
912 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
916 val.psz_string = strdup( psz_new );
917 var_Set( p_vout, "filter", val);
918 vlc_object_release( p_vout );
920 if( val.psz_string ) free( val.psz_string );
921 brightness_slider->Enable();
922 saturation_slider->Enable();
923 contrast_slider->Enable();
924 hue_slider->Enable();
928 if( psz_filters != NULL )
933 for( i = 0; i< strlen(psz_filters ); i++)
935 if ( !strncasecmp( &psz_filters[i],"adjust",6 ))
938 if( psz_filters[i-1] == ':' ) i--;
939 psz_current = strchr( &psz_filters[i+1] , ':' );
941 psz_filters[i] = '\0';
944 memmove( &psz_filters[i] , psz_current,
945 &psz_filters[strlen(psz_filters)]-psz_current
950 config_PutPsz( p_intf, "filter", psz_filters);
952 val.psz_string = strdup( psz_filters );
953 vout_thread_t *p_vout =
954 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
958 var_Set( p_vout, "filter", val);
959 vlc_object_release( p_vout );
961 if( val.psz_string ) free( val.psz_string );
963 brightness_slider->Disable();
964 saturation_slider->Disable();
965 contrast_slider->Disable();
966 hue_slider->Disable();
968 if(psz_filters) free(psz_filters);
969 if(psz_new) free(psz_new);
972 void Interface::OnHueUpdate( wxScrollEvent& event)
974 config_PutInt( p_intf , "hue" , event.GetPosition() );
977 void Interface::OnSaturationUpdate( wxScrollEvent& event)
979 config_PutFloat( p_intf , "saturation" , (float)event.GetPosition()/100 );
982 void Interface::OnBrightnessUpdate( wxScrollEvent& event)
984 config_PutFloat( p_intf , "brightness", (float)event.GetPosition()/100 );
987 void Interface::OnContrastUpdate(wxScrollEvent& event)
989 config_PutFloat( p_intf , "contrast" , (float)event.GetPosition()/100 );
993 void Interface::OnRatio( wxCommandEvent& event )
995 config_PutPsz( p_intf, "aspect-ratio", ratio_combo->GetValue().mb_str() );
998 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
1000 wxCommandEvent dummy;
1001 playlist_t *p_playlist =
1002 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1004 if( p_playlist == NULL ) return;
1006 if( p_playlist->i_size && p_playlist->i_enabled )
1010 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
1013 if( p_input == NULL )
1015 /* No stream was playing, start one */
1016 playlist_Play( p_playlist );
1017 TogglePlayButton( PLAYING_S );
1018 vlc_object_release( p_playlist );
1022 var_Get( p_input, "state", &state );
1024 if( state.i_int != PAUSE_S )
1026 /* A stream is being played, pause it */
1027 state.i_int = PAUSE_S;
1031 /* Stream is paused, resume it */
1032 state.i_int = PLAYING_S;
1034 var_Set( p_input, "state", state );
1036 TogglePlayButton( state.i_int );
1037 vlc_object_release( p_input );
1038 vlc_object_release( p_playlist );
1042 /* If the playlist is empty, open a file requester instead */
1043 vlc_object_release( p_playlist );
1044 OnShowDialog( dummy );
1048 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
1050 playlist_t * p_playlist =
1051 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1053 if( p_playlist == NULL )
1058 playlist_Stop( p_playlist );
1059 TogglePlayButton( PAUSE_S );
1060 vlc_object_release( p_playlist );
1063 void Interface::OnSliderUpdate( wxScrollEvent& event )
1065 vlc_mutex_lock( &p_intf->change_lock );
1068 if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
1069 || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
1072 if( p_intf->p_sys->i_slider_pos != event.GetPosition()
1073 && p_intf->p_sys->p_input )
1076 pos.f_float = (float)event.GetPosition() / (float)SLIDER_MAX_POS;
1078 var_Set( p_intf->p_sys->p_input, "position", pos );
1082 p_intf->p_sys->b_slider_free = VLC_TRUE;
1086 p_intf->p_sys->b_slider_free = VLC_FALSE;
1088 if( p_intf->p_sys->p_input )
1090 /* Update stream date */
1091 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
1092 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
1094 slider_box->SetLabel(
1095 wxU(input_OffsetToTime( p_intf->p_sys->p_input,
1097 p_area->i_size * event.GetPosition()
1098 / SLIDER_MAX_POS )) );
1104 vlc_mutex_unlock( &p_intf->change_lock );
1107 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
1109 playlist_t * p_playlist =
1110 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1112 if( p_playlist == NULL )
1117 vlc_mutex_lock( &p_playlist->object_lock );
1118 if( p_playlist->p_input != NULL )
1120 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1121 if( p_playlist->p_input->stream.p_selected_area->i_id > 1 )
1123 vlc_value_t val; val.b_bool = VLC_TRUE;
1124 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1125 var_Set( p_playlist->p_input, "prev-title", val );
1126 vlc_mutex_unlock( &p_playlist->object_lock );
1127 vlc_object_release( p_playlist );
1130 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1132 vlc_mutex_unlock( &p_playlist->object_lock );
1134 playlist_Prev( p_playlist );
1135 vlc_object_release( p_playlist );
1138 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1140 playlist_t * p_playlist =
1141 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1143 if( p_playlist == NULL )
1148 vlc_mutex_lock( &p_playlist->object_lock );
1149 if( p_playlist->p_input != NULL )
1151 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1152 if( p_playlist->p_input->stream.i_area_nb > 1 &&
1153 p_playlist->p_input->stream.p_selected_area->i_id <
1154 p_playlist->p_input->stream.i_area_nb - 1 )
1156 vlc_value_t val; val.b_bool = VLC_TRUE;
1157 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1158 var_Set( p_playlist->p_input, "next-title", val );
1159 vlc_mutex_unlock( &p_playlist->object_lock );
1160 vlc_object_release( p_playlist );
1163 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1165 vlc_mutex_unlock( &p_playlist->object_lock );
1167 playlist_Next( p_playlist );
1168 vlc_object_release( p_playlist );
1171 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1173 input_thread_t *p_input =
1174 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1178 vlc_value_t val; val.b_bool = VLC_TRUE;
1180 var_Set( p_input, "rate-slower", val );
1181 vlc_object_release( p_input );
1185 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1187 input_thread_t *p_input =
1188 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1192 vlc_value_t val; val.b_bool = VLC_TRUE;
1194 var_Set( p_input, "rate-faster", val );
1195 vlc_object_release( p_input );
1199 void Interface::TogglePlayButton( int i_playing_status )
1201 if( i_playing_status == i_old_playing_status )
1204 GetToolBar()->DeleteTool( PlayStream_Event );
1206 if( i_playing_status == PLAYING_S )
1208 GetToolBar()->InsertTool( 5, PlayStream_Event, wxU(_("Pause")),
1209 wxBitmap( pause_xpm ), wxNullBitmap,
1210 wxITEM_NORMAL, wxU(_(HELP_PAUSE)) );
1214 GetToolBar()->InsertTool( 5, PlayStream_Event, wxU(_("Play")),
1215 wxBitmap( play_xpm ), wxNullBitmap,
1216 wxITEM_NORMAL, wxU(_(HELP_PLAY)) );
1219 GetToolBar()->Realize();
1221 i_old_playing_status = i_playing_status;
1224 #if !defined(__WXX11__)
1225 /*****************************************************************************
1226 * Definition of DragAndDrop class.
1227 *****************************************************************************/
1228 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf )
1233 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1234 const wxArrayString& filenames )
1236 /* Add dropped files to the playlist */
1238 playlist_t *p_playlist =
1239 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1241 if( p_playlist == NULL )
1246 for( size_t i = 0; i < filenames.GetCount(); i++ )
1247 playlist_Add( p_playlist, (const char *)filenames[i].mb_str(), 0, 0,
1248 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );
1250 vlc_object_release( p_playlist );
1256 /*****************************************************************************
1257 * Definition of wxVolCtrl class.
1258 *****************************************************************************/
1259 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id )
1260 : wxGauge( parent, id, 200, wxDefaultPosition, wxDefaultSize,
1261 wxGA_VERTICAL | wxGA_SMOOTH )
1266 void wxVolCtrl::OnChange( wxMouseEvent& event )
1268 if( !event.LeftDown() && !event.LeftIsDown() ) return;
1270 int i_volume = (GetClientSize().GetHeight() - event.GetY()) * 200 /
1271 GetClientSize().GetHeight();
1275 void wxVolCtrl::Change( int i_volume )
1277 aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 / 2 );
1278 SetValue( i_volume );
1279 SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),