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" );
211 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 );
225 #define PUSH_SEPARATOR if( ai_objects.size() != i_last_separator ) { \
226 ai_objects.push_back( 0 ); \
227 as_varnames.push_back( "" ); \
228 i_last_separator = ai_objects.size(); }
230 #define POPUP_BOILERPLATE \
231 unsigned int i_last_separator = 0; \
232 vector<int> ai_objects; \
233 vector<string> as_varnames; \
234 playlist_t *p_playlist = (playlist_t *) vlc_object_find( p_intf, \
235 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );\
238 input_thread_t *p_input = p_playlist->p_input;
240 #define CREATE_POPUP \
241 Menu popupmenu( p_intf, PopupMenu_Events ); \
242 popupmenu.Populate( as_varnames, ai_objects ); \
243 p_intf->p_sys->p_popup_menu = &popupmenu; \
244 p_parent->PopupMenu( &popupmenu, pos.x, pos.y ); \
245 p_intf->p_sys->p_popup_menu = NULL; \
247 #define POPUP_STATIC_ENTRIES \
248 if( p_input != NULL ) \
251 popupmenu.InsertSeparator( 0 ); \
254 popupmenu.Insert( 0, Stop_Event, wxU(_("Stop")) ); \
255 popupmenu.Insert( 0, Previous_Event, wxU(_("Previous")) ); \
256 popupmenu.Insert( 0, Next_Event, wxU(_("Next")) ); \
259 var_Get( p_input, "state", &val ); \
260 if( val.i_int == PAUSE_S ) \
261 popupmenu.Insert( 0, Play_Event, wxU(_("Play")) ); \
263 popupmenu.Insert( 0, Pause_Event, wxU(_("Pause")) ); \
265 vlc_object_release( p_input ); \
269 if( p_playlist && p_playlist->i_size ) \
271 popupmenu.InsertSeparator( 0 ); \
272 popupmenu.Insert( 0, Play_Event, wxU(_("Play")) ); \
274 if( p_playlist ) vlc_object_release( p_playlist ); \
277 popupmenu.Append( MenuDummy_Event, wxU(_("Miscellaneous")), \
278 MiscMenu( p_intf ), wxT("") ); \
281 void VideoPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
287 vlc_object_yield( p_input );
288 as_varnames.push_back( "video-es" );
289 ai_objects.push_back( p_input->i_object_id );
290 as_varnames.push_back( "spu-es" );
291 ai_objects.push_back( p_input->i_object_id );
292 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
293 VLC_OBJECT_VOUT, FIND_CHILD );
296 VideoAutoMenuBuilder( p_vout, ai_objects, as_varnames );
297 vlc_object_release( p_vout );
299 vlc_object_release( p_input );
301 vlc_object_release( p_playlist );
305 void AudioPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
311 vlc_object_yield( p_input );
312 as_varnames.push_back( "audio-es" );
313 ai_objects.push_back( p_input->i_object_id );
314 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
315 VLC_OBJECT_AOUT, FIND_ANYWHERE );
318 AudioAutoMenuBuilder( p_aout, ai_objects, as_varnames );
319 vlc_object_release( p_aout );
321 vlc_object_release( p_input );
323 vlc_object_release( p_playlist );
327 /* Navigation stuff, and general */
328 void MiscPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
335 vlc_object_yield( p_input );
336 as_varnames.push_back( "audio-es" );
337 InputAutoMenuBuilder( VLC_OBJECT(p_input), ai_objects, as_varnames );
340 IntfAutoMenuBuilder( p_intf, ai_objects, as_varnames, true );
342 Menu popupmenu( p_intf, PopupMenu_Events );
343 popupmenu.Populate( as_varnames, ai_objects );
345 POPUP_STATIC_ENTRIES;
346 popupmenu.Append( MenuDummy_Event, wxU(_("Open")),
347 OpenStreamMenu( p_intf ), wxT("") );
349 p_intf->p_sys->p_popup_menu = &popupmenu;
350 p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
351 p_intf->p_sys->p_popup_menu = NULL;
352 vlc_object_release( p_playlist );
355 void PopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
358 int minimal = config_GetInt( p_intf, "wx-minimal" );
362 vlc_object_yield( p_input );
363 InputAutoMenuBuilder( VLC_OBJECT(p_input), ai_objects, as_varnames );
367 as_varnames.push_back( "video-es" );
368 ai_objects.push_back( p_input->i_object_id );
369 as_varnames.push_back( "spu-es" );
370 ai_objects.push_back( p_input->i_object_id );
371 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
372 VLC_OBJECT_VOUT, FIND_CHILD );
375 VideoAutoMenuBuilder( p_vout, ai_objects, as_varnames );
376 vlc_object_release( p_vout );
380 as_varnames.push_back( "audio-es" );
381 ai_objects.push_back( p_input->i_object_id );
382 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
383 VLC_OBJECT_AOUT, FIND_ANYWHERE );
386 AudioAutoMenuBuilder( p_aout, ai_objects, as_varnames );
387 vlc_object_release( p_aout );
393 IntfAutoMenuBuilder( p_intf, ai_objects, as_varnames, true );
396 Menu popupmenu( p_intf, PopupMenu_Events );
397 popupmenu.Populate( as_varnames, ai_objects );
398 POPUP_STATIC_ENTRIES;
402 popupmenu.Append( MenuDummy_Event, wxU(_("Open")),
403 OpenStreamMenu( p_intf ), wxT("") );
405 p_intf->p_sys->p_popup_menu = &popupmenu;
406 p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
407 p_intf->p_sys->p_popup_menu = NULL;
408 vlc_object_release( p_playlist );
411 /*****************************************************************************
413 *****************************************************************************/
414 wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
416 vlc_object_t *p_object;
417 vector<int> ai_objects;
418 vector<string> as_varnames;
420 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
422 if( p_object != NULL )
424 PUSH_VAR( "audio-es" );
425 vlc_object_release( p_object );
428 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_AOUT,
432 AudioAutoMenuBuilder( p_object, ai_objects, as_varnames );
433 vlc_object_release( p_object );
437 Menu *p_vlc_menu = (Menu *)p_menu;
439 p_vlc_menu = new Menu( _p_intf, AudioMenu_Events );
443 p_vlc_menu->Populate( as_varnames, ai_objects );
448 wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
450 vlc_object_t *p_object;
451 vector<int> ai_objects;
452 vector<string> as_varnames;
454 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
456 if( p_object != NULL )
458 PUSH_VAR( "video-es" );
459 PUSH_VAR( "spu-es" );
460 vlc_object_release( p_object );
463 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_VOUT,
465 if( p_object != NULL )
467 VideoAutoMenuBuilder( p_object, ai_objects, as_varnames );
468 vlc_object_release( p_object );
472 Menu *p_vlc_menu = (Menu *)p_menu;
474 p_vlc_menu = new Menu( _p_intf, VideoMenu_Events );
478 p_vlc_menu->Populate( as_varnames, ai_objects );
482 wxMenu *NavigMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
484 vlc_object_t *p_object;
485 vector<int> ai_objects;
486 vector<string> as_varnames;
488 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
490 if( p_object != NULL )
492 InputAutoMenuBuilder( p_object, ai_objects, as_varnames );
493 PUSH_VAR( "prev-title"); PUSH_VAR ( "next-title" );
494 PUSH_VAR( "prev-chapter"); PUSH_VAR( "next-chapter" );
495 vlc_object_release( p_object );
499 Menu *p_vlc_menu = (Menu *)p_menu;
501 p_vlc_menu = new Menu( _p_intf, NavigMenu_Events );
505 p_vlc_menu->Populate( as_varnames, ai_objects );
510 wxMenu *SettingsMenu( intf_thread_t *_p_intf, wxWindow *p_parent,
513 vlc_object_t *p_object;
514 vector<int> ai_objects;
515 vector<string> as_varnames;
517 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INTF,
519 if( p_object != NULL )
521 PUSH_VAR( "intf-switch" );
522 PUSH_VAR( "intf-add" );
523 vlc_object_release( p_object );
527 Menu *p_vlc_menu = (Menu *)p_menu;
529 p_vlc_menu = new Menu( _p_intf, SettingsMenu_Events );
533 p_vlc_menu->Populate( as_varnames, ai_objects );
538 /*****************************************************************************
540 *****************************************************************************/
541 Menu::Menu( intf_thread_t *_p_intf, int _i_start_id ) : wxMenu( )
543 /* Initializations */
545 i_start_id = _i_start_id;
552 /*****************************************************************************
554 *****************************************************************************/
555 void Menu::Populate( vector<string> & ras_varnames, vector<int> & rai_objects )
557 vlc_object_t *p_object;
558 vlc_bool_t b_section_empty = VLC_FALSE;
561 i_item_id = i_start_id;
563 for( i = 0; i < rai_objects.size() ; i++ )
565 if( ras_varnames[i] == "" )
567 if( b_section_empty )
569 Append( MenuDummy_Event + i, wxU(_("Empty")) );
570 Enable( MenuDummy_Event + i, FALSE );
573 b_section_empty = VLC_TRUE;
577 if( rai_objects[i] == 0 )
579 Append( MenuDummy_Event, wxU(ras_varnames[i].c_str()) );
580 b_section_empty = VLC_FALSE;
584 p_object = (vlc_object_t *)vlc_object_get( p_intf,
586 if( p_object == NULL ) continue;
588 b_section_empty = VLC_FALSE;
589 CreateMenuItem( this, ras_varnames[i].c_str(), p_object );
590 vlc_object_release( p_object );
593 /* Special case for empty menus */
594 if( GetMenuItemCount() == 0 || b_section_empty )
596 Append( MenuDummy_Event + i, wxU(_("Empty")) );
597 Enable( MenuDummy_Event + i, FALSE );
601 /* Work-around helper for buggy wxGTK */
602 static void RecursiveDestroy( wxMenu *menu )
604 wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
607 wxMenuItem *item = node->GetData();
608 node = node->GetNext();
610 /* Delete the submenus */
611 wxMenu *submenu = item->GetSubMenu();
614 RecursiveDestroy( submenu );
616 menu->Delete( item );
622 RecursiveDestroy( this );
625 /*****************************************************************************
627 *****************************************************************************/
628 static bool IsMenuEmpty( char *psz_var, vlc_object_t *p_object,
631 vlc_value_t val, val_list;
632 int i_type, i_result, i;
634 /* Check the type of the object variable */
635 i_type = var_Type( p_object, psz_var );
637 /* Check if we want to display the variable */
638 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
640 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
641 if( val.i_int == 0 ) return TRUE;
643 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
645 /* Very evil hack ! intf-switch can have only one value */
646 if( !strcmp( psz_var, "intf-switch" ) ) return FALSE;
647 if( val.i_int == 1 && b_root ) return TRUE;
651 /* Check children variables in case of VLC_VAR_VARIABLE */
652 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
657 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
659 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
667 /* clean up everything */
668 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
673 void Menu::CreateMenuItem( wxMenu *menu, const char *psz_var,
674 vlc_object_t *p_object )
676 wxMenuItemExt *menuitem;
677 vlc_value_t val, text;
680 /* Check the type of the object variable */
681 i_type = var_Type( p_object, psz_var );
683 switch( i_type & VLC_VAR_TYPE )
687 case VLC_VAR_VARIABLE:
689 case VLC_VAR_INTEGER:
693 /* Variable doesn't exist or isn't handled */
697 /* Make sure we want to display the variable */
698 if( IsMenuEmpty( psz_var, p_object ) ) return;
700 /* Get the descriptive name of the variable */
701 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
703 if( i_type & VLC_VAR_HASCHOICE )
705 menu->Append( MenuDummy_Event,
706 wxU(text.psz_string ? text.psz_string : psz_var),
707 CreateChoicesMenu( psz_var, p_object, TRUE ),
708 wxT("")/* Nothing for now (maybe use a GETLONGTEXT) */ );
710 if( text.psz_string ) free( text.psz_string );
715 switch( i_type & VLC_VAR_TYPE )
718 var_Get( p_object, psz_var, &val );
719 menuitem = new wxMenuItemExt( menu, ++i_item_id,
720 wxU(text.psz_string ?
721 text.psz_string : psz_var),
722 wxT(""), wxITEM_NORMAL, strdup(psz_var),
723 p_object->i_object_id, val, i_type );
724 menu->Append( menuitem );
728 var_Get( p_object, psz_var, &val );
729 val.b_bool = !val.b_bool;
730 menuitem = new wxMenuItemExt( menu, ++i_item_id,
731 wxU(text.psz_string ?
732 text.psz_string : psz_var),
733 wxT(""), wxITEM_CHECK, strdup(psz_var),
734 p_object->i_object_id, val, i_type );
735 menu->Append( menuitem );
736 Check( i_item_id, val.b_bool ? FALSE : TRUE );
740 if( text.psz_string ) free( text.psz_string );
743 wxMenu *Menu::CreateChoicesMenu( char *psz_var, vlc_object_t *p_object,
746 vlc_value_t val, val_list, text_list;
749 /* Check the type of the object variable */
750 i_type = var_Type( p_object, psz_var );
752 /* Make sure we want to display the variable */
753 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return NULL;
755 switch( i_type & VLC_VAR_TYPE )
759 case VLC_VAR_VARIABLE:
761 case VLC_VAR_INTEGER:
765 /* Variable doesn't exist or isn't handled */
769 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
770 &val_list, &text_list ) < 0 )
775 wxMenu *menu = new wxMenu;
776 for( i = 0; i < val_list.p_list->i_count; i++ )
778 vlc_value_t another_val;
779 wxMenuItemExt *menuitem;
781 switch( i_type & VLC_VAR_TYPE )
783 case VLC_VAR_VARIABLE:
784 menu->Append( MenuDummy_Event,
785 wxU(text_list.p_list->p_values[i].psz_string ?
786 text_list.p_list->p_values[i].psz_string :
787 val_list.p_list->p_values[i].psz_string),
789 val_list.p_list->p_values[i].psz_string,
790 p_object, FALSE ), wxT("") );
794 var_Get( p_object, psz_var, &val );
796 another_val.psz_string =
797 strdup(val_list.p_list->p_values[i].psz_string);
799 new wxMenuItemExt( menu, ++i_item_id,
800 wxU(text_list.p_list->p_values[i].psz_string ?
801 text_list.p_list->p_values[i].psz_string :
802 another_val.psz_string), wxT(""),
803 i_type & VLC_VAR_ISCOMMAND ?
804 wxITEM_NORMAL : wxITEM_RADIO,
806 p_object->i_object_id, another_val, i_type );
808 menu->Append( menuitem );
810 if( !(i_type & VLC_VAR_ISCOMMAND) && val.psz_string &&
811 !strcmp( val.psz_string,
812 val_list.p_list->p_values[i].psz_string ) )
813 menu->Check( i_item_id, TRUE );
815 if( val.psz_string ) free( val.psz_string );
818 case VLC_VAR_INTEGER:
819 var_Get( p_object, psz_var, &val );
822 new wxMenuItemExt( menu, ++i_item_id,
823 text_list.p_list->p_values[i].psz_string ?
825 text_list.p_list->p_values[i].psz_string) :
826 wxString::Format(wxT("%d"),
827 val_list.p_list->p_values[i].i_int), wxT(""),
828 i_type & VLC_VAR_ISCOMMAND ?
829 wxITEM_NORMAL : wxITEM_RADIO,
831 p_object->i_object_id,
832 val_list.p_list->p_values[i], i_type );
834 menu->Append( menuitem );
836 if( !(i_type & VLC_VAR_ISCOMMAND) &&
837 val_list.p_list->p_values[i].i_int == val.i_int )
838 menu->Check( i_item_id, TRUE );
842 var_Get( p_object, psz_var, &val );
845 new wxMenuItemExt( menu, ++i_item_id,
846 text_list.p_list->p_values[i].psz_string ?
848 text_list.p_list->p_values[i].psz_string) :
849 wxString::Format(wxT("%.2f"),
850 val_list.p_list->p_values[i].f_float),wxT(""),
851 i_type & VLC_VAR_ISCOMMAND ?
852 wxITEM_NORMAL : wxITEM_RADIO,
854 p_object->i_object_id,
855 val_list.p_list->p_values[i], i_type );
857 menu->Append( menuitem );
859 if( !(i_type & VLC_VAR_ISCOMMAND) &&
860 val_list.p_list->p_values[i].f_float == val.f_float )
861 menu->Check( i_item_id, TRUE );
869 /* clean up everything */
870 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
875 /*****************************************************************************
876 * A small helper class which intercepts all popup menu events
877 *****************************************************************************/
878 MenuEvtHandler::MenuEvtHandler( intf_thread_t *_p_intf,
879 Interface *_p_main_interface )
881 /* Initializations */
883 p_main_interface = _p_main_interface;
886 MenuEvtHandler::~MenuEvtHandler()
890 void MenuEvtHandler::OnShowDialog( wxCommandEvent& event )
892 if( p_intf->p_sys->pf_show_dialog )
896 switch( event.GetId() )
898 case OpenFileSimple_Event:
899 i_id = INTF_DIALOG_FILE_SIMPLE;
902 i_id = INTF_DIALOG_FILE;
904 case OpenDirectory_Event:
905 i_id = INTF_DIALOG_DIRECTORY;
908 i_id = INTF_DIALOG_DISC;
911 i_id = INTF_DIALOG_NET;
913 case OpenCapture_Event:
914 i_id = INTF_DIALOG_CAPTURE;
916 case MediaInfo_Event:
917 i_id = INTF_DIALOG_FILEINFO;
920 i_id = INTF_DIALOG_MESSAGES;
922 case Preferences_Event:
923 i_id = INTF_DIALOG_PREFS;
926 i_id = INTF_DIALOG_FILE;
931 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
935 void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
937 wxMenuItem *p_menuitem = NULL;
938 int i_hotkey_event = p_intf->p_sys->i_first_hotkey_event;
939 int i_hotkeys = p_intf->p_sys->i_hotkeys;
941 if( event.GetId() >= Play_Event && event.GetId() <= Stop_Event )
943 input_thread_t *p_input;
944 playlist_t * p_playlist =
945 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
947 if( !p_playlist ) return;
949 switch( event.GetId() )
954 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
956 if( !p_input ) playlist_Play( p_playlist );
960 var_Get( p_input, "state", &val );
961 if( val.i_int != PAUSE_S ) val.i_int = PAUSE_S;
962 else val.i_int = PLAYING_S;
963 var_Set( p_input, "state", val );
964 vlc_object_release( p_input );
968 playlist_Stop( p_playlist );
971 playlist_Prev( p_playlist );
974 playlist_Next( p_playlist );
978 vlc_object_release( p_playlist );
982 /* Check if this is an auto generated menu item */
983 if( event.GetId() < FirstAutoGenerated_Event )
989 /* Check if this is an hotkey event */
990 if( event.GetId() >= i_hotkey_event &&
991 event.GetId() < i_hotkey_event + i_hotkeys )
996 p_intf->p_vlc->p_hotkeys[event.GetId() - i_hotkey_event].i_key;
998 /* Get the key combination and send it to the hotkey handler */
999 var_Set( p_intf->p_vlc, "key-pressed", val );
1003 if( !p_main_interface ||
1004 (p_menuitem = p_main_interface->GetMenuBar()->FindItem(event.GetId()))
1007 if( p_intf->p_sys->p_popup_menu )
1010 p_intf->p_sys->p_popup_menu->FindItem( event.GetId() );
1016 wxMenuItemExt *p_menuitemext = (wxMenuItemExt *)p_menuitem;
1017 vlc_object_t *p_object;
1019 p_object = (vlc_object_t *)vlc_object_get( p_intf,
1020 p_menuitemext->i_object_id );
1021 if( p_object == NULL ) return;
1023 wxMutexGuiLeave(); // We don't want deadlocks
1024 var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val );
1025 //wxMutexGuiEnter();
1027 vlc_object_release( p_object );
1033 /*****************************************************************************
1034 * A small helper class which encapsulate wxMenuitem with some other useful
1036 *****************************************************************************/
1037 wxMenuItemExt::wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
1038 const wxString& helpString, wxItemKind kind,
1039 char *_psz_var, int _i_object_id, vlc_value_t _val, int _i_val_type ):
1040 wxMenuItem( parentMenu, id, text, helpString, kind )
1042 /* Initializations */
1044 i_val_type = _i_val_type;
1045 i_object_id = _i_object_id;
1049 wxMenuItemExt::~wxMenuItemExt()
1051 if( psz_var ) free( psz_var );
1052 if( ((i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
1053 && val.psz_string ) free( val.psz_string );