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 )
212 PUSH_VAR( "intf-switch" );
217 PUSH_VAR( "intf-switch" );
219 PUSH_VAR( "intf-add" );
220 PUSH_VAR( "intf-skins" );
221 vlc_object_release( p_object );
227 /*****************************************************************************
229 *****************************************************************************/
230 #define PUSH_VAR( var ) as_varnames.Add( var ); \
231 ai_objects.Add( p_object->i_object_id )
233 #define PUSH_SEPARATOR if( ai_objects.GetCount() != i_last_separator ) { \
234 ai_objects.Add( 0 ); \
235 as_varnames.Add( "" ); \
236 i_last_separator = ai_objects.GetCount(); }
238 #define POPUP_BOILERPLATE \
239 unsigned int i_last_separator = 0; \
240 ArrayOfInts ai_objects; \
241 ArrayOfStrings as_varnames; \
242 playlist_t *p_playlist = (playlist_t *) vlc_object_find( p_intf, \
243 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );\
246 input_thread_t *p_input = p_playlist->p_input
248 #define CREATE_POPUP \
249 Menu popupmenu( p_intf, PopupMenu_Events ); \
250 popupmenu.Populate( as_varnames, ai_objects ); \
251 p_intf->p_sys->p_popup_menu = &popupmenu; \
252 p_parent->PopupMenu( &popupmenu, pos.x, pos.y ); \
253 p_intf->p_sys->p_popup_menu = NULL; \
254 i_last_separator = 0 /* stop compiler warning */
256 #define POPUP_STATIC_ENTRIES \
257 if( p_input != NULL ) \
260 popupmenu.InsertSeparator( 0 ); \
263 popupmenu.Insert( 0, Stop_Event, wxU(_("Stop")) ); \
264 popupmenu.Insert( 0, Previous_Event, wxU(_("Previous")) ); \
265 popupmenu.Insert( 0, Next_Event, wxU(_("Next")) ); \
268 var_Get( p_input, "state", &val ); \
269 if( val.i_int == PAUSE_S ) \
270 popupmenu.Insert( 0, Play_Event, wxU(_("Play")) ); \
272 popupmenu.Insert( 0, Pause_Event, wxU(_("Pause")) ); \
274 vlc_object_release( p_input ); \
278 if( p_playlist && !playlist_IsEmpty( p_playlist ) ) \
280 popupmenu.InsertSeparator( 0 ); \
281 popupmenu.Insert( 0, Play_Event, wxU(_("Play")) ); \
283 if( p_playlist ) vlc_object_release( p_playlist ); \
286 popupmenu.Append( MenuDummy_Event, wxU(_("Miscellaneous")), \
287 MiscMenu( p_intf ), wxT("") )
290 void VideoPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
296 vlc_object_yield( p_input );
297 as_varnames.Add( "video-es" );
298 ai_objects.Add( p_input->i_object_id );
299 as_varnames.Add( "spu-es" );
300 ai_objects.Add( p_input->i_object_id );
301 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
302 VLC_OBJECT_VOUT, FIND_CHILD );
305 VideoAutoMenuBuilder( p_vout, ai_objects, as_varnames );
306 vlc_object_release( p_vout );
308 vlc_object_release( p_input );
310 vlc_object_release( p_playlist );
314 void AudioPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
320 vlc_object_yield( p_input );
321 as_varnames.Add( "audio-es" );
322 ai_objects.Add( p_input->i_object_id );
323 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
324 VLC_OBJECT_AOUT, FIND_ANYWHERE );
327 AudioAutoMenuBuilder( p_aout, ai_objects, as_varnames );
328 vlc_object_release( p_aout );
330 vlc_object_release( p_input );
332 vlc_object_release( p_playlist );
336 /* Navigation stuff, and general */
337 void MiscPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
344 vlc_object_yield( p_input );
345 as_varnames.Add( "audio-es" );
346 InputAutoMenuBuilder( VLC_OBJECT(p_input), ai_objects, as_varnames );
349 IntfAutoMenuBuilder( p_intf, ai_objects, as_varnames, true );
351 Menu popupmenu( p_intf, PopupMenu_Events );
352 popupmenu.Populate( as_varnames, ai_objects );
354 POPUP_STATIC_ENTRIES;
355 popupmenu.Append( MenuDummy_Event, wxU(_("Open")),
356 OpenStreamMenu( p_intf ), wxT("") );
358 p_intf->p_sys->p_popup_menu = &popupmenu;
359 p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
360 p_intf->p_sys->p_popup_menu = NULL;
361 vlc_object_release( p_playlist );
364 void PopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
367 int minimal = config_GetInt( p_intf, "wx-minimal" );
371 vlc_object_yield( p_input );
372 InputAutoMenuBuilder( VLC_OBJECT(p_input), ai_objects, as_varnames );
376 as_varnames.Add( "video-es" );
377 ai_objects.Add( p_input->i_object_id );
378 as_varnames.Add( "spu-es" );
379 ai_objects.Add( p_input->i_object_id );
380 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
381 VLC_OBJECT_VOUT, FIND_CHILD );
384 VideoAutoMenuBuilder( p_vout, ai_objects, as_varnames );
385 vlc_object_release( p_vout );
389 as_varnames.Add( "audio-es" );
390 ai_objects.Add( p_input->i_object_id );
391 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
392 VLC_OBJECT_AOUT, FIND_ANYWHERE );
395 AudioAutoMenuBuilder( p_aout, ai_objects, as_varnames );
396 vlc_object_release( p_aout );
402 IntfAutoMenuBuilder( p_intf, ai_objects, as_varnames, true );
405 Menu popupmenu( p_intf, PopupMenu_Events );
406 popupmenu.Populate( as_varnames, ai_objects );
407 POPUP_STATIC_ENTRIES;
411 popupmenu.Append( MenuDummy_Event, wxU(_("Open")),
412 OpenStreamMenu( p_intf ), wxT("") );
414 p_intf->p_sys->p_popup_menu = &popupmenu;
415 p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
416 p_intf->p_sys->p_popup_menu = NULL;
417 vlc_object_release( p_playlist );
420 /*****************************************************************************
422 *****************************************************************************/
423 wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
425 vlc_object_t *p_object;
426 ArrayOfInts ai_objects;
427 ArrayOfStrings as_varnames;
429 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
431 if( p_object != NULL )
433 PUSH_VAR( "audio-es" );
434 vlc_object_release( p_object );
437 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_AOUT,
441 AudioAutoMenuBuilder( p_object, ai_objects, as_varnames );
442 vlc_object_release( p_object );
446 Menu *p_vlc_menu = (Menu *)p_menu;
448 p_vlc_menu = new Menu( _p_intf, AudioMenu_Events );
452 p_vlc_menu->Populate( as_varnames, ai_objects );
457 wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
459 vlc_object_t *p_object;
460 ArrayOfInts ai_objects;
461 ArrayOfStrings as_varnames;
463 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
465 if( p_object != NULL )
467 PUSH_VAR( "video-es" );
468 PUSH_VAR( "spu-es" );
469 vlc_object_release( p_object );
472 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_VOUT,
474 if( p_object != NULL )
476 VideoAutoMenuBuilder( p_object, ai_objects, as_varnames );
477 vlc_object_release( p_object );
481 Menu *p_vlc_menu = (Menu *)p_menu;
483 p_vlc_menu = new Menu( _p_intf, VideoMenu_Events );
487 p_vlc_menu->Populate( as_varnames, ai_objects );
491 wxMenu *NavigMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
493 vlc_object_t *p_object;
494 ArrayOfInts ai_objects;
495 ArrayOfStrings as_varnames;
497 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
499 if( p_object != NULL )
501 InputAutoMenuBuilder( p_object, ai_objects, as_varnames );
502 PUSH_VAR( "prev-title"); PUSH_VAR ( "next-title" );
503 PUSH_VAR( "prev-chapter"); PUSH_VAR( "next-chapter" );
504 vlc_object_release( p_object );
508 Menu *p_vlc_menu = (Menu *)p_menu;
510 p_vlc_menu = new Menu( _p_intf, NavigMenu_Events );
514 p_vlc_menu->Populate( as_varnames, ai_objects );
519 wxMenu *SettingsMenu( intf_thread_t *_p_intf, wxWindow *p_parent,
522 vlc_object_t *p_object;
523 ArrayOfInts ai_objects;
524 ArrayOfStrings as_varnames;
526 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INTF,
528 if( p_object != NULL )
530 PUSH_VAR( "intf-switch" );
531 PUSH_VAR( "intf-add" );
532 vlc_object_release( p_object );
536 Menu *p_vlc_menu = (Menu *)p_menu;
538 p_vlc_menu = new Menu( _p_intf, SettingsMenu_Events );
542 p_vlc_menu->Populate( as_varnames, ai_objects );
547 /*****************************************************************************
549 *****************************************************************************/
550 Menu::Menu( intf_thread_t *_p_intf, int _i_start_id ) : wxMenu( )
552 /* Initializations */
554 i_start_id = _i_start_id;
561 /*****************************************************************************
563 *****************************************************************************/
564 void Menu::Populate( ArrayOfStrings & ras_varnames,
565 ArrayOfInts & rai_objects )
567 vlc_object_t *p_object;
568 vlc_bool_t b_section_empty = VLC_FALSE;
571 i_item_id = i_start_id;
573 for( i = 0; i < (int)rai_objects.GetCount() ; i++ )
575 if( !ras_varnames[i] || !*ras_varnames[i] )
577 if( b_section_empty )
579 Append( MenuDummy_Event + i, wxU(_("Empty")) );
580 Enable( MenuDummy_Event + i, FALSE );
583 b_section_empty = VLC_TRUE;
587 if( rai_objects[i] == 0 )
589 Append( MenuDummy_Event, wxU(ras_varnames[i]) );
590 b_section_empty = VLC_FALSE;
594 p_object = (vlc_object_t *)vlc_object_get( rai_objects[i] );
595 if( p_object == NULL ) continue;
597 b_section_empty = VLC_FALSE;
598 CreateMenuItem( this, ras_varnames[i], p_object );
599 vlc_object_release( p_object );
602 /* Special case for empty menus */
603 if( GetMenuItemCount() == 0 || b_section_empty )
605 Append( MenuDummy_Event + i, wxU(_("Empty")) );
606 Enable( MenuDummy_Event + i, FALSE );
610 /* Work-around helper for buggy wxGTK */
611 static void RecursiveDestroy( wxMenu *menu )
613 wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
616 wxMenuItem *item = node->GetData();
617 node = node->GetNext();
619 /* Delete the submenus */
620 wxMenu *submenu = item->GetSubMenu();
623 RecursiveDestroy( submenu );
625 menu->Delete( item );
631 RecursiveDestroy( this );
634 /*****************************************************************************
636 *****************************************************************************/
637 static bool IsMenuEmpty( const char *psz_var, vlc_object_t *p_object,
640 vlc_value_t val, val_list;
641 int i_type, i_result, i;
643 /* Check the type of the object variable */
644 i_type = var_Type( p_object, psz_var );
646 /* Check if we want to display the variable */
647 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
649 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
650 if( val.i_int == 0 ) return TRUE;
652 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
654 /* Very evil hack ! intf-switch can have only one value */
655 if( !strcmp( psz_var, "intf-switch" ) ) return FALSE;
656 if( val.i_int == 1 && b_root ) return TRUE;
660 /* Check children variables in case of VLC_VAR_VARIABLE */
661 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
666 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
668 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
676 /* clean up everything */
677 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
682 void Menu::CreateMenuItem( wxMenu *menu, const char *psz_var,
683 vlc_object_t *p_object )
685 wxMenuItemExt *menuitem;
686 vlc_value_t val, text;
689 /* Check the type of the object variable */
690 i_type = var_Type( p_object, psz_var );
692 switch( i_type & VLC_VAR_TYPE )
696 case VLC_VAR_VARIABLE:
698 case VLC_VAR_INTEGER:
702 /* Variable doesn't exist or isn't handled */
706 /* Make sure we want to display the variable */
707 if( IsMenuEmpty( psz_var, p_object ) ) return;
709 /* Get the descriptive name of the variable */
710 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
712 if( i_type & VLC_VAR_HASCHOICE )
714 menu->Append( MenuDummy_Event,
715 wxU(text.psz_string ? text.psz_string : psz_var),
716 CreateChoicesMenu( psz_var, p_object, TRUE ),
717 wxT("")/* Nothing for now (maybe use a GETLONGTEXT) */ );
719 if( text.psz_string ) free( text.psz_string );
724 switch( i_type & VLC_VAR_TYPE )
727 var_Get( p_object, psz_var, &val );
728 menuitem = new wxMenuItemExt( menu, ++i_item_id,
729 wxU(text.psz_string ?
730 text.psz_string : psz_var),
731 wxT(""), wxITEM_NORMAL, strdup(psz_var),
732 p_object->i_object_id, val, i_type );
733 menu->Append( menuitem );
737 var_Get( p_object, psz_var, &val );
738 val.b_bool = !val.b_bool;
739 menuitem = new wxMenuItemExt( menu, ++i_item_id,
740 wxU(text.psz_string ?
741 text.psz_string : psz_var),
742 wxT(""), wxITEM_CHECK, strdup(psz_var),
743 p_object->i_object_id, val, i_type );
744 menu->Append( menuitem );
745 Check( i_item_id, val.b_bool ? FALSE : TRUE );
749 if( text.psz_string ) free( text.psz_string );
752 wxMenu *Menu::CreateChoicesMenu( const char *psz_var, vlc_object_t *p_object,
755 vlc_value_t val, val_list, text_list;
758 /* Check the type of the object variable */
759 i_type = var_Type( p_object, psz_var );
761 /* Make sure we want to display the variable */
762 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return NULL;
764 switch( i_type & VLC_VAR_TYPE )
768 case VLC_VAR_VARIABLE:
770 case VLC_VAR_INTEGER:
774 /* Variable doesn't exist or isn't handled */
778 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
779 &val_list, &text_list ) < 0 )
784 wxMenu *menu = new wxMenu;
785 for( i = 0; i < val_list.p_list->i_count; i++ )
787 vlc_value_t another_val;
788 wxMenuItemExt *menuitem;
790 switch( i_type & VLC_VAR_TYPE )
792 case VLC_VAR_VARIABLE:
793 menu->Append( MenuDummy_Event,
794 wxU(text_list.p_list->p_values[i].psz_string ?
795 text_list.p_list->p_values[i].psz_string :
796 val_list.p_list->p_values[i].psz_string),
798 val_list.p_list->p_values[i].psz_string,
799 p_object, FALSE ), wxT("") );
803 var_Get( p_object, psz_var, &val );
805 another_val.psz_string =
806 strdup(val_list.p_list->p_values[i].psz_string);
808 new wxMenuItemExt( menu, ++i_item_id,
809 wxU(text_list.p_list->p_values[i].psz_string ?
810 text_list.p_list->p_values[i].psz_string :
811 another_val.psz_string), wxT(""),
812 i_type & VLC_VAR_ISCOMMAND ?
813 wxITEM_NORMAL : wxITEM_RADIO,
815 p_object->i_object_id, another_val, i_type );
817 menu->Append( menuitem );
819 if( !(i_type & VLC_VAR_ISCOMMAND) && val.psz_string &&
820 !strcmp( val.psz_string,
821 val_list.p_list->p_values[i].psz_string ) )
822 menu->Check( i_item_id, TRUE );
824 if( val.psz_string ) free( val.psz_string );
827 case VLC_VAR_INTEGER:
828 var_Get( p_object, psz_var, &val );
831 new wxMenuItemExt( menu, ++i_item_id,
832 text_list.p_list->p_values[i].psz_string ?
834 text_list.p_list->p_values[i].psz_string) :
835 wxString::Format(wxT("%d"),
836 val_list.p_list->p_values[i].i_int), wxT(""),
837 i_type & VLC_VAR_ISCOMMAND ?
838 wxITEM_NORMAL : wxITEM_RADIO,
840 p_object->i_object_id,
841 val_list.p_list->p_values[i], i_type );
843 menu->Append( menuitem );
845 if( !(i_type & VLC_VAR_ISCOMMAND) &&
846 val_list.p_list->p_values[i].i_int == val.i_int )
847 menu->Check( i_item_id, TRUE );
851 var_Get( p_object, psz_var, &val );
854 new wxMenuItemExt( menu, ++i_item_id,
855 text_list.p_list->p_values[i].psz_string ?
857 text_list.p_list->p_values[i].psz_string) :
858 wxString::Format(wxT("%.2f"),
859 val_list.p_list->p_values[i].f_float),wxT(""),
860 i_type & VLC_VAR_ISCOMMAND ?
861 wxITEM_NORMAL : wxITEM_RADIO,
863 p_object->i_object_id,
864 val_list.p_list->p_values[i], i_type );
866 menu->Append( menuitem );
868 if( !(i_type & VLC_VAR_ISCOMMAND) &&
869 val_list.p_list->p_values[i].f_float == val.f_float )
870 menu->Check( i_item_id, TRUE );
878 /* clean up everything */
879 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
884 /*****************************************************************************
885 * A small helper class which intercepts all popup menu events
886 *****************************************************************************/
887 MenuEvtHandler::MenuEvtHandler( intf_thread_t *_p_intf,
888 Interface *_p_main_interface )
890 /* Initializations */
892 p_main_interface = _p_main_interface;
895 MenuEvtHandler::~MenuEvtHandler()
899 void MenuEvtHandler::OnShowDialog( wxCommandEvent& event )
901 if( p_intf->p_sys->pf_show_dialog )
905 switch( event.GetId() )
907 case OpenFileSimple_Event:
908 i_id = INTF_DIALOG_FILE_SIMPLE;
911 i_id = INTF_DIALOG_FILE;
913 case OpenDirectory_Event:
914 i_id = INTF_DIALOG_DIRECTORY;
917 i_id = INTF_DIALOG_DISC;
920 i_id = INTF_DIALOG_NET;
922 case OpenCapture_Event:
923 i_id = INTF_DIALOG_CAPTURE;
925 case MediaInfo_Event:
926 i_id = INTF_DIALOG_FILEINFO;
929 i_id = INTF_DIALOG_MESSAGES;
931 case Preferences_Event:
932 i_id = INTF_DIALOG_PREFS;
935 i_id = INTF_DIALOG_FILE;
940 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
944 void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
946 wxMenuItem *p_menuitem = NULL;
947 int i_hotkey_event = p_intf->p_sys->i_first_hotkey_event;
948 int i_hotkeys = p_intf->p_sys->i_hotkeys;
950 if( event.GetId() >= Play_Event && event.GetId() <= Stop_Event )
952 input_thread_t *p_input;
953 playlist_t * p_playlist =
954 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
956 if( !p_playlist ) return;
958 switch( event.GetId() )
963 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
965 if( !p_input ) playlist_Play( p_playlist );
969 var_Get( p_input, "state", &val );
970 if( val.i_int != PAUSE_S ) val.i_int = PAUSE_S;
971 else val.i_int = PLAYING_S;
972 var_Set( p_input, "state", val );
973 vlc_object_release( p_input );
977 playlist_Stop( p_playlist );
980 playlist_Prev( p_playlist );
983 playlist_Next( p_playlist );
987 vlc_object_release( p_playlist );
991 /* Check if this is an auto generated menu item */
992 if( event.GetId() < FirstAutoGenerated_Event )
998 /* Check if this is an hotkey event */
999 if( event.GetId() >= i_hotkey_event &&
1000 event.GetId() < i_hotkey_event + i_hotkeys )
1005 p_intf->p_libvlc->p_hotkeys[event.GetId() - i_hotkey_event].i_key;
1007 /* Get the key combination and send it to the hotkey handler */
1008 var_Set( p_intf->p_libvlc, "key-pressed", val );
1012 if( !p_main_interface ||
1013 (p_menuitem = p_main_interface->GetMenuBar()->FindItem(event.GetId()))
1016 if( p_intf->p_sys->p_popup_menu )
1019 p_intf->p_sys->p_popup_menu->FindItem( event.GetId() );
1025 wxMenuItemExt *p_menuitemext = (wxMenuItemExt *)p_menuitem;
1026 vlc_object_t *p_object;
1028 p_object = (vlc_object_t *)vlc_object_get( p_menuitemext->i_object_id );
1029 if( p_object == NULL ) return;
1031 wxMutexGuiLeave(); // We don't want deadlocks
1032 var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val );
1033 //wxMutexGuiEnter();
1035 vlc_object_release( p_object );
1041 /*****************************************************************************
1042 * A small helper class which encapsulate wxMenuitem with some other useful
1044 *****************************************************************************/
1045 wxMenuItemExt::wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
1046 const wxString& helpString, wxItemKind kind,
1047 char *_psz_var, int _i_object_id, vlc_value_t _val, int _i_val_type ):
1048 wxMenuItem( parentMenu, id, text, helpString, kind )
1050 /* Initializations */
1052 i_val_type = _i_val_type;
1053 i_object_id = _i_object_id;
1057 wxMenuItemExt::~wxMenuItemExt()
1059 if( psz_var ) free( psz_var );
1060 if( ((i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
1061 && val.psz_string ) free( val.psz_string );