1 /*****************************************************************************
2 * menus.cpp : wxWidgets plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
25 #include <vlc_interface.h>
27 #include "wxwidgets.hpp"
28 #include "interface.hpp"
30 #include <wx/dynarray.h>
31 WX_DEFINE_ARRAY(int, ArrayOfInts);
32 WX_DEFINE_ARRAY_PTR(const char *, ArrayOfStrings);
35 class wxMenuItemExt: public wxMenuItem
39 wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
40 const wxString& helpString, wxItemKind kind,
41 char *_psz_var, int _i_object_id, vlc_value_t _val,
43 virtual ~wxMenuItemExt();
51 class Menu: public wxMenu
55 Menu( intf_thread_t *p_intf, int i_start_id );
58 void Populate( ArrayOfStrings &, ArrayOfInts &);
62 wxMenu *CreateDummyMenu();
63 void CreateMenuItem( wxMenu *, const char *, vlc_object_t * );
64 wxMenu *CreateChoicesMenu( const char *, vlc_object_t *, bool );
66 DECLARE_EVENT_TABLE();
68 intf_thread_t *p_intf;
74 /*****************************************************************************
76 *****************************************************************************/
80 MenuDummy_Event = wxID_HIGHEST + 1000,
81 OpenFileSimple_Event = wxID_HIGHEST + 1100,
95 FirstAutoGenerated_Event = wxID_HIGHEST + 1999,
96 SettingsMenu_Events = wxID_HIGHEST + 5000,
97 AudioMenu_Events = wxID_HIGHEST + 2000,
98 VideoMenu_Events = wxID_HIGHEST + 3000,
99 NavigMenu_Events = wxID_HIGHEST + 4000,
100 PopupMenu_Events = wxID_HIGHEST + 6000,
101 Hotkeys_Events = wxID_HIGHEST + 7000
104 BEGIN_EVENT_TABLE(Menu, wxMenu)
107 BEGIN_EVENT_TABLE(MenuEvtHandler, wxEvtHandler)
108 EVT_MENU(OpenFileSimple_Event, MenuEvtHandler::OnShowDialog)
109 EVT_MENU(OpenFile_Event, MenuEvtHandler::OnShowDialog)
110 EVT_MENU(OpenDirectory_Event, MenuEvtHandler::OnShowDialog)
111 EVT_MENU(OpenDisc_Event, MenuEvtHandler::OnShowDialog)
112 EVT_MENU(OpenNet_Event, MenuEvtHandler::OnShowDialog)
113 EVT_MENU(OpenCapture_Event, MenuEvtHandler::OnShowDialog)
114 EVT_MENU(MediaInfo_Event, MenuEvtHandler::OnShowDialog)
115 EVT_MENU(Messages_Event, MenuEvtHandler::OnShowDialog)
116 EVT_MENU(Preferences_Event, MenuEvtHandler::OnShowDialog)
117 EVT_MENU(-1, MenuEvtHandler::OnMenuEvent)
120 /*****************************************************************************
121 * Static menu helpers
122 *****************************************************************************/
123 wxMenu *OpenStreamMenu( intf_thread_t *p_intf )
125 wxMenu *menu = new wxMenu;
126 menu->Append( OpenFileSimple_Event, wxU(_("Quick &Open File...")) );
127 menu->Append( OpenFile_Event, wxU(_("Open &File...")) );
128 menu->Append( OpenDirectory_Event, wxU(_("Open D&irectory...")) );
129 menu->Append( OpenDisc_Event, wxU(_("Open &Disc...")) );
130 menu->Append( OpenNet_Event, wxU(_("Open &Network Stream...")) );
131 menu->Append( OpenCapture_Event, wxU(_("Open &Capture Device...")) );
135 wxMenu *MiscMenu( intf_thread_t *p_intf )
137 wxMenu *menu = new wxMenu;
138 menu->Append( MediaInfo_Event, wxU(_("Media &Info...")) );
139 menu->Append( Messages_Event, wxU(_("&Messages...")) );
140 menu->Append( Preferences_Event, wxU(_("&Preferences...")) );
144 /*****************************************************************************
145 * Builders for the dynamic menus
146 *****************************************************************************/
147 #define PUSH_VAR( var ) rs_varnames.Add( var ); \
148 ri_objects.Add( p_object->i_object_id )
150 int InputAutoMenuBuilder( vlc_object_t *p_object, ArrayOfInts &ri_objects,
151 ArrayOfStrings &rs_varnames )
153 PUSH_VAR( "bookmark");
155 PUSH_VAR ("chapter" );
156 PUSH_VAR( "program" );
157 PUSH_VAR( "navigation" );
158 PUSH_VAR( "dvd_menus" );
162 int VideoAutoMenuBuilder( vlc_object_t *p_object, ArrayOfInts &ri_objects,
163 ArrayOfStrings &rs_varnames )
165 PUSH_VAR( "fullscreen" );
167 PUSH_VAR( "deinterlace" );
168 PUSH_VAR( "aspect-ratio" );
170 PUSH_VAR( "video-on-top" );
171 PUSH_VAR( "directx-wallpaper" );
172 PUSH_VAR( "video-snapshot" );
174 vlc_object_t *p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
177 if( p_dec_obj != NULL )
179 vlc_object_t *p_object = p_dec_obj;
180 PUSH_VAR( "ffmpeg-pp-q" );
181 vlc_object_release( p_dec_obj );
186 int AudioAutoMenuBuilder( vlc_object_t *p_object, ArrayOfInts &ri_objects,
187 ArrayOfStrings &rs_varnames )
189 PUSH_VAR( "audio-device" );
190 PUSH_VAR( "audio-channels" );
191 PUSH_VAR( "visual" );
192 PUSH_VAR( "equalizer" );
196 int IntfAutoMenuBuilder( intf_thread_t *p_intf, ArrayOfInts &ri_objects,
197 ArrayOfStrings &rs_varnames, bool is_popup)
199 /* vlc_object_find is needed because of the dialogs provider case */
200 vlc_object_t *p_object;
201 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INTF,
203 if( p_object != NULL )
208 PUSH_VAR( "intf-switch" );
213 PUSH_VAR( "intf-switch" );
215 PUSH_VAR( "intf-add" );
216 PUSH_VAR( "intf-skins" );
217 vlc_object_release( p_object );
223 /*****************************************************************************
225 *****************************************************************************/
226 #define PUSH_VAR( var ) as_varnames.Add( var ); \
227 ai_objects.Add( p_object->i_object_id )
229 #define PUSH_SEPARATOR if( ai_objects.GetCount() != i_last_separator ) { \
230 ai_objects.Add( 0 ); \
231 as_varnames.Add( "" ); \
232 i_last_separator = ai_objects.GetCount(); }
234 #define POPUP_BOILERPLATE \
235 unsigned int i_last_separator = 0; \
236 ArrayOfInts ai_objects; \
237 ArrayOfStrings as_varnames; \
238 playlist_t *p_playlist = (playlist_t *) vlc_object_find( p_intf, \
239 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );\
242 input_thread_t *p_input = p_playlist->p_input
244 #define CREATE_POPUP \
245 Menu popupmenu( p_intf, PopupMenu_Events ); \
246 popupmenu.Populate( as_varnames, ai_objects ); \
247 p_intf->p_sys->p_popup_menu = &popupmenu; \
248 p_parent->PopupMenu( &popupmenu, pos.x, pos.y ); \
249 p_intf->p_sys->p_popup_menu = NULL; \
250 i_last_separator = 0 /* stop compiler warning */
252 #define POPUP_STATIC_ENTRIES \
253 if( p_input != NULL ) \
256 popupmenu.InsertSeparator( 0 ); \
259 popupmenu.Insert( 0, Stop_Event, wxU(_("Stop")) ); \
260 popupmenu.Insert( 0, Previous_Event, wxU(_("Previous")) ); \
261 popupmenu.Insert( 0, Next_Event, wxU(_("Next")) ); \
264 var_Get( p_input, "state", &val ); \
265 if( val.i_int == PAUSE_S ) \
266 popupmenu.Insert( 0, Play_Event, wxU(_("Play")) ); \
268 popupmenu.Insert( 0, Pause_Event, wxU(_("Pause")) ); \
270 vlc_object_release( p_input ); \
274 if( p_playlist && !playlist_IsEmpty( p_playlist ) ) \
276 popupmenu.InsertSeparator( 0 ); \
277 popupmenu.Insert( 0, Play_Event, wxU(_("Play")) ); \
279 if( p_playlist ) vlc_object_release( p_playlist ); \
282 popupmenu.Append( MenuDummy_Event, wxU(_("Miscellaneous")), \
283 MiscMenu( p_intf ), wxT("") )
286 void VideoPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
292 vlc_object_yield( p_input );
293 as_varnames.Add( "video-es" );
294 ai_objects.Add( p_input->i_object_id );
295 as_varnames.Add( "spu-es" );
296 ai_objects.Add( p_input->i_object_id );
297 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
298 VLC_OBJECT_VOUT, FIND_CHILD );
301 VideoAutoMenuBuilder( p_vout, ai_objects, as_varnames );
302 vlc_object_release( p_vout );
304 vlc_object_release( p_input );
306 vlc_object_release( p_playlist );
310 void AudioPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
316 vlc_object_yield( p_input );
317 as_varnames.Add( "audio-es" );
318 ai_objects.Add( p_input->i_object_id );
319 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
320 VLC_OBJECT_AOUT, FIND_ANYWHERE );
323 AudioAutoMenuBuilder( p_aout, ai_objects, as_varnames );
324 vlc_object_release( p_aout );
326 vlc_object_release( p_input );
328 vlc_object_release( p_playlist );
332 /* Navigation stuff, and general */
333 void MiscPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
340 vlc_object_yield( p_input );
341 as_varnames.Add( "audio-es" );
342 InputAutoMenuBuilder( VLC_OBJECT(p_input), ai_objects, as_varnames );
345 IntfAutoMenuBuilder( p_intf, ai_objects, as_varnames, true );
347 Menu popupmenu( p_intf, PopupMenu_Events );
348 popupmenu.Populate( as_varnames, ai_objects );
350 POPUP_STATIC_ENTRIES;
351 popupmenu.Append( MenuDummy_Event, wxU(_("Open")),
352 OpenStreamMenu( p_intf ), wxT("") );
354 p_intf->p_sys->p_popup_menu = &popupmenu;
355 p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
356 p_intf->p_sys->p_popup_menu = NULL;
357 vlc_object_release( p_playlist );
360 void PopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
363 int minimal = config_GetInt( p_intf, "wx-minimal" );
367 vlc_object_yield( p_input );
368 InputAutoMenuBuilder( VLC_OBJECT(p_input), ai_objects, as_varnames );
372 as_varnames.Add( "video-es" );
373 ai_objects.Add( p_input->i_object_id );
374 as_varnames.Add( "spu-es" );
375 ai_objects.Add( p_input->i_object_id );
376 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
377 VLC_OBJECT_VOUT, FIND_CHILD );
380 VideoAutoMenuBuilder( p_vout, ai_objects, as_varnames );
381 vlc_object_release( p_vout );
385 as_varnames.Add( "audio-es" );
386 ai_objects.Add( p_input->i_object_id );
387 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
388 VLC_OBJECT_AOUT, FIND_ANYWHERE );
391 AudioAutoMenuBuilder( p_aout, ai_objects, as_varnames );
392 vlc_object_release( p_aout );
398 IntfAutoMenuBuilder( p_intf, ai_objects, as_varnames, true );
401 Menu popupmenu( p_intf, PopupMenu_Events );
402 popupmenu.Populate( as_varnames, ai_objects );
403 POPUP_STATIC_ENTRIES;
407 popupmenu.Append( MenuDummy_Event, wxU(_("Open")),
408 OpenStreamMenu( p_intf ), wxT("") );
410 p_intf->p_sys->p_popup_menu = &popupmenu;
411 p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
412 p_intf->p_sys->p_popup_menu = NULL;
413 vlc_object_release( p_playlist );
416 /*****************************************************************************
418 *****************************************************************************/
419 wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
421 vlc_object_t *p_object;
422 ArrayOfInts ai_objects;
423 ArrayOfStrings as_varnames;
425 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
427 if( p_object != NULL )
429 PUSH_VAR( "audio-es" );
430 vlc_object_release( p_object );
433 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_AOUT,
437 AudioAutoMenuBuilder( p_object, ai_objects, as_varnames );
438 vlc_object_release( p_object );
442 Menu *p_vlc_menu = (Menu *)p_menu;
444 p_vlc_menu = new Menu( _p_intf, AudioMenu_Events );
448 p_vlc_menu->Populate( as_varnames, ai_objects );
453 wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
455 vlc_object_t *p_object;
456 ArrayOfInts ai_objects;
457 ArrayOfStrings as_varnames;
459 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
461 if( p_object != NULL )
463 PUSH_VAR( "video-es" );
464 PUSH_VAR( "spu-es" );
465 vlc_object_release( p_object );
468 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_VOUT,
470 if( p_object != NULL )
472 VideoAutoMenuBuilder( p_object, ai_objects, as_varnames );
473 vlc_object_release( p_object );
477 Menu *p_vlc_menu = (Menu *)p_menu;
479 p_vlc_menu = new Menu( _p_intf, VideoMenu_Events );
483 p_vlc_menu->Populate( as_varnames, ai_objects );
487 wxMenu *NavigMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
489 vlc_object_t *p_object;
490 ArrayOfInts ai_objects;
491 ArrayOfStrings as_varnames;
493 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
495 if( p_object != NULL )
497 InputAutoMenuBuilder( p_object, ai_objects, as_varnames );
498 PUSH_VAR( "prev-title"); PUSH_VAR ( "next-title" );
499 PUSH_VAR( "prev-chapter"); PUSH_VAR( "next-chapter" );
500 vlc_object_release( p_object );
504 Menu *p_vlc_menu = (Menu *)p_menu;
506 p_vlc_menu = new Menu( _p_intf, NavigMenu_Events );
510 p_vlc_menu->Populate( as_varnames, ai_objects );
515 wxMenu *SettingsMenu( intf_thread_t *_p_intf, wxWindow *p_parent,
518 vlc_object_t *p_object;
519 ArrayOfInts ai_objects;
520 ArrayOfStrings as_varnames;
522 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INTF,
524 if( p_object != NULL )
526 PUSH_VAR( "intf-switch" );
527 PUSH_VAR( "intf-add" );
528 vlc_object_release( p_object );
532 Menu *p_vlc_menu = (Menu *)p_menu;
534 p_vlc_menu = new Menu( _p_intf, SettingsMenu_Events );
538 p_vlc_menu->Populate( as_varnames, ai_objects );
543 /*****************************************************************************
545 *****************************************************************************/
546 Menu::Menu( intf_thread_t *_p_intf, int _i_start_id ) : wxMenu( )
548 /* Initializations */
550 i_start_id = _i_start_id;
557 /*****************************************************************************
559 *****************************************************************************/
560 void Menu::Populate( ArrayOfStrings & ras_varnames,
561 ArrayOfInts & rai_objects )
563 vlc_object_t *p_object;
564 vlc_bool_t b_section_empty = VLC_FALSE;
567 i_item_id = i_start_id;
569 for( i = 0; i < (int)rai_objects.GetCount() ; i++ )
571 if( !ras_varnames[i] || !*ras_varnames[i] )
573 if( b_section_empty )
575 Append( MenuDummy_Event + i, wxU(_("Empty")) );
576 Enable( MenuDummy_Event + i, FALSE );
579 b_section_empty = VLC_TRUE;
583 if( rai_objects[i] == 0 )
585 Append( MenuDummy_Event, wxU(ras_varnames[i]) );
586 b_section_empty = VLC_FALSE;
590 p_object = (vlc_object_t *)vlc_object_get( p_intf,
592 if( p_object == NULL ) continue;
594 b_section_empty = VLC_FALSE;
595 CreateMenuItem( this, ras_varnames[i], p_object );
596 vlc_object_release( p_object );
599 /* Special case for empty menus */
600 if( GetMenuItemCount() == 0 || b_section_empty )
602 Append( MenuDummy_Event + i, wxU(_("Empty")) );
603 Enable( MenuDummy_Event + i, FALSE );
607 /* Work-around helper for buggy wxGTK */
608 static void RecursiveDestroy( wxMenu *menu )
610 wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
613 wxMenuItem *item = node->GetData();
614 node = node->GetNext();
616 /* Delete the submenus */
617 wxMenu *submenu = item->GetSubMenu();
620 RecursiveDestroy( submenu );
622 menu->Delete( item );
628 RecursiveDestroy( this );
631 /*****************************************************************************
633 *****************************************************************************/
634 static bool IsMenuEmpty( const char *psz_var, vlc_object_t *p_object,
637 vlc_value_t val, val_list;
638 int i_type, i_result, i;
640 /* Check the type of the object variable */
641 i_type = var_Type( p_object, psz_var );
643 /* Check if we want to display the variable */
644 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
646 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
647 if( val.i_int == 0 ) return TRUE;
649 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
651 /* Very evil hack ! intf-switch can have only one value */
652 if( !strcmp( psz_var, "intf-switch" ) ) return FALSE;
653 if( val.i_int == 1 && b_root ) return TRUE;
657 /* Check children variables in case of VLC_VAR_VARIABLE */
658 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
663 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
665 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
673 /* clean up everything */
674 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
679 void Menu::CreateMenuItem( wxMenu *menu, const char *psz_var,
680 vlc_object_t *p_object )
682 wxMenuItemExt *menuitem;
683 vlc_value_t val, text;
686 /* Check the type of the object variable */
687 i_type = var_Type( p_object, psz_var );
689 switch( i_type & VLC_VAR_TYPE )
693 case VLC_VAR_VARIABLE:
695 case VLC_VAR_INTEGER:
699 /* Variable doesn't exist or isn't handled */
703 /* Make sure we want to display the variable */
704 if( IsMenuEmpty( psz_var, p_object ) ) return;
706 /* Get the descriptive name of the variable */
707 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
709 if( i_type & VLC_VAR_HASCHOICE )
711 menu->Append( MenuDummy_Event,
712 wxU(text.psz_string ? text.psz_string : psz_var),
713 CreateChoicesMenu( psz_var, p_object, TRUE ),
714 wxT("")/* Nothing for now (maybe use a GETLONGTEXT) */ );
716 if( text.psz_string ) free( text.psz_string );
721 switch( i_type & VLC_VAR_TYPE )
724 var_Get( p_object, psz_var, &val );
725 menuitem = new wxMenuItemExt( menu, ++i_item_id,
726 wxU(text.psz_string ?
727 text.psz_string : psz_var),
728 wxT(""), wxITEM_NORMAL, strdup(psz_var),
729 p_object->i_object_id, val, i_type );
730 menu->Append( menuitem );
734 var_Get( p_object, psz_var, &val );
735 val.b_bool = !val.b_bool;
736 menuitem = new wxMenuItemExt( menu, ++i_item_id,
737 wxU(text.psz_string ?
738 text.psz_string : psz_var),
739 wxT(""), wxITEM_CHECK, strdup(psz_var),
740 p_object->i_object_id, val, i_type );
741 menu->Append( menuitem );
742 Check( i_item_id, val.b_bool ? FALSE : TRUE );
746 if( text.psz_string ) free( text.psz_string );
749 wxMenu *Menu::CreateChoicesMenu( const char *psz_var, vlc_object_t *p_object,
752 vlc_value_t val, val_list, text_list;
755 /* Check the type of the object variable */
756 i_type = var_Type( p_object, psz_var );
758 /* Make sure we want to display the variable */
759 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return NULL;
761 switch( i_type & VLC_VAR_TYPE )
765 case VLC_VAR_VARIABLE:
767 case VLC_VAR_INTEGER:
771 /* Variable doesn't exist or isn't handled */
775 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
776 &val_list, &text_list ) < 0 )
781 wxMenu *menu = new wxMenu;
782 for( i = 0; i < val_list.p_list->i_count; i++ )
784 vlc_value_t another_val;
785 wxMenuItemExt *menuitem;
787 switch( i_type & VLC_VAR_TYPE )
789 case VLC_VAR_VARIABLE:
790 menu->Append( MenuDummy_Event,
791 wxU(text_list.p_list->p_values[i].psz_string ?
792 text_list.p_list->p_values[i].psz_string :
793 val_list.p_list->p_values[i].psz_string),
795 val_list.p_list->p_values[i].psz_string,
796 p_object, FALSE ), wxT("") );
800 var_Get( p_object, psz_var, &val );
802 another_val.psz_string =
803 strdup(val_list.p_list->p_values[i].psz_string);
805 new wxMenuItemExt( menu, ++i_item_id,
806 wxU(text_list.p_list->p_values[i].psz_string ?
807 text_list.p_list->p_values[i].psz_string :
808 another_val.psz_string), wxT(""),
809 i_type & VLC_VAR_ISCOMMAND ?
810 wxITEM_NORMAL : wxITEM_RADIO,
812 p_object->i_object_id, another_val, i_type );
814 menu->Append( menuitem );
816 if( !(i_type & VLC_VAR_ISCOMMAND) && val.psz_string &&
817 !strcmp( val.psz_string,
818 val_list.p_list->p_values[i].psz_string ) )
819 menu->Check( i_item_id, TRUE );
821 if( val.psz_string ) free( val.psz_string );
824 case VLC_VAR_INTEGER:
825 var_Get( p_object, psz_var, &val );
828 new wxMenuItemExt( menu, ++i_item_id,
829 text_list.p_list->p_values[i].psz_string ?
831 text_list.p_list->p_values[i].psz_string) :
832 wxString::Format(wxT("%d"),
833 val_list.p_list->p_values[i].i_int), wxT(""),
834 i_type & VLC_VAR_ISCOMMAND ?
835 wxITEM_NORMAL : wxITEM_RADIO,
837 p_object->i_object_id,
838 val_list.p_list->p_values[i], i_type );
840 menu->Append( menuitem );
842 if( !(i_type & VLC_VAR_ISCOMMAND) &&
843 val_list.p_list->p_values[i].i_int == val.i_int )
844 menu->Check( i_item_id, TRUE );
848 var_Get( p_object, psz_var, &val );
851 new wxMenuItemExt( menu, ++i_item_id,
852 text_list.p_list->p_values[i].psz_string ?
854 text_list.p_list->p_values[i].psz_string) :
855 wxString::Format(wxT("%.2f"),
856 val_list.p_list->p_values[i].f_float),wxT(""),
857 i_type & VLC_VAR_ISCOMMAND ?
858 wxITEM_NORMAL : wxITEM_RADIO,
860 p_object->i_object_id,
861 val_list.p_list->p_values[i], i_type );
863 menu->Append( menuitem );
865 if( !(i_type & VLC_VAR_ISCOMMAND) &&
866 val_list.p_list->p_values[i].f_float == val.f_float )
867 menu->Check( i_item_id, TRUE );
875 /* clean up everything */
876 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
881 /*****************************************************************************
882 * A small helper class which intercepts all popup menu events
883 *****************************************************************************/
884 MenuEvtHandler::MenuEvtHandler( intf_thread_t *_p_intf,
885 Interface *_p_main_interface )
887 /* Initializations */
889 p_main_interface = _p_main_interface;
892 MenuEvtHandler::~MenuEvtHandler()
896 void MenuEvtHandler::OnShowDialog( wxCommandEvent& event )
898 if( p_intf->p_sys->pf_show_dialog )
902 switch( event.GetId() )
904 case OpenFileSimple_Event:
905 i_id = INTF_DIALOG_FILE_SIMPLE;
908 i_id = INTF_DIALOG_FILE;
910 case OpenDirectory_Event:
911 i_id = INTF_DIALOG_DIRECTORY;
914 i_id = INTF_DIALOG_DISC;
917 i_id = INTF_DIALOG_NET;
919 case OpenCapture_Event:
920 i_id = INTF_DIALOG_CAPTURE;
922 case MediaInfo_Event:
923 i_id = INTF_DIALOG_FILEINFO;
926 i_id = INTF_DIALOG_MESSAGES;
928 case Preferences_Event:
929 i_id = INTF_DIALOG_PREFS;
932 i_id = INTF_DIALOG_FILE;
937 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
941 void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
943 wxMenuItem *p_menuitem = NULL;
944 int i_hotkey_event = p_intf->p_sys->i_first_hotkey_event;
945 int i_hotkeys = p_intf->p_sys->i_hotkeys;
947 if( event.GetId() >= Play_Event && event.GetId() <= Stop_Event )
949 input_thread_t *p_input;
950 playlist_t * p_playlist =
951 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
953 if( !p_playlist ) return;
955 switch( event.GetId() )
960 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
962 if( !p_input ) playlist_Play( p_playlist );
966 var_Get( p_input, "state", &val );
967 if( val.i_int != PAUSE_S ) val.i_int = PAUSE_S;
968 else val.i_int = PLAYING_S;
969 var_Set( p_input, "state", val );
970 vlc_object_release( p_input );
974 playlist_Stop( p_playlist );
977 playlist_Prev( p_playlist );
980 playlist_Next( p_playlist );
984 vlc_object_release( p_playlist );
988 /* Check if this is an auto generated menu item */
989 if( event.GetId() < FirstAutoGenerated_Event )
995 /* Check if this is an hotkey event */
996 if( event.GetId() >= i_hotkey_event &&
997 event.GetId() < i_hotkey_event + i_hotkeys )
1002 p_intf->p_libvlc->p_hotkeys[event.GetId() - i_hotkey_event].i_key;
1004 /* Get the key combination and send it to the hotkey handler */
1005 var_Set( p_intf->p_libvlc, "key-pressed", val );
1009 if( !p_main_interface ||
1010 (p_menuitem = p_main_interface->GetMenuBar()->FindItem(event.GetId()))
1013 if( p_intf->p_sys->p_popup_menu )
1016 p_intf->p_sys->p_popup_menu->FindItem( event.GetId() );
1022 wxMenuItemExt *p_menuitemext = (wxMenuItemExt *)p_menuitem;
1023 vlc_object_t *p_object;
1025 p_object = (vlc_object_t *)vlc_object_get( p_intf,
1026 p_menuitemext->i_object_id );
1027 if( p_object == NULL ) return;
1029 wxMutexGuiLeave(); // We don't want deadlocks
1030 var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val );
1031 //wxMutexGuiEnter();
1033 vlc_object_release( p_object );
1039 /*****************************************************************************
1040 * A small helper class which encapsulate wxMenuitem with some other useful
1042 *****************************************************************************/
1043 wxMenuItemExt::wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
1044 const wxString& helpString, wxItemKind kind,
1045 char *_psz_var, int _i_object_id, vlc_value_t _val, int _i_val_type ):
1046 wxMenuItem( parentMenu, id, text, helpString, kind )
1048 /* Initializations */
1050 i_val_type = _i_val_type;
1051 i_object_id = _i_object_id;
1055 wxMenuItemExt::~wxMenuItemExt()
1057 if( psz_var ) free( psz_var );
1058 if( ((i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
1059 && val.psz_string ) free( val.psz_string );