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"
34 class wxMenuItemExt: public wxMenuItem
38 wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
39 const wxString& helpString, wxItemKind kind,
40 char *_psz_var, int _i_object_id, vlc_value_t _val,
42 virtual ~wxMenuItemExt();
50 class Menu: public wxMenu
54 Menu( intf_thread_t *p_intf, int i_start_id );
57 void Populate( vector<string> &, vector<int> &);
61 wxMenu *CreateDummyMenu();
62 void CreateMenuItem( wxMenu *, char *, vlc_object_t * );
63 wxMenu *CreateChoicesMenu( char *, vlc_object_t *, bool );
65 DECLARE_EVENT_TABLE();
67 intf_thread_t *p_intf;
73 /*****************************************************************************
75 *****************************************************************************/
79 MenuDummy_Event = wxID_HIGHEST + 1000,
80 OpenFileSimple_Event = wxID_HIGHEST + 1100,
94 FirstAutoGenerated_Event = wxID_HIGHEST + 1999,
95 SettingsMenu_Events = wxID_HIGHEST + 5000,
96 AudioMenu_Events = wxID_HIGHEST + 2000,
97 VideoMenu_Events = wxID_HIGHEST + 3000,
98 NavigMenu_Events = wxID_HIGHEST + 4000,
99 PopupMenu_Events = wxID_HIGHEST + 6000,
100 Hotkeys_Events = wxID_HIGHEST + 7000
103 BEGIN_EVENT_TABLE(Menu, wxMenu)
106 BEGIN_EVENT_TABLE(MenuEvtHandler, wxEvtHandler)
107 EVT_MENU(OpenFileSimple_Event, MenuEvtHandler::OnShowDialog)
108 EVT_MENU(OpenFile_Event, MenuEvtHandler::OnShowDialog)
109 EVT_MENU(OpenDirectory_Event, MenuEvtHandler::OnShowDialog)
110 EVT_MENU(OpenDisc_Event, MenuEvtHandler::OnShowDialog)
111 EVT_MENU(OpenNet_Event, MenuEvtHandler::OnShowDialog)
112 EVT_MENU(OpenCapture_Event, MenuEvtHandler::OnShowDialog)
113 EVT_MENU(MediaInfo_Event, MenuEvtHandler::OnShowDialog)
114 EVT_MENU(Messages_Event, MenuEvtHandler::OnShowDialog)
115 EVT_MENU(Preferences_Event, MenuEvtHandler::OnShowDialog)
116 EVT_MENU(-1, MenuEvtHandler::OnMenuEvent)
119 /*****************************************************************************
120 * Static menu helpers
121 *****************************************************************************/
122 wxMenu *OpenStreamMenu( intf_thread_t *p_intf )
124 wxMenu *menu = new wxMenu;
125 menu->Append( OpenFileSimple_Event, wxU(_("Quick &Open File...")) );
126 menu->Append( OpenFile_Event, wxU(_("Open &File...")) );
127 menu->Append( OpenDirectory_Event, wxU(_("Open D&irectory...")) );
128 menu->Append( OpenDisc_Event, wxU(_("Open &Disc...")) );
129 menu->Append( OpenNet_Event, wxU(_("Open &Network Stream...")) );
130 menu->Append( OpenCapture_Event, wxU(_("Open &Capture Device...")) );
134 wxMenu *MiscMenu( intf_thread_t *p_intf )
136 wxMenu *menu = new wxMenu;
137 menu->Append( MediaInfo_Event, wxU(_("Media &Info...")) );
138 menu->Append( Messages_Event, wxU(_("&Messages...")) );
139 menu->Append( Preferences_Event, wxU(_("&Preferences...")) );
143 /*****************************************************************************
144 * Builders for the dynamic menus
145 *****************************************************************************/
146 #define PUSH_VAR( var ) rs_varnames.push_back( var ); \
147 ri_objects.push_back( p_object->i_object_id );
149 int InputAutoMenuBuilder( vlc_object_t *p_object,
150 vector<int> &ri_objects, vector<string> &rs_varnames )
152 PUSH_VAR( "bookmark");
154 PUSH_VAR ("chapter" );
155 PUSH_VAR( "program" );
156 PUSH_VAR( "navigation" );
157 PUSH_VAR( "dvd_menus" );
161 int VideoAutoMenuBuilder( vlc_object_t *p_object,
162 vector<int> &ri_objects, vector<string> &rs_varnames )
164 PUSH_VAR( "fullscreen" );
166 PUSH_VAR( "deinterlace" );
167 PUSH_VAR( "aspect-ratio" );
169 PUSH_VAR( "video-on-top" );
170 PUSH_VAR( "directx-wallpaper" );
171 PUSH_VAR( "video-snapshot" );
173 vlc_object_t *p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
176 if( p_dec_obj != NULL )
178 PUSH_VAR( "ffmpeg-pp-q" );
179 vlc_object_release( p_dec_obj );
184 int AudioAutoMenuBuilder( vlc_object_t *p_object,
185 vector<int> &ri_objects, vector<string> &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,
195 vector<int> &ri_objects, vector<string> &rs_varnames )
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 )
203 PUSH_VAR( "intf-add" );
204 PUSH_VAR( "intf-skins" );
205 vlc_object_release( p_object );
211 /*****************************************************************************
213 *****************************************************************************/
214 #define PUSH_VAR( var ) as_varnames.push_back( var ); \
215 ai_objects.push_back( p_object->i_object_id );
216 #define PUSH_SEPARATOR if( ai_objects.size() != i_last_separator ) { \
217 ai_objects.push_back( 0 ); \
218 as_varnames.push_back( "" ); \
219 i_last_separator = ai_objects.size(); }
221 #define POPUP_BOILERPLATE \
222 unsigned int i_last_separator = 0; \
223 vector<int> ai_objects; \
224 vector<string> as_varnames; \
225 playlist_t *p_playlist = (playlist_t *) vlc_object_find( p_intf, \
226 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );\
229 input_thread_t *p_input = p_playlist->p_input;
231 #define CREATE_POPUP \
232 Menu popupmenu( p_intf, PopupMenu_Events ); \
233 popupmenu.Populate( as_varnames, ai_objects ); \
234 p_intf->p_sys->p_popup_menu = &popupmenu; \
235 p_parent->PopupMenu( &popupmenu, pos.x, pos.y ); \
236 p_intf->p_sys->p_popup_menu = NULL; \
238 #define POPUP_STATIC_ENTRIES \
239 if( p_input != NULL ) \
242 popupmenu.InsertSeparator( 0 ); \
245 popupmenu.Insert( 0, Stop_Event, wxU(_("Stop")) ); \
246 popupmenu.Insert( 0, Previous_Event, wxU(_("Previous")) ); \
247 popupmenu.Insert( 0, Next_Event, wxU(_("Next")) ); \
250 var_Get( p_input, "state", &val ); \
251 if( val.i_int == PAUSE_S ) \
252 popupmenu.Insert( 0, Play_Event, wxU(_("Play")) ); \
254 popupmenu.Insert( 0, Pause_Event, wxU(_("Pause")) ); \
256 vlc_object_release( p_input ); \
260 if( p_playlist && p_playlist->i_size ) \
262 popupmenu.InsertSeparator( 0 ); \
263 popupmenu.Insert( 0, Play_Event, wxU(_("Play")) ); \
265 if( p_playlist ) vlc_object_release( p_playlist ); \
268 popupmenu.Append( MenuDummy_Event, wxU(_("Miscellaneous")), \
269 MiscMenu( p_intf ), wxT("") ); \
272 void VideoPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
278 vlc_object_yield( p_input );
279 as_varnames.push_back( "video-es" );
280 ai_objects.push_back( p_input->i_object_id );
281 as_varnames.push_back( "spu-es" );
282 ai_objects.push_back( p_input->i_object_id );
283 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
284 VLC_OBJECT_VOUT, FIND_CHILD );
287 VideoAutoMenuBuilder( p_vout, ai_objects, as_varnames );
288 vlc_object_release( p_vout );
290 vlc_object_release( p_input );
292 vlc_object_release( p_playlist );
296 void AudioPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
302 vlc_object_yield( p_input );
303 as_varnames.push_back( "audio-es" );
304 ai_objects.push_back( p_input->i_object_id );
305 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
306 VLC_OBJECT_AOUT, FIND_ANYWHERE );
309 AudioAutoMenuBuilder( p_aout, ai_objects, as_varnames );
310 vlc_object_release( p_aout );
312 vlc_object_release( p_input );
314 vlc_object_release( p_playlist );
318 /* Navigation stuff, and general */
319 void MiscPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
326 vlc_object_yield( p_input );
327 as_varnames.push_back( "audio-es" );
328 InputAutoMenuBuilder( VLC_OBJECT(p_input), ai_objects, as_varnames );
331 IntfAutoMenuBuilder( p_intf, ai_objects, as_varnames );
333 Menu popupmenu( p_intf, PopupMenu_Events );
334 popupmenu.Populate( as_varnames, ai_objects );
336 POPUP_STATIC_ENTRIES;
337 popupmenu.Append( MenuDummy_Event, wxU(_("Open")),
338 OpenStreamMenu( p_intf ), wxT("") );
340 p_intf->p_sys->p_popup_menu = &popupmenu;
341 p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
342 p_intf->p_sys->p_popup_menu = NULL;
343 vlc_object_release( p_playlist );
346 void PopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
349 int minimal = config_GetInt( p_intf, "wx-minimal" );
353 vlc_object_yield( p_input );
354 InputAutoMenuBuilder( VLC_OBJECT(p_input), ai_objects, as_varnames );
358 as_varnames.push_back( "video-es" );
359 ai_objects.push_back( p_input->i_object_id );
360 as_varnames.push_back( "spu-es" );
361 ai_objects.push_back( p_input->i_object_id );
362 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
363 VLC_OBJECT_VOUT, FIND_CHILD );
366 VideoAutoMenuBuilder( p_vout, ai_objects, as_varnames );
367 vlc_object_release( p_vout );
371 as_varnames.push_back( "audio-es" );
372 ai_objects.push_back( p_input->i_object_id );
373 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
374 VLC_OBJECT_AOUT, FIND_ANYWHERE );
377 AudioAutoMenuBuilder( p_aout, ai_objects, as_varnames );
378 vlc_object_release( p_aout );
384 IntfAutoMenuBuilder( p_intf, ai_objects, as_varnames );
387 Menu popupmenu( p_intf, PopupMenu_Events );
388 popupmenu.Populate( as_varnames, ai_objects );
389 POPUP_STATIC_ENTRIES;
393 popupmenu.Append( MenuDummy_Event, wxU(_("Open")),
394 OpenStreamMenu( p_intf ), wxT("") );
396 p_intf->p_sys->p_popup_menu = &popupmenu;
397 p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
398 p_intf->p_sys->p_popup_menu = NULL;
399 vlc_object_release( p_playlist );
402 /*****************************************************************************
404 *****************************************************************************/
405 wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
407 vlc_object_t *p_object;
408 vector<int> ai_objects;
409 vector<string> as_varnames;
411 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
413 if( p_object != NULL )
415 PUSH_VAR( "audio-es" );
416 vlc_object_release( p_object );
419 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_AOUT,
423 AudioAutoMenuBuilder( p_object, ai_objects, as_varnames );
424 vlc_object_release( p_object );
428 Menu *p_vlc_menu = (Menu *)p_menu;
430 p_vlc_menu = new Menu( _p_intf, AudioMenu_Events );
434 p_vlc_menu->Populate( as_varnames, ai_objects );
439 wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
441 vlc_object_t *p_object;
442 vector<int> ai_objects;
443 vector<string> as_varnames;
445 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
447 if( p_object != NULL )
449 PUSH_VAR( "video-es" );
450 PUSH_VAR( "spu-es" );
451 vlc_object_release( p_object );
454 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_VOUT,
456 if( p_object != NULL )
458 VideoAutoMenuBuilder( p_object, ai_objects, as_varnames );
459 vlc_object_release( p_object );
463 Menu *p_vlc_menu = (Menu *)p_menu;
465 p_vlc_menu = new Menu( _p_intf, VideoMenu_Events );
469 p_vlc_menu->Populate( as_varnames, ai_objects );
473 wxMenu *NavigMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
475 vlc_object_t *p_object;
476 vector<int> ai_objects;
477 vector<string> as_varnames;
479 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
481 if( p_object != NULL )
483 InputAutoMenuBuilder( p_object, ai_objects, as_varnames );
484 PUSH_VAR( "prev-title"); PUSH_VAR ( "next-title" );
485 PUSH_VAR( "prev-chapter"); PUSH_VAR( "next-chapter" );
486 vlc_object_release( p_object );
490 Menu *p_vlc_menu = (Menu *)p_menu;
492 p_vlc_menu = new Menu( _p_intf, NavigMenu_Events );
496 p_vlc_menu->Populate( as_varnames, ai_objects );
501 wxMenu *SettingsMenu( intf_thread_t *_p_intf, wxWindow *p_parent,
504 vlc_object_t *p_object;
505 vector<int> ai_objects;
506 vector<string> as_varnames;
508 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INTF,
510 if( p_object != NULL )
512 PUSH_VAR( "intf-add" );
513 vlc_object_release( p_object );
517 Menu *p_vlc_menu = (Menu *)p_menu;
519 p_vlc_menu = new Menu( _p_intf, SettingsMenu_Events );
523 p_vlc_menu->Populate( as_varnames, ai_objects );
528 /*****************************************************************************
530 *****************************************************************************/
531 Menu::Menu( intf_thread_t *_p_intf, int _i_start_id ) : wxMenu( )
533 /* Initializations */
535 i_start_id = _i_start_id;
542 /*****************************************************************************
544 *****************************************************************************/
545 void Menu::Populate( vector<string> & ras_varnames, vector<int> & rai_objects )
547 vlc_object_t *p_object;
548 vlc_bool_t b_section_empty = VLC_FALSE;
551 i_item_id = i_start_id;
553 for( i = 0; i < rai_objects.size() ; i++ )
555 if( ras_varnames[i] == "" )
557 if( b_section_empty )
559 Append( MenuDummy_Event + i, wxU(_("Empty")) );
560 Enable( MenuDummy_Event + i, FALSE );
563 b_section_empty = VLC_TRUE;
567 if( rai_objects[i] == 0 )
569 Append( MenuDummy_Event, wxU(ras_varnames[i].c_str()) );
570 b_section_empty = VLC_FALSE;
574 p_object = (vlc_object_t *)vlc_object_get( p_intf,
576 if( p_object == NULL ) continue;
578 b_section_empty = VLC_FALSE;
579 CreateMenuItem( this, ras_varnames[i].c_str(), p_object );
580 vlc_object_release( p_object );
583 /* Special case for empty menus */
584 if( GetMenuItemCount() == 0 || b_section_empty )
586 Append( MenuDummy_Event + i, wxU(_("Empty")) );
587 Enable( MenuDummy_Event + i, FALSE );
591 /* Work-around helper for buggy wxGTK */
592 static void RecursiveDestroy( wxMenu *menu )
594 wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
597 wxMenuItem *item = node->GetData();
598 node = node->GetNext();
600 /* Delete the submenus */
601 wxMenu *submenu = item->GetSubMenu();
604 RecursiveDestroy( submenu );
606 menu->Delete( item );
612 RecursiveDestroy( this );
615 /*****************************************************************************
617 *****************************************************************************/
618 static bool IsMenuEmpty( char *psz_var, vlc_object_t *p_object,
621 vlc_value_t val, val_list;
622 int i_type, i_result, i;
624 /* Check the type of the object variable */
625 i_type = var_Type( p_object, psz_var );
627 /* Check if we want to display the variable */
628 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
630 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
631 if( val.i_int == 0 ) return TRUE;
633 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
635 if( val.i_int == 1 && b_root ) return TRUE;
639 /* Check children variables in case of VLC_VAR_VARIABLE */
640 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
645 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
647 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
655 /* clean up everything */
656 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
661 void Menu::CreateMenuItem( wxMenu *menu, char *psz_var,
662 vlc_object_t *p_object )
664 wxMenuItemExt *menuitem;
665 vlc_value_t val, text;
668 /* Check the type of the object variable */
669 i_type = var_Type( p_object, psz_var );
671 switch( i_type & VLC_VAR_TYPE )
675 case VLC_VAR_VARIABLE:
677 case VLC_VAR_INTEGER:
681 /* Variable doesn't exist or isn't handled */
685 /* Make sure we want to display the variable */
686 if( IsMenuEmpty( psz_var, p_object ) ) return;
688 /* Get the descriptive name of the variable */
689 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
691 if( i_type & VLC_VAR_HASCHOICE )
693 menu->Append( MenuDummy_Event,
694 wxU(text.psz_string ? text.psz_string : psz_var),
695 CreateChoicesMenu( psz_var, p_object, TRUE ),
696 wxT("")/* Nothing for now (maybe use a GETLONGTEXT) */ );
698 if( text.psz_string ) free( text.psz_string );
703 switch( i_type & VLC_VAR_TYPE )
706 var_Get( p_object, psz_var, &val );
707 menuitem = new wxMenuItemExt( menu, ++i_item_id,
708 wxU(text.psz_string ?
709 text.psz_string : psz_var),
710 wxT(""), wxITEM_NORMAL, strdup(psz_var),
711 p_object->i_object_id, val, i_type );
712 menu->Append( menuitem );
716 var_Get( p_object, psz_var, &val );
717 val.b_bool = !val.b_bool;
718 menuitem = new wxMenuItemExt( menu, ++i_item_id,
719 wxU(text.psz_string ?
720 text.psz_string : psz_var),
721 wxT(""), wxITEM_CHECK, strdup(psz_var),
722 p_object->i_object_id, val, i_type );
723 menu->Append( menuitem );
724 Check( i_item_id, val.b_bool ? FALSE : TRUE );
728 if( text.psz_string ) free( text.psz_string );
731 wxMenu *Menu::CreateChoicesMenu( char *psz_var, vlc_object_t *p_object,
734 vlc_value_t val, val_list, text_list;
737 /* Check the type of the object variable */
738 i_type = var_Type( p_object, psz_var );
740 /* Make sure we want to display the variable */
741 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return NULL;
743 switch( i_type & VLC_VAR_TYPE )
747 case VLC_VAR_VARIABLE:
749 case VLC_VAR_INTEGER:
753 /* Variable doesn't exist or isn't handled */
757 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
758 &val_list, &text_list ) < 0 )
763 wxMenu *menu = new wxMenu;
764 for( i = 0; i < val_list.p_list->i_count; i++ )
766 vlc_value_t another_val;
767 wxMenuItemExt *menuitem;
769 switch( i_type & VLC_VAR_TYPE )
771 case VLC_VAR_VARIABLE:
772 menu->Append( MenuDummy_Event,
773 wxU(text_list.p_list->p_values[i].psz_string ?
774 text_list.p_list->p_values[i].psz_string :
775 val_list.p_list->p_values[i].psz_string),
777 val_list.p_list->p_values[i].psz_string,
778 p_object, FALSE ), wxT("") );
782 var_Get( p_object, psz_var, &val );
784 another_val.psz_string =
785 strdup(val_list.p_list->p_values[i].psz_string);
787 new wxMenuItemExt( menu, ++i_item_id,
788 wxU(text_list.p_list->p_values[i].psz_string ?
789 text_list.p_list->p_values[i].psz_string :
790 another_val.psz_string), wxT(""),
791 i_type & VLC_VAR_ISCOMMAND ?
792 wxITEM_NORMAL : wxITEM_RADIO,
794 p_object->i_object_id, another_val, i_type );
796 menu->Append( menuitem );
798 if( !(i_type & VLC_VAR_ISCOMMAND) && val.psz_string &&
799 !strcmp( val.psz_string,
800 val_list.p_list->p_values[i].psz_string ) )
801 menu->Check( i_item_id, TRUE );
803 if( val.psz_string ) free( val.psz_string );
806 case VLC_VAR_INTEGER:
807 var_Get( p_object, psz_var, &val );
810 new wxMenuItemExt( menu, ++i_item_id,
811 text_list.p_list->p_values[i].psz_string ?
813 text_list.p_list->p_values[i].psz_string) :
814 wxString::Format(wxT("%d"),
815 val_list.p_list->p_values[i].i_int), wxT(""),
816 i_type & VLC_VAR_ISCOMMAND ?
817 wxITEM_NORMAL : wxITEM_RADIO,
819 p_object->i_object_id,
820 val_list.p_list->p_values[i], i_type );
822 menu->Append( menuitem );
824 if( !(i_type & VLC_VAR_ISCOMMAND) &&
825 val_list.p_list->p_values[i].i_int == val.i_int )
826 menu->Check( i_item_id, TRUE );
830 var_Get( p_object, psz_var, &val );
833 new wxMenuItemExt( menu, ++i_item_id,
834 text_list.p_list->p_values[i].psz_string ?
836 text_list.p_list->p_values[i].psz_string) :
837 wxString::Format(wxT("%.2f"),
838 val_list.p_list->p_values[i].f_float),wxT(""),
839 i_type & VLC_VAR_ISCOMMAND ?
840 wxITEM_NORMAL : wxITEM_RADIO,
842 p_object->i_object_id,
843 val_list.p_list->p_values[i], i_type );
845 menu->Append( menuitem );
847 if( !(i_type & VLC_VAR_ISCOMMAND) &&
848 val_list.p_list->p_values[i].f_float == val.f_float )
849 menu->Check( i_item_id, TRUE );
857 /* clean up everything */
858 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
863 /*****************************************************************************
864 * A small helper class which intercepts all popup menu events
865 *****************************************************************************/
866 MenuEvtHandler::MenuEvtHandler( intf_thread_t *_p_intf,
867 Interface *_p_main_interface )
869 /* Initializations */
871 p_main_interface = _p_main_interface;
874 MenuEvtHandler::~MenuEvtHandler()
878 void MenuEvtHandler::OnShowDialog( wxCommandEvent& event )
880 if( p_intf->p_sys->pf_show_dialog )
884 switch( event.GetId() )
886 case OpenFileSimple_Event:
887 i_id = INTF_DIALOG_FILE_SIMPLE;
890 i_id = INTF_DIALOG_FILE;
892 case OpenDirectory_Event:
893 i_id = INTF_DIALOG_DIRECTORY;
896 i_id = INTF_DIALOG_DISC;
899 i_id = INTF_DIALOG_NET;
901 case OpenCapture_Event:
902 i_id = INTF_DIALOG_CAPTURE;
904 case MediaInfo_Event:
905 i_id = INTF_DIALOG_FILEINFO;
908 i_id = INTF_DIALOG_MESSAGES;
910 case Preferences_Event:
911 i_id = INTF_DIALOG_PREFS;
914 i_id = INTF_DIALOG_FILE;
919 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
923 void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
925 wxMenuItem *p_menuitem = NULL;
926 int i_hotkey_event = p_intf->p_sys->i_first_hotkey_event;
927 int i_hotkeys = p_intf->p_sys->i_hotkeys;
929 if( event.GetId() >= Play_Event && event.GetId() <= Stop_Event )
931 input_thread_t *p_input;
932 playlist_t * p_playlist =
933 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
935 if( !p_playlist ) return;
937 switch( event.GetId() )
942 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
944 if( !p_input ) playlist_Play( p_playlist );
948 var_Get( p_input, "state", &val );
949 if( val.i_int != PAUSE_S ) val.i_int = PAUSE_S;
950 else val.i_int = PLAYING_S;
951 var_Set( p_input, "state", val );
952 vlc_object_release( p_input );
956 playlist_Stop( p_playlist );
959 playlist_Prev( p_playlist );
962 playlist_Next( p_playlist );
966 vlc_object_release( p_playlist );
970 /* Check if this is an auto generated menu item */
971 if( event.GetId() < FirstAutoGenerated_Event )
977 /* Check if this is an hotkey event */
978 if( event.GetId() >= i_hotkey_event &&
979 event.GetId() < i_hotkey_event + i_hotkeys )
984 p_intf->p_vlc->p_hotkeys[event.GetId() - i_hotkey_event].i_key;
986 /* Get the key combination and send it to the hotkey handler */
987 var_Set( p_intf->p_vlc, "key-pressed", val );
991 if( !p_main_interface ||
992 (p_menuitem = p_main_interface->GetMenuBar()->FindItem(event.GetId()))
995 if( p_intf->p_sys->p_popup_menu )
998 p_intf->p_sys->p_popup_menu->FindItem( event.GetId() );
1004 wxMenuItemExt *p_menuitemext = (wxMenuItemExt *)p_menuitem;
1005 vlc_object_t *p_object;
1007 p_object = (vlc_object_t *)vlc_object_get( p_intf,
1008 p_menuitemext->i_object_id );
1009 if( p_object == NULL ) return;
1011 wxMutexGuiLeave(); // We don't want deadlocks
1012 var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val );
1013 //wxMutexGuiEnter();
1015 vlc_object_release( p_object );
1021 /*****************************************************************************
1022 * A small helper class which encapsulate wxMenuitem with some other useful
1024 *****************************************************************************/
1025 wxMenuItemExt::wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
1026 const wxString& helpString, wxItemKind kind,
1027 char *_psz_var, int _i_object_id, vlc_value_t _val, int _i_val_type ):
1028 wxMenuItem( parentMenu, id, text, helpString, kind )
1030 /* Initializations */
1032 i_val_type = _i_val_type;
1033 i_object_id = _i_object_id;
1037 wxMenuItemExt::~wxMenuItemExt()
1039 if( psz_var ) free( psz_var );
1040 if( ((i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
1041 && val.psz_string ) free( val.psz_string );