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 );
295 void AudioPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
301 vlc_object_yield( p_input );
302 as_varnames.push_back( "audio-es" );
303 ai_objects.push_back( p_input->i_object_id );
304 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
305 VLC_OBJECT_AOUT, FIND_ANYWHERE );
308 AudioAutoMenuBuilder( p_aout, ai_objects, as_varnames );
309 vlc_object_release( p_aout );
311 vlc_object_release( p_input );
316 /* Navigation stuff, and general */
317 void MiscPopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
324 vlc_object_yield( p_input );
325 as_varnames.push_back( "audio-es" );
326 InputAutoMenuBuilder( VLC_OBJECT(p_input), ai_objects, as_varnames );
329 IntfAutoMenuBuilder( p_intf, ai_objects, as_varnames );
331 Menu popupmenu( p_intf, PopupMenu_Events );
332 popupmenu.Populate( as_varnames, ai_objects );
334 POPUP_STATIC_ENTRIES;
335 popupmenu.Append( MenuDummy_Event, wxU(_("Open")),
336 OpenStreamMenu( p_intf ), wxT("") );
338 p_intf->p_sys->p_popup_menu = &popupmenu;
339 p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
340 p_intf->p_sys->p_popup_menu = NULL;
343 void PopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
346 int minimal = config_GetInt( p_intf, "wx-minimal" );
350 vlc_object_yield( p_input );
351 InputAutoMenuBuilder( VLC_OBJECT(p_input), ai_objects, as_varnames );
355 as_varnames.push_back( "video-es" );
356 ai_objects.push_back( p_input->i_object_id );
357 as_varnames.push_back( "spu-es" );
358 ai_objects.push_back( p_input->i_object_id );
359 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
360 VLC_OBJECT_VOUT, FIND_CHILD );
363 VideoAutoMenuBuilder( p_vout, ai_objects, as_varnames );
364 vlc_object_release( p_vout );
368 as_varnames.push_back( "audio-es" );
369 ai_objects.push_back( p_input->i_object_id );
370 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
371 VLC_OBJECT_AOUT, FIND_ANYWHERE );
374 AudioAutoMenuBuilder( p_aout, ai_objects, as_varnames );
375 vlc_object_release( p_aout );
381 IntfAutoMenuBuilder( p_intf, ai_objects, as_varnames );
384 Menu popupmenu( p_intf, PopupMenu_Events );
385 popupmenu.Populate( as_varnames, ai_objects );
386 POPUP_STATIC_ENTRIES;
390 popupmenu.Append( MenuDummy_Event, wxU(_("Open")),
391 OpenStreamMenu( p_intf ), wxT("") );
393 p_intf->p_sys->p_popup_menu = &popupmenu;
394 p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
395 p_intf->p_sys->p_popup_menu = NULL;
398 /*****************************************************************************
400 *****************************************************************************/
401 wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
403 vlc_object_t *p_object;
404 vector<int> ai_objects;
405 vector<string> as_varnames;
407 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
409 if( p_object != NULL )
411 PUSH_VAR( "audio-es" );
412 vlc_object_release( p_object );
415 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_AOUT,
419 AudioAutoMenuBuilder( p_object, ai_objects, as_varnames );
420 vlc_object_release( p_object );
424 Menu *p_vlc_menu = (Menu *)p_menu;
426 p_vlc_menu = new Menu( _p_intf, AudioMenu_Events );
430 p_vlc_menu->Populate( as_varnames, ai_objects );
435 wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
437 vlc_object_t *p_object;
438 vector<int> ai_objects;
439 vector<string> as_varnames;
441 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
443 if( p_object != NULL )
445 PUSH_VAR( "video-es" );
446 PUSH_VAR( "spu-es" );
447 vlc_object_release( p_object );
450 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_VOUT,
452 if( p_object != NULL )
454 VideoAutoMenuBuilder( p_object, ai_objects, as_varnames );
455 vlc_object_release( p_object );
459 Menu *p_vlc_menu = (Menu *)p_menu;
461 p_vlc_menu = new Menu( _p_intf, VideoMenu_Events );
465 p_vlc_menu->Populate( as_varnames, ai_objects );
469 wxMenu *NavigMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
471 vlc_object_t *p_object;
472 vector<int> ai_objects;
473 vector<string> as_varnames;
475 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
477 if( p_object != NULL )
479 InputAutoMenuBuilder( p_object, ai_objects, as_varnames );
480 PUSH_VAR( "prev-title"); PUSH_VAR ( "next-title" );
481 PUSH_VAR( "prev-chapter"); PUSH_VAR( "next-chapter" );
482 vlc_object_release( p_object );
486 Menu *p_vlc_menu = (Menu *)p_menu;
488 p_vlc_menu = new Menu( _p_intf, NavigMenu_Events );
492 p_vlc_menu->Populate( as_varnames, ai_objects );
497 wxMenu *SettingsMenu( intf_thread_t *_p_intf, wxWindow *p_parent,
500 vlc_object_t *p_object;
501 vector<int> ai_objects;
502 vector<string> as_varnames;
504 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INTF,
506 if( p_object != NULL )
508 PUSH_VAR( "intf-add" );
509 vlc_object_release( p_object );
513 Menu *p_vlc_menu = (Menu *)p_menu;
515 p_vlc_menu = new Menu( _p_intf, SettingsMenu_Events );
519 p_vlc_menu->Populate( as_varnames, ai_objects );
524 /*****************************************************************************
526 *****************************************************************************/
527 Menu::Menu( intf_thread_t *_p_intf, int _i_start_id ) : wxMenu( )
529 /* Initializations */
531 i_start_id = _i_start_id;
538 /*****************************************************************************
540 *****************************************************************************/
541 void Menu::Populate( vector<string> & ras_varnames, vector<int> & rai_objects )
543 vlc_object_t *p_object;
544 vlc_bool_t b_section_empty = VLC_FALSE;
547 i_item_id = i_start_id;
549 for( i = 0; i < rai_objects.size() ; i++ )
551 if( ras_varnames[i] == "" )
553 if( b_section_empty )
555 Append( MenuDummy_Event + i, wxU(_("Empty")) );
556 Enable( MenuDummy_Event + i, FALSE );
559 b_section_empty = VLC_TRUE;
563 if( rai_objects[i] == 0 )
565 Append( MenuDummy_Event, wxU(ras_varnames[i].c_str()) );
566 b_section_empty = VLC_FALSE;
570 p_object = (vlc_object_t *)vlc_object_get( p_intf,
572 if( p_object == NULL ) continue;
574 b_section_empty = VLC_FALSE;
575 CreateMenuItem( this, ras_varnames[i].c_str(), p_object );
576 vlc_object_release( p_object );
579 /* Special case for empty menus */
580 if( GetMenuItemCount() == 0 || b_section_empty )
582 Append( MenuDummy_Event + i, wxU(_("Empty")) );
583 Enable( MenuDummy_Event + i, FALSE );
587 /* Work-around helper for buggy wxGTK */
588 static void RecursiveDestroy( wxMenu *menu )
590 wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
593 wxMenuItem *item = node->GetData();
594 node = node->GetNext();
596 /* Delete the submenus */
597 wxMenu *submenu = item->GetSubMenu();
600 RecursiveDestroy( submenu );
602 menu->Delete( item );
608 RecursiveDestroy( this );
611 /*****************************************************************************
613 *****************************************************************************/
614 static bool IsMenuEmpty( char *psz_var, vlc_object_t *p_object,
617 vlc_value_t val, val_list;
618 int i_type, i_result, i;
620 /* Check the type of the object variable */
621 i_type = var_Type( p_object, psz_var );
623 /* Check if we want to display the variable */
624 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
626 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
627 if( val.i_int == 0 ) return TRUE;
629 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
631 if( val.i_int == 1 && b_root ) return TRUE;
635 /* Check children variables in case of VLC_VAR_VARIABLE */
636 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
641 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
643 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
651 /* clean up everything */
652 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
657 void Menu::CreateMenuItem( wxMenu *menu, char *psz_var,
658 vlc_object_t *p_object )
660 wxMenuItemExt *menuitem;
661 vlc_value_t val, text;
664 /* Check the type of the object variable */
665 i_type = var_Type( p_object, psz_var );
667 switch( i_type & VLC_VAR_TYPE )
671 case VLC_VAR_VARIABLE:
673 case VLC_VAR_INTEGER:
677 /* Variable doesn't exist or isn't handled */
681 /* Make sure we want to display the variable */
682 if( IsMenuEmpty( psz_var, p_object ) ) return;
684 /* Get the descriptive name of the variable */
685 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
687 if( i_type & VLC_VAR_HASCHOICE )
689 menu->Append( MenuDummy_Event,
690 wxU(text.psz_string ? text.psz_string : psz_var),
691 CreateChoicesMenu( psz_var, p_object, TRUE ),
692 wxT("")/* Nothing for now (maybe use a GETLONGTEXT) */ );
694 if( text.psz_string ) free( text.psz_string );
699 switch( i_type & VLC_VAR_TYPE )
702 var_Get( p_object, psz_var, &val );
703 menuitem = new wxMenuItemExt( menu, ++i_item_id,
704 wxU(text.psz_string ?
705 text.psz_string : psz_var),
706 wxT(""), wxITEM_NORMAL, strdup(psz_var),
707 p_object->i_object_id, val, i_type );
708 menu->Append( menuitem );
712 var_Get( p_object, psz_var, &val );
713 val.b_bool = !val.b_bool;
714 menuitem = new wxMenuItemExt( menu, ++i_item_id,
715 wxU(text.psz_string ?
716 text.psz_string : psz_var),
717 wxT(""), wxITEM_CHECK, strdup(psz_var),
718 p_object->i_object_id, val, i_type );
719 menu->Append( menuitem );
720 Check( i_item_id, val.b_bool ? FALSE : TRUE );
724 if( text.psz_string ) free( text.psz_string );
727 wxMenu *Menu::CreateChoicesMenu( char *psz_var, vlc_object_t *p_object,
730 vlc_value_t val, val_list, text_list;
733 /* Check the type of the object variable */
734 i_type = var_Type( p_object, psz_var );
736 /* Make sure we want to display the variable */
737 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return NULL;
739 switch( i_type & VLC_VAR_TYPE )
743 case VLC_VAR_VARIABLE:
745 case VLC_VAR_INTEGER:
749 /* Variable doesn't exist or isn't handled */
753 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
754 &val_list, &text_list ) < 0 )
759 wxMenu *menu = new wxMenu;
760 for( i = 0; i < val_list.p_list->i_count; i++ )
762 vlc_value_t another_val;
763 wxMenuItemExt *menuitem;
765 switch( i_type & VLC_VAR_TYPE )
767 case VLC_VAR_VARIABLE:
768 menu->Append( MenuDummy_Event,
769 wxU(text_list.p_list->p_values[i].psz_string ?
770 text_list.p_list->p_values[i].psz_string :
771 val_list.p_list->p_values[i].psz_string),
773 val_list.p_list->p_values[i].psz_string,
774 p_object, FALSE ), wxT("") );
778 var_Get( p_object, psz_var, &val );
780 another_val.psz_string =
781 strdup(val_list.p_list->p_values[i].psz_string);
783 new wxMenuItemExt( menu, ++i_item_id,
784 wxU(text_list.p_list->p_values[i].psz_string ?
785 text_list.p_list->p_values[i].psz_string :
786 another_val.psz_string), wxT(""),
787 i_type & VLC_VAR_ISCOMMAND ?
788 wxITEM_NORMAL : wxITEM_RADIO,
790 p_object->i_object_id, another_val, i_type );
792 menu->Append( menuitem );
794 if( !(i_type & VLC_VAR_ISCOMMAND) && val.psz_string &&
795 !strcmp( val.psz_string,
796 val_list.p_list->p_values[i].psz_string ) )
797 menu->Check( i_item_id, TRUE );
799 if( val.psz_string ) free( val.psz_string );
802 case VLC_VAR_INTEGER:
803 var_Get( p_object, psz_var, &val );
806 new wxMenuItemExt( menu, ++i_item_id,
807 text_list.p_list->p_values[i].psz_string ?
809 text_list.p_list->p_values[i].psz_string) :
810 wxString::Format(wxT("%d"),
811 val_list.p_list->p_values[i].i_int), wxT(""),
812 i_type & VLC_VAR_ISCOMMAND ?
813 wxITEM_NORMAL : wxITEM_RADIO,
815 p_object->i_object_id,
816 val_list.p_list->p_values[i], i_type );
818 menu->Append( menuitem );
820 if( !(i_type & VLC_VAR_ISCOMMAND) &&
821 val_list.p_list->p_values[i].i_int == val.i_int )
822 menu->Check( i_item_id, TRUE );
826 var_Get( p_object, psz_var, &val );
829 new wxMenuItemExt( menu, ++i_item_id,
830 text_list.p_list->p_values[i].psz_string ?
832 text_list.p_list->p_values[i].psz_string) :
833 wxString::Format(wxT("%.2f"),
834 val_list.p_list->p_values[i].f_float),wxT(""),
835 i_type & VLC_VAR_ISCOMMAND ?
836 wxITEM_NORMAL : wxITEM_RADIO,
838 p_object->i_object_id,
839 val_list.p_list->p_values[i], i_type );
841 menu->Append( menuitem );
843 if( !(i_type & VLC_VAR_ISCOMMAND) &&
844 val_list.p_list->p_values[i].f_float == val.f_float )
845 menu->Check( i_item_id, TRUE );
853 /* clean up everything */
854 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
859 /*****************************************************************************
860 * A small helper class which intercepts all popup menu events
861 *****************************************************************************/
862 MenuEvtHandler::MenuEvtHandler( intf_thread_t *_p_intf,
863 Interface *_p_main_interface )
865 /* Initializations */
867 p_main_interface = _p_main_interface;
870 MenuEvtHandler::~MenuEvtHandler()
874 void MenuEvtHandler::OnShowDialog( wxCommandEvent& event )
876 if( p_intf->p_sys->pf_show_dialog )
880 switch( event.GetId() )
882 case OpenFileSimple_Event:
883 i_id = INTF_DIALOG_FILE_SIMPLE;
886 i_id = INTF_DIALOG_FILE;
888 case OpenDirectory_Event:
889 i_id = INTF_DIALOG_DIRECTORY;
892 i_id = INTF_DIALOG_DISC;
895 i_id = INTF_DIALOG_NET;
897 case OpenCapture_Event:
898 i_id = INTF_DIALOG_CAPTURE;
900 case MediaInfo_Event:
901 i_id = INTF_DIALOG_FILEINFO;
904 i_id = INTF_DIALOG_MESSAGES;
906 case Preferences_Event:
907 i_id = INTF_DIALOG_PREFS;
910 i_id = INTF_DIALOG_FILE;
915 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
919 void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
921 wxMenuItem *p_menuitem = NULL;
922 int i_hotkey_event = p_intf->p_sys->i_first_hotkey_event;
923 int i_hotkeys = p_intf->p_sys->i_hotkeys;
925 if( event.GetId() >= Play_Event && event.GetId() <= Stop_Event )
927 input_thread_t *p_input;
928 playlist_t * p_playlist =
929 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
931 if( !p_playlist ) return;
933 switch( event.GetId() )
938 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
940 if( !p_input ) playlist_Play( p_playlist );
944 var_Get( p_input, "state", &val );
945 if( val.i_int != PAUSE_S ) val.i_int = PAUSE_S;
946 else val.i_int = PLAYING_S;
947 var_Set( p_input, "state", val );
948 vlc_object_release( p_input );
952 playlist_Stop( p_playlist );
955 playlist_Prev( p_playlist );
958 playlist_Next( p_playlist );
962 vlc_object_release( p_playlist );
966 /* Check if this is an auto generated menu item */
967 if( event.GetId() < FirstAutoGenerated_Event )
973 /* Check if this is an hotkey event */
974 if( event.GetId() >= i_hotkey_event &&
975 event.GetId() < i_hotkey_event + i_hotkeys )
980 p_intf->p_vlc->p_hotkeys[event.GetId() - i_hotkey_event].i_key;
982 /* Get the key combination and send it to the hotkey handler */
983 var_Set( p_intf->p_vlc, "key-pressed", val );
987 if( !p_main_interface ||
988 (p_menuitem = p_main_interface->GetMenuBar()->FindItem(event.GetId()))
991 if( p_intf->p_sys->p_popup_menu )
994 p_intf->p_sys->p_popup_menu->FindItem( event.GetId() );
1000 wxMenuItemExt *p_menuitemext = (wxMenuItemExt *)p_menuitem;
1001 vlc_object_t *p_object;
1003 p_object = (vlc_object_t *)vlc_object_get( p_intf,
1004 p_menuitemext->i_object_id );
1005 if( p_object == NULL ) return;
1007 wxMutexGuiLeave(); // We don't want deadlocks
1008 var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val );
1009 //wxMutexGuiEnter();
1011 vlc_object_release( p_object );
1017 /*****************************************************************************
1018 * A small helper class which encapsulate wxMenuitem with some other useful
1020 *****************************************************************************/
1021 wxMenuItemExt::wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
1022 const wxString& helpString, wxItemKind kind,
1023 char *_psz_var, int _i_object_id, vlc_value_t _val, int _i_val_type ):
1024 wxMenuItem( parentMenu, id, text, helpString, kind )
1026 /* Initializations */
1028 i_val_type = _i_val_type;
1029 i_object_id = _i_object_id;
1033 wxMenuItemExt::~wxMenuItemExt()
1035 if( psz_var ) free( psz_var );
1036 if( ((i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
1037 && val.psz_string ) free( val.psz_string );