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 *****************************************************************************/
27 #include "wxwidgets.hpp"
28 #include "interface.hpp"
33 class wxMenuItemExt: public wxMenuItem
37 wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
38 const wxString& helpString, wxItemKind kind,
39 char *_psz_var, int _i_object_id, vlc_value_t _val,
41 virtual ~wxMenuItemExt();
49 class Menu: public wxMenu
53 Menu( intf_thread_t *p_intf, int i_start_id );
56 void Populate( vector<const char *> &, vector<int> &);
60 wxMenu *CreateDummyMenu();
61 void CreateMenuItem( wxMenu *, const char *, vlc_object_t * );
62 wxMenu *CreateChoicesMenu( const char *, vlc_object_t *, bool );
64 DECLARE_EVENT_TABLE();
66 intf_thread_t *p_intf;
72 /*****************************************************************************
74 *****************************************************************************/
78 MenuDummy_Event = wxID_HIGHEST + 1000,
79 OpenFileSimple_Event = wxID_HIGHEST + 1100,
93 FirstAutoGenerated_Event = wxID_HIGHEST + 1999,
94 SettingsMenu_Events = wxID_HIGHEST + 5000,
95 AudioMenu_Events = wxID_HIGHEST + 2000,
96 VideoMenu_Events = wxID_HIGHEST + 3000,
97 NavigMenu_Events = wxID_HIGHEST + 4000,
98 PopupMenu_Events = wxID_HIGHEST + 6000,
99 Hotkeys_Events = wxID_HIGHEST + 7000
102 BEGIN_EVENT_TABLE(Menu, wxMenu)
105 BEGIN_EVENT_TABLE(MenuEvtHandler, wxEvtHandler)
106 EVT_MENU(OpenFileSimple_Event, MenuEvtHandler::OnShowDialog)
107 EVT_MENU(OpenFile_Event, MenuEvtHandler::OnShowDialog)
108 EVT_MENU(OpenDirectory_Event, MenuEvtHandler::OnShowDialog)
109 EVT_MENU(OpenDisc_Event, MenuEvtHandler::OnShowDialog)
110 EVT_MENU(OpenNet_Event, MenuEvtHandler::OnShowDialog)
111 EVT_MENU(OpenCapture_Event, MenuEvtHandler::OnShowDialog)
112 EVT_MENU(MediaInfo_Event, MenuEvtHandler::OnShowDialog)
113 EVT_MENU(Messages_Event, MenuEvtHandler::OnShowDialog)
114 EVT_MENU(Preferences_Event, MenuEvtHandler::OnShowDialog)
115 EVT_MENU(-1, MenuEvtHandler::OnMenuEvent)
118 /*****************************************************************************
119 * Static menu helpers
120 *****************************************************************************/
121 wxMenu *OpenStreamMenu( intf_thread_t *p_intf )
123 wxMenu *menu = new wxMenu;
124 menu->Append( OpenFileSimple_Event, wxU(_("Quick &Open File...")) );
125 menu->Append( OpenFile_Event, wxU(_("Open &File...")) );
126 menu->Append( OpenDirectory_Event, wxU(_("Open D&irectory...")) );
127 menu->Append( OpenDisc_Event, wxU(_("Open &Disc...")) );
128 menu->Append( OpenNet_Event, wxU(_("Open &Network Stream...")) );
129 menu->Append( OpenCapture_Event, wxU(_("Open &Capture Device...")) );
133 wxMenu *MiscMenu( intf_thread_t *p_intf )
135 wxMenu *menu = new wxMenu;
136 menu->Append( MediaInfo_Event, wxU(_("Media &Info...")) );
137 menu->Append( Messages_Event, wxU(_("&Messages...")) );
138 menu->Append( Preferences_Event, wxU(_("&Preferences...")) );
142 /*****************************************************************************
143 * Builders for the dynamic menus
144 *****************************************************************************/
145 #define PUSH_VAR( var ) rs_varnames.push_back( var ); \
146 ri_objects.push_back( p_object->i_object_id )
148 int InputAutoMenuBuilder( vlc_object_t *p_object, vector<int> &ri_objects,
149 vector<const char *> &rs_varnames )
151 PUSH_VAR( "bookmark");
153 PUSH_VAR ("chapter" );
154 PUSH_VAR( "program" );
155 PUSH_VAR( "navigation" );
156 PUSH_VAR( "dvd_menus" );
160 int VideoAutoMenuBuilder( vlc_object_t *p_object, vector<int> &ri_objects,
161 vector<const char *> &rs_varnames )
163 PUSH_VAR( "fullscreen" );
165 PUSH_VAR( "deinterlace" );
166 PUSH_VAR( "aspect-ratio" );
168 PUSH_VAR( "video-on-top" );
169 PUSH_VAR( "directx-wallpaper" );
170 PUSH_VAR( "video-snapshot" );
172 vlc_object_t *p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
175 if( p_dec_obj != NULL )
177 vlc_object_t *p_object = p_dec_obj;
178 PUSH_VAR( "ffmpeg-pp-q" );
179 vlc_object_release( p_dec_obj );
184 int AudioAutoMenuBuilder( vlc_object_t *p_object, vector<int> &ri_objects,
185 vector<const char *> &rs_varnames )
187 PUSH_VAR( "audio-device" );
188 PUSH_VAR( "audio-channels" );
189 PUSH_VAR( "visual" );
190 PUSH_VAR( "equalizer" );
194 int IntfAutoMenuBuilder( intf_thread_t *p_intf, vector<int> &ri_objects,
195 vector<const char *> &rs_varnames, bool is_popup)
197 /* vlc_object_find is needed because of the dialogs provider case */
198 vlc_object_t *p_object;
199 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INTF,
201 if( p_object != NULL )
206 PUSH_VAR( "intf-switch" );
211 PUSH_VAR( "intf-switch" );
213 PUSH_VAR( "intf-add" );
214 PUSH_VAR( "intf-skins" );
215 vlc_object_release( p_object );
221 /*****************************************************************************
223 *****************************************************************************/
224 #define PUSH_VAR( var ) as_varnames.push_back( var ); \
225 ai_objects.push_back( p_object->i_object_id )
227 #define PUSH_SEPARATOR if( ai_objects.size() != i_last_separator ) { \
228 ai_objects.push_back( 0 ); \
229 as_varnames.push_back( "" ); \
230 i_last_separator = ai_objects.size(); }
232 #define POPUP_BOILERPLATE \
233 unsigned int i_last_separator = 0; \
234 vector<int> ai_objects; \
235 vector<const char *> as_varnames; \
236 playlist_t *p_playlist = (playlist_t *) vlc_object_find( p_intf, \
237 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );\
240 input_thread_t *p_input = p_playlist->p_input
242 #define CREATE_POPUP \
243 Menu popupmenu( p_intf, PopupMenu_Events ); \
244 popupmenu.Populate( as_varnames, ai_objects ); \
245 p_intf->p_sys->p_popup_menu = &popupmenu; \
246 p_parent->PopupMenu( &popupmenu, pos.x, pos.y ); \
247 p_intf->p_sys->p_popup_menu = NULL; \
248 i_last_separator = 0 /* stop compiler warning */
250 #define POPUP_STATIC_ENTRIES \
251 if( p_input != NULL ) \
254 popupmenu.InsertSeparator( 0 ); \
257 popupmenu.Insert( 0, Stop_Event, wxU(_("Stop")) ); \
258 popupmenu.Insert( 0, Previous_Event, wxU(_("Previous")) ); \
259 popupmenu.Insert( 0, Next_Event, wxU(_("Next")) ); \
262 var_Get( p_input, "state", &val ); \
263 if( val.i_int == PAUSE_S ) \
264 popupmenu.Insert( 0, Play_Event, wxU(_("Play")) ); \
266 popupmenu.Insert( 0, Pause_Event, wxU(_("Pause")) ); \
268 vlc_object_release( p_input ); \
272 if( p_playlist && p_playlist->i_size ) \
274 popupmenu.InsertSeparator( 0 ); \
275 popupmenu.Insert( 0, Play_Event, wxU(_("Play")) ); \
277 if( p_playlist ) vlc_object_release( p_playlist ); \
280 popupmenu.Append( MenuDummy_Event, wxU(_("Miscellaneous")), \
281 MiscMenu( p_intf ), wxT("") )
284 void VideoPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
290 vlc_object_yield( p_input );
291 as_varnames.push_back( "video-es" );
292 ai_objects.push_back( p_input->i_object_id );
293 as_varnames.push_back( "spu-es" );
294 ai_objects.push_back( p_input->i_object_id );
295 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
296 VLC_OBJECT_VOUT, FIND_CHILD );
299 VideoAutoMenuBuilder( p_vout, ai_objects, as_varnames );
300 vlc_object_release( p_vout );
302 vlc_object_release( p_input );
304 vlc_object_release( p_playlist );
308 void AudioPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
314 vlc_object_yield( p_input );
315 as_varnames.push_back( "audio-es" );
316 ai_objects.push_back( p_input->i_object_id );
317 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
318 VLC_OBJECT_AOUT, FIND_ANYWHERE );
321 AudioAutoMenuBuilder( p_aout, ai_objects, as_varnames );
322 vlc_object_release( p_aout );
324 vlc_object_release( p_input );
326 vlc_object_release( p_playlist );
330 /* Navigation stuff, and general */
331 void MiscPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
338 vlc_object_yield( p_input );
339 as_varnames.push_back( "audio-es" );
340 InputAutoMenuBuilder( VLC_OBJECT(p_input), ai_objects, as_varnames );
343 IntfAutoMenuBuilder( p_intf, ai_objects, as_varnames, true );
345 Menu popupmenu( p_intf, PopupMenu_Events );
346 popupmenu.Populate( as_varnames, ai_objects );
348 POPUP_STATIC_ENTRIES;
349 popupmenu.Append( MenuDummy_Event, wxU(_("Open")),
350 OpenStreamMenu( p_intf ), wxT("") );
352 p_intf->p_sys->p_popup_menu = &popupmenu;
353 p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
354 p_intf->p_sys->p_popup_menu = NULL;
355 vlc_object_release( p_playlist );
358 void PopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
361 int minimal = config_GetInt( p_intf, "wx-minimal" );
365 vlc_object_yield( p_input );
366 InputAutoMenuBuilder( VLC_OBJECT(p_input), ai_objects, as_varnames );
370 as_varnames.push_back( "video-es" );
371 ai_objects.push_back( p_input->i_object_id );
372 as_varnames.push_back( "spu-es" );
373 ai_objects.push_back( p_input->i_object_id );
374 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
375 VLC_OBJECT_VOUT, FIND_CHILD );
378 VideoAutoMenuBuilder( p_vout, ai_objects, as_varnames );
379 vlc_object_release( p_vout );
383 as_varnames.push_back( "audio-es" );
384 ai_objects.push_back( p_input->i_object_id );
385 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
386 VLC_OBJECT_AOUT, FIND_ANYWHERE );
389 AudioAutoMenuBuilder( p_aout, ai_objects, as_varnames );
390 vlc_object_release( p_aout );
396 IntfAutoMenuBuilder( p_intf, ai_objects, as_varnames, true );
399 Menu popupmenu( p_intf, PopupMenu_Events );
400 popupmenu.Populate( as_varnames, ai_objects );
401 POPUP_STATIC_ENTRIES;
405 popupmenu.Append( MenuDummy_Event, wxU(_("Open")),
406 OpenStreamMenu( p_intf ), wxT("") );
408 p_intf->p_sys->p_popup_menu = &popupmenu;
409 p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
410 p_intf->p_sys->p_popup_menu = NULL;
411 vlc_object_release( p_playlist );
414 /*****************************************************************************
416 *****************************************************************************/
417 wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
419 vlc_object_t *p_object;
420 vector<int> ai_objects;
421 vector<const char *> as_varnames;
423 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
425 if( p_object != NULL )
427 PUSH_VAR( "audio-es" );
428 vlc_object_release( p_object );
431 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_AOUT,
435 AudioAutoMenuBuilder( p_object, ai_objects, as_varnames );
436 vlc_object_release( p_object );
440 Menu *p_vlc_menu = (Menu *)p_menu;
442 p_vlc_menu = new Menu( _p_intf, AudioMenu_Events );
446 p_vlc_menu->Populate( as_varnames, ai_objects );
451 wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
453 vlc_object_t *p_object;
454 vector<int> ai_objects;
455 vector<const char *> as_varnames;
457 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
459 if( p_object != NULL )
461 PUSH_VAR( "video-es" );
462 PUSH_VAR( "spu-es" );
463 vlc_object_release( p_object );
466 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_VOUT,
468 if( p_object != NULL )
470 VideoAutoMenuBuilder( p_object, ai_objects, as_varnames );
471 vlc_object_release( p_object );
475 Menu *p_vlc_menu = (Menu *)p_menu;
477 p_vlc_menu = new Menu( _p_intf, VideoMenu_Events );
481 p_vlc_menu->Populate( as_varnames, ai_objects );
485 wxMenu *NavigMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
487 vlc_object_t *p_object;
488 vector<int> ai_objects;
489 vector<const char *> as_varnames;
491 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
493 if( p_object != NULL )
495 InputAutoMenuBuilder( p_object, ai_objects, as_varnames );
496 PUSH_VAR( "prev-title"); PUSH_VAR ( "next-title" );
497 PUSH_VAR( "prev-chapter"); PUSH_VAR( "next-chapter" );
498 vlc_object_release( p_object );
502 Menu *p_vlc_menu = (Menu *)p_menu;
504 p_vlc_menu = new Menu( _p_intf, NavigMenu_Events );
508 p_vlc_menu->Populate( as_varnames, ai_objects );
513 wxMenu *SettingsMenu( intf_thread_t *_p_intf, wxWindow *p_parent,
516 vlc_object_t *p_object;
517 vector<int> ai_objects;
518 vector<const char *> as_varnames;
520 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INTF,
522 if( p_object != NULL )
524 PUSH_VAR( "intf-switch" );
525 PUSH_VAR( "intf-add" );
526 vlc_object_release( p_object );
530 Menu *p_vlc_menu = (Menu *)p_menu;
532 p_vlc_menu = new Menu( _p_intf, SettingsMenu_Events );
536 p_vlc_menu->Populate( as_varnames, ai_objects );
541 /*****************************************************************************
543 *****************************************************************************/
544 Menu::Menu( intf_thread_t *_p_intf, int _i_start_id ) : wxMenu( )
546 /* Initializations */
548 i_start_id = _i_start_id;
555 /*****************************************************************************
557 *****************************************************************************/
558 void Menu::Populate( vector<const char *> & ras_varnames,
559 vector<int> & rai_objects )
561 vlc_object_t *p_object;
562 vlc_bool_t b_section_empty = VLC_FALSE;
565 i_item_id = i_start_id;
567 for( i = 0; i < (int)rai_objects.size() ; i++ )
569 if( !ras_varnames[i] || !*ras_varnames[i] )
571 if( b_section_empty )
573 Append( MenuDummy_Event + i, wxU(_("Empty")) );
574 Enable( MenuDummy_Event + i, FALSE );
577 b_section_empty = VLC_TRUE;
581 if( rai_objects[i] == 0 )
583 Append( MenuDummy_Event, wxU(ras_varnames[i]) );
584 b_section_empty = VLC_FALSE;
588 p_object = (vlc_object_t *)vlc_object_get( p_intf,
590 if( p_object == NULL ) continue;
592 b_section_empty = VLC_FALSE;
593 CreateMenuItem( this, ras_varnames[i], p_object );
594 vlc_object_release( p_object );
597 /* Special case for empty menus */
598 if( GetMenuItemCount() == 0 || b_section_empty )
600 Append( MenuDummy_Event + i, wxU(_("Empty")) );
601 Enable( MenuDummy_Event + i, FALSE );
605 /* Work-around helper for buggy wxGTK */
606 static void RecursiveDestroy( wxMenu *menu )
608 wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
611 wxMenuItem *item = node->GetData();
612 node = node->GetNext();
614 /* Delete the submenus */
615 wxMenu *submenu = item->GetSubMenu();
618 RecursiveDestroy( submenu );
620 menu->Delete( item );
626 RecursiveDestroy( this );
629 /*****************************************************************************
631 *****************************************************************************/
632 static bool IsMenuEmpty( const char *psz_var, vlc_object_t *p_object,
635 vlc_value_t val, val_list;
636 int i_type, i_result, i;
638 /* Check the type of the object variable */
639 i_type = var_Type( p_object, psz_var );
641 /* Check if we want to display the variable */
642 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
644 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
645 if( val.i_int == 0 ) return TRUE;
647 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
649 /* Very evil hack ! intf-switch can have only one value */
650 if( !strcmp( psz_var, "intf-switch" ) ) return FALSE;
651 if( val.i_int == 1 && b_root ) return TRUE;
655 /* Check children variables in case of VLC_VAR_VARIABLE */
656 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
661 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
663 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
671 /* clean up everything */
672 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
677 void Menu::CreateMenuItem( wxMenu *menu, const char *psz_var,
678 vlc_object_t *p_object )
680 wxMenuItemExt *menuitem;
681 vlc_value_t val, text;
684 /* Check the type of the object variable */
685 i_type = var_Type( p_object, psz_var );
687 switch( i_type & VLC_VAR_TYPE )
691 case VLC_VAR_VARIABLE:
693 case VLC_VAR_INTEGER:
697 /* Variable doesn't exist or isn't handled */
701 /* Make sure we want to display the variable */
702 if( IsMenuEmpty( psz_var, p_object ) ) return;
704 /* Get the descriptive name of the variable */
705 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
707 if( i_type & VLC_VAR_HASCHOICE )
709 menu->Append( MenuDummy_Event,
710 wxU(text.psz_string ? text.psz_string : psz_var),
711 CreateChoicesMenu( psz_var, p_object, TRUE ),
712 wxT("")/* Nothing for now (maybe use a GETLONGTEXT) */ );
714 if( text.psz_string ) free( text.psz_string );
719 switch( i_type & VLC_VAR_TYPE )
722 var_Get( p_object, psz_var, &val );
723 menuitem = new wxMenuItemExt( menu, ++i_item_id,
724 wxU(text.psz_string ?
725 text.psz_string : psz_var),
726 wxT(""), wxITEM_NORMAL, strdup(psz_var),
727 p_object->i_object_id, val, i_type );
728 menu->Append( menuitem );
732 var_Get( p_object, psz_var, &val );
733 val.b_bool = !val.b_bool;
734 menuitem = new wxMenuItemExt( menu, ++i_item_id,
735 wxU(text.psz_string ?
736 text.psz_string : psz_var),
737 wxT(""), wxITEM_CHECK, strdup(psz_var),
738 p_object->i_object_id, val, i_type );
739 menu->Append( menuitem );
740 Check( i_item_id, val.b_bool ? FALSE : TRUE );
744 if( text.psz_string ) free( text.psz_string );
747 wxMenu *Menu::CreateChoicesMenu( const char *psz_var, vlc_object_t *p_object,
750 vlc_value_t val, val_list, text_list;
753 /* Check the type of the object variable */
754 i_type = var_Type( p_object, psz_var );
756 /* Make sure we want to display the variable */
757 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return NULL;
759 switch( i_type & VLC_VAR_TYPE )
763 case VLC_VAR_VARIABLE:
765 case VLC_VAR_INTEGER:
769 /* Variable doesn't exist or isn't handled */
773 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
774 &val_list, &text_list ) < 0 )
779 wxMenu *menu = new wxMenu;
780 for( i = 0; i < val_list.p_list->i_count; i++ )
782 vlc_value_t another_val;
783 wxMenuItemExt *menuitem;
785 switch( i_type & VLC_VAR_TYPE )
787 case VLC_VAR_VARIABLE:
788 menu->Append( MenuDummy_Event,
789 wxU(text_list.p_list->p_values[i].psz_string ?
790 text_list.p_list->p_values[i].psz_string :
791 val_list.p_list->p_values[i].psz_string),
793 val_list.p_list->p_values[i].psz_string,
794 p_object, FALSE ), wxT("") );
798 var_Get( p_object, psz_var, &val );
800 another_val.psz_string =
801 strdup(val_list.p_list->p_values[i].psz_string);
803 new wxMenuItemExt( menu, ++i_item_id,
804 wxU(text_list.p_list->p_values[i].psz_string ?
805 text_list.p_list->p_values[i].psz_string :
806 another_val.psz_string), wxT(""),
807 i_type & VLC_VAR_ISCOMMAND ?
808 wxITEM_NORMAL : wxITEM_RADIO,
810 p_object->i_object_id, another_val, i_type );
812 menu->Append( menuitem );
814 if( !(i_type & VLC_VAR_ISCOMMAND) && val.psz_string &&
815 !strcmp( val.psz_string,
816 val_list.p_list->p_values[i].psz_string ) )
817 menu->Check( i_item_id, TRUE );
819 if( val.psz_string ) free( val.psz_string );
822 case VLC_VAR_INTEGER:
823 var_Get( p_object, psz_var, &val );
826 new wxMenuItemExt( menu, ++i_item_id,
827 text_list.p_list->p_values[i].psz_string ?
829 text_list.p_list->p_values[i].psz_string) :
830 wxString::Format(wxT("%d"),
831 val_list.p_list->p_values[i].i_int), wxT(""),
832 i_type & VLC_VAR_ISCOMMAND ?
833 wxITEM_NORMAL : wxITEM_RADIO,
835 p_object->i_object_id,
836 val_list.p_list->p_values[i], i_type );
838 menu->Append( menuitem );
840 if( !(i_type & VLC_VAR_ISCOMMAND) &&
841 val_list.p_list->p_values[i].i_int == val.i_int )
842 menu->Check( i_item_id, TRUE );
846 var_Get( p_object, psz_var, &val );
849 new wxMenuItemExt( menu, ++i_item_id,
850 text_list.p_list->p_values[i].psz_string ?
852 text_list.p_list->p_values[i].psz_string) :
853 wxString::Format(wxT("%.2f"),
854 val_list.p_list->p_values[i].f_float),wxT(""),
855 i_type & VLC_VAR_ISCOMMAND ?
856 wxITEM_NORMAL : wxITEM_RADIO,
858 p_object->i_object_id,
859 val_list.p_list->p_values[i], i_type );
861 menu->Append( menuitem );
863 if( !(i_type & VLC_VAR_ISCOMMAND) &&
864 val_list.p_list->p_values[i].f_float == val.f_float )
865 menu->Check( i_item_id, TRUE );
873 /* clean up everything */
874 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
879 /*****************************************************************************
880 * A small helper class which intercepts all popup menu events
881 *****************************************************************************/
882 MenuEvtHandler::MenuEvtHandler( intf_thread_t *_p_intf,
883 Interface *_p_main_interface )
885 /* Initializations */
887 p_main_interface = _p_main_interface;
890 MenuEvtHandler::~MenuEvtHandler()
894 void MenuEvtHandler::OnShowDialog( wxCommandEvent& event )
896 if( p_intf->p_sys->pf_show_dialog )
900 switch( event.GetId() )
902 case OpenFileSimple_Event:
903 i_id = INTF_DIALOG_FILE_SIMPLE;
906 i_id = INTF_DIALOG_FILE;
908 case OpenDirectory_Event:
909 i_id = INTF_DIALOG_DIRECTORY;
912 i_id = INTF_DIALOG_DISC;
915 i_id = INTF_DIALOG_NET;
917 case OpenCapture_Event:
918 i_id = INTF_DIALOG_CAPTURE;
920 case MediaInfo_Event:
921 i_id = INTF_DIALOG_FILEINFO;
924 i_id = INTF_DIALOG_MESSAGES;
926 case Preferences_Event:
927 i_id = INTF_DIALOG_PREFS;
930 i_id = INTF_DIALOG_FILE;
935 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
939 void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
941 wxMenuItem *p_menuitem = NULL;
942 int i_hotkey_event = p_intf->p_sys->i_first_hotkey_event;
943 int i_hotkeys = p_intf->p_sys->i_hotkeys;
945 if( event.GetId() >= Play_Event && event.GetId() <= Stop_Event )
947 input_thread_t *p_input;
948 playlist_t * p_playlist =
949 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
951 if( !p_playlist ) return;
953 switch( event.GetId() )
958 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
960 if( !p_input ) playlist_Play( p_playlist );
964 var_Get( p_input, "state", &val );
965 if( val.i_int != PAUSE_S ) val.i_int = PAUSE_S;
966 else val.i_int = PLAYING_S;
967 var_Set( p_input, "state", val );
968 vlc_object_release( p_input );
972 playlist_Stop( p_playlist );
975 playlist_Prev( p_playlist );
978 playlist_Next( p_playlist );
982 vlc_object_release( p_playlist );
986 /* Check if this is an auto generated menu item */
987 if( event.GetId() < FirstAutoGenerated_Event )
993 /* Check if this is an hotkey event */
994 if( event.GetId() >= i_hotkey_event &&
995 event.GetId() < i_hotkey_event + i_hotkeys )
1000 p_intf->p_libvlc->p_hotkeys[event.GetId() - i_hotkey_event].i_key;
1002 /* Get the key combination and send it to the hotkey handler */
1003 var_Set( p_intf->p_libvlc, "key-pressed", val );
1007 if( !p_main_interface ||
1008 (p_menuitem = p_main_interface->GetMenuBar()->FindItem(event.GetId()))
1011 if( p_intf->p_sys->p_popup_menu )
1014 p_intf->p_sys->p_popup_menu->FindItem( event.GetId() );
1020 wxMenuItemExt *p_menuitemext = (wxMenuItemExt *)p_menuitem;
1021 vlc_object_t *p_object;
1023 p_object = (vlc_object_t *)vlc_object_get( p_intf,
1024 p_menuitemext->i_object_id );
1025 if( p_object == NULL ) return;
1027 wxMutexGuiLeave(); // We don't want deadlocks
1028 var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val );
1029 //wxMutexGuiEnter();
1031 vlc_object_release( p_object );
1037 /*****************************************************************************
1038 * A small helper class which encapsulate wxMenuitem with some other useful
1040 *****************************************************************************/
1041 wxMenuItemExt::wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
1042 const wxString& helpString, wxItemKind kind,
1043 char *_psz_var, int _i_object_id, vlc_value_t _val, int _i_val_type ):
1044 wxMenuItem( parentMenu, id, text, helpString, kind )
1046 /* Initializations */
1048 i_val_type = _i_val_type;
1049 i_object_id = _i_object_id;
1053 wxMenuItemExt::~wxMenuItemExt()
1055 if( psz_var ) free( psz_var );
1056 if( ((i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
1057 && val.psz_string ) free( val.psz_string );