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 *****************************************************************************/
29 #include <vlc_interface.h>
31 #include "wxwidgets.hpp"
32 #include "interface.hpp"
34 #include <wx/dynarray.h>
35 WX_DEFINE_ARRAY(int, ArrayOfInts);
36 WX_DEFINE_ARRAY_PTR(const char *, ArrayOfStrings);
39 class wxMenuItemExt: public wxMenuItem
43 wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
44 const wxString& helpString, wxItemKind kind,
45 char *_psz_var, int _i_object_id, vlc_value_t _val,
47 virtual ~wxMenuItemExt();
55 class Menu: public wxMenu
59 Menu( intf_thread_t *p_intf, int i_start_id );
62 void Populate( ArrayOfStrings &, ArrayOfInts &);
66 wxMenu *CreateDummyMenu();
67 void CreateMenuItem( wxMenu *, const char *, vlc_object_t * );
68 wxMenu *CreateChoicesMenu( const char *, vlc_object_t *, bool );
70 DECLARE_EVENT_TABLE();
72 intf_thread_t *p_intf;
78 /*****************************************************************************
80 *****************************************************************************/
84 MenuDummy_Event = wxID_HIGHEST + 1000,
85 OpenFileSimple_Event = wxID_HIGHEST + 1100,
99 FirstAutoGenerated_Event = wxID_HIGHEST + 1999,
100 SettingsMenu_Events = wxID_HIGHEST + 5000,
101 AudioMenu_Events = wxID_HIGHEST + 2000,
102 VideoMenu_Events = wxID_HIGHEST + 3000,
103 NavigMenu_Events = wxID_HIGHEST + 4000,
104 PopupMenu_Events = wxID_HIGHEST + 6000,
105 Hotkeys_Events = wxID_HIGHEST + 7000
108 BEGIN_EVENT_TABLE(Menu, wxMenu)
111 BEGIN_EVENT_TABLE(MenuEvtHandler, wxEvtHandler)
112 EVT_MENU(OpenFileSimple_Event, MenuEvtHandler::OnShowDialog)
113 EVT_MENU(OpenFile_Event, MenuEvtHandler::OnShowDialog)
114 EVT_MENU(OpenDirectory_Event, MenuEvtHandler::OnShowDialog)
115 EVT_MENU(OpenDisc_Event, MenuEvtHandler::OnShowDialog)
116 EVT_MENU(OpenNet_Event, MenuEvtHandler::OnShowDialog)
117 EVT_MENU(OpenCapture_Event, MenuEvtHandler::OnShowDialog)
118 EVT_MENU(MediaInfo_Event, MenuEvtHandler::OnShowDialog)
119 EVT_MENU(Messages_Event, MenuEvtHandler::OnShowDialog)
120 EVT_MENU(Preferences_Event, MenuEvtHandler::OnShowDialog)
121 EVT_MENU(-1, MenuEvtHandler::OnMenuEvent)
124 /*****************************************************************************
125 * Static menu helpers
126 *****************************************************************************/
127 wxMenu *OpenStreamMenu( intf_thread_t *p_intf )
129 wxMenu *menu = new wxMenu;
130 menu->Append( OpenFileSimple_Event, wxU(_("Quick &Open File...")) );
131 menu->Append( OpenFile_Event, wxU(_("Open &File...")) );
132 menu->Append( OpenDirectory_Event, wxU(_("Open D&irectory...")) );
133 menu->Append( OpenDisc_Event, wxU(_("Open &Disc...")) );
134 menu->Append( OpenNet_Event, wxU(_("Open &Network Stream...")) );
135 menu->Append( OpenCapture_Event, wxU(_("Open &Capture Device...")) );
139 wxMenu *MiscMenu( intf_thread_t *p_intf )
141 wxMenu *menu = new wxMenu;
142 menu->Append( MediaInfo_Event, wxU(_("Media &Info...")) );
143 menu->Append( Messages_Event, wxU(_("&Messages...")) );
144 menu->Append( Preferences_Event, wxU(_("&Preferences...")) );
148 /*****************************************************************************
149 * Builders for the dynamic menus
150 *****************************************************************************/
151 #define PUSH_VAR( var ) rs_varnames.Add( var ); \
152 ri_objects.Add( p_object->i_object_id )
154 int InputAutoMenuBuilder( vlc_object_t *p_object, ArrayOfInts &ri_objects,
155 ArrayOfStrings &rs_varnames )
157 PUSH_VAR( "bookmark");
159 PUSH_VAR ("chapter" );
160 PUSH_VAR( "program" );
161 PUSH_VAR( "navigation" );
162 PUSH_VAR( "dvd_menus" );
166 int VideoAutoMenuBuilder( vlc_object_t *p_object, ArrayOfInts &ri_objects,
167 ArrayOfStrings &rs_varnames )
169 PUSH_VAR( "fullscreen" );
171 PUSH_VAR( "deinterlace" );
172 PUSH_VAR( "aspect-ratio" );
174 PUSH_VAR( "video-on-top" );
175 PUSH_VAR( "directx-wallpaper" );
176 PUSH_VAR( "video-snapshot" );
178 vlc_object_t *p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
181 if( p_dec_obj != NULL )
183 vlc_object_t *p_object = p_dec_obj;
184 PUSH_VAR( "ffmpeg-pp-q" );
185 vlc_object_release( p_dec_obj );
190 int AudioAutoMenuBuilder( vlc_object_t *p_object, ArrayOfInts &ri_objects,
191 ArrayOfStrings &rs_varnames )
193 PUSH_VAR( "audio-device" );
194 PUSH_VAR( "audio-channels" );
195 PUSH_VAR( "visual" );
196 PUSH_VAR( "equalizer" );
200 int IntfAutoMenuBuilder( intf_thread_t *p_intf, ArrayOfInts &ri_objects,
201 ArrayOfStrings &rs_varnames, bool is_popup)
203 /* vlc_object_find is needed because of the dialogs provider case */
204 vlc_object_t *p_object;
205 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INTF,
207 if( p_object != NULL )
209 PUSH_VAR( "intf-add" );
210 PUSH_VAR( "intf-skins" );
211 vlc_object_release( p_object );
217 /*****************************************************************************
219 *****************************************************************************/
220 #define PUSH_VAR( var ) as_varnames.Add( var ); \
221 ai_objects.Add( p_object->i_object_id )
223 #define PUSH_SEPARATOR if( ai_objects.GetCount() != i_last_separator ) { \
224 ai_objects.Add( 0 ); \
225 as_varnames.Add( "" ); \
226 i_last_separator = ai_objects.GetCount(); }
228 #define POPUP_BOILERPLATE \
229 unsigned int i_last_separator = 0; \
230 ArrayOfInts ai_objects; \
231 ArrayOfStrings as_varnames; \
232 playlist_t *p_playlist = (playlist_t *) vlc_object_find( p_intf, \
233 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );\
236 input_thread_t *p_input = p_playlist->p_input
238 #define CREATE_POPUP \
239 Menu popupmenu( p_intf, PopupMenu_Events ); \
240 popupmenu.Populate( as_varnames, ai_objects ); \
241 p_intf->p_sys->p_popup_menu = &popupmenu; \
242 p_parent->PopupMenu( &popupmenu, pos.x, pos.y ); \
243 p_intf->p_sys->p_popup_menu = NULL; \
244 i_last_separator = 0 /* stop compiler warning */
246 #define POPUP_STATIC_ENTRIES \
247 if( p_input != NULL ) \
250 popupmenu.InsertSeparator( 0 ); \
253 popupmenu.Insert( 0, Stop_Event, wxU(_("Stop")) ); \
254 popupmenu.Insert( 0, Previous_Event, wxU(_("Previous")) ); \
255 popupmenu.Insert( 0, Next_Event, wxU(_("Next")) ); \
258 var_Get( p_input, "state", &val ); \
259 if( val.i_int == PAUSE_S ) \
260 popupmenu.Insert( 0, Play_Event, wxU(_("Play")) ); \
262 popupmenu.Insert( 0, Pause_Event, wxU(_("Pause")) ); \
264 vlc_object_release( p_input ); \
268 if( p_playlist && !playlist_IsEmpty( p_playlist ) ) \
270 popupmenu.InsertSeparator( 0 ); \
271 popupmenu.Insert( 0, Play_Event, wxU(_("Play")) ); \
273 if( p_playlist ) vlc_object_release( p_playlist ); \
276 popupmenu.Append( MenuDummy_Event, wxU(_("Miscellaneous")), \
277 MiscMenu( p_intf ), wxT("") )
280 void VideoPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
286 vlc_object_yield( p_input );
287 as_varnames.Add( "video-es" );
288 ai_objects.Add( p_input->i_object_id );
289 as_varnames.Add( "spu-es" );
290 ai_objects.Add( p_input->i_object_id );
291 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
292 VLC_OBJECT_VOUT, FIND_CHILD );
295 VideoAutoMenuBuilder( p_vout, ai_objects, as_varnames );
296 vlc_object_release( p_vout );
298 vlc_object_release( p_input );
300 vlc_object_release( p_playlist );
304 void AudioPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
310 vlc_object_yield( p_input );
311 as_varnames.Add( "audio-es" );
312 ai_objects.Add( p_input->i_object_id );
313 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
314 VLC_OBJECT_AOUT, FIND_ANYWHERE );
317 AudioAutoMenuBuilder( p_aout, ai_objects, as_varnames );
318 vlc_object_release( p_aout );
320 vlc_object_release( p_input );
322 vlc_object_release( p_playlist );
326 /* Navigation stuff, and general */
327 void MiscPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
334 vlc_object_yield( p_input );
335 as_varnames.Add( "audio-es" );
336 InputAutoMenuBuilder( VLC_OBJECT(p_input), ai_objects, as_varnames );
339 IntfAutoMenuBuilder( p_intf, ai_objects, as_varnames, true );
341 Menu popupmenu( p_intf, PopupMenu_Events );
342 popupmenu.Populate( as_varnames, ai_objects );
344 POPUP_STATIC_ENTRIES;
345 popupmenu.Append( MenuDummy_Event, wxU(_("Open")),
346 OpenStreamMenu( p_intf ), wxT("") );
348 p_intf->p_sys->p_popup_menu = &popupmenu;
349 p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
350 p_intf->p_sys->p_popup_menu = NULL;
351 vlc_object_release( p_playlist );
354 void PopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
357 int minimal = config_GetInt( p_intf, "wx-minimal" );
361 vlc_object_yield( p_input );
362 InputAutoMenuBuilder( VLC_OBJECT(p_input), ai_objects, as_varnames );
366 as_varnames.Add( "video-es" );
367 ai_objects.Add( p_input->i_object_id );
368 as_varnames.Add( "spu-es" );
369 ai_objects.Add( p_input->i_object_id );
370 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
371 VLC_OBJECT_VOUT, FIND_CHILD );
374 VideoAutoMenuBuilder( p_vout, ai_objects, as_varnames );
375 vlc_object_release( p_vout );
379 as_varnames.Add( "audio-es" );
380 ai_objects.Add( p_input->i_object_id );
381 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
382 VLC_OBJECT_AOUT, FIND_ANYWHERE );
385 AudioAutoMenuBuilder( p_aout, ai_objects, as_varnames );
386 vlc_object_release( p_aout );
392 IntfAutoMenuBuilder( p_intf, ai_objects, as_varnames, true );
395 Menu popupmenu( p_intf, PopupMenu_Events );
396 popupmenu.Populate( as_varnames, ai_objects );
397 POPUP_STATIC_ENTRIES;
401 popupmenu.Append( MenuDummy_Event, wxU(_("Open")),
402 OpenStreamMenu( p_intf ), wxT("") );
404 p_intf->p_sys->p_popup_menu = &popupmenu;
405 p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
406 p_intf->p_sys->p_popup_menu = NULL;
407 vlc_object_release( p_playlist );
410 /*****************************************************************************
412 *****************************************************************************/
413 wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
415 vlc_object_t *p_object;
416 ArrayOfInts ai_objects;
417 ArrayOfStrings as_varnames;
419 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
421 if( p_object != NULL )
423 PUSH_VAR( "audio-es" );
424 vlc_object_release( p_object );
427 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_AOUT,
431 AudioAutoMenuBuilder( p_object, ai_objects, as_varnames );
432 vlc_object_release( p_object );
436 Menu *p_vlc_menu = (Menu *)p_menu;
438 p_vlc_menu = new Menu( _p_intf, AudioMenu_Events );
442 p_vlc_menu->Populate( as_varnames, ai_objects );
447 wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
449 vlc_object_t *p_object;
450 ArrayOfInts ai_objects;
451 ArrayOfStrings as_varnames;
453 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
455 if( p_object != NULL )
457 PUSH_VAR( "video-es" );
458 PUSH_VAR( "spu-es" );
459 vlc_object_release( p_object );
462 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_VOUT,
464 if( p_object != NULL )
466 VideoAutoMenuBuilder( p_object, ai_objects, as_varnames );
467 vlc_object_release( p_object );
471 Menu *p_vlc_menu = (Menu *)p_menu;
473 p_vlc_menu = new Menu( _p_intf, VideoMenu_Events );
477 p_vlc_menu->Populate( as_varnames, ai_objects );
481 wxMenu *NavigMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
483 vlc_object_t *p_object;
484 ArrayOfInts ai_objects;
485 ArrayOfStrings as_varnames;
487 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
489 if( p_object != NULL )
491 InputAutoMenuBuilder( p_object, ai_objects, as_varnames );
492 PUSH_VAR( "prev-title"); PUSH_VAR ( "next-title" );
493 PUSH_VAR( "prev-chapter"); PUSH_VAR( "next-chapter" );
494 vlc_object_release( p_object );
498 Menu *p_vlc_menu = (Menu *)p_menu;
500 p_vlc_menu = new Menu( _p_intf, NavigMenu_Events );
504 p_vlc_menu->Populate( as_varnames, ai_objects );
509 wxMenu *SettingsMenu( intf_thread_t *_p_intf, wxWindow *p_parent,
512 vlc_object_t *p_object;
513 ArrayOfInts ai_objects;
514 ArrayOfStrings as_varnames;
516 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INTF,
518 if( p_object != NULL )
520 PUSH_VAR( "intf-add" );
521 vlc_object_release( p_object );
525 Menu *p_vlc_menu = (Menu *)p_menu;
527 p_vlc_menu = new Menu( _p_intf, SettingsMenu_Events );
531 p_vlc_menu->Populate( as_varnames, ai_objects );
536 /*****************************************************************************
538 *****************************************************************************/
539 Menu::Menu( intf_thread_t *_p_intf, int _i_start_id ) : wxMenu( )
541 /* Initializations */
543 i_start_id = _i_start_id;
550 /*****************************************************************************
552 *****************************************************************************/
553 void Menu::Populate( ArrayOfStrings & ras_varnames,
554 ArrayOfInts & rai_objects )
556 vlc_object_t *p_object;
557 vlc_bool_t b_section_empty = VLC_FALSE;
560 i_item_id = i_start_id;
562 for( i = 0; i < (int)rai_objects.GetCount() ; i++ )
564 if( !ras_varnames[i] || !*ras_varnames[i] )
566 if( b_section_empty )
568 Append( MenuDummy_Event + i, wxU(_("Empty")) );
569 Enable( MenuDummy_Event + i, FALSE );
572 b_section_empty = VLC_TRUE;
576 if( rai_objects[i] == 0 )
578 Append( MenuDummy_Event, wxU(ras_varnames[i]) );
579 b_section_empty = VLC_FALSE;
583 p_object = (vlc_object_t *)vlc_object_get( rai_objects[i] );
584 if( p_object == NULL ) continue;
586 b_section_empty = VLC_FALSE;
587 CreateMenuItem( this, ras_varnames[i], p_object );
588 vlc_object_release( p_object );
591 /* Special case for empty menus */
592 if( GetMenuItemCount() == 0 || b_section_empty )
594 Append( MenuDummy_Event + i, wxU(_("Empty")) );
595 Enable( MenuDummy_Event + i, FALSE );
599 /* Work-around helper for buggy wxGTK */
600 static void RecursiveDestroy( wxMenu *menu )
602 wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
605 wxMenuItem *item = node->GetData();
606 node = node->GetNext();
608 /* Delete the submenus */
609 wxMenu *submenu = item->GetSubMenu();
612 RecursiveDestroy( submenu );
614 menu->Delete( item );
620 RecursiveDestroy( this );
623 /*****************************************************************************
625 *****************************************************************************/
626 static bool IsMenuEmpty( const char *psz_var, vlc_object_t *p_object,
629 vlc_value_t val, val_list;
630 int i_type, i_result, i;
632 /* Check the type of the object variable */
633 i_type = var_Type( p_object, psz_var );
635 /* Check if we want to display the variable */
636 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
638 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
639 if( val.i_int == 0 ) return TRUE;
641 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
643 if( val.i_int == 1 && b_root ) return TRUE;
647 /* Check children variables in case of VLC_VAR_VARIABLE */
648 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
653 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
655 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
663 /* clean up everything */
664 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
669 void Menu::CreateMenuItem( wxMenu *menu, const char *psz_var,
670 vlc_object_t *p_object )
672 wxMenuItemExt *menuitem;
673 vlc_value_t val, text;
676 /* Check the type of the object variable */
677 i_type = var_Type( p_object, psz_var );
679 switch( i_type & VLC_VAR_TYPE )
683 case VLC_VAR_VARIABLE:
685 case VLC_VAR_INTEGER:
689 /* Variable doesn't exist or isn't handled */
693 /* Make sure we want to display the variable */
694 if( IsMenuEmpty( psz_var, p_object ) ) return;
696 /* Get the descriptive name of the variable */
697 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
699 if( i_type & VLC_VAR_HASCHOICE )
701 menu->Append( MenuDummy_Event,
702 wxU(text.psz_string ? text.psz_string : psz_var),
703 CreateChoicesMenu( psz_var, p_object, TRUE ),
704 wxT("")/* Nothing for now (maybe use a GETLONGTEXT) */ );
706 free( text.psz_string );
711 switch( i_type & VLC_VAR_TYPE )
714 var_Get( p_object, psz_var, &val );
715 menuitem = new wxMenuItemExt( menu, ++i_item_id,
716 wxU(text.psz_string ?
717 text.psz_string : psz_var),
718 wxT(""), wxITEM_NORMAL, strdup(psz_var),
719 p_object->i_object_id, val, i_type );
720 menu->Append( menuitem );
724 var_Get( p_object, psz_var, &val );
725 val.b_bool = !val.b_bool;
726 menuitem = new wxMenuItemExt( menu, ++i_item_id,
727 wxU(text.psz_string ?
728 text.psz_string : psz_var),
729 wxT(""), wxITEM_CHECK, strdup(psz_var),
730 p_object->i_object_id, val, i_type );
731 menu->Append( menuitem );
732 Check( i_item_id, val.b_bool ? FALSE : TRUE );
736 free( text.psz_string );
739 wxMenu *Menu::CreateChoicesMenu( const char *psz_var, vlc_object_t *p_object,
742 vlc_value_t val, val_list, text_list;
745 /* Check the type of the object variable */
746 i_type = var_Type( p_object, psz_var );
748 /* Make sure we want to display the variable */
749 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return NULL;
751 switch( i_type & VLC_VAR_TYPE )
755 case VLC_VAR_VARIABLE:
757 case VLC_VAR_INTEGER:
761 /* Variable doesn't exist or isn't handled */
765 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
766 &val_list, &text_list ) < 0 )
771 wxMenu *menu = new wxMenu;
772 for( i = 0; i < val_list.p_list->i_count; i++ )
774 vlc_value_t another_val;
775 wxMenuItemExt *menuitem;
777 switch( i_type & VLC_VAR_TYPE )
779 case VLC_VAR_VARIABLE:
780 menu->Append( MenuDummy_Event,
781 wxU(text_list.p_list->p_values[i].psz_string ?
782 text_list.p_list->p_values[i].psz_string :
783 val_list.p_list->p_values[i].psz_string),
785 val_list.p_list->p_values[i].psz_string,
786 p_object, FALSE ), wxT("") );
790 var_Get( p_object, psz_var, &val );
792 another_val.psz_string =
793 strdup(val_list.p_list->p_values[i].psz_string);
795 new wxMenuItemExt( menu, ++i_item_id,
796 wxU(text_list.p_list->p_values[i].psz_string ?
797 text_list.p_list->p_values[i].psz_string :
798 another_val.psz_string), wxT(""),
799 i_type & VLC_VAR_ISCOMMAND ?
800 wxITEM_NORMAL : wxITEM_RADIO,
802 p_object->i_object_id, another_val, i_type );
804 menu->Append( menuitem );
806 if( !(i_type & VLC_VAR_ISCOMMAND) && val.psz_string &&
807 !strcmp( val.psz_string,
808 val_list.p_list->p_values[i].psz_string ) )
809 menu->Check( i_item_id, TRUE );
811 free( val.psz_string );
814 case VLC_VAR_INTEGER:
815 var_Get( p_object, psz_var, &val );
818 new wxMenuItemExt( menu, ++i_item_id,
819 text_list.p_list->p_values[i].psz_string ?
821 text_list.p_list->p_values[i].psz_string) :
822 wxString::Format(wxT("%d"),
823 val_list.p_list->p_values[i].i_int), wxT(""),
824 i_type & VLC_VAR_ISCOMMAND ?
825 wxITEM_NORMAL : wxITEM_RADIO,
827 p_object->i_object_id,
828 val_list.p_list->p_values[i], i_type );
830 menu->Append( menuitem );
832 if( !(i_type & VLC_VAR_ISCOMMAND) &&
833 val_list.p_list->p_values[i].i_int == val.i_int )
834 menu->Check( i_item_id, TRUE );
838 var_Get( p_object, psz_var, &val );
841 new wxMenuItemExt( menu, ++i_item_id,
842 text_list.p_list->p_values[i].psz_string ?
844 text_list.p_list->p_values[i].psz_string) :
845 wxString::Format(wxT("%.2f"),
846 val_list.p_list->p_values[i].f_float),wxT(""),
847 i_type & VLC_VAR_ISCOMMAND ?
848 wxITEM_NORMAL : wxITEM_RADIO,
850 p_object->i_object_id,
851 val_list.p_list->p_values[i], i_type );
853 menu->Append( menuitem );
855 if( !(i_type & VLC_VAR_ISCOMMAND) &&
856 val_list.p_list->p_values[i].f_float == val.f_float )
857 menu->Check( i_item_id, TRUE );
865 /* clean up everything */
866 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
871 /*****************************************************************************
872 * A small helper class which intercepts all popup menu events
873 *****************************************************************************/
874 MenuEvtHandler::MenuEvtHandler( intf_thread_t *_p_intf,
875 Interface *_p_main_interface )
877 /* Initializations */
879 p_main_interface = _p_main_interface;
882 MenuEvtHandler::~MenuEvtHandler()
886 void MenuEvtHandler::OnShowDialog( wxCommandEvent& event )
888 if( p_intf->p_sys->pf_show_dialog )
892 switch( event.GetId() )
894 case OpenFileSimple_Event:
895 i_id = INTF_DIALOG_FILE_SIMPLE;
898 i_id = INTF_DIALOG_FILE;
900 case OpenDirectory_Event:
901 i_id = INTF_DIALOG_DIRECTORY;
904 i_id = INTF_DIALOG_DISC;
907 i_id = INTF_DIALOG_NET;
909 case OpenCapture_Event:
910 i_id = INTF_DIALOG_CAPTURE;
912 case MediaInfo_Event:
913 i_id = INTF_DIALOG_FILEINFO;
916 i_id = INTF_DIALOG_MESSAGES;
918 case Preferences_Event:
919 i_id = INTF_DIALOG_PREFS;
922 i_id = INTF_DIALOG_FILE;
927 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
931 void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
933 wxMenuItem *p_menuitem = NULL;
934 int i_hotkey_event = p_intf->p_sys->i_first_hotkey_event;
935 int i_hotkeys = p_intf->p_sys->i_hotkeys;
937 if( event.GetId() >= Play_Event && event.GetId() <= Stop_Event )
939 input_thread_t *p_input;
940 playlist_t * p_playlist =
941 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
943 if( !p_playlist ) return;
945 switch( event.GetId() )
950 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
952 if( !p_input ) playlist_Play( p_playlist );
956 var_Get( p_input, "state", &val );
957 if( val.i_int != PAUSE_S ) val.i_int = PAUSE_S;
958 else val.i_int = PLAYING_S;
959 var_Set( p_input, "state", val );
960 vlc_object_release( p_input );
964 playlist_Stop( p_playlist );
967 playlist_Prev( p_playlist );
970 playlist_Next( p_playlist );
974 vlc_object_release( p_playlist );
978 /* Check if this is an auto generated menu item */
979 if( event.GetId() < FirstAutoGenerated_Event )
985 /* Check if this is an hotkey event */
986 if( event.GetId() >= i_hotkey_event &&
987 event.GetId() < i_hotkey_event + i_hotkeys )
992 p_intf->p_libvlc->p_hotkeys[event.GetId() - i_hotkey_event].i_key;
994 /* Get the key combination and send it to the hotkey handler */
995 var_Set( p_intf->p_libvlc, "key-pressed", val );
999 if( !p_main_interface ||
1000 (p_menuitem = p_main_interface->GetMenuBar()->FindItem(event.GetId()))
1003 if( p_intf->p_sys->p_popup_menu )
1006 p_intf->p_sys->p_popup_menu->FindItem( event.GetId() );
1012 wxMenuItemExt *p_menuitemext = (wxMenuItemExt *)p_menuitem;
1013 vlc_object_t *p_object;
1015 p_object = (vlc_object_t *)vlc_object_get( p_menuitemext->i_object_id );
1016 if( p_object == NULL ) return;
1018 wxMutexGuiLeave(); // We don't want deadlocks
1019 var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val );
1020 //wxMutexGuiEnter();
1022 vlc_object_release( p_object );
1028 /*****************************************************************************
1029 * A small helper class which encapsulate wxMenuitem with some other useful
1031 *****************************************************************************/
1032 wxMenuItemExt::wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
1033 const wxString& helpString, wxItemKind kind,
1034 char *_psz_var, int _i_object_id, vlc_value_t _val, int _i_val_type ):
1035 wxMenuItem( parentMenu, id, text, helpString, kind )
1037 /* Initializations */
1039 i_val_type = _i_val_type;
1040 i_object_id = _i_object_id;
1044 wxMenuItemExt::~wxMenuItemExt()
1047 if( ( i_val_type & VLC_VAR_TYPE ) == VLC_VAR_STRING )
1048 free( val.psz_string );