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 ppsz_varnames[i] = "equalizer";
169 pi_objects[i++] = p_object->i_object_id;
170 vlc_object_release( p_object );
174 ppsz_varnames[i++] = NULL; /* Separator */
175 ppsz_varnames[i++] = _("Video menu");
176 ppsz_varnames[i++] = NULL; /* Separator */
178 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
180 if( p_object != NULL )
182 vlc_object_t *p_dec_obj;
184 ppsz_varnames[i] = "fullscreen";
185 pi_objects[i++] = p_object->i_object_id;
186 ppsz_varnames[i] = "zoom";
187 pi_objects[i++] = p_object->i_object_id;
188 ppsz_varnames[i] = "deinterlace";
189 pi_objects[i++] = p_object->i_object_id;
190 ppsz_varnames[i] = "aspect-ratio";
191 pi_objects[i++] = p_object->i_object_id;
192 ppsz_varnames[i] = "crop";
193 pi_objects[i++] = p_object->i_object_id;
194 ppsz_varnames[i] = "video-on-top";
195 pi_objects[i++] = p_object->i_object_id;
196 ppsz_varnames[i] = "directx-wallpaper";
197 pi_objects[i++] = p_object->i_object_id;
199 p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
202 if( p_dec_obj != NULL )
204 ppsz_varnames[i] = "ffmpeg-pp-q";
205 pi_objects[i++] = p_dec_obj->i_object_id;
206 vlc_object_release( p_dec_obj );
209 vlc_object_release( p_object );
213 ppsz_varnames[i++] = NULL; /* Separator */
214 ppsz_varnames[i++] = _("Input menu");
215 ppsz_varnames[i++] = NULL; /* Separator */
217 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
219 if( p_object != NULL )
221 ppsz_varnames[i] = "bookmark";
222 pi_objects[i++] = p_object->i_object_id;
223 ppsz_varnames[i] = "title";
224 pi_objects[i++] = p_object->i_object_id;
225 ppsz_varnames[i] = "chapter";
226 pi_objects[i++] = p_object->i_object_id;
227 ppsz_varnames[i] = "program";
228 pi_objects[i++] = p_object->i_object_id;
229 ppsz_varnames[i] = "navigation";
230 pi_objects[i++] = p_object->i_object_id;
231 ppsz_varnames[i] = "dvd_menus";
232 pi_objects[i++] = p_object->i_object_id;
234 ppsz_varnames[i] = "video-es";
235 pi_objects[i++] = p_object->i_object_id;
236 ppsz_varnames[i] = "audio-es";
237 pi_objects[i++] = p_object->i_object_id;
238 ppsz_varnames[i] = "spu-es";
239 pi_objects[i++] = p_object->i_object_id;
241 vlc_object_release( p_object );
245 ppsz_varnames[i++] = NULL; /* Separator */
246 ppsz_varnames[i++] = _("Interface menu");
247 ppsz_varnames[i++] = NULL; /* Separator */
249 /* vlc_object_find is needed because of the dialogs provider case */
250 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INTF,
252 if( p_object != NULL )
254 ppsz_varnames[i] = "intf-switch";
255 pi_objects[i++] = p_object->i_object_id;
256 ppsz_varnames[i] = "intf-add";
257 pi_objects[i++] = p_object->i_object_id;
258 ppsz_varnames[i] = "intf-skins";
259 pi_objects[i++] = p_object->i_object_id;
261 vlc_object_release( p_object );
265 Menu popupmenu( p_intf, PopupMenu_Events );
266 popupmenu.Populate( i, ppsz_varnames, pi_objects );
268 /* Add static entries */
269 popupmenu.AppendSeparator();
270 popupmenu.Append( MenuDummy_Event, wxU(_("Open")),
271 OpenStreamMenu( p_intf ), wxT("") );
272 popupmenu.Append( MenuDummy_Event, wxU(_("Miscellaneous")),
273 MiscMenu( p_intf ), wxT("") );
275 p_intf->p_sys->p_popup_menu = &popupmenu;
276 p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
277 p_intf->p_sys->p_popup_menu = NULL;
280 wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
282 #define MAX_AUDIO_ITEMS 10
284 vlc_object_t *p_object;
285 char *ppsz_varnames[MAX_AUDIO_ITEMS];
286 int pi_objects[MAX_AUDIO_ITEMS];
289 /* Initializations */
290 memset( pi_objects, 0, MAX_AUDIO_ITEMS * sizeof(int) );
292 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
294 if( p_object != NULL )
296 ppsz_varnames[i] = "audio-es";
297 pi_objects[i++] = p_object->i_object_id;
298 vlc_object_release( p_object );
301 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_AOUT,
303 if( p_object != NULL )
305 ppsz_varnames[i] = "audio-device";
306 pi_objects[i++] = p_object->i_object_id;
307 ppsz_varnames[i] = "audio-channels";
308 pi_objects[i++] = p_object->i_object_id;
309 ppsz_varnames[i] = "visual";
310 pi_objects[i++] = p_object->i_object_id;
311 ppsz_varnames[i] = "equalizer";
312 pi_objects[i++] = p_object->i_object_id;
313 vlc_object_release( p_object );
317 Menu *p_vlc_menu = (Menu *)p_menu;
319 p_vlc_menu = new Menu( _p_intf, AudioMenu_Events );
323 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
328 wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
330 #define MAX_VIDEO_ITEMS 15
332 vlc_object_t *p_object;
333 char *ppsz_varnames[MAX_VIDEO_ITEMS];
334 int pi_objects[MAX_VIDEO_ITEMS];
337 /* Initializations */
338 memset( pi_objects, 0, MAX_VIDEO_ITEMS * sizeof(int) );
340 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
342 if( p_object != NULL )
344 ppsz_varnames[i] = "video-es";
345 pi_objects[i++] = p_object->i_object_id;
346 ppsz_varnames[i] = "spu-es";
347 pi_objects[i++] = p_object->i_object_id;
348 vlc_object_release( p_object );
351 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_VOUT,
353 if( p_object != NULL )
355 vlc_object_t *p_dec_obj;
357 ppsz_varnames[i] = "fullscreen";
358 pi_objects[i++] = p_object->i_object_id;
359 ppsz_varnames[i] = "zoom";
360 pi_objects[i++] = p_object->i_object_id;
361 ppsz_varnames[i] = "deinterlace";
362 pi_objects[i++] = p_object->i_object_id;
363 ppsz_varnames[i] = "aspect-ratio";
364 pi_objects[i++] = p_object->i_object_id;
365 ppsz_varnames[i] = "crop";
366 pi_objects[i++] = p_object->i_object_id;
367 ppsz_varnames[i] = "video-on-top";
368 pi_objects[i++] = p_object->i_object_id;
369 ppsz_varnames[i] = "directx-wallpaper";
370 pi_objects[i++] = p_object->i_object_id;
372 p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
375 if( p_dec_obj != NULL )
377 ppsz_varnames[i] = "ffmpeg-pp-q";
378 pi_objects[i++] = p_dec_obj->i_object_id;
379 vlc_object_release( p_dec_obj );
382 vlc_object_release( p_object );
386 Menu *p_vlc_menu = (Menu *)p_menu;
388 p_vlc_menu = new Menu( _p_intf, VideoMenu_Events );
392 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
397 wxMenu *NavigMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
399 #define MAX_NAVIG_ITEMS 10
401 vlc_object_t *p_object;
402 char *ppsz_varnames[MAX_NAVIG_ITEMS];
403 int pi_objects[MAX_NAVIG_ITEMS];
406 /* Initializations */
407 memset( pi_objects, 0, MAX_NAVIG_ITEMS * sizeof(int) );
409 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
411 if( p_object != NULL )
413 ppsz_varnames[i] = "bookmark";
414 pi_objects[i++] = p_object->i_object_id;
415 ppsz_varnames[i] = "title";
416 pi_objects[i++] = p_object->i_object_id;
417 ppsz_varnames[i] = "chapter";
418 pi_objects[i++] = p_object->i_object_id;
419 ppsz_varnames[i] = "program";
420 pi_objects[i++] = p_object->i_object_id;
421 ppsz_varnames[i] = "navigation";
422 pi_objects[i++] = p_object->i_object_id;
423 ppsz_varnames[i] = "dvd_menus";
424 pi_objects[i++] = p_object->i_object_id;
426 ppsz_varnames[i] = "prev-title";
427 pi_objects[i++] = p_object->i_object_id;
428 ppsz_varnames[i] = "next-title";
429 pi_objects[i++] = p_object->i_object_id;
430 ppsz_varnames[i] = "prev-chapter";
431 pi_objects[i++] = p_object->i_object_id;
432 ppsz_varnames[i] = "next-chapter";
433 pi_objects[i++] = p_object->i_object_id;
435 vlc_object_release( p_object );
439 Menu *p_vlc_menu = (Menu *)p_menu;
441 p_vlc_menu = new Menu( _p_intf, NavigMenu_Events );
445 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
450 wxMenu *SettingsMenu( intf_thread_t *_p_intf, wxWindow *p_parent,
453 #define MAX_SETTINGS_ITEMS 10
455 vlc_object_t *p_object;
456 char *ppsz_varnames[MAX_SETTINGS_ITEMS];
457 int pi_objects[MAX_SETTINGS_ITEMS];
460 /* Initializations */
461 memset( pi_objects, 0, MAX_SETTINGS_ITEMS * sizeof(int) );
463 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INTF,
465 if( p_object != NULL )
467 ppsz_varnames[i] = "intf-switch";
468 pi_objects[i++] = p_object->i_object_id;
469 ppsz_varnames[i] = "intf-add";
470 pi_objects[i++] = p_object->i_object_id;
471 vlc_object_release( p_object );
475 Menu *p_vlc_menu = (Menu *)p_menu;
477 p_vlc_menu = new Menu( _p_intf, SettingsMenu_Events );
481 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
486 /*****************************************************************************
488 *****************************************************************************/
489 Menu::Menu( intf_thread_t *_p_intf, int _i_start_id ) : wxMenu( )
491 /* Initializations */
493 i_start_id = _i_start_id;
500 /*****************************************************************************
502 *****************************************************************************/
503 void Menu::Populate( int i_count, char **ppsz_varnames, int *pi_objects )
505 vlc_object_t *p_object;
506 vlc_bool_t b_section_empty = VLC_FALSE;
509 i_item_id = i_start_id;
511 for( i = 0; i < i_count; i++ )
513 if( !ppsz_varnames[i] )
515 if( b_section_empty )
517 Append( MenuDummy_Event + i, wxU(_("Empty")) );
518 Enable( MenuDummy_Event + i, FALSE );
522 b_section_empty = VLC_TRUE;
528 Append( MenuDummy_Event, wxU(ppsz_varnames[i]) );
529 b_section_empty = VLC_FALSE;
533 p_object = (vlc_object_t *)vlc_object_get( p_intf, pi_objects[i] );
534 if( p_object == NULL ) continue;
536 b_section_empty = VLC_FALSE;
537 CreateMenuItem( this, ppsz_varnames[i], p_object );
538 vlc_object_release( p_object );
541 /* Special case for empty menus */
542 if( GetMenuItemCount() == 0 || b_section_empty )
544 Append( MenuDummy_Event + i, wxU(_("Empty")) );
545 Enable( MenuDummy_Event + i, FALSE );
549 /* Work-around helper for buggy wxGTK */
550 static void RecursiveDestroy( wxMenu *menu )
552 wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
555 wxMenuItem *item = node->GetData();
556 node = node->GetNext();
558 /* Delete the submenus */
559 wxMenu *submenu = item->GetSubMenu();
562 RecursiveDestroy( submenu );
564 menu->Delete( item );
570 RecursiveDestroy( this );
573 /*****************************************************************************
575 *****************************************************************************/
576 static bool IsMenuEmpty( char *psz_var, vlc_object_t *p_object,
579 vlc_value_t val, val_list;
580 int i_type, i_result, i;
582 /* Check the type of the object variable */
583 i_type = var_Type( p_object, psz_var );
585 /* Check if we want to display the variable */
586 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
588 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
589 if( val.i_int == 0 ) return TRUE;
591 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
593 if( val.i_int == 1 && b_root ) return TRUE;
597 /* Check children variables in case of VLC_VAR_VARIABLE */
598 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
603 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
605 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
613 /* clean up everything */
614 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
619 void Menu::CreateMenuItem( wxMenu *menu, char *psz_var,
620 vlc_object_t *p_object )
622 wxMenuItemExt *menuitem;
623 vlc_value_t val, text;
626 /* Check the type of the object variable */
627 i_type = var_Type( p_object, psz_var );
629 switch( i_type & VLC_VAR_TYPE )
633 case VLC_VAR_VARIABLE:
635 case VLC_VAR_INTEGER:
639 /* Variable doesn't exist or isn't handled */
643 /* Make sure we want to display the variable */
644 if( IsMenuEmpty( psz_var, p_object ) ) return;
646 /* Get the descriptive name of the variable */
647 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
649 if( i_type & VLC_VAR_HASCHOICE )
651 menu->Append( MenuDummy_Event,
652 wxU(text.psz_string ? text.psz_string : psz_var),
653 CreateChoicesMenu( psz_var, p_object, TRUE ),
654 wxT("")/* Nothing for now (maybe use a GETLONGTEXT) */ );
656 if( text.psz_string ) free( text.psz_string );
661 switch( i_type & VLC_VAR_TYPE )
664 var_Get( p_object, psz_var, &val );
665 menuitem = new wxMenuItemExt( menu, ++i_item_id,
666 wxU(text.psz_string ?
667 text.psz_string : psz_var),
668 wxT(""), wxITEM_NORMAL, strdup(psz_var),
669 p_object->i_object_id, val, i_type );
670 menu->Append( menuitem );
674 var_Get( p_object, psz_var, &val );
675 val.b_bool = !val.b_bool;
676 menuitem = new wxMenuItemExt( menu, ++i_item_id,
677 wxU(text.psz_string ?
678 text.psz_string : psz_var),
679 wxT(""), wxITEM_CHECK, strdup(psz_var),
680 p_object->i_object_id, val, i_type );
681 menu->Append( menuitem );
682 Check( i_item_id, val.b_bool ? FALSE : TRUE );
686 if( text.psz_string ) free( text.psz_string );
689 wxMenu *Menu::CreateChoicesMenu( char *psz_var, vlc_object_t *p_object,
692 vlc_value_t val, val_list, text_list;
695 /* Check the type of the object variable */
696 i_type = var_Type( p_object, psz_var );
698 /* Make sure we want to display the variable */
699 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return NULL;
701 switch( i_type & VLC_VAR_TYPE )
705 case VLC_VAR_VARIABLE:
707 case VLC_VAR_INTEGER:
711 /* Variable doesn't exist or isn't handled */
715 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
716 &val_list, &text_list ) < 0 )
721 wxMenu *menu = new wxMenu;
722 for( i = 0; i < val_list.p_list->i_count; i++ )
724 vlc_value_t another_val;
725 wxMenuItemExt *menuitem;
727 switch( i_type & VLC_VAR_TYPE )
729 case VLC_VAR_VARIABLE:
730 menu->Append( MenuDummy_Event,
731 wxU(text_list.p_list->p_values[i].psz_string ?
732 text_list.p_list->p_values[i].psz_string :
733 val_list.p_list->p_values[i].psz_string),
735 val_list.p_list->p_values[i].psz_string,
736 p_object, FALSE ), wxT("") );
740 var_Get( p_object, psz_var, &val );
742 another_val.psz_string =
743 strdup(val_list.p_list->p_values[i].psz_string);
745 new wxMenuItemExt( menu, ++i_item_id,
746 wxU(text_list.p_list->p_values[i].psz_string ?
747 text_list.p_list->p_values[i].psz_string :
748 another_val.psz_string), wxT(""),
749 i_type & VLC_VAR_ISCOMMAND ?
750 wxITEM_NORMAL : wxITEM_RADIO,
752 p_object->i_object_id, another_val, i_type );
754 menu->Append( menuitem );
756 if( !(i_type & VLC_VAR_ISCOMMAND) && val.psz_string &&
757 !strcmp( val.psz_string,
758 val_list.p_list->p_values[i].psz_string ) )
759 menu->Check( i_item_id, TRUE );
761 if( val.psz_string ) free( val.psz_string );
764 case VLC_VAR_INTEGER:
765 var_Get( p_object, psz_var, &val );
768 new wxMenuItemExt( menu, ++i_item_id,
769 text_list.p_list->p_values[i].psz_string ?
771 text_list.p_list->p_values[i].psz_string) :
772 wxString::Format(wxT("%d"),
773 val_list.p_list->p_values[i].i_int), wxT(""),
774 i_type & VLC_VAR_ISCOMMAND ?
775 wxITEM_NORMAL : wxITEM_RADIO,
777 p_object->i_object_id,
778 val_list.p_list->p_values[i], i_type );
780 menu->Append( menuitem );
782 if( !(i_type & VLC_VAR_ISCOMMAND) &&
783 val_list.p_list->p_values[i].i_int == val.i_int )
784 menu->Check( i_item_id, TRUE );
788 var_Get( p_object, psz_var, &val );
791 new wxMenuItemExt( menu, ++i_item_id,
792 text_list.p_list->p_values[i].psz_string ?
794 text_list.p_list->p_values[i].psz_string) :
795 wxString::Format(wxT("%.2f"),
796 val_list.p_list->p_values[i].f_float),wxT(""),
797 i_type & VLC_VAR_ISCOMMAND ?
798 wxITEM_NORMAL : wxITEM_RADIO,
800 p_object->i_object_id,
801 val_list.p_list->p_values[i], i_type );
803 menu->Append( menuitem );
805 if( !(i_type & VLC_VAR_ISCOMMAND) &&
806 val_list.p_list->p_values[i].f_float == val.f_float )
807 menu->Check( i_item_id, TRUE );
815 /* clean up everything */
816 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
821 /*****************************************************************************
822 * A small helper class which intercepts all popup menu events
823 *****************************************************************************/
824 MenuEvtHandler::MenuEvtHandler( intf_thread_t *_p_intf,
825 Interface *_p_main_interface )
827 /* Initializations */
829 p_main_interface = _p_main_interface;
832 MenuEvtHandler::~MenuEvtHandler()
836 void MenuEvtHandler::OnShowDialog( wxCommandEvent& event )
838 if( p_intf->p_sys->pf_show_dialog )
842 switch( event.GetId() )
844 case OpenFileSimple_Event:
845 i_id = INTF_DIALOG_FILE_SIMPLE;
848 i_id = INTF_DIALOG_FILE;
851 i_id = INTF_DIALOG_DISC;
854 i_id = INTF_DIALOG_NET;
856 case OpenCapture_Event:
857 i_id = INTF_DIALOG_CAPTURE;
859 case MediaInfo_Event:
860 i_id = INTF_DIALOG_FILEINFO;
863 i_id = INTF_DIALOG_MESSAGES;
865 case Preferences_Event:
866 i_id = INTF_DIALOG_PREFS;
869 i_id = INTF_DIALOG_FILE;
874 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
878 void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
880 wxMenuItem *p_menuitem = NULL;
881 int i_hotkey_event = p_intf->p_sys->i_first_hotkey_event;
882 int i_hotkeys = p_intf->p_sys->i_hotkeys;
884 /* Check if this is an auto generated menu item */
885 if( event.GetId() < FirstAutoGenerated_Event )
891 /* Check if this is an hotkey event */
892 if( event.GetId() >= i_hotkey_event &&
893 event.GetId() < i_hotkey_event + i_hotkeys )
898 p_intf->p_vlc->p_hotkeys[event.GetId() - i_hotkey_event].i_key;
900 /* Get the key combination and send it to the hotkey handler */
901 var_Set( p_intf->p_vlc, "key-pressed", val );
905 if( !p_main_interface ||
906 (p_menuitem = p_main_interface->GetMenuBar()->FindItem(event.GetId()))
909 if( p_intf->p_sys->p_popup_menu )
912 p_intf->p_sys->p_popup_menu->FindItem( event.GetId() );
918 wxMenuItemExt *p_menuitemext = (wxMenuItemExt *)p_menuitem;
919 vlc_object_t *p_object;
921 p_object = (vlc_object_t *)vlc_object_get( p_intf,
922 p_menuitemext->i_object_id );
923 if( p_object == NULL ) return;
925 wxMutexGuiLeave(); // We don't want deadlocks
926 var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val );
929 vlc_object_release( p_object );
935 /*****************************************************************************
936 * A small helper class which encapsulate wxMenuitem with some other useful
938 *****************************************************************************/
939 wxMenuItemExt::wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
940 const wxString& helpString, wxItemKind kind,
941 char *_psz_var, int _i_object_id, vlc_value_t _val, int _i_val_type ):
942 wxMenuItem( parentMenu, id, text, helpString, kind )
944 /* Initializations */
946 i_val_type = _i_val_type;
947 i_object_id = _i_object_id;
951 wxMenuItemExt::~wxMenuItemExt()
953 if( psz_var ) free( psz_var );
954 if( ((i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
955 && val.psz_string ) free( val.psz_string );