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 PUSH_VAR( "ffmpeg-pp-q" );
178 vlc_object_release( p_dec_obj );
183 int AudioAutoMenuBuilder( vlc_object_t *p_object, vector<int> &ri_objects,
184 vector<const char *> &rs_varnames )
186 PUSH_VAR( "audio-device" );
187 PUSH_VAR( "audio-channels" );
188 PUSH_VAR( "visual" );
189 PUSH_VAR( "equalizer" );
193 int IntfAutoMenuBuilder( intf_thread_t *p_intf, vector<int> &ri_objects,
194 vector<const char *> &rs_varnames, bool is_popup)
196 /* vlc_object_find is needed because of the dialogs provider case */
197 vlc_object_t *p_object;
198 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INTF,
200 if( p_object != NULL )
205 PUSH_VAR( "intf-switch" );
210 PUSH_VAR( "intf-switch" );
212 PUSH_VAR( "intf-add" );
213 PUSH_VAR( "intf-skins" );
214 vlc_object_release( p_object );
220 /*****************************************************************************
222 *****************************************************************************/
223 #define PUSH_VAR( var ) as_varnames.push_back( var ); \
224 ai_objects.push_back( p_object->i_object_id )
226 #define PUSH_SEPARATOR if( ai_objects.size() != i_last_separator ) { \
227 ai_objects.push_back( 0 ); \
228 as_varnames.push_back( "" ); \
229 i_last_separator = ai_objects.size(); }
231 #define POPUP_BOILERPLATE \
232 unsigned int i_last_separator = 0; \
233 vector<int> ai_objects; \
234 vector<const char *> as_varnames; \
235 playlist_t *p_playlist = (playlist_t *) vlc_object_find( p_intf, \
236 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );\
239 input_thread_t *p_input = p_playlist->p_input
241 #define CREATE_POPUP \
242 Menu popupmenu( p_intf, PopupMenu_Events ); \
243 popupmenu.Populate( as_varnames, ai_objects ); \
244 p_intf->p_sys->p_popup_menu = &popupmenu; \
245 p_parent->PopupMenu( &popupmenu, pos.x, pos.y ); \
246 p_intf->p_sys->p_popup_menu = NULL; \
247 i_last_separator = 0 /* stop compiler warning */
249 #define POPUP_STATIC_ENTRIES \
250 if( p_input != NULL ) \
253 popupmenu.InsertSeparator( 0 ); \
256 popupmenu.Insert( 0, Stop_Event, wxU(_("Stop")) ); \
257 popupmenu.Insert( 0, Previous_Event, wxU(_("Previous")) ); \
258 popupmenu.Insert( 0, Next_Event, wxU(_("Next")) ); \
261 var_Get( p_input, "state", &val ); \
262 if( val.i_int == PAUSE_S ) \
263 popupmenu.Insert( 0, Play_Event, wxU(_("Play")) ); \
265 popupmenu.Insert( 0, Pause_Event, wxU(_("Pause")) ); \
267 vlc_object_release( p_input ); \
271 if( p_playlist && p_playlist->i_size ) \
273 popupmenu.InsertSeparator( 0 ); \
274 popupmenu.Insert( 0, Play_Event, wxU(_("Play")) ); \
276 if( p_playlist ) vlc_object_release( p_playlist ); \
279 popupmenu.Append( MenuDummy_Event, wxU(_("Miscellaneous")), \
280 MiscMenu( p_intf ), wxT("") )
283 void VideoPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
289 vlc_object_yield( p_input );
290 as_varnames.push_back( "video-es" );
291 ai_objects.push_back( p_input->i_object_id );
292 as_varnames.push_back( "spu-es" );
293 ai_objects.push_back( p_input->i_object_id );
294 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
295 VLC_OBJECT_VOUT, FIND_CHILD );
298 VideoAutoMenuBuilder( p_vout, ai_objects, as_varnames );
299 vlc_object_release( p_vout );
301 vlc_object_release( p_input );
303 vlc_object_release( p_playlist );
307 void AudioPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
313 vlc_object_yield( p_input );
314 as_varnames.push_back( "audio-es" );
315 ai_objects.push_back( p_input->i_object_id );
316 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
317 VLC_OBJECT_AOUT, FIND_ANYWHERE );
320 AudioAutoMenuBuilder( p_aout, ai_objects, as_varnames );
321 vlc_object_release( p_aout );
323 vlc_object_release( p_input );
325 vlc_object_release( p_playlist );
329 /* Navigation stuff, and general */
330 void MiscPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
337 vlc_object_yield( p_input );
338 as_varnames.push_back( "audio-es" );
339 InputAutoMenuBuilder( VLC_OBJECT(p_input), ai_objects, as_varnames );
342 IntfAutoMenuBuilder( p_intf, ai_objects, as_varnames, true );
344 Menu popupmenu( p_intf, PopupMenu_Events );
345 popupmenu.Populate( as_varnames, ai_objects );
347 POPUP_STATIC_ENTRIES;
348 popupmenu.Append( MenuDummy_Event, wxU(_("Open")),
349 OpenStreamMenu( p_intf ), wxT("") );
351 p_intf->p_sys->p_popup_menu = &popupmenu;
352 p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
353 p_intf->p_sys->p_popup_menu = NULL;
354 vlc_object_release( p_playlist );
357 void PopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
360 int minimal = config_GetInt( p_intf, "wx-minimal" );
364 vlc_object_yield( p_input );
365 InputAutoMenuBuilder( VLC_OBJECT(p_input), ai_objects, as_varnames );
369 as_varnames.push_back( "video-es" );
370 ai_objects.push_back( p_input->i_object_id );
371 as_varnames.push_back( "spu-es" );
372 ai_objects.push_back( p_input->i_object_id );
373 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
374 VLC_OBJECT_VOUT, FIND_CHILD );
377 VideoAutoMenuBuilder( p_vout, ai_objects, as_varnames );
378 vlc_object_release( p_vout );
382 as_varnames.push_back( "audio-es" );
383 ai_objects.push_back( p_input->i_object_id );
384 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
385 VLC_OBJECT_AOUT, FIND_ANYWHERE );
388 AudioAutoMenuBuilder( p_aout, ai_objects, as_varnames );
389 vlc_object_release( p_aout );
395 IntfAutoMenuBuilder( p_intf, ai_objects, as_varnames, true );
398 Menu popupmenu( p_intf, PopupMenu_Events );
399 popupmenu.Populate( as_varnames, ai_objects );
400 POPUP_STATIC_ENTRIES;
404 popupmenu.Append( MenuDummy_Event, wxU(_("Open")),
405 OpenStreamMenu( p_intf ), wxT("") );
407 p_intf->p_sys->p_popup_menu = &popupmenu;
408 p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
409 p_intf->p_sys->p_popup_menu = NULL;
410 vlc_object_release( p_playlist );
413 /*****************************************************************************
415 *****************************************************************************/
416 wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
418 vlc_object_t *p_object;
419 vector<int> ai_objects;
420 vector<const char *> as_varnames;
422 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
424 if( p_object != NULL )
426 PUSH_VAR( "audio-es" );
427 vlc_object_release( p_object );
430 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_AOUT,
434 AudioAutoMenuBuilder( p_object, ai_objects, as_varnames );
435 vlc_object_release( p_object );
439 Menu *p_vlc_menu = (Menu *)p_menu;
441 p_vlc_menu = new Menu( _p_intf, AudioMenu_Events );
445 p_vlc_menu->Populate( as_varnames, ai_objects );
450 wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
452 vlc_object_t *p_object;
453 vector<int> ai_objects;
454 vector<const char *> as_varnames;
456 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
458 if( p_object != NULL )
460 PUSH_VAR( "video-es" );
461 PUSH_VAR( "spu-es" );
462 vlc_object_release( p_object );
465 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_VOUT,
467 if( p_object != NULL )
469 VideoAutoMenuBuilder( p_object, ai_objects, as_varnames );
470 vlc_object_release( p_object );
474 Menu *p_vlc_menu = (Menu *)p_menu;
476 p_vlc_menu = new Menu( _p_intf, VideoMenu_Events );
480 p_vlc_menu->Populate( as_varnames, ai_objects );
484 wxMenu *NavigMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
486 vlc_object_t *p_object;
487 vector<int> ai_objects;
488 vector<const char *> as_varnames;
490 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
492 if( p_object != NULL )
494 InputAutoMenuBuilder( p_object, ai_objects, as_varnames );
495 PUSH_VAR( "prev-title"); PUSH_VAR ( "next-title" );
496 PUSH_VAR( "prev-chapter"); PUSH_VAR( "next-chapter" );
497 vlc_object_release( p_object );
501 Menu *p_vlc_menu = (Menu *)p_menu;
503 p_vlc_menu = new Menu( _p_intf, NavigMenu_Events );
507 p_vlc_menu->Populate( as_varnames, ai_objects );
512 wxMenu *SettingsMenu( intf_thread_t *_p_intf, wxWindow *p_parent,
515 vlc_object_t *p_object;
516 vector<int> ai_objects;
517 vector<const char *> as_varnames;
519 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INTF,
521 if( p_object != NULL )
523 PUSH_VAR( "intf-switch" );
524 PUSH_VAR( "intf-add" );
525 vlc_object_release( p_object );
529 Menu *p_vlc_menu = (Menu *)p_menu;
531 p_vlc_menu = new Menu( _p_intf, SettingsMenu_Events );
535 p_vlc_menu->Populate( as_varnames, ai_objects );
540 /*****************************************************************************
542 *****************************************************************************/
543 Menu::Menu( intf_thread_t *_p_intf, int _i_start_id ) : wxMenu( )
545 /* Initializations */
547 i_start_id = _i_start_id;
554 /*****************************************************************************
556 *****************************************************************************/
557 void Menu::Populate( vector<const char *> & ras_varnames,
558 vector<int> & rai_objects )
560 vlc_object_t *p_object;
561 vlc_bool_t b_section_empty = VLC_FALSE;
564 i_item_id = i_start_id;
566 for( i = 0; i < (int)rai_objects.size() ; i++ )
568 if( !ras_varnames[i] || !*ras_varnames[i] )
570 if( b_section_empty )
572 Append( MenuDummy_Event + i, wxU(_("Empty")) );
573 Enable( MenuDummy_Event + i, FALSE );
576 b_section_empty = VLC_TRUE;
580 if( rai_objects[i] == 0 )
582 Append( MenuDummy_Event, wxU(ras_varnames[i]) );
583 b_section_empty = VLC_FALSE;
587 p_object = (vlc_object_t *)vlc_object_get( p_intf,
589 if( p_object == NULL ) continue;
591 b_section_empty = VLC_FALSE;
592 CreateMenuItem( this, ras_varnames[i], p_object );
593 vlc_object_release( p_object );
596 /* Special case for empty menus */
597 if( GetMenuItemCount() == 0 || b_section_empty )
599 Append( MenuDummy_Event + i, wxU(_("Empty")) );
600 Enable( MenuDummy_Event + i, FALSE );
604 /* Work-around helper for buggy wxGTK */
605 static void RecursiveDestroy( wxMenu *menu )
607 wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
610 wxMenuItem *item = node->GetData();
611 node = node->GetNext();
613 /* Delete the submenus */
614 wxMenu *submenu = item->GetSubMenu();
617 RecursiveDestroy( submenu );
619 menu->Delete( item );
625 RecursiveDestroy( this );
628 /*****************************************************************************
630 *****************************************************************************/
631 static bool IsMenuEmpty( const char *psz_var, vlc_object_t *p_object,
634 vlc_value_t val, val_list;
635 int i_type, i_result, i;
637 /* Check the type of the object variable */
638 i_type = var_Type( p_object, psz_var );
640 /* Check if we want to display the variable */
641 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
643 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
644 if( val.i_int == 0 ) return TRUE;
646 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
648 /* Very evil hack ! intf-switch can have only one value */
649 if( !strcmp( psz_var, "intf-switch" ) ) return FALSE;
650 if( val.i_int == 1 && b_root ) return TRUE;
654 /* Check children variables in case of VLC_VAR_VARIABLE */
655 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
660 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
662 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
670 /* clean up everything */
671 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
676 void Menu::CreateMenuItem( wxMenu *menu, const char *psz_var,
677 vlc_object_t *p_object )
679 wxMenuItemExt *menuitem;
680 vlc_value_t val, text;
683 /* Check the type of the object variable */
684 i_type = var_Type( p_object, psz_var );
686 switch( i_type & VLC_VAR_TYPE )
690 case VLC_VAR_VARIABLE:
692 case VLC_VAR_INTEGER:
696 /* Variable doesn't exist or isn't handled */
700 /* Make sure we want to display the variable */
701 if( IsMenuEmpty( psz_var, p_object ) ) return;
703 /* Get the descriptive name of the variable */
704 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
706 if( i_type & VLC_VAR_HASCHOICE )
708 menu->Append( MenuDummy_Event,
709 wxU(text.psz_string ? text.psz_string : psz_var),
710 CreateChoicesMenu( psz_var, p_object, TRUE ),
711 wxT("")/* Nothing for now (maybe use a GETLONGTEXT) */ );
713 if( text.psz_string ) free( text.psz_string );
718 switch( i_type & VLC_VAR_TYPE )
721 var_Get( p_object, psz_var, &val );
722 menuitem = new wxMenuItemExt( menu, ++i_item_id,
723 wxU(text.psz_string ?
724 text.psz_string : psz_var),
725 wxT(""), wxITEM_NORMAL, strdup(psz_var),
726 p_object->i_object_id, val, i_type );
727 menu->Append( menuitem );
731 var_Get( p_object, psz_var, &val );
732 val.b_bool = !val.b_bool;
733 menuitem = new wxMenuItemExt( menu, ++i_item_id,
734 wxU(text.psz_string ?
735 text.psz_string : psz_var),
736 wxT(""), wxITEM_CHECK, strdup(psz_var),
737 p_object->i_object_id, val, i_type );
738 menu->Append( menuitem );
739 Check( i_item_id, val.b_bool ? FALSE : TRUE );
743 if( text.psz_string ) free( text.psz_string );
746 wxMenu *Menu::CreateChoicesMenu( const char *psz_var, vlc_object_t *p_object,
749 vlc_value_t val, val_list, text_list;
752 /* Check the type of the object variable */
753 i_type = var_Type( p_object, psz_var );
755 /* Make sure we want to display the variable */
756 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return NULL;
758 switch( i_type & VLC_VAR_TYPE )
762 case VLC_VAR_VARIABLE:
764 case VLC_VAR_INTEGER:
768 /* Variable doesn't exist or isn't handled */
772 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
773 &val_list, &text_list ) < 0 )
778 wxMenu *menu = new wxMenu;
779 for( i = 0; i < val_list.p_list->i_count; i++ )
781 vlc_value_t another_val;
782 wxMenuItemExt *menuitem;
784 switch( i_type & VLC_VAR_TYPE )
786 case VLC_VAR_VARIABLE:
787 menu->Append( MenuDummy_Event,
788 wxU(text_list.p_list->p_values[i].psz_string ?
789 text_list.p_list->p_values[i].psz_string :
790 val_list.p_list->p_values[i].psz_string),
792 val_list.p_list->p_values[i].psz_string,
793 p_object, FALSE ), wxT("") );
797 var_Get( p_object, psz_var, &val );
799 another_val.psz_string =
800 strdup(val_list.p_list->p_values[i].psz_string);
802 new wxMenuItemExt( menu, ++i_item_id,
803 wxU(text_list.p_list->p_values[i].psz_string ?
804 text_list.p_list->p_values[i].psz_string :
805 another_val.psz_string), wxT(""),
806 i_type & VLC_VAR_ISCOMMAND ?
807 wxITEM_NORMAL : wxITEM_RADIO,
809 p_object->i_object_id, another_val, i_type );
811 menu->Append( menuitem );
813 if( !(i_type & VLC_VAR_ISCOMMAND) && val.psz_string &&
814 !strcmp( val.psz_string,
815 val_list.p_list->p_values[i].psz_string ) )
816 menu->Check( i_item_id, TRUE );
818 if( val.psz_string ) free( val.psz_string );
821 case VLC_VAR_INTEGER:
822 var_Get( p_object, psz_var, &val );
825 new wxMenuItemExt( menu, ++i_item_id,
826 text_list.p_list->p_values[i].psz_string ?
828 text_list.p_list->p_values[i].psz_string) :
829 wxString::Format(wxT("%d"),
830 val_list.p_list->p_values[i].i_int), wxT(""),
831 i_type & VLC_VAR_ISCOMMAND ?
832 wxITEM_NORMAL : wxITEM_RADIO,
834 p_object->i_object_id,
835 val_list.p_list->p_values[i], i_type );
837 menu->Append( menuitem );
839 if( !(i_type & VLC_VAR_ISCOMMAND) &&
840 val_list.p_list->p_values[i].i_int == val.i_int )
841 menu->Check( i_item_id, TRUE );
845 var_Get( p_object, psz_var, &val );
848 new wxMenuItemExt( menu, ++i_item_id,
849 text_list.p_list->p_values[i].psz_string ?
851 text_list.p_list->p_values[i].psz_string) :
852 wxString::Format(wxT("%.2f"),
853 val_list.p_list->p_values[i].f_float),wxT(""),
854 i_type & VLC_VAR_ISCOMMAND ?
855 wxITEM_NORMAL : wxITEM_RADIO,
857 p_object->i_object_id,
858 val_list.p_list->p_values[i], i_type );
860 menu->Append( menuitem );
862 if( !(i_type & VLC_VAR_ISCOMMAND) &&
863 val_list.p_list->p_values[i].f_float == val.f_float )
864 menu->Check( i_item_id, TRUE );
872 /* clean up everything */
873 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
878 /*****************************************************************************
879 * A small helper class which intercepts all popup menu events
880 *****************************************************************************/
881 MenuEvtHandler::MenuEvtHandler( intf_thread_t *_p_intf,
882 Interface *_p_main_interface )
884 /* Initializations */
886 p_main_interface = _p_main_interface;
889 MenuEvtHandler::~MenuEvtHandler()
893 void MenuEvtHandler::OnShowDialog( wxCommandEvent& event )
895 if( p_intf->p_sys->pf_show_dialog )
899 switch( event.GetId() )
901 case OpenFileSimple_Event:
902 i_id = INTF_DIALOG_FILE_SIMPLE;
905 i_id = INTF_DIALOG_FILE;
907 case OpenDirectory_Event:
908 i_id = INTF_DIALOG_DIRECTORY;
911 i_id = INTF_DIALOG_DISC;
914 i_id = INTF_DIALOG_NET;
916 case OpenCapture_Event:
917 i_id = INTF_DIALOG_CAPTURE;
919 case MediaInfo_Event:
920 i_id = INTF_DIALOG_FILEINFO;
923 i_id = INTF_DIALOG_MESSAGES;
925 case Preferences_Event:
926 i_id = INTF_DIALOG_PREFS;
929 i_id = INTF_DIALOG_FILE;
934 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
938 void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
940 wxMenuItem *p_menuitem = NULL;
941 int i_hotkey_event = p_intf->p_sys->i_first_hotkey_event;
942 int i_hotkeys = p_intf->p_sys->i_hotkeys;
944 if( event.GetId() >= Play_Event && event.GetId() <= Stop_Event )
946 input_thread_t *p_input;
947 playlist_t * p_playlist =
948 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
950 if( !p_playlist ) return;
952 switch( event.GetId() )
957 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
959 if( !p_input ) playlist_Play( p_playlist );
963 var_Get( p_input, "state", &val );
964 if( val.i_int != PAUSE_S ) val.i_int = PAUSE_S;
965 else val.i_int = PLAYING_S;
966 var_Set( p_input, "state", val );
967 vlc_object_release( p_input );
971 playlist_Stop( p_playlist );
974 playlist_Prev( p_playlist );
977 playlist_Next( p_playlist );
981 vlc_object_release( p_playlist );
985 /* Check if this is an auto generated menu item */
986 if( event.GetId() < FirstAutoGenerated_Event )
992 /* Check if this is an hotkey event */
993 if( event.GetId() >= i_hotkey_event &&
994 event.GetId() < i_hotkey_event + i_hotkeys )
999 p_intf->p_vlc->p_hotkeys[event.GetId() - i_hotkey_event].i_key;
1001 /* Get the key combination and send it to the hotkey handler */
1002 var_Set( p_intf->p_vlc, "key-pressed", val );
1006 if( !p_main_interface ||
1007 (p_menuitem = p_main_interface->GetMenuBar()->FindItem(event.GetId()))
1010 if( p_intf->p_sys->p_popup_menu )
1013 p_intf->p_sys->p_popup_menu->FindItem( event.GetId() );
1019 wxMenuItemExt *p_menuitemext = (wxMenuItemExt *)p_menuitem;
1020 vlc_object_t *p_object;
1022 p_object = (vlc_object_t *)vlc_object_get( p_intf,
1023 p_menuitemext->i_object_id );
1024 if( p_object == NULL ) return;
1026 wxMutexGuiLeave(); // We don't want deadlocks
1027 var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val );
1028 //wxMutexGuiEnter();
1030 vlc_object_release( p_object );
1036 /*****************************************************************************
1037 * A small helper class which encapsulate wxMenuitem with some other useful
1039 *****************************************************************************/
1040 wxMenuItemExt::wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
1041 const wxString& helpString, wxItemKind kind,
1042 char *_psz_var, int _i_object_id, vlc_value_t _val, int _i_val_type ):
1043 wxMenuItem( parentMenu, id, text, helpString, kind )
1045 /* Initializations */
1047 i_val_type = _i_val_type;
1048 i_object_id = _i_object_id;
1052 wxMenuItemExt::~wxMenuItemExt()
1054 if( psz_var ) free( psz_var );
1055 if( ((i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
1056 && val.psz_string ) free( val.psz_string );