1 /*****************************************************************************
2 * menus.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004 VideoLAN
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <errno.h> /* ENOMEM */
29 #include <string.h> /* strerror() */
35 #include "wxwindows.h"
37 class wxMenuItemExt: public wxMenuItem
41 wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
42 const wxString& helpString, wxItemKind kind,
43 char *_psz_var, int _i_object_id, vlc_value_t _val,
46 virtual ~wxMenuItemExt();
57 class Menu: public wxMenu
61 Menu( intf_thread_t *p_intf, int i_start_id );
64 void Populate( int i_count, char **ppsz_names, int *pi_objects );
68 wxMenu *Menu::CreateDummyMenu();
69 void Menu::CreateMenuItem( wxMenu *, char *, vlc_object_t * );
70 wxMenu *Menu::CreateChoicesMenu( char *, vlc_object_t *, bool );
72 DECLARE_EVENT_TABLE();
74 intf_thread_t *p_intf;
80 /*****************************************************************************
82 *****************************************************************************/
84 /* IDs for the controls and the menu commands */
88 MenuDummy_Event = wxID_HIGHEST + 1000,
89 OpenFileSimple_Event = wxID_HIGHEST + 1100,
97 FirstAutoGenerated_Event = wxID_HIGHEST + 1999,
98 SettingsMenu_Events = wxID_HIGHEST + 5000,
99 AudioMenu_Events = wxID_HIGHEST + 2000,
100 VideoMenu_Events = wxID_HIGHEST + 3000,
101 NavigMenu_Events = wxID_HIGHEST + 4000,
102 PopupMenu_Events = wxID_HIGHEST + 6000,
103 Hotkeys_Events = wxID_HIGHEST + 7000
106 BEGIN_EVENT_TABLE(Menu, wxMenu)
109 BEGIN_EVENT_TABLE(MenuEvtHandler, wxEvtHandler)
110 EVT_MENU(OpenFileSimple_Event, MenuEvtHandler::OnShowDialog)
111 EVT_MENU(OpenFile_Event, MenuEvtHandler::OnShowDialog)
112 EVT_MENU(OpenDisc_Event, MenuEvtHandler::OnShowDialog)
113 EVT_MENU(OpenNet_Event, MenuEvtHandler::OnShowDialog)
114 EVT_MENU(OpenCapture_Event, MenuEvtHandler::OnShowDialog)
115 EVT_MENU(MediaInfo_Event, MenuEvtHandler::OnShowDialog)
116 EVT_MENU(Messages_Event, MenuEvtHandler::OnShowDialog)
117 EVT_MENU(Preferences_Event, MenuEvtHandler::OnShowDialog)
118 EVT_MENU(-1, MenuEvtHandler::OnMenuEvent)
121 wxMenu *OpenStreamMenu( intf_thread_t *p_intf )
123 wxMenu *menu = new wxMenu;
124 menu->Append( OpenFileSimple_Event, wxU(_("Quick &Open File...")) );
125 menu->Append( OpenFile_Event, wxU(_("Open &File...")) );
126 menu->Append( OpenDisc_Event, wxU(_("Open &Disc...")) );
127 menu->Append( OpenNet_Event, wxU(_("Open &Network Stream...")) );
128 menu->Append( OpenCapture_Event, wxU(_("Open &Capture Device...")) );
132 wxMenu *MiscMenu( intf_thread_t *p_intf )
134 wxMenu *menu = new wxMenu;
135 menu->Append( MediaInfo_Event, wxU(_("Media &Info...")) );
136 menu->Append( Messages_Event, wxU(_("&Messages...")) );
137 menu->Append( Preferences_Event, wxU(_("&Preferences...")) );
141 void PopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
144 #define MAX_POPUP_ITEMS 35
146 vlc_object_t *p_object;
147 char *ppsz_varnames[MAX_POPUP_ITEMS];
148 int pi_objects[MAX_POPUP_ITEMS];
151 /* Initializations */
152 memset( pi_objects, 0, MAX_POPUP_ITEMS * sizeof(int) );
155 ppsz_varnames[i++] = _("Audio menu");
156 ppsz_varnames[i++] = NULL; /* Separator */
158 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
160 if( p_object != NULL )
162 ppsz_varnames[i] = "audio-device";
163 pi_objects[i++] = p_object->i_object_id;
164 ppsz_varnames[i] = "audio-channels";
165 pi_objects[i++] = p_object->i_object_id;
166 ppsz_varnames[i] = "visual";
167 pi_objects[i++] = p_object->i_object_id;
168 vlc_object_release( p_object );
172 ppsz_varnames[i++] = NULL; /* Separator */
173 ppsz_varnames[i++] = _("Video menu");
174 ppsz_varnames[i++] = NULL; /* Separator */
176 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
178 if( p_object != NULL )
180 vlc_object_t *p_dec_obj;
182 ppsz_varnames[i] = "fullscreen";
183 pi_objects[i++] = p_object->i_object_id;
184 ppsz_varnames[i] = "zoom";
185 pi_objects[i++] = p_object->i_object_id;
186 ppsz_varnames[i] = "deinterlace";
187 pi_objects[i++] = p_object->i_object_id;
188 ppsz_varnames[i] = "aspect-ratio";
189 pi_objects[i++] = p_object->i_object_id;
190 ppsz_varnames[i] = "crop";
191 pi_objects[i++] = p_object->i_object_id;
192 ppsz_varnames[i] = "video-on-top";
193 pi_objects[i++] = p_object->i_object_id;
194 ppsz_varnames[i] = "directx-wallpaper";
195 pi_objects[i++] = p_object->i_object_id;
197 p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
200 if( p_dec_obj != NULL )
202 ppsz_varnames[i] = "ffmpeg-pp-q";
203 pi_objects[i++] = p_dec_obj->i_object_id;
204 vlc_object_release( p_dec_obj );
207 vlc_object_release( p_object );
211 ppsz_varnames[i++] = NULL; /* Separator */
212 ppsz_varnames[i++] = _("Input menu");
213 ppsz_varnames[i++] = NULL; /* Separator */
215 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
217 if( p_object != NULL )
219 ppsz_varnames[i] = "bookmark";
220 pi_objects[i++] = p_object->i_object_id;
221 ppsz_varnames[i] = "title";
222 pi_objects[i++] = p_object->i_object_id;
223 ppsz_varnames[i] = "chapter";
224 pi_objects[i++] = p_object->i_object_id;
225 ppsz_varnames[i] = "program";
226 pi_objects[i++] = p_object->i_object_id;
227 ppsz_varnames[i] = "navigation";
228 pi_objects[i++] = p_object->i_object_id;
229 ppsz_varnames[i] = "dvd_menus";
230 pi_objects[i++] = p_object->i_object_id;
232 ppsz_varnames[i] = "video-es";
233 pi_objects[i++] = p_object->i_object_id;
234 ppsz_varnames[i] = "audio-es";
235 pi_objects[i++] = p_object->i_object_id;
236 ppsz_varnames[i] = "spu-es";
237 pi_objects[i++] = p_object->i_object_id;
239 vlc_object_release( p_object );
243 ppsz_varnames[i++] = NULL; /* Separator */
244 ppsz_varnames[i++] = _("Interface menu");
245 ppsz_varnames[i++] = NULL; /* Separator */
247 /* vlc_object_find is needed because of the dialogs provider case */
248 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INTF,
250 if( p_object != NULL )
252 ppsz_varnames[i] = "intf-switch";
253 pi_objects[i++] = p_object->i_object_id;
254 ppsz_varnames[i] = "intf-add";
255 pi_objects[i++] = p_object->i_object_id;
257 vlc_object_release( p_object );
261 Menu popupmenu( p_intf, PopupMenu_Events );
262 popupmenu.Populate( i, ppsz_varnames, pi_objects );
264 /* Add static entries */
265 popupmenu.AppendSeparator();
266 popupmenu.Append( MenuDummy_Event, wxU(_("Open")),
267 OpenStreamMenu( p_intf ), wxT("") );
268 popupmenu.Append( MenuDummy_Event, wxU(_("Miscellaneous")),
269 MiscMenu( p_intf ), wxT("") );
271 p_intf->p_sys->p_popup_menu = &popupmenu;
272 p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
273 p_intf->p_sys->p_popup_menu = NULL;
276 wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
278 #define MAX_AUDIO_ITEMS 10
280 vlc_object_t *p_object;
281 char *ppsz_varnames[MAX_AUDIO_ITEMS];
282 int pi_objects[MAX_AUDIO_ITEMS];
285 /* Initializations */
286 memset( pi_objects, 0, MAX_AUDIO_ITEMS * sizeof(int) );
288 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
290 if( p_object != NULL )
292 ppsz_varnames[i] = "audio-es";
293 pi_objects[i++] = p_object->i_object_id;
294 vlc_object_release( p_object );
297 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_AOUT,
299 if( p_object != NULL )
301 ppsz_varnames[i] = "audio-device";
302 pi_objects[i++] = p_object->i_object_id;
303 ppsz_varnames[i] = "audio-channels";
304 pi_objects[i++] = p_object->i_object_id;
305 ppsz_varnames[i] = "visual";
306 pi_objects[i++] = p_object->i_object_id;
307 vlc_object_release( p_object );
311 Menu *p_vlc_menu = (Menu *)p_menu;
313 p_vlc_menu = new Menu( _p_intf, AudioMenu_Events );
317 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
322 wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
324 #define MAX_VIDEO_ITEMS 15
326 vlc_object_t *p_object;
327 char *ppsz_varnames[MAX_VIDEO_ITEMS];
328 int pi_objects[MAX_VIDEO_ITEMS];
331 /* Initializations */
332 memset( pi_objects, 0, MAX_VIDEO_ITEMS * sizeof(int) );
334 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
336 if( p_object != NULL )
338 ppsz_varnames[i] = "video-es";
339 pi_objects[i++] = p_object->i_object_id;
340 ppsz_varnames[i] = "spu-es";
341 pi_objects[i++] = p_object->i_object_id;
342 vlc_object_release( p_object );
345 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_VOUT,
347 if( p_object != NULL )
349 vlc_object_t *p_dec_obj;
351 ppsz_varnames[i] = "fullscreen";
352 pi_objects[i++] = p_object->i_object_id;
353 ppsz_varnames[i] = "zoom";
354 pi_objects[i++] = p_object->i_object_id;
355 ppsz_varnames[i] = "deinterlace";
356 pi_objects[i++] = p_object->i_object_id;
357 ppsz_varnames[i] = "aspect-ratio";
358 pi_objects[i++] = p_object->i_object_id;
359 ppsz_varnames[i] = "crop";
360 pi_objects[i++] = p_object->i_object_id;
361 ppsz_varnames[i] = "video-on-top";
362 pi_objects[i++] = p_object->i_object_id;
363 ppsz_varnames[i] = "directx-wallpaper";
364 pi_objects[i++] = p_object->i_object_id;
366 p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
369 if( p_dec_obj != NULL )
371 ppsz_varnames[i] = "ffmpeg-pp-q";
372 pi_objects[i++] = p_dec_obj->i_object_id;
373 vlc_object_release( p_dec_obj );
376 vlc_object_release( p_object );
380 Menu *p_vlc_menu = (Menu *)p_menu;
382 p_vlc_menu = new Menu( _p_intf, VideoMenu_Events );
386 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
391 wxMenu *NavigMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
393 #define MAX_NAVIG_ITEMS 10
395 vlc_object_t *p_object;
396 char *ppsz_varnames[MAX_NAVIG_ITEMS];
397 int pi_objects[MAX_NAVIG_ITEMS];
400 /* Initializations */
401 memset( pi_objects, 0, MAX_NAVIG_ITEMS * sizeof(int) );
403 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
405 if( p_object != NULL )
407 ppsz_varnames[i] = "bookmark";
408 pi_objects[i++] = p_object->i_object_id;
409 ppsz_varnames[i] = "title";
410 pi_objects[i++] = p_object->i_object_id;
411 ppsz_varnames[i] = "chapter";
412 pi_objects[i++] = p_object->i_object_id;
413 ppsz_varnames[i] = "program";
414 pi_objects[i++] = p_object->i_object_id;
415 ppsz_varnames[i] = "navigation";
416 pi_objects[i++] = p_object->i_object_id;
417 ppsz_varnames[i] = "dvd_menus";
418 pi_objects[i++] = p_object->i_object_id;
420 ppsz_varnames[i] = "prev-title";
421 pi_objects[i++] = p_object->i_object_id;
422 ppsz_varnames[i] = "next-title";
423 pi_objects[i++] = p_object->i_object_id;
424 ppsz_varnames[i] = "prev-chapter";
425 pi_objects[i++] = p_object->i_object_id;
426 ppsz_varnames[i] = "next-chapter";
427 pi_objects[i++] = p_object->i_object_id;
429 vlc_object_release( p_object );
433 Menu *p_vlc_menu = (Menu *)p_menu;
435 p_vlc_menu = new Menu( _p_intf, NavigMenu_Events );
439 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
444 wxMenu *SettingsMenu( intf_thread_t *_p_intf, wxWindow *p_parent,
447 #define MAX_SETTINGS_ITEMS 10
449 vlc_object_t *p_object;
450 char *ppsz_varnames[MAX_SETTINGS_ITEMS];
451 int pi_objects[MAX_SETTINGS_ITEMS];
454 /* Initializations */
455 memset( pi_objects, 0, MAX_SETTINGS_ITEMS * sizeof(int) );
457 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INTF,
459 if( p_object != NULL )
461 ppsz_varnames[i] = "intf-switch";
462 pi_objects[i++] = p_object->i_object_id;
463 ppsz_varnames[i] = "intf-add";
464 pi_objects[i++] = p_object->i_object_id;
465 vlc_object_release( p_object );
469 Menu *p_vlc_menu = (Menu *)p_menu;
471 p_vlc_menu = new Menu( _p_intf, SettingsMenu_Events );
475 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
480 /*****************************************************************************
482 *****************************************************************************/
483 Menu::Menu( intf_thread_t *_p_intf, int _i_start_id ) : wxMenu( )
485 /* Initializations */
487 i_start_id = _i_start_id;
494 /*****************************************************************************
496 *****************************************************************************/
497 void Menu::Populate( int i_count, char **ppsz_varnames, int *pi_objects )
499 vlc_object_t *p_object;
500 vlc_bool_t b_section_empty = VLC_FALSE;
503 i_item_id = i_start_id;
505 for( i = 0; i < i_count; i++ )
507 if( !ppsz_varnames[i] )
509 if( b_section_empty )
511 Append( MenuDummy_Event + i, wxU(_("Empty")) );
512 Enable( MenuDummy_Event + i, FALSE );
516 b_section_empty = VLC_TRUE;
522 Append( MenuDummy_Event, wxU(ppsz_varnames[i]) );
523 b_section_empty = VLC_FALSE;
527 p_object = (vlc_object_t *)vlc_object_get( p_intf, pi_objects[i] );
528 if( p_object == NULL ) continue;
530 b_section_empty = VLC_FALSE;
531 CreateMenuItem( this, ppsz_varnames[i], p_object );
532 vlc_object_release( p_object );
535 /* Special case for empty menus */
536 if( GetMenuItemCount() == 0 || b_section_empty )
538 Append( MenuDummy_Event + i, wxU(_("Empty")) );
539 Enable( MenuDummy_Event + i, FALSE );
543 /* Work-around helper for buggy wxGTK */
544 static void RecursiveDestroy( wxMenu *menu )
546 wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
549 wxMenuItem *item = node->GetData();
550 node = node->GetNext();
552 /* Delete the submenus */
553 wxMenu *submenu = item->GetSubMenu();
556 RecursiveDestroy( submenu );
558 menu->Delete( item );
564 RecursiveDestroy( this );
567 /*****************************************************************************
569 *****************************************************************************/
570 static bool IsMenuEmpty( char *psz_var, vlc_object_t *p_object,
573 vlc_value_t val, val_list;
574 int i_type, i_result, i;
576 /* Check the type of the object variable */
577 i_type = var_Type( p_object, psz_var );
579 /* Check if we want to display the variable */
580 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
582 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
583 if( val.i_int == 0 ) return TRUE;
585 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
587 if( val.i_int == 1 && b_root ) return TRUE;
591 /* Check children variables in case of VLC_VAR_VARIABLE */
592 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
597 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
599 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
607 /* clean up everything */
608 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
613 void Menu::CreateMenuItem( wxMenu *menu, char *psz_var,
614 vlc_object_t *p_object )
616 wxMenuItemExt *menuitem;
617 vlc_value_t val, text;
620 /* Check the type of the object variable */
621 i_type = var_Type( p_object, psz_var );
623 switch( i_type & VLC_VAR_TYPE )
627 case VLC_VAR_VARIABLE:
629 case VLC_VAR_INTEGER:
633 /* Variable doesn't exist or isn't handled */
637 /* Make sure we want to display the variable */
638 if( IsMenuEmpty( psz_var, p_object ) ) return;
640 /* Get the descriptive name of the variable */
641 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
643 if( i_type & VLC_VAR_HASCHOICE )
645 menu->Append( MenuDummy_Event,
646 wxU(text.psz_string ? text.psz_string : psz_var),
647 CreateChoicesMenu( psz_var, p_object, TRUE ),
648 wxT("")/* Nothing for now (maybe use a GETLONGTEXT) */ );
650 if( text.psz_string ) free( text.psz_string );
655 switch( i_type & VLC_VAR_TYPE )
658 var_Get( p_object, psz_var, &val );
659 menuitem = new wxMenuItemExt( menu, ++i_item_id,
660 wxU(text.psz_string ?
661 text.psz_string : psz_var),
662 wxT(""), wxITEM_NORMAL, strdup(psz_var),
663 p_object->i_object_id, val, i_type );
664 menu->Append( menuitem );
668 var_Get( p_object, psz_var, &val );
669 val.b_bool = !val.b_bool;
670 menuitem = new wxMenuItemExt( menu, ++i_item_id,
671 wxU(text.psz_string ?
672 text.psz_string : psz_var),
673 wxT(""), wxITEM_CHECK, strdup(psz_var),
674 p_object->i_object_id, val, i_type );
675 menu->Append( menuitem );
676 Check( i_item_id, val.b_bool ? FALSE : TRUE );
680 if( text.psz_string ) free( text.psz_string );
683 wxMenu *Menu::CreateChoicesMenu( char *psz_var, vlc_object_t *p_object,
686 vlc_value_t val, val_list, text_list;
689 /* Check the type of the object variable */
690 i_type = var_Type( p_object, psz_var );
692 /* Make sure we want to display the variable */
693 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return NULL;
695 switch( i_type & VLC_VAR_TYPE )
699 case VLC_VAR_VARIABLE:
701 case VLC_VAR_INTEGER:
705 /* Variable doesn't exist or isn't handled */
709 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
710 &val_list, &text_list ) < 0 )
715 wxMenu *menu = new wxMenu;
716 for( i = 0; i < val_list.p_list->i_count; i++ )
718 vlc_value_t another_val;
719 wxMenuItemExt *menuitem;
721 switch( i_type & VLC_VAR_TYPE )
723 case VLC_VAR_VARIABLE:
724 menu->Append( MenuDummy_Event,
725 wxU(text_list.p_list->p_values[i].psz_string ?
726 text_list.p_list->p_values[i].psz_string :
727 val_list.p_list->p_values[i].psz_string),
729 val_list.p_list->p_values[i].psz_string,
730 p_object, FALSE ), wxT("") );
734 var_Get( p_object, psz_var, &val );
736 another_val.psz_string =
737 strdup(val_list.p_list->p_values[i].psz_string);
739 new wxMenuItemExt( menu, ++i_item_id,
740 wxU(text_list.p_list->p_values[i].psz_string ?
741 text_list.p_list->p_values[i].psz_string :
742 another_val.psz_string), wxT(""),
743 i_type & VLC_VAR_ISCOMMAND ?
744 wxITEM_NORMAL : wxITEM_RADIO,
746 p_object->i_object_id, another_val, i_type );
748 menu->Append( menuitem );
750 if( !(i_type & VLC_VAR_ISCOMMAND) && val.psz_string &&
751 !strcmp( val.psz_string,
752 val_list.p_list->p_values[i].psz_string ) )
753 menu->Check( i_item_id, TRUE );
755 if( val.psz_string ) free( val.psz_string );
758 case VLC_VAR_INTEGER:
759 var_Get( p_object, psz_var, &val );
762 new wxMenuItemExt( menu, ++i_item_id,
763 text_list.p_list->p_values[i].psz_string ?
765 text_list.p_list->p_values[i].psz_string) :
766 wxString::Format(wxT("%d"),
767 val_list.p_list->p_values[i].i_int), wxT(""),
768 i_type & VLC_VAR_ISCOMMAND ?
769 wxITEM_NORMAL : wxITEM_RADIO,
771 p_object->i_object_id,
772 val_list.p_list->p_values[i], i_type );
774 menu->Append( menuitem );
776 if( !(i_type & VLC_VAR_ISCOMMAND) &&
777 val_list.p_list->p_values[i].i_int == val.i_int )
778 menu->Check( i_item_id, TRUE );
782 var_Get( p_object, psz_var, &val );
785 new wxMenuItemExt( menu, ++i_item_id,
786 text_list.p_list->p_values[i].psz_string ?
788 text_list.p_list->p_values[i].psz_string) :
789 wxString::Format(wxT("%.2f"),
790 val_list.p_list->p_values[i].f_float),wxT(""),
791 i_type & VLC_VAR_ISCOMMAND ?
792 wxITEM_NORMAL : wxITEM_RADIO,
794 p_object->i_object_id,
795 val_list.p_list->p_values[i], i_type );
797 menu->Append( menuitem );
799 if( !(i_type & VLC_VAR_ISCOMMAND) &&
800 val_list.p_list->p_values[i].f_float == val.f_float )
801 menu->Check( i_item_id, TRUE );
809 /* clean up everything */
810 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
815 /*****************************************************************************
816 * A small helper class which intercepts all popup menu events
817 *****************************************************************************/
818 MenuEvtHandler::MenuEvtHandler( intf_thread_t *_p_intf,
819 Interface *_p_main_interface )
821 /* Initializations */
823 p_main_interface = _p_main_interface;
826 MenuEvtHandler::~MenuEvtHandler()
830 void MenuEvtHandler::OnShowDialog( wxCommandEvent& event )
832 if( p_intf->p_sys->pf_show_dialog )
836 switch( event.GetId() )
838 case OpenFileSimple_Event:
839 i_id = INTF_DIALOG_FILE_SIMPLE;
842 i_id = INTF_DIALOG_FILE;
845 i_id = INTF_DIALOG_DISC;
848 i_id = INTF_DIALOG_NET;
850 case OpenCapture_Event:
851 i_id = INTF_DIALOG_CAPTURE;
853 case MediaInfo_Event:
854 i_id = INTF_DIALOG_FILEINFO;
857 i_id = INTF_DIALOG_MESSAGES;
859 case Preferences_Event:
860 i_id = INTF_DIALOG_PREFS;
863 i_id = INTF_DIALOG_FILE;
868 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
872 void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
874 wxMenuItem *p_menuitem = NULL;
875 int i_hotkey_event = p_intf->p_sys->i_first_hotkey_event;
876 int i_hotkeys = p_intf->p_sys->i_hotkeys;
878 /* Check if this is an auto generated menu item */
879 if( event.GetId() < FirstAutoGenerated_Event )
885 /* Check if this is an hotkey event */
886 if( event.GetId() >= i_hotkey_event &&
887 event.GetId() < i_hotkey_event + i_hotkeys )
892 p_intf->p_vlc->p_hotkeys[event.GetId() - i_hotkey_event].i_key;
894 /* Get the key combination and send it to the hotkey handler */
895 var_Set( p_intf->p_vlc, "key-pressed", val );
896 msg_Err( p_intf, "received key event: %i", event.GetId() );
900 if( !p_main_interface ||
901 (p_menuitem = p_main_interface->GetMenuBar()->FindItem(event.GetId()))
904 if( p_intf->p_sys->p_popup_menu )
907 p_intf->p_sys->p_popup_menu->FindItem( event.GetId() );
913 wxMenuItemExt *p_menuitemext = (wxMenuItemExt *)p_menuitem;
914 vlc_object_t *p_object;
916 p_object = (vlc_object_t *)vlc_object_get( p_intf,
917 p_menuitemext->i_object_id );
918 if( p_object == NULL ) return;
920 wxMutexGuiLeave(); // We don't want deadlocks
921 var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val );
924 vlc_object_release( p_object );
930 /*****************************************************************************
931 * A small helper class which encapsulate wxMenuitem with some other useful
933 *****************************************************************************/
934 wxMenuItemExt::wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
935 const wxString& helpString, wxItemKind kind,
936 char *_psz_var, int _i_object_id, vlc_value_t _val, int _i_val_type ):
937 wxMenuItem( parentMenu, id, text, helpString, kind )
939 /* Initializations */
941 i_val_type = _i_val_type;
942 i_object_id = _i_object_id;
946 wxMenuItemExt::~wxMenuItemExt()
948 if( psz_var ) free( psz_var );
949 if( ((i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
950 && val.psz_string ) free( val.psz_string );