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 *, const 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,
198 /* vlc_object_find is needed because of the dialogs provider case */
199 vlc_object_t *p_object;
200 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INTF,
202 if( p_object != NULL )
207 PUSH_VAR( "intf-switch" );
212 PUSH_VAR( "intf-switch" );
214 PUSH_VAR( "intf-add" );
215 PUSH_VAR( "intf-skins" );
216 vlc_object_release( p_object );
222 /*****************************************************************************
224 *****************************************************************************/
225 #define PUSH_VAR( var ) as_varnames.push_back( var ); \
226 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<string> 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; \
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<string> 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<string> 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<string> 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<string> 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<string> & ras_varnames, vector<int> & rai_objects )
559 vlc_object_t *p_object;
560 vlc_bool_t b_section_empty = VLC_FALSE;
563 i_item_id = i_start_id;
565 for( i = 0; i < rai_objects.size() ; i++ )
567 if( ras_varnames[i] == "" )
569 if( b_section_empty )
571 Append( MenuDummy_Event + i, wxU(_("Empty")) );
572 Enable( MenuDummy_Event + i, FALSE );
575 b_section_empty = VLC_TRUE;
579 if( rai_objects[i] == 0 )
581 Append( MenuDummy_Event, wxU(ras_varnames[i].c_str()) );
582 b_section_empty = VLC_FALSE;
586 p_object = (vlc_object_t *)vlc_object_get( p_intf,
588 if( p_object == NULL ) continue;
590 b_section_empty = VLC_FALSE;
591 CreateMenuItem( this, ras_varnames[i].c_str(), p_object );
592 vlc_object_release( p_object );
595 /* Special case for empty menus */
596 if( GetMenuItemCount() == 0 || b_section_empty )
598 Append( MenuDummy_Event + i, wxU(_("Empty")) );
599 Enable( MenuDummy_Event + i, FALSE );
603 /* Work-around helper for buggy wxGTK */
604 static void RecursiveDestroy( wxMenu *menu )
606 wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
609 wxMenuItem *item = node->GetData();
610 node = node->GetNext();
612 /* Delete the submenus */
613 wxMenu *submenu = item->GetSubMenu();
616 RecursiveDestroy( submenu );
618 menu->Delete( item );
624 RecursiveDestroy( this );
627 /*****************************************************************************
629 *****************************************************************************/
630 static bool IsMenuEmpty( char *psz_var, vlc_object_t *p_object,
633 vlc_value_t val, val_list;
634 int i_type, i_result, i;
636 /* Check the type of the object variable */
637 i_type = var_Type( p_object, psz_var );
639 /* Check if we want to display the variable */
640 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
642 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
643 if( val.i_int == 0 ) return TRUE;
645 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
647 /* Very evil hack ! intf-switch can have only one value */
648 if( !strcmp( psz_var, "intf-switch" ) ) return FALSE;
649 if( val.i_int == 1 && b_root ) return TRUE;
653 /* Check children variables in case of VLC_VAR_VARIABLE */
654 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
659 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
661 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
669 /* clean up everything */
670 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
675 void Menu::CreateMenuItem( wxMenu *menu, const char *psz_var,
676 vlc_object_t *p_object )
678 wxMenuItemExt *menuitem;
679 vlc_value_t val, text;
682 /* Check the type of the object variable */
683 i_type = var_Type( p_object, psz_var );
685 switch( i_type & VLC_VAR_TYPE )
689 case VLC_VAR_VARIABLE:
691 case VLC_VAR_INTEGER:
695 /* Variable doesn't exist or isn't handled */
699 /* Make sure we want to display the variable */
700 if( IsMenuEmpty( psz_var, p_object ) ) return;
702 /* Get the descriptive name of the variable */
703 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
705 if( i_type & VLC_VAR_HASCHOICE )
707 menu->Append( MenuDummy_Event,
708 wxU(text.psz_string ? text.psz_string : psz_var),
709 CreateChoicesMenu( psz_var, p_object, TRUE ),
710 wxT("")/* Nothing for now (maybe use a GETLONGTEXT) */ );
712 if( text.psz_string ) free( text.psz_string );
717 switch( i_type & VLC_VAR_TYPE )
720 var_Get( p_object, psz_var, &val );
721 menuitem = new wxMenuItemExt( menu, ++i_item_id,
722 wxU(text.psz_string ?
723 text.psz_string : psz_var),
724 wxT(""), wxITEM_NORMAL, strdup(psz_var),
725 p_object->i_object_id, val, i_type );
726 menu->Append( menuitem );
730 var_Get( p_object, psz_var, &val );
731 val.b_bool = !val.b_bool;
732 menuitem = new wxMenuItemExt( menu, ++i_item_id,
733 wxU(text.psz_string ?
734 text.psz_string : psz_var),
735 wxT(""), wxITEM_CHECK, strdup(psz_var),
736 p_object->i_object_id, val, i_type );
737 menu->Append( menuitem );
738 Check( i_item_id, val.b_bool ? FALSE : TRUE );
742 if( text.psz_string ) free( text.psz_string );
745 wxMenu *Menu::CreateChoicesMenu( char *psz_var, vlc_object_t *p_object,
748 vlc_value_t val, val_list, text_list;
751 /* Check the type of the object variable */
752 i_type = var_Type( p_object, psz_var );
754 /* Make sure we want to display the variable */
755 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return NULL;
757 switch( i_type & VLC_VAR_TYPE )
761 case VLC_VAR_VARIABLE:
763 case VLC_VAR_INTEGER:
767 /* Variable doesn't exist or isn't handled */
771 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
772 &val_list, &text_list ) < 0 )
777 wxMenu *menu = new wxMenu;
778 for( i = 0; i < val_list.p_list->i_count; i++ )
780 vlc_value_t another_val;
781 wxMenuItemExt *menuitem;
783 switch( i_type & VLC_VAR_TYPE )
785 case VLC_VAR_VARIABLE:
786 menu->Append( MenuDummy_Event,
787 wxU(text_list.p_list->p_values[i].psz_string ?
788 text_list.p_list->p_values[i].psz_string :
789 val_list.p_list->p_values[i].psz_string),
791 val_list.p_list->p_values[i].psz_string,
792 p_object, FALSE ), wxT("") );
796 var_Get( p_object, psz_var, &val );
798 another_val.psz_string =
799 strdup(val_list.p_list->p_values[i].psz_string);
801 new wxMenuItemExt( menu, ++i_item_id,
802 wxU(text_list.p_list->p_values[i].psz_string ?
803 text_list.p_list->p_values[i].psz_string :
804 another_val.psz_string), wxT(""),
805 i_type & VLC_VAR_ISCOMMAND ?
806 wxITEM_NORMAL : wxITEM_RADIO,
808 p_object->i_object_id, another_val, i_type );
810 menu->Append( menuitem );
812 if( !(i_type & VLC_VAR_ISCOMMAND) && val.psz_string &&
813 !strcmp( val.psz_string,
814 val_list.p_list->p_values[i].psz_string ) )
815 menu->Check( i_item_id, TRUE );
817 if( val.psz_string ) free( val.psz_string );
820 case VLC_VAR_INTEGER:
821 var_Get( p_object, psz_var, &val );
824 new wxMenuItemExt( menu, ++i_item_id,
825 text_list.p_list->p_values[i].psz_string ?
827 text_list.p_list->p_values[i].psz_string) :
828 wxString::Format(wxT("%d"),
829 val_list.p_list->p_values[i].i_int), wxT(""),
830 i_type & VLC_VAR_ISCOMMAND ?
831 wxITEM_NORMAL : wxITEM_RADIO,
833 p_object->i_object_id,
834 val_list.p_list->p_values[i], i_type );
836 menu->Append( menuitem );
838 if( !(i_type & VLC_VAR_ISCOMMAND) &&
839 val_list.p_list->p_values[i].i_int == val.i_int )
840 menu->Check( i_item_id, TRUE );
844 var_Get( p_object, psz_var, &val );
847 new wxMenuItemExt( menu, ++i_item_id,
848 text_list.p_list->p_values[i].psz_string ?
850 text_list.p_list->p_values[i].psz_string) :
851 wxString::Format(wxT("%.2f"),
852 val_list.p_list->p_values[i].f_float),wxT(""),
853 i_type & VLC_VAR_ISCOMMAND ?
854 wxITEM_NORMAL : wxITEM_RADIO,
856 p_object->i_object_id,
857 val_list.p_list->p_values[i], i_type );
859 menu->Append( menuitem );
861 if( !(i_type & VLC_VAR_ISCOMMAND) &&
862 val_list.p_list->p_values[i].f_float == val.f_float )
863 menu->Check( i_item_id, TRUE );
871 /* clean up everything */
872 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
877 /*****************************************************************************
878 * A small helper class which intercepts all popup menu events
879 *****************************************************************************/
880 MenuEvtHandler::MenuEvtHandler( intf_thread_t *_p_intf,
881 Interface *_p_main_interface )
883 /* Initializations */
885 p_main_interface = _p_main_interface;
888 MenuEvtHandler::~MenuEvtHandler()
892 void MenuEvtHandler::OnShowDialog( wxCommandEvent& event )
894 if( p_intf->p_sys->pf_show_dialog )
898 switch( event.GetId() )
900 case OpenFileSimple_Event:
901 i_id = INTF_DIALOG_FILE_SIMPLE;
904 i_id = INTF_DIALOG_FILE;
906 case OpenDirectory_Event:
907 i_id = INTF_DIALOG_DIRECTORY;
910 i_id = INTF_DIALOG_DISC;
913 i_id = INTF_DIALOG_NET;
915 case OpenCapture_Event:
916 i_id = INTF_DIALOG_CAPTURE;
918 case MediaInfo_Event:
919 i_id = INTF_DIALOG_FILEINFO;
922 i_id = INTF_DIALOG_MESSAGES;
924 case Preferences_Event:
925 i_id = INTF_DIALOG_PREFS;
928 i_id = INTF_DIALOG_FILE;
933 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
937 void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
939 wxMenuItem *p_menuitem = NULL;
940 int i_hotkey_event = p_intf->p_sys->i_first_hotkey_event;
941 int i_hotkeys = p_intf->p_sys->i_hotkeys;
943 if( event.GetId() >= Play_Event && event.GetId() <= Stop_Event )
945 input_thread_t *p_input;
946 playlist_t * p_playlist =
947 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
949 if( !p_playlist ) return;
951 switch( event.GetId() )
956 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
958 if( !p_input ) playlist_Play( p_playlist );
962 var_Get( p_input, "state", &val );
963 if( val.i_int != PAUSE_S ) val.i_int = PAUSE_S;
964 else val.i_int = PLAYING_S;
965 var_Set( p_input, "state", val );
966 vlc_object_release( p_input );
970 playlist_Stop( p_playlist );
973 playlist_Prev( p_playlist );
976 playlist_Next( p_playlist );
980 vlc_object_release( p_playlist );
984 /* Check if this is an auto generated menu item */
985 if( event.GetId() < FirstAutoGenerated_Event )
991 /* Check if this is an hotkey event */
992 if( event.GetId() >= i_hotkey_event &&
993 event.GetId() < i_hotkey_event + i_hotkeys )
998 p_intf->p_vlc->p_hotkeys[event.GetId() - i_hotkey_event].i_key;
1000 /* Get the key combination and send it to the hotkey handler */
1001 var_Set( p_intf->p_vlc, "key-pressed", val );
1005 if( !p_main_interface ||
1006 (p_menuitem = p_main_interface->GetMenuBar()->FindItem(event.GetId()))
1009 if( p_intf->p_sys->p_popup_menu )
1012 p_intf->p_sys->p_popup_menu->FindItem( event.GetId() );
1018 wxMenuItemExt *p_menuitemext = (wxMenuItemExt *)p_menuitem;
1019 vlc_object_t *p_object;
1021 p_object = (vlc_object_t *)vlc_object_get( p_intf,
1022 p_menuitemext->i_object_id );
1023 if( p_object == NULL ) return;
1025 wxMutexGuiLeave(); // We don't want deadlocks
1026 var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val );
1027 //wxMutexGuiEnter();
1029 vlc_object_release( p_object );
1035 /*****************************************************************************
1036 * A small helper class which encapsulate wxMenuitem with some other useful
1038 *****************************************************************************/
1039 wxMenuItemExt::wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
1040 const wxString& helpString, wxItemKind kind,
1041 char *_psz_var, int _i_object_id, vlc_value_t _val, int _i_val_type ):
1042 wxMenuItem( parentMenu, id, text, helpString, kind )
1044 /* Initializations */
1046 i_val_type = _i_val_type;
1047 i_object_id = _i_object_id;
1051 wxMenuItemExt::~wxMenuItemExt()
1053 if( psz_var ) free( psz_var );
1054 if( ((i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
1055 && val.psz_string ) free( val.psz_string );