1 /*****************************************************************************
2 * interface.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: interface.cpp,v 1.61 2003/10/06 16:23:30 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() */
35 #include "stream_control.h"
37 #include "wxwindows.h"
39 /* include the toolbar graphics */
40 #include "bitmaps/file.xpm"
41 #include "bitmaps/disc.xpm"
42 #include "bitmaps/net.xpm"
44 #include "bitmaps/sat.xpm"
46 #include "bitmaps/play.xpm"
47 #include "bitmaps/pause.xpm"
48 #include "bitmaps/stop.xpm"
49 #include "bitmaps/previous.xpm"
50 #include "bitmaps/next.xpm"
51 #include "bitmaps/playlist.xpm"
52 #include "bitmaps/fast.xpm"
53 #include "bitmaps/slow.xpm"
55 #define TOOLBAR_BMP_WIDTH 36
56 #define TOOLBAR_BMP_HEIGHT 36
58 /* include the icon graphic */
59 #include "../../../share/vlc32x32.xpm"
61 /*****************************************************************************
62 * Local class declarations.
63 *****************************************************************************/
64 class wxMenuExt: public wxMenu
68 wxMenuExt( wxMenu* parentMenu, int id, const wxString& text,
69 const wxString& helpString, wxItemKind kind,
70 char *_psz_var, int _i_object_id, vlc_value_t _val,
73 virtual ~wxMenuExt() {};
84 class wxVolCtrl: public wxGauge
88 wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id );
89 virtual ~wxVolCtrl() {};
91 void Change( int i_volume );
93 void OnChange( wxMouseEvent& event );
96 intf_thread_t *p_intf;
98 DECLARE_EVENT_TABLE();
101 BEGIN_EVENT_TABLE(wxVolCtrl, wxWindow)
103 EVT_LEFT_DOWN(wxVolCtrl::OnChange)
104 EVT_MOTION(wxVolCtrl::OnChange)
107 /*****************************************************************************
109 *****************************************************************************/
111 /* IDs for the controls and the menu commands */
115 Exit_Event = wxID_HIGHEST,
116 OpenFileSimple_Event,
145 /* it is important for the id corresponding to the "About" command to have
146 * this standard value as otherwise it won't be handled properly under Mac
147 * (where it is special and put into the "Apple" menu) */
148 About_Event = wxID_ABOUT
151 BEGIN_EVENT_TABLE(Interface, wxFrame)
153 EVT_MENU(Exit_Event, Interface::OnExit)
154 EVT_MENU(About_Event, Interface::OnAbout)
156 EVT_MENU(Playlist_Event, Interface::OnShowDialog)
157 EVT_MENU(Logs_Event, Interface::OnShowDialog)
158 EVT_MENU(FileInfo_Event, Interface::OnShowDialog)
159 EVT_MENU(Prefs_Event, Interface::OnShowDialog)
161 EVT_MENU_OPEN(Interface::OnMenuOpen)
163 EVT_MENU( Extra_Event, Interface::OnExtra)
164 EVT_CHECKBOX( Adjust_Event, Interface::OnEnableAdjust)
166 EVT_COMBOBOX( Ratio_Event, Interface::OnRatio)
168 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
169 EVT_CONTEXT_MENU(Interface::OnContextMenu2)
171 EVT_RIGHT_UP(Interface::OnContextMenu)
174 EVT_MENU(OpenFileSimple_Event, Interface::OnShowDialog)
175 EVT_MENU(OpenFile_Event, Interface::OnShowDialog)
176 EVT_MENU(OpenDisc_Event, Interface::OnShowDialog)
177 EVT_MENU(OpenNet_Event, Interface::OnShowDialog)
178 EVT_MENU(OpenSat_Event, Interface::OnShowDialog)
179 EVT_MENU(StopStream_Event, Interface::OnStopStream)
180 EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
181 EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
182 EVT_MENU(NextStream_Event, Interface::OnNextStream)
183 EVT_MENU(SlowStream_Event, Interface::OnSlowStream)
184 EVT_MENU(FastStream_Event, Interface::OnFastStream)
187 EVT_COMMAND_SCROLL(SliderScroll_Event, Interface::OnSliderUpdate)
189 EVT_COMMAND_SCROLL(Hue_Event, Interface::OnHueUpdate)
190 EVT_COMMAND_SCROLL(Contrast_Event, Interface::OnContrastUpdate)
191 EVT_COMMAND_SCROLL(Brightness_Event, Interface::OnBrightnessUpdate)
192 EVT_COMMAND_SCROLL(Saturation_Event, Interface::OnSaturationUpdate)
196 /*****************************************************************************
198 *****************************************************************************/
199 Interface::Interface( intf_thread_t *_p_intf ):
200 wxFrame( NULL, -1, wxT("VLC media player"),
201 wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE )
203 /* Initializations */
205 i_old_playing_status = PAUSE_S;
208 /* Give our interface a nice little icon */
209 SetIcon( wxIcon( vlc_xpm ) );
211 /* Create a sizer for the main frame */
212 //frame_sizer= new wxFlexGridSizer( 1, 0, 0);
213 frame_sizer = new wxBoxSizer( wxVERTICAL );
214 SetSizer( frame_sizer );
216 /* Create a dummy widget that can get the keyboard focus */
217 wxWindow *p_dummy = new wxWindow( this, 0, wxDefaultPosition,
220 frame_sizer->Add( p_dummy );
222 /* Creation of the menu bar */
225 /* Creation of the tool bar */
228 /* Creation of the slider sub-window */
230 frame_sizer->Add( slider_frame, 0, wxEXPAND , 0 );
231 frame_sizer->Hide( slider_frame );
233 /* Create the extra panel */
234 CreateOurExtraPanel();
235 frame_sizer->Add( extra_frame, 0, wxEXPAND , 0 );
236 frame_sizer->Hide( extra_frame );
238 /* Creation of the status bar
239 * Helptext for menu items and toolbar tools will automatically get
241 int i_status_width[3] = {-6, -2, -9};
242 statusbar = CreateStatusBar( 3 ); /* 2 fields */
243 statusbar->SetStatusWidths( 3, i_status_width );
244 statusbar->SetStatusText( wxString::Format(wxT("x%.2f"), 1.0), 1 );
246 /* Make sure we've got the right background colour */
247 SetBackgroundColour( slider_frame->GetBackgroundColour() );
249 /* Layout everything */
250 SetAutoLayout( TRUE );
251 frame_sizer->Layout();
252 frame_sizer->Fit(this);
254 #if !defined(__WXX11__)
255 /* Associate drop targets with the main interface */
256 SetDropTarget( new DragAndDrop( p_intf ) );
259 UpdateAcceleratorTable();
262 Interface::~Interface()
264 if( p_intf->p_sys->p_wxwindow )
266 delete p_intf->p_sys->p_wxwindow;
271 /*****************************************************************************
273 *****************************************************************************/
274 void Interface::CreateOurMenuBar()
276 #define HELP_FILE N_("Open a file")
277 #define HELP_DISC N_("Open a DVD or (S)VCD")
278 #define HELP_NET N_("Open a network stream")
279 #define HELP_SAT N_("Open a satellite stream")
280 #define HELP_EJECT N_("Eject the DVD/CD")
281 #define HELP_EXIT N_("Exit this program")
283 #define HELP_PLAYLIST N_("Open the playlist")
284 #define HELP_LOGS N_("Show the program logs")
285 #define HELP_FILEINFO N_("Show information about the file being played")
287 #define HELP_PREFS N_("Go to the preferences menu")
288 #define EXTRA_PREFS N_("Open the extended GUI")
290 #define HELP_ABOUT N_("About this program")
292 /* Create the "File" menu */
293 wxMenu *file_menu = new wxMenu;
294 file_menu->Append( OpenFileSimple_Event, wxU(_("Simple &Open ...")),
296 file_menu->Append( OpenFile_Event, wxU(_("Open &File...")),
298 file_menu->Append( OpenDisc_Event, wxU(_("Open &Disc...")),
300 file_menu->Append( OpenNet_Event, wxU(_("Open &Network Stream...")),
303 file_menu->Append( OpenSat_Event, wxU(_("Open &Satellite Stream...")),
307 file_menu->AppendSeparator();
308 file_menu->Append( EjectDisc_Event, wxU(_("&Eject Disc")),
309 wxU(_(HELP_EJECT)) );
311 file_menu->AppendSeparator();
312 file_menu->Append( Exit_Event, wxU(_("E&xit")), wxU(_(HELP_EXIT)) );
314 /* Create the "View" menu */
315 wxMenu *view_menu = new wxMenu;
316 view_menu->Append( Playlist_Event, wxU(_("&Playlist...")),
317 wxU(_(HELP_PLAYLIST)) );
318 view_menu->Append( Logs_Event, wxU(_("&Messages...")), wxU(_(HELP_LOGS)) );
319 view_menu->Append( FileInfo_Event, wxU(_("&File info...")),
320 wxU(_(HELP_FILEINFO)) );
322 /* Create the "Settings" menu */
323 wxMenu *settings_menu = new wxMenu;
324 settings_menu->Append( Prefs_Event, wxU(_("&Preferences...")),
325 wxU(_(HELP_PREFS)) );
326 settings_menu->Append( Extra_Event, wxU(_("&Extra GUI") ),
327 wxU(_(EXTRA_PREFS)) );
330 /* Create the "Audio" menu */
331 p_audio_menu = new wxMenu;
334 /* Create the "Video" menu */
335 p_video_menu = new wxMenu;
338 /* Create the "Navigation" menu */
339 p_navig_menu = new wxMenu;
342 /* Create the "Help" menu */
343 wxMenu *help_menu = new wxMenu;
344 help_menu->Append( About_Event, wxU(_("&About...")), wxU(_(HELP_ABOUT)) );
346 /* Append the freshly created menus to the menu bar... */
347 wxMenuBar *menubar = new wxMenuBar( wxMB_DOCKABLE );
348 menubar->Append( file_menu, wxU(_("&File")) );
349 menubar->Append( view_menu, wxU(_("&View")) );
350 menubar->Append( settings_menu, wxU(_("&Settings")) );
351 menubar->Append( p_audio_menu, wxU(_("&Audio")) );
352 menubar->Append( p_video_menu, wxU(_("&Video")) );
353 menubar->Append( p_navig_menu, wxU(_("&Navigation")) );
354 menubar->Append( help_menu, wxU(_("&Help")) );
356 /* Attach the menu bar to the frame */
357 SetMenuBar( menubar );
359 /* Intercept all menu events in our custom event handler */
360 PushEventHandler( new MenuEvtHandler( p_intf, this ) );
362 #if !defined(__WXX11__)
363 /* Associate drop targets with the menubar */
364 menubar->SetDropTarget( new DragAndDrop( p_intf ) );
368 void Interface::CreateOurToolBar()
370 #define HELP_STOP N_("Stop current playlist item")
371 #define HELP_PLAY N_("Play current playlist item")
372 #define HELP_PAUSE N_("Pause current playlist item")
373 #define HELP_PLO N_("Open playlist")
374 #define HELP_PLP N_("Previous playlist item")
375 #define HELP_PLN N_("Next playlist item")
376 #define HELP_SLOW N_("Play slower")
377 #define HELP_FAST N_("Play faster")
379 wxLogNull LogDummy; /* Hack to suppress annoying log message on the win32
380 * version because we don't include wx.rc */
382 wxToolBar *toolbar = CreateToolBar(
383 wxTB_HORIZONTAL | wxTB_FLAT | wxTB_DOCKABLE );
385 toolbar->SetToolBitmapSize( wxSize(TOOLBAR_BMP_WIDTH,TOOLBAR_BMP_HEIGHT) );
387 toolbar->AddTool( OpenFile_Event, wxU(_("File")), wxBitmap( file_xpm ),
389 toolbar->AddTool( OpenDisc_Event, wxU(_("Disc")), wxBitmap( disc_xpm ),
391 toolbar->AddTool( OpenNet_Event, wxU(_("Net")), wxBitmap( net_xpm ),
394 toolbar->AddTool( OpenSat_Event, wxU(_("Sat")), wxBitmap( sat_xpm ),
397 toolbar->AddSeparator();
398 toolbar->AddTool( StopStream_Event, wxU(_("Stop")), wxBitmap( stop_xpm ),
400 toolbar->AddTool( PlayStream_Event, wxU(_("Play")), wxBitmap( play_xpm ),
402 toolbar->AddSeparator();
403 toolbar->AddTool( Playlist_Event, wxU(_("Playlist")),
404 wxBitmap( playlist_xpm ), wxU(_(HELP_PLO)) );
405 toolbar->AddTool( PrevStream_Event, wxU(_("Prev")),
406 wxBitmap( previous_xpm ), wxU(_(HELP_PLP)) );
407 toolbar->AddTool( NextStream_Event, wxU(_("Next")), wxBitmap( next_xpm ),
409 toolbar->AddTool( SlowStream_Event, wxU(_("Slower")), wxBitmap( slow_xpm ),
411 toolbar->AddTool( FastStream_Event, wxU(_("Faster")), wxBitmap( fast_xpm ),
416 /* Place the toolbar in a sizer, so we can calculate the width of the
417 * toolbar and set this as the minimum for the main frame size. */
418 wxBoxSizer *toolbar_sizer = new wxBoxSizer( wxHORIZONTAL );
419 toolbar_sizer->Add( toolbar, 0, 0, 0 );
421 toolbar_sizer->Layout();
424 frame_sizer->SetMinSize( toolbar_sizer->GetMinSize().GetWidth(), -1 );
426 frame_sizer->SetMinSize( toolbar->GetToolSize().GetWidth() *
427 toolbar->GetToolsCount(), -1 );
430 #if !defined(__WXX11__)
431 /* Associate drop targets with the toolbar */
432 toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
436 void Interface::CreateOurSlider()
438 /* Create a new frame and sizer containing the slider */
439 slider_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
440 slider_frame->SetAutoLayout( TRUE );
441 wxBoxSizer *frame_sizer =
442 new wxBoxSizer( wxHORIZONTAL );
444 /* Create static box to surround the slider */
445 slider_box = new wxStaticBox( slider_frame, -1, wxT("") );
447 /* Create sizer for slider frame */
448 wxStaticBoxSizer *slider_sizer =
449 new wxStaticBoxSizer( slider_box, wxHORIZONTAL );
450 slider_sizer->SetMinSize( -1, 50 );
453 slider = new wxSlider( slider_frame, SliderScroll_Event, 0, 0,
454 SLIDER_MAX_POS, wxDefaultPosition, wxDefaultSize );
455 slider_sizer->Add( slider, 1, wxEXPAND | wxALL, 5 );
458 volctrl = new wxVolCtrl( p_intf, slider_frame, -1 );
460 /* Add everything to the frame */
461 frame_sizer->Add( slider_sizer, 1, wxEXPAND | wxBOTTOM, 5 );
462 frame_sizer->Add( volctrl, 0, wxEXPAND | wxALL, 5 );
463 slider_frame->SetSizer( frame_sizer );
464 frame_sizer->Layout();
465 frame_sizer->SetSizeHints(slider_frame);
467 /* Hide the slider by default */
468 slider_frame->Hide();
472 void Interface::CreateOurExtraPanel()
476 extra_frame = new wxPanel( this, -1, wxDefaultPosition, wxDefaultSize );
477 extra_frame->SetAutoLayout( TRUE );
478 wxBoxSizer *extra_sizer = new wxBoxSizer( wxHORIZONTAL );
480 /* Create static box to surround the adjust controls */
481 adjust_box = new wxStaticBox( extra_frame, -1,
482 wxT(_("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,
544 wxT(_("Video Options")) );
546 /* Create the sizer for the frame */
547 wxStaticBoxSizer *other_sizer =
548 new wxStaticBoxSizer( other_box, wxVERTICAL );
549 other_sizer->SetMinSize( -1, 50 );
551 static const wxString ratio_array[] =
557 wxBoxSizer *ratio_sizer = new wxBoxSizer( wxHORIZONTAL );
558 wxStaticText *ratio_text = new wxStaticText( extra_frame, -1,
561 ratio_combo = new wxComboBox( extra_frame, Ratio_Event, wxT(""),
562 wxDefaultPosition, wxSize(120,-1),
563 WXSIZEOF(ratio_array), ratio_array,
566 ratio_sizer->Add( ratio_text, 0, wxALL, 2 );
567 ratio_sizer->Add( ratio_combo, 0, wxALL, 2 );
568 ratio_sizer->Layout();
570 other_sizer->Add(ratio_sizer,0,wxALL,0 );
572 extra_sizer->Add(other_sizer,0,wxBOTTOM,5);
574 extra_frame->SetSizer( extra_sizer );
576 /* Layout the whole panel */
577 extra_sizer->Layout();
579 extra_sizer->SetSizeHints(extra_frame);
581 /* Write down initial values */
582 psz_filters = config_GetPsz( p_intf, "filter" );
584 if(psz_filters == NULL) psz_filters=strdup("");
586 if( strstr(psz_filters,"adjust") )
588 adjust_check->SetValue( 1 );
589 saturation_slider->Enable();
590 contrast_slider->Enable();
591 brightness_slider->Enable();
592 hue_slider->Enable();
596 adjust_check->SetValue( 0 );
597 saturation_slider->Disable();
598 contrast_slider->Disable();
599 brightness_slider->Disable();
600 hue_slider->Disable();
607 void Interface::UpdateAcceleratorTable()
609 /* Set some hotkeys */
610 wxAcceleratorEntry entries[7];
611 int i_key = config_GetInt( p_intf, "quit-key" );
613 entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
615 i_key = config_GetInt( p_intf, "stop-key" );
616 entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
618 i_key = config_GetInt( p_intf, "play-pause-key" );
619 entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
621 i_key = config_GetInt( p_intf, "next-key" );
622 entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
624 i_key = config_GetInt( p_intf, "prev-key" );
625 entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
627 i_key = config_GetInt( p_intf, "faster-key" );
628 entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
630 i_key = config_GetInt( p_intf, "slower-key" );
631 entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ),
634 wxAcceleratorTable accel( 7, entries );
637 msg_Err( p_intf, "invalid accelerator table" );
639 SetAcceleratorTable( accel );
640 msg_Dbg( p_intf, "accelerator table loaded" );
646 /*****************************************************************************
648 *****************************************************************************/
649 /* Work-around helper for buggy wxGTK */
650 void RecursiveDestroy( wxMenu *menu )
652 wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
655 wxMenuItem *item = node->GetData();
656 node = node->GetNext();
658 /* Delete the submenus */
659 wxMenu *submenu = item->GetSubMenu();
662 RecursiveDestroy( submenu );
664 menu->Delete( item );
668 void Interface::OnMenuOpen(wxMenuEvent& event)
670 #if !defined( __WXMSW__ )
671 if( event.GetEventObject() == p_audio_menu )
675 p_audio_menu = AudioMenu( p_intf, this );
677 /* Work-around for buggy wxGTK */
678 wxMenu *menu = GetMenuBar()->GetMenu( 3 );
679 RecursiveDestroy( menu );
680 /* End work-around */
683 GetMenuBar()->Replace( 3, p_audio_menu, wxU(_("&Audio")) );
684 if( menu ) delete menu;
688 else b_audio_menu = 1;
690 else if( event.GetEventObject() == p_video_menu )
694 p_video_menu = VideoMenu( p_intf, this );
696 /* Work-around for buggy wxGTK */
697 wxMenu *menu = GetMenuBar()->GetMenu( 4 );
698 RecursiveDestroy( menu );
699 /* End work-around */
702 GetMenuBar()->Replace( 4, p_video_menu, wxU(_("&Video")) );
703 if( menu ) delete menu;
707 else b_video_menu = 1;
709 else if( event.GetEventObject() == p_navig_menu )
713 p_navig_menu = NavigMenu( p_intf, this );
715 /* Work-around for buggy wxGTK */
716 wxMenu *menu = GetMenuBar()->GetMenu( 5 );
717 RecursiveDestroy( menu );
718 /* End work-around */
721 GetMenuBar()->Replace( 5, p_navig_menu, wxU(_("&Navigation")));
722 if( menu ) delete menu;
726 else b_navig_menu = 1;
730 p_audio_menu = AudioMenu( p_intf, this );
731 wxMenu *menu = GetMenuBar()->Replace( 3, p_audio_menu, wxU(_("&Audio")) );
732 if( menu ) delete menu;
734 p_video_menu = VideoMenu( p_intf, this );
735 menu = GetMenuBar()->Replace( 4, p_video_menu, wxU(_("&Video")) );
736 if( menu ) delete menu;
738 p_navig_menu = NavigMenu( p_intf, this );
739 menu = GetMenuBar()->Replace( 5, p_navig_menu, wxU(_("&Navigation")) );
740 if( menu ) delete menu;
745 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
746 void Interface::OnContextMenu2(wxContextMenuEvent& event)
748 /* Only show the context menu for the main interface */
749 if( GetId() != event.GetId() )
755 if( p_intf->p_sys->pf_show_dialog )
756 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
759 void Interface::OnContextMenu(wxMouseEvent& event)
761 if( p_intf->p_sys->pf_show_dialog )
762 p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU, 1, 0 );
765 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
767 /* TRUE is to force the frame to close. */
771 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
774 msg.Printf( wxString(wxT("VLC media player " VERSION)) +
775 wxU(_(" (wxWindows interface)\n\n")) +
776 wxU(_("(C) 1996-2003 - the VideoLAN Team\n\n")) +
777 wxU( INTF_ABOUT_MSG ) + wxT("\n\n") +
778 wxU(_("The VideoLAN team <videolan@videolan.org>\n"
779 "http://www.videolan.org/\n\n")) );
781 wxMessageBox( msg, wxString::Format(wxU(_("About %s")),
782 wxT("VLC media player")), wxOK | wxICON_INFORMATION, this );
785 void Interface::OnShowDialog( wxCommandEvent& event )
787 if( p_intf->p_sys->pf_show_dialog )
791 switch( event.GetId() )
793 case OpenFileSimple_Event:
794 i_id = INTF_DIALOG_FILE_SIMPLE;
797 i_id = INTF_DIALOG_FILE;
800 i_id = INTF_DIALOG_DISC;
803 i_id = INTF_DIALOG_NET;
806 i_id = INTF_DIALOG_SAT;
809 i_id = INTF_DIALOG_PLAYLIST;
812 i_id = INTF_DIALOG_MESSAGES;
815 i_id = INTF_DIALOG_FILEINFO;
818 i_id = INTF_DIALOG_PREFS;
821 i_id = INTF_DIALOG_FILE;
826 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
830 void Interface::OnExtra(wxCommandEvent& event)
832 if( b_extra == VLC_FALSE)
835 frame_sizer->Show( extra_frame );
841 frame_sizer->Hide( extra_frame );
844 frame_sizer->Layout();
845 frame_sizer->Fit(this);
848 void Interface::OnEnableAdjust(wxCommandEvent& event)
850 char *psz_filters=config_GetPsz( p_intf, "filter");
851 char *psz_new = NULL;
852 if( event.IsChecked() )
854 if(psz_filters == NULL)
856 psz_new = strdup( "adjust" );
860 psz_new= (char *) malloc(strlen(psz_filters) + 8 );
861 sprintf( psz_new, "%s:adjust", psz_filters);
863 config_PutPsz( p_intf, "filter", psz_new );
865 brightness_slider->Enable();
866 saturation_slider->Enable();
867 contrast_slider->Enable();
868 hue_slider->Enable();
872 if( psz_filters != NULL )
877 for( i = 0; i< strlen(psz_filters ); i++)
879 if ( !strncasecmp( &psz_filters[i],"adjust",6 ))
882 if( psz_filters[i-1] == ':' ) i--;
883 psz_current = strchr( &psz_filters[i+1] , ':' );
885 psz_filters[i] = '\0';
888 memmove( &psz_filters[i] , psz_current,
889 &psz_filters[strlen(psz_filters)]-psz_current
894 config_PutPsz( p_intf, "filter", psz_filters);
896 brightness_slider->Disable();
897 saturation_slider->Disable();
898 contrast_slider->Disable();
899 hue_slider->Disable();
901 if(psz_filters) free(psz_filters);
902 if(psz_new) free(psz_new);
905 void Interface::OnHueUpdate( wxScrollEvent& event)
907 config_PutInt( p_intf , "hue" , event.GetPosition() );
910 void Interface::OnSaturationUpdate( wxScrollEvent& event)
912 config_PutFloat( p_intf , "saturation" , (float)event.GetPosition()/300 );
915 void Interface::OnBrightnessUpdate( wxScrollEvent& event)
917 config_PutFloat( p_intf , "brightness", (float)event.GetPosition()/200 );
920 void Interface::OnContrastUpdate(wxScrollEvent& event)
922 config_PutFloat( p_intf , "contrast" , (float)event.GetPosition()/200 );
926 void Interface::OnRatio( wxCommandEvent& event )
928 config_PutPsz( p_intf, "aspect-ratio", ratio_combo->GetValue() );
932 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
934 wxCommandEvent dummy;
935 playlist_t *p_playlist =
936 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
938 if( p_playlist == NULL ) return;
940 if( p_playlist->i_size && p_playlist->i_enabled )
944 input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
947 if( p_input == NULL )
949 /* No stream was playing, start one */
950 playlist_Play( p_playlist );
951 TogglePlayButton( PLAYING_S );
952 vlc_object_release( p_playlist );
956 var_Get( p_input, "state", &state );
958 if( state.i_int != PAUSE_S )
960 /* A stream is being played, pause it */
961 state.i_int = PAUSE_S;
965 /* Stream is paused, resume it */
966 state.i_int = PLAYING_S;
968 var_Set( p_input, "state", state );
970 TogglePlayButton( state.i_int );
971 vlc_object_release( p_input );
972 vlc_object_release( p_playlist );
976 /* If the playlist is empty, open a file requester instead */
977 vlc_object_release( p_playlist );
978 OnShowDialog( dummy );
982 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
984 playlist_t * p_playlist =
985 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
987 if( p_playlist == NULL )
992 playlist_Stop( p_playlist );
993 TogglePlayButton( PAUSE_S );
994 vlc_object_release( p_playlist );
997 void Interface::OnSliderUpdate( wxScrollEvent& event )
999 vlc_mutex_lock( &p_intf->change_lock );
1002 if( event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
1003 || event.GetEventType() == wxEVT_SCROLL_ENDSCROLL )
1006 if( p_intf->p_sys->i_slider_pos != event.GetPosition()
1007 && p_intf->p_sys->p_input )
1010 pos.f_float = (float)event.GetPosition() / (float)SLIDER_MAX_POS;
1012 var_Set( p_intf->p_sys->p_input, "position", pos );
1016 p_intf->p_sys->b_slider_free = VLC_TRUE;
1020 p_intf->p_sys->b_slider_free = VLC_FALSE;
1022 if( p_intf->p_sys->p_input )
1024 /* Update stream date */
1025 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
1026 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
1028 slider_box->SetLabel(
1029 wxU(input_OffsetToTime( p_intf->p_sys->p_input,
1031 p_area->i_size * event.GetPosition()
1032 / SLIDER_MAX_POS )) );
1038 vlc_mutex_unlock( &p_intf->change_lock );
1041 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
1043 playlist_t * p_playlist =
1044 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1046 if( p_playlist == NULL )
1051 vlc_mutex_lock( &p_playlist->object_lock );
1052 if( p_playlist->p_input != NULL )
1054 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1055 if( p_playlist->p_input->stream.p_selected_area->i_id > 1 )
1057 vlc_value_t val; val.b_bool = VLC_TRUE;
1058 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1059 var_Set( p_playlist->p_input, "prev-title", val );
1060 vlc_mutex_unlock( &p_playlist->object_lock );
1061 vlc_object_release( p_playlist );
1064 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1066 vlc_mutex_unlock( &p_playlist->object_lock );
1068 playlist_Prev( p_playlist );
1069 vlc_object_release( p_playlist );
1072 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
1074 playlist_t * p_playlist =
1075 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1077 if( p_playlist == NULL )
1082 vlc_mutex_lock( &p_playlist->object_lock );
1083 if( p_playlist->p_input != NULL )
1085 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1086 if( p_playlist->p_input->stream.i_area_nb > 1 &&
1087 p_playlist->p_input->stream.p_selected_area->i_id <
1088 p_playlist->p_input->stream.i_area_nb - 1 )
1090 vlc_value_t val; val.b_bool = VLC_TRUE;
1091 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1092 var_Set( p_playlist->p_input, "next-title", val );
1093 vlc_mutex_unlock( &p_playlist->object_lock );
1094 vlc_object_release( p_playlist );
1097 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1099 vlc_mutex_unlock( &p_playlist->object_lock );
1101 playlist_Next( p_playlist );
1102 vlc_object_release( p_playlist );
1105 void Interface::OnSlowStream( wxCommandEvent& WXUNUSED(event) )
1107 input_thread_t *p_input =
1108 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1112 vlc_value_t val; val.b_bool = VLC_TRUE;
1114 var_Set( p_input, "rate-slower", val );
1115 vlc_object_release( p_input );
1119 void Interface::OnFastStream( wxCommandEvent& WXUNUSED(event) )
1121 input_thread_t *p_input =
1122 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
1126 vlc_value_t val; val.b_bool = VLC_TRUE;
1128 var_Set( p_input, "rate-faster", val );
1129 vlc_object_release( p_input );
1133 void Interface::TogglePlayButton( int i_playing_status )
1135 if( i_playing_status == i_old_playing_status )
1138 GetToolBar()->DeleteTool( PlayStream_Event );
1140 if( i_playing_status == PLAYING_S )
1142 GetToolBar()->InsertTool( 5, PlayStream_Event, wxU(_("Pause")),
1143 wxBitmap( pause_xpm ), wxNullBitmap,
1144 wxITEM_NORMAL, wxU(_(HELP_PAUSE)) );
1148 GetToolBar()->InsertTool( 5, PlayStream_Event, wxU(_("Play")),
1149 wxBitmap( play_xpm ), wxNullBitmap,
1150 wxITEM_NORMAL, wxU(_(HELP_PLAY)) );
1153 GetToolBar()->Realize();
1155 i_old_playing_status = i_playing_status;
1158 #if !defined(__WXX11__)
1159 /*****************************************************************************
1160 * Definition of DragAndDrop class.
1161 *****************************************************************************/
1162 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf )
1167 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
1168 const wxArrayString& filenames )
1170 /* Add dropped files to the playlist */
1172 playlist_t *p_playlist =
1173 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1175 if( p_playlist == NULL )
1180 for( size_t i = 0; i < filenames.GetCount(); i++ )
1181 playlist_Add( p_playlist, (const char *)filenames[i].mb_str(), 0, 0,
1182 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );
1184 vlc_object_release( p_playlist );
1190 /*****************************************************************************
1191 * Definition of wxVolCtrl class.
1192 *****************************************************************************/
1193 wxVolCtrl::wxVolCtrl( intf_thread_t *_p_intf, wxWindow* parent, wxWindowID id )
1194 : wxGauge( parent, id, 200, wxDefaultPosition, wxDefaultSize,
1195 wxGA_VERTICAL | wxGA_SMOOTH )
1200 void wxVolCtrl::OnChange( wxMouseEvent& event )
1202 if( !event.LeftDown() && !event.LeftIsDown() ) return;
1204 int i_volume = (GetClientSize().GetHeight() - event.GetY()) * 200 /
1205 GetClientSize().GetHeight();
1209 void wxVolCtrl::Change( int i_volume )
1211 aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_MAX / 200 );
1212 SetValue( i_volume );
1213 SetToolTip( wxString::Format((wxString)wxU(_("Volume")) + wxT(" %d"),