1 /*****************************************************************************
2 * interface.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: interface.cpp,v 1.64 2003/10/08 12:18:50 zorglub 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,
146 /* it is important for the id corresponding to the "About" command to have
147 * this standard value as otherwise it won't be handled properly under Mac
148 * (where it is special and put into the "Apple" menu) */
149 About_Event = wxID_ABOUT
152 BEGIN_EVENT_TABLE(Interface, wxFrame)
154 EVT_MENU(Exit_Event, Interface::OnExit)
155 EVT_MENU(About_Event, Interface::OnAbout)
157 EVT_MENU(Playlist_Event, Interface::OnShowDialog)
158 EVT_MENU(Logs_Event, Interface::OnShowDialog)
159 EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
160 EVT_MENU(Prefs_Event, Interface::OnShowDialog)
162 EVT_MENU_OPEN(Interface::OnMenuOpen)
164 EVT_MENU( Extra_Event, Interface::OnExtra)
165 EVT_CHECKBOX( Adjust_Event, Interface::OnEnableAdjust)
167 EVT_COMBOBOX( Ratio_Event, Interface::OnRatio)
169 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
170 EVT_CONTEXT_MENU(Interface::OnContextMenu2)
172 EVT_RIGHT_UP(Interface::OnContextMenu)
175 EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
176 EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
177 EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
178 EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
179 EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
180 EVT_MENU(StopStream_Event, Interface::OnStopStream)
181 EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
182 EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
183 EVT_MENU(NextStream_Event, Interface::OnNextStream)
184 EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
185 EVT_MENU(FastStream_Event, Interface::OnFastStream)
188 EVT_COMMAND_SCROLL(SliderScroll_Event, Interface::OnSliderUpdate)
190 EVT_COMMAND_SCROLL(Hue_Event, Interface::OnHueUpdate)
191 EVT_COMMAND_SCROLL(Contrast_Event, Interface::OnContrastUpdate)
192 EVT_COMMAND_SCROLL(Brightness_Event, Interface::OnBrightnessUpdate)
193 EVT_COMMAND_SCROLL(Saturation_Event, Interface::OnSaturationUpdate)
197 /*****************************************************************************
199 *****************************************************************************/
200 Interface::Interface( intf_thread_t *_p_intf ):
201 wxFrame( NULL, -1, wxT("VLC media player"),
202 wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE )
204 /* Initializations */
206 i_old_playing_status = PAUSE_S;
209 /* Give our interface a nice little icon */
210 SetIcon( wxIcon( vlc_xpm ) );
212 /* Create a sizer for the main frame */
213 //frame_sizer= new wxFlexGridSizer( 1, 0, 0);
214 frame_sizer = new wxBoxSizer( wxVERTICAL );
215 SetSizer( frame_sizer );
217 /* Create a dummy widget that can get the keyboard focus */
218 wxWindow *p_dummy = new wxWindow( this, 0, wxDefaultPosition,
221 frame_sizer->Add( p_dummy );
223 /* Creation of the menu bar */
226 /* Creation of the tool bar */
229 /* Creation of the slider sub-window */
231 frame_sizer->Add( slider_frame, 0, wxEXPAND , 0 );
232 frame_sizer->Hide( slider_frame );
234 /* Create the extra panel */
235 CreateOurExtraPanel();
236 frame_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
237 frame_sizer->Hide( extra_frame );
239 /* Creation of the status bar
240 * Helptext for menu items and toolbar tools will automatically get
242 int i_status_width[3] = {-6, -2, -9};
243 statusbar = CreateStatusBar( 3 ); /* 2 fields */
244 statusbar->SetStatusWidths( 3, i_status_width );
245 statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
247 /* Make sure we've got the right background colour */
248 SetBackgroundColour( slider_frame->GetBackgroundColour() );
250 /* Layout everything */
251 SetAutoLayout( TRUE );
252 frame_sizer->Layout();
253 frame_sizer->Fit(this);
255 #if !defined(__WXX11__)
256 /* Associate drop targets with the main interface */
257 SetDropTarget( new DragAndDrop( p_intf ) );
260 UpdateAcceleratorTable();
263 Interface::~Interface()
265 if( p_intf->p_sys->p_wxwindow )
267 delete p_intf->p_sys->p_wxwindow;
272 /*****************************************************************************
274 *****************************************************************************/
275 void Interface::CreateOurMenuBar()
277 #define HELP_FILE N_("Open a file")
278 #define HELP_DISC N_("Open a DVD or (S)VCD")
279 #define HELP_NET N_("Open a network stream")
280 #define HELP_SAT N_("Open a satellite stream")
281 #define HELP_EJECT N_("Eject the DVD/CD")
282 #define HELP_EXIT N_("Exit this program")
284 #define HELP_PLAYLIST N_("Open the playlist")
285 #define HELP_LOGS N_("Show the program logs")
286 #define HELP_FILEINFO N_("Show information about the file being played")
288 #define HELP_PREFS N_("Go to the preferences menu")
289 #define EXTRA_PREFS N_("Shows the extended GUI")
291 #define HELP_ABOUT N_("About this program")
293 /* Create the "File" menu */
294 wxMenu *file_menu = new wxMenu;
295 file_menu->Append( OpenFileSimple_Event, wxU(_("Simple &Open ...")),
297 file_menu->Append( OpenFile_Event, wxU(_("Open &File...")),
299 file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...")),
301 file_menu->Append( OpenNet_Event, wxU(_("Open &Network Stream...")),
304 file_menu->Append( OpenSat_Event, wxU(_("Open &Satellite Stream...")),
308 file_menu->AppendSeparator();
309 file_menu->Append( EjectDisc_Event, wxU(_("&Eject Disc")),
310 wxU(_(HELP_EJECT)) );
312 file_menu->AppendSeparator();
313 file_menu->Append( Exit_Event, wxU(_("E&xit")), wxU(_(HELP_EXIT)) );
315 /* Create the "View" menu */
316 wxMenu *view_menu = new wxMenu;
317 view_menu->Append( Playlist_Event, wxU(_("&Playlist...")),
318 wxU(_(HELP_PLAYLIST)) );
319 view_menu->Append( Logs_Event, wxU(_("&Messages...")), wxU(_(HELP_LOGS)) );
320 view_menu->Append( FileInfo_Event, wxU(_("&File info...")),
321 wxU(_(HELP_FILEINFO)) );
323 /* Create the "Settings" menu */
324 wxMenu *settings_menu = new wxMenu;
325 settings_menu->Append( Prefs_Event, wxU(_("&Preferences...")),
326 wxU(_(HELP_PREFS)) );
327 settings_menu->AppendCheckItem( Extra_Event, wxU(_("&Extended GUI") ),
328 wxU(_(EXTRA_PREFS)) );
331 /* Create the "Audio" menu */
332 p_audio_menu = new wxMenu;
335 /* Create the "Video" menu */
336 p_video_menu = new wxMenu;
339 /* Create the "Navigation" menu */
340 p_navig_menu = new wxMenu;
343 /* Create the "Help" menu */
344 wxMenu *help_menu = new wxMenu;
345 help_menu->Append( About_Event, wxU(_("&About...")), wxU(_(HELP_ABOUT)) );
347 /* Append the freshly created menus to the menu bar... */
348 wxMenuBar *menubar = new wxMenuBar( wxMB_DOCKABLE );
349 menubar->Append( file_menu, wxU(_("&File")) );
350 menubar->Append( view_menu, wxU(_("&View")) );
351 menubar->Append( settings_menu, wxU(_("&Settings")) );
352 menubar->Append( p_audio_menu, wxU(_("&Audio")) );
353 menubar->Append( p_video_menu, wxU(_("&Video")) );
354 menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
355 menubar->Append( help_menu, wxU(_("&Help")) );
357 /* Attach the menu bar to the frame */
358 SetMenuBar( menubar );
360 /* Intercept all menu events in our custom event handler */
361 PushEventHandler( new MenuEvtHandler( p_intf, this ) );
363 #if !defined(__WXX11__)
364 /* Associate drop targets with the menubar */
365 menubar->SetDropTarget( new DragAndDrop( p_intf ) );
369 void Interface::CreateOurToolBar()
371 #define HELP_STOP N_("Stop current playlist item")
372 #define HELP_PLAY N_("Play current playlist item")
373 #define HELP_PAUSE N_("Pause current playlist item")
374 #define HELP_PLO N_("Open playlist")
375 #define HELP_PLP N_("Previous playlist item")
376 #define HELP_PLN N_("Next playlist item")
377 #define HELP_SLOW N_("Play slower")
378 #define HELP_FAST N_("Play faster")
380 wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
381 * version because we don't include wx.rc */
383 wxToolBar *toolbar = CreateToolBar(
384 wxTB_HORIZONTAL | wxTB_FLAT | wxTB_DOCKABLE );
386 toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
388 toolbar->AddTool( OpenFile_Event, wxU(_("File")), wxBitmap( file_xpm ),
390 toolbar->AddTool( OpenDisc_Event, wxU(_("Disc")), wxBitmap( disc_xpm ),
392 toolbar->AddTool( OpenNet_Event, wxU(_("Net")), wxBitmap( net_xpm ),
395 toolbar->AddTool( OpenSat_Event, wxU(_("Sat")), wxBitmap( sat_xpm ),
398 toolbar->AddSeparator();
399 toolbar->AddTool( StopStream_Event, wxU(_("Stop")), wxBitmap( stop_xpm ),
401 toolbar->AddTool( PlayStream_Event, wxU(_("Play")), wxBitmap( play_xpm ),
403 toolbar->AddSeparator();
404 toolbar->AddTool( Playlist_Event, wxU(_("Playlist")),
405 wxBitmap( playlist_xpm ), wxU(_(HELP_PLO)) );
406 toolbar->AddTool( PrevStream_Event, wxU(_("Prev")),
407 wxBitmap( previous_xpm ), wxU(_(HELP_PLP)) );
408 toolbar->AddTool( NextStream_Event, wxU(_("Next")), wxBitmap( next_xpm ),
410 toolbar->AddTool( SlowStream_Event, wxU(_("Slower")), wxBitmap( slow_xpm ),
412 toolbar->AddTool( FastStream_Event, wxU(_("Faster")), wxBitmap( fast_xpm ),
417 /* Place the toolbar in a sizer, so we can calculate the width of the
418 * toolbar and set this as the minimum for the main frame size. */
419 wxBoxSizer *toolbar_sizer = new wxBoxSizer( wxHORIZONTAL );
420 toolbar_sizer->Add( toolbar, 0, 0, 0 );
422 toolbar_sizer->Layout();
425 frame_sizer->SetMinSize( toolbar_sizer->GetMinSize().GetWidth(), -1 );
427 frame_sizer->SetMinSize( toolbar->GetToolSize().GetWidth() *
428 toolbar->GetToolsCount(), -1 );
431 #if !defined(__WXX11__)
432 /* Associate drop targets with the toolbar */
433 toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
437 void Interface::CreateOurSlider()
439 /* Create a new frame and sizer containing the slider */
440 slider_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
441 slider_frame->SetAutoLayout( TRUE );
442 wxBoxSizer *frame_sizer =
443 new wxBoxSizer( wxHORIZONTAL );
445 /* Create static box to surround the slider */
446 slider_box = new wxStaticBox( slider_frame, -1, wxT("") );
448 /* Create sizer for slider frame */
449 wxStaticBoxSizer *slider_sizer =
450 new wxStaticBoxSizer( slider_box, wxHORIZONTAL );
451 slider_sizer->SetMinSize( -1, 50 );
454 slider = new wxSlider( slider_frame, SliderScroll_Event, 0, 0,
455 SLIDER_MAX_POS, wxDefaultPosition, wxDefaultSize );
456 slider_sizer->Add( slider, 1, wxEXPAND | wxALL, 5 );
459 volctrl = new wxVolCtrl( p_intf, slider_frame, -1 );
461 /* Add everything to the frame */
462 frame_sizer->Add( slider_sizer, 1, wxEXPAND | wxBOTTOM, 5 );
463 frame_sizer->Add( volctrl, 0, wxEXPAND | wxALL, 5 );
464 slider_frame->SetSizer( frame_sizer );
465 frame_sizer->Layout();
466 frame_sizer->SetSizeHints(slider_frame);
468 /* Hide the slider by default */
469 slider_frame->Hide();
473 void Interface::CreateOurExtraPanel()
477 extra_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
478 extra_frame->SetAutoLayout( TRUE );
479 wxBoxSizer *extra_sizer = new wxBoxSizer( wxHORIZONTAL );
481 /* Create static box to surround the adjust controls */
482 adjust_box = new wxStaticBox( extra_frame, -1, wxU(_("Image adjust")) );
484 /* Create the size for the frame */
485 wxStaticBoxSizer *adjust_sizer =
486 new wxStaticBoxSizer( adjust_box, wxVERTICAL );
487 adjust_sizer->SetMinSize( -1, 50 );
489 /* Create every controls */
491 /* Create the adjust button */
492 wxCheckBox * adjust_check = new wxCheckBox( extra_frame, Adjust_Event,
496 wxBoxSizer *hue_sizer = new wxBoxSizer( wxHORIZONTAL );
497 wxStaticText *hue_text = new wxStaticText( extra_frame, -1,
499 hue_slider = new wxSlider ( extra_frame, Hue_Event, 0, 0,
500 360, wxDefaultPosition, wxDefaultSize );
502 hue_sizer->Add(hue_text,1, 0 ,0);
503 hue_sizer->Add(hue_slider,1, 0 ,0);
506 wxBoxSizer *contrast_sizer = new wxBoxSizer( wxHORIZONTAL );
507 wxStaticText *contrast_text = new wxStaticText( extra_frame, -1,
508 wxU(_("Contrast")) );
509 contrast_slider = new wxSlider ( extra_frame, Contrast_Event, 0, 0,
510 200, wxDefaultPosition, wxDefaultSize);
511 contrast_sizer->Add(contrast_text,1, 0 ,0);
512 contrast_sizer->Add(contrast_slider,1, 0 ,0);
513 contrast_sizer->Layout();
515 wxBoxSizer *brightness_sizer = new wxBoxSizer( wxHORIZONTAL );
516 wxStaticText *brightness_text = new wxStaticText( extra_frame, -1,
517 wxU(_("Brightness")) );
518 brightness_slider = new wxSlider ( extra_frame, Brightness_Event, 0, 0,
519 200, wxDefaultPosition, wxDefaultSize) ;
520 brightness_sizer->Add(brightness_text,1,0,0);
521 brightness_sizer->Add(brightness_slider,1,0,0);
522 brightness_sizer->Layout();
524 wxBoxSizer *saturation_sizer = new wxBoxSizer( wxHORIZONTAL );
525 wxStaticText *saturation_text = new wxStaticText( extra_frame, -1,
526 wxU(_("Saturation")) );
527 saturation_slider = new wxSlider ( extra_frame, Saturation_Event, 0, 0,
528 300, wxDefaultPosition, wxDefaultSize );
529 saturation_sizer->Add(saturation_text,1,0,0);
530 saturation_sizer->Add(saturation_slider,1,0,0);
531 saturation_sizer->Layout();
533 adjust_sizer->Add(adjust_check, 1, wxEXPAND, 0);
534 adjust_sizer->Add(hue_sizer, 1, wxEXPAND, 0);
535 adjust_sizer->Add(contrast_sizer, 1, wxEXPAND, 0);
536 adjust_sizer->Add(brightness_sizer, 1, wxEXPAND, 0);
537 adjust_sizer->Add(saturation_sizer, 1, wxEXPAND, 0);
539 extra_sizer->Add(adjust_sizer,1,wxBOTTOM,5);
542 /* Create static box to surround the other controls */
543 other_box = new wxStaticBox( extra_frame, -1, wxU(_("Video Options")) );
545 /* Create the sizer for the frame */
546 wxStaticBoxSizer *other_sizer =
547 new wxStaticBoxSizer( other_box, wxVERTICAL );
548 other_sizer->SetMinSize( -1, 50 );
550 static const wxString ratio_array[] =
556 wxBoxSizer *ratio_sizer = new wxBoxSizer( wxHORIZONTAL );
557 wxStaticText *ratio_text = new wxStaticText( extra_frame, -1,
560 ratio_combo = new wxComboBox( extra_frame, Ratio_Event, wxT(""),
561 wxDefaultPosition, wxSize(120,-1),
562 WXSIZEOF(ratio_array), ratio_array,
565 ratio_sizer->Add( ratio_text, 0, wxALL, 2 );
566 ratio_sizer->Add( ratio_combo, 0, wxALL, 2 );
567 ratio_sizer->Layout();
569 other_sizer->Add(ratio_sizer,0,wxALL,0 );
571 extra_sizer->Add(other_sizer,0,wxBOTTOM,5);
573 extra_frame->SetSizer( extra_sizer );
575 /* Layout the whole panel */
576 extra_sizer->Layout();
578 extra_sizer->SetSizeHints(extra_frame);
580 /* Write down initial values */
581 psz_filters = config_GetPsz( p_intf, "filter" );
583 if(psz_filters == NULL) psz_filters=strdup("");
585 if( strstr(psz_filters,"adjust") )
587 adjust_check->SetValue( 1 );
588 saturation_slider->Enable();
589 contrast_slider->Enable();
590 brightness_slider->Enable();
591 hue_slider->Enable();
595 adjust_check->SetValue( 0 );
596 saturation_slider->Disable();
597 contrast_slider->Disable();
598 brightness_slider->Disable();
599 hue_slider->Disable();
602 int i_value = config_GetInt( p_intf, "hue" );
603 if( i_value > 0 && i_value < 360 )
604 hue_slider->SetValue( i_value );
607 f_value = config_GetFloat( p_intf, "saturation" );
608 if( f_value > 0 && f_value < 5 )
609 saturation_slider->SetValue( (int)(100 * f_value) );
610 f_value = config_GetFloat( p_intf, "contrast" );
611 if( f_value > 0 && f_value < 4 )
612 contrast_slider->SetValue( (int)(100 * f_value) );
613 f_value = config_GetFloat( p_intf, "brightness" );
614 if( f_value > 0 && f_value < 2 )
615 brightness_slider->SetValue( (int)(100 * f_value) );
621 void Interface::UpdateAcceleratorTable()
623 /* Set some hotkeys */
624 wxAcceleratorEntry entries[7];
625 int i_key = config_GetInt( p_intf, "quit-key" );
627 entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
629 i_key = config_GetInt( p_intf, "stop-key" );
630 entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
632 i_key = config_GetInt( p_intf, "play-pause-key" );
633 entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
635 i_key = config_GetInt( p_intf, "next-key" );
636 entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
638 i_key = config_GetInt( p_intf, "prev-key" );
639 entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
641 i_key = config_GetInt( p_intf, "faster-key" );
642 entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
644 i_key = config_GetInt( p_intf, "slower-key" );
645 entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
648 wxAcceleratorTable accel( 7, entries );
651 msg_Err( p_intf, "invalid accelerator table" );
653 SetAcceleratorTable( accel );
654 msg_Dbg( p_intf, "accelerator table loaded" );
660 /*****************************************************************************
662 *****************************************************************************/
663 /* Work-around helper for buggy wxGTK */
664 void RecursiveDestroy( wxMenu *menu )
666 wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
669 wxMenuItem *item = node->GetData();
670 node = node->GetNext();
672 /* Delete the submenus */
673 wxMenu *submenu = item->GetSubMenu();
676 RecursiveDestroy( submenu );
678 menu->Delete( item );
682 void Interface::OnMenuOpen(wxMenuEvent& event)
684 #if !defined( __WXMSW__ )
685 if( event.GetEventObject() == p_audio_menu )
689 p_audio_menu = AudioMenu( p_intf, this );
691 /* Work-around for buggy wxGTK */
692 wxMenu *menu = GetMenuBar()->GetMenu( 3 );
693 RecursiveDestroy( menu );
694 /* End work-around */
697 GetMenuBar()->Replace( 3, p_audio_menu, wxU(_("&Audio")) );
698 if( menu ) delete menu;
702 else b_audio_menu = 1;
704 else if( event.GetEventObject() == p_video_menu )
708 p_video_menu = VideoMenu( p_intf, this );
710 /* Work-around for buggy wxGTK */
711 wxMenu *menu = GetMenuBar()->GetMenu( 4 );
712 RecursiveDestroy( menu );
713 /* End work-around */
716 GetMenuBar()->Replace( 4, p_video_menu, wxU(_("&Video")) );
717 if( menu ) delete menu;
721 else b_video_menu = 1;
723 else if( event.GetEventObject() == p_navig_menu )
727 p_navig_menu = NavigMenu( p_intf, this );
729 /* Work-around for buggy wxGTK */
730 wxMenu *menu = GetMenuBar()->GetMenu( 5 );
731 RecursiveDestroy( menu );
732 /* End work-around */
735 GetMenuBar()->Replace( 5, p_navig_menu, wxU(_("&Navigation")));
736 if( menu ) delete menu;
740 else b_navig_menu = 1;
744 p_audio_menu = AudioMenu( p_intf, this );
745 wxMenu *menu = GetMenuBar()->Replace( 3, p_audio_menu, wxU(_("&Audio")) );
746 if( menu ) delete menu;
748 p_video_menu = VideoMenu( p_intf, this );
749 menu = GetMenuBar()->Replace( 4, p_video_menu, wxU(_("&Video")) );
750 if( menu ) delete menu;
752 p_navig_menu = NavigMenu( p_intf, this );
753 menu = GetMenuBar()->Replace( 5, p_navig_menu, wxU(_("&Navigation")) );
754 if( menu ) delete menu;
759 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
760 void Interface::OnContextMenu2(wxContextMenuEvent& event)
762 /* Only show the context menu for the main interface */
763 if( GetId() != event.GetId() )
769 if( p_intf->p_sys->pf_show_dialog )
770 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
773 void Interface::OnContextMenu(wxMouseEvent& event)
775 if( p_intf->p_sys->pf_show_dialog )
776 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
779 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
781 /* TRUE is to force the frame to close. */
785 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
788 msg.Printf( wxString(wxT("VLC media player " VERSION)) +
789 wxU(_(" (wxWindows interface)\n\n")) +
790 wxU(_("(C) 1996-2003 - the VideoLAN Team\n\n")) +
791 wxU( INTF_ABOUT_MSG ) + wxT("\n\n") +
792 wxU(_("The VideoLAN team <videolan@videolan.org>\n"
793 "http://www.videolan.org/\n\n")) );
795 wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
796 wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
799 void Interface::OnShowDialog( wxCommandEvent& event )
801 if( p_intf->p_sys->pf_show_dialog )
805 switch( event.GetId() )
807 case OpenFileSimple_Event:
808 i_id = INTF_DIALOG_FILE_SIMPLE;
811 i_id = INTF_DIALOG_FILE;
814 i_id = INTF_DIALOG_DISC;
817 i_id = INTF_DIALOG_NET;
820 i_id = INTF_DIALOG_SAT;
823 i_id = INTF_DIALOG_PLAYLIST;
826 i_id = INTF_DIALOG_MESSAGES;
829 i_id = INTF_DIALOG_FILEINFO;
832 i_id = INTF_DIALOG_PREFS;
835 i_id = INTF_DIALOG_FILE;
840 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
844 void Interface::OnExtra(wxCommandEvent& event)
846 if( b_extra == VLC_FALSE)
849 frame_sizer->Show( extra_frame );
855 frame_sizer->Hide( extra_frame );
858 frame_sizer->Layout();
859 frame_sizer->Fit(this);
862 void Interface::OnEnableAdjust(wxCommandEvent& event)
864 char *psz_filters=config_GetPsz( p_intf, "filter");
865 char *psz_new = NULL;
866 if( event.IsChecked() )
868 if(psz_filters == NULL)
870 psz_new = strdup( "adjust" );
874 psz_new= (char *) malloc(strlen(psz_filters) + 8 );
875 sprintf( psz_new, "%s:adjust", psz_filters);
877 config_PutPsz( p_intf, "filter", psz_new );
879 vout_thread_t *p_vout =
880 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
884 val.psz_string = strdup( psz_new );
885 var_Set( p_vout, "filter", val);
886 vlc_object_release( p_vout );
888 if( val.psz_string ) free( val.psz_string );
889 brightness_slider->Enable();
890 saturation_slider->Enable();
891 contrast_slider->Enable();
892 hue_slider->Enable();
896 if( psz_filters != NULL )
901 for( i = 0; i< strlen(psz_filters ); i++)
903 if ( !strncasecmp( &psz_filters[i],"adjust",6 ))
906 if( psz_filters[i-1] == ':' ) i--;
907 psz_current = strchr( &psz_filters[i+1] , ':' );
909 psz_filters[i] = '\0';
912 memmove( &psz_filters[i] , psz_current,
913 &psz_filters[strlen(psz_filters)]-psz_current
918 config_PutPsz( p_intf, "filter", psz_filters);
920 val.psz_string = strdup( psz_filters );
921 vout_thread_t *p_vout =
922 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
926 var_Set( p_vout, "filter", val);
927 vlc_object_release( p_vout );
929 if( val.psz_string ) free( val.psz_string );
931 brightness_slider->Disable();
932 saturation_slider->Disable();
933 contrast_slider->Disable();
934 hue_slider->Disable();
936 if(psz_filters) free(psz_filters);
937 if(psz_new) free(psz_new);
940 void Interface::OnHueUpdate( wxScrollEvent& event)
942 config_PutInt( p_intf , "hue" , event.GetPosition() );
945 void Interface::OnSaturationUpdate( wxScrollEvent& event)
947 config_PutFloat( p_intf , "saturation" , (float)event.GetPosition()/100 );
950 void Interface::OnBrightnessUpdate( wxScrollEvent& event)
952 config_PutFloat( p_intf , "brightness", (float)event.GetPosition()/100 );
955 void Interface::OnContrastUpdate(wxScrollEvent& event)
957 config_PutFloat( p_intf , "contrast" , (float)event.GetPosition()/100 );
961 void Interface::OnRatio( wxCommandEvent& event )
963 config_PutPsz( p_intf, "aspect-ratio", ratio_combo->GetValue().mb_str() );
966 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
968 wxCommandEvent dummy;
969 playlist_t *p_playlist =
970 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
972 if( p_playlist == NULL ) return;
974 if( p_playlist->i_size && p_playlist->i_enabled )
978 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
981 if( p_input == NULL )
983 /* No stream was playing, start one */
984 playlist_Play( p_playlist );
985 TogglePlayButton( PLAYING_S );
986 vlc_object_release( p_playlist );
990 var_Get( p_input, "state", &state );
992 if( state.i_int != PAUSE_S )
994 /* A stream is being played, pause it */
995 state.i_int = PAUSE_S;
999 /* Stream is paused, resume it */
1000 state.i_int = PLAYING_S;
1002 var_Set( p_input, "state", state );
1004 TogglePlayButton( state.i_int );
1005 vlc_object_release( p_input );
1006 vlc_object_release( p_playlist );
1010 /* If the playlist is empty, open a file requester instead */
1011 vlc_object_release( p_playlist );
1012 OnShowDialog( dummy );
1016 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
1018 playlist_t * p_playlist =
1019 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1021 if( p_playlist == NULL )
1026 playlist_Stop( p_playlist );
1027 TogglePlayButton( PAUSE_S );
1028 vlc_object_release( p_playlist );
1031 void Interface::OnSliderUpdate( wxScrollEvent& event )
1033 vlc_mutex_lock( &p_intf->change_lock );
1036 if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
1037 || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
1040 if( p_intf->p_sys->i_slider_pos != event.GetPosition()
1041 && p_intf->p_sys->p_input )
1044 pos.f_float = (float)event.GetPosition() / (float)SLIDER_MAX_POS;
1046 var_Set( p_intf->p_sys->p_input, "position", pos );
1050 p_intf->p_sys->b_slider_free = VLC_TRUE;
1054 p_intf->p_sys->b_slider_free = VLC_FALSE;
1056 if( p_intf->p_sys->p_input )
1058 /* Update stream date */
1059 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
1060 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
1062 slider_box->SetLabel(
1063 wxU(input_OffsetToTime( p_intf->p_sys->p_input,
1065 p_area->i_size * event.GetPosition()
1066 / SLIDER_MAX_POS )) );
1072 vlc_mutex_unlock( &p_intf->change_lock );
1075 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
1077 playlist_t * p_playlist =
1078 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1080 if( p_playlist == NULL )
1085 vlc_mutex_lock( &p_playlist->object_lock );
1086 if( p_playlist->p_input != NULL )
1088 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1089 if( p_playlist->p_input->stream.p_selected_area->i_id > 1 )
1091 vlc_value_t val; val.b_bool = VLC_TRUE;
1092 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1093 var_Set( p_playlist->p_input, "prev-title", val );
1094 vlc_mutex_unlock( &p_playlist->object_lock );
1095 vlc_object_release( p_playlist );
1098 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1100 vlc_mutex_unlock( &p_playlist->object_lock );
1102 playlist_Prev( p_playlist );
1103 vlc_object_release( p_playlist );
1106 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1108 playlist_t * p_playlist =
1109 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1111 if( p_playlist == NULL )
1116 vlc_mutex_lock( &p_playlist->object_lock );
1117 if( p_playlist->p_input != NULL )
1119 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1120 if( p_playlist->p_input->stream.i_area_nb > 1 &&
1121 p_playlist->p_input->stream.p_selected_area->i_id <
1122 p_playlist->p_input->stream.i_area_nb - 1 )
1124 vlc_value_t val; val.b_bool = VLC_TRUE;
1125 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1126 var_Set( p_playlist->p_input, "next-title", val );
1127 vlc_mutex_unlock( &p_playlist->object_lock );
1128 vlc_object_release( p_playlist );
1131 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1133 vlc_mutex_unlock( &p_playlist->object_lock );
1135 playlist_Next( p_playlist );
1136 vlc_object_release( p_playlist );
1139 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1141 input_thread_t *p_input =
1142 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1146 vlc_value_t val; val.b_bool = VLC_TRUE;
1148 var_Set( p_input, "rate-slower", val );
1149 vlc_object_release( p_input );
1153 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1155 input_thread_t *p_input =
1156 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1160 vlc_value_t val; val.b_bool = VLC_TRUE;
1162 var_Set( p_input, "rate-faster", val );
1163 vlc_object_release( p_input );
1167 void Interface::TogglePlayButton( int i_playing_status )
1169 if( i_playing_status == i_old_playing_status )
1172 GetToolBar()->DeleteTool( PlayStream_Event );
1174 if( i_playing_status == PLAYING_S )
1176 GetToolBar()->InsertTool( 5, PlayStream_Event, wxU(_("Pause")),
1177 wxBitmap( pause_xpm ), wxNullBitmap,
1178 wxITEM_NORMAL, wxU(_(HELP_PAUSE)) );
1182 GetToolBar()->InsertTool( 5, PlayStream_Event, wxU(_("Play")),
1183 wxBitmap( play_xpm ), wxNullBitmap,
1184 wxITEM_NORMAL, wxU(_(HELP_PLAY)) );
1187 GetToolBar()->Realize();
1189 i_old_playing_status = i_playing_status;
1192 #if !defined(__WXX11__)
1193 /*****************************************************************************
1194 * Definition of DragAndDrop class.
1195 *****************************************************************************/
1196 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf )
1201 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1202 const wxArrayString& filenames )
1204 /* Add dropped files to the playlist */
1206 playlist_t *p_playlist =
1207 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1209 if( p_playlist == NULL )
1214 for( size_t i = 0; i < filenames.GetCount(); i++ )
1215 playlist_Add( p_playlist, (const char *)filenames[i].mb_str(), 0, 0,
1216 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );
1218 vlc_object_release( p_playlist );
1224 /*****************************************************************************
1225 * Definition of wxVolCtrl class.
1226 *****************************************************************************/
1227 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id )
1228 : wxGauge( parent, id, 200, wxDefaultPosition, wxDefaultSize,
1229 wxGA_VERTICAL | wxGA_SMOOTH )
1234 void wxVolCtrl::OnChange( wxMouseEvent& event )
1236 if( !event.LeftDown() && !event.LeftIsDown() ) return;
1238 int i_volume = (GetClientSize().GetHeight() - event.GetY()) * 200 /
1239 GetClientSize().GetHeight();
1243 void wxVolCtrl::Change( int i_volume )
1245 aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 );
1246 SetValue( i_volume );
1247 SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),