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,
95 FirstAutoGenerated_Event = wxID_HIGHEST + 1999,
96 SettingsMenu_Events = wxID_HIGHEST + 5000,
97 AudioMenu_Events = wxID_HIGHEST + 2000,
98 VideoMenu_Events = wxID_HIGHEST + 3000,
99 NavigMenu_Events = wxID_HIGHEST + 4000,
100 PopupMenu_Events = wxID_HIGHEST + 6000,
101 Hotkeys_Events = wxID_HIGHEST + 7000
104 BEGIN_EVENT_TABLE(Menu, wxMenu)
107 BEGIN_EVENT_TABLE(MenuEvtHandler, wxEvtHandler)
108 EVT_MENU(OpenFileSimple_Event, MenuEvtHandler::OnShowDialog)
109 EVT_MENU(OpenFile_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(Preferences_Event, MenuEvtHandler::OnShowDialog)
114 EVT_MENU(-1, MenuEvtHandler::OnMenuEvent)
117 wxMenu *OpenStreamMenu( intf_thread_t *p_intf )
119 wxMenu *menu = new wxMenu;
120 menu->Append( OpenFileSimple_Event, wxU(_("Quick &Open File...")) );
121 menu->Append( OpenFile_Event, wxU(_("Open &File...")) );
122 menu->Append( OpenDisc_Event, wxU(_("Open &Disc...")) );
123 menu->Append( OpenNet_Event, wxU(_("Open &Network Stream...")) );
124 menu->Append( OpenCapture_Event, wxU(_("Open &Capture Device...")) );
128 void PopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
131 #define MAX_POPUP_ITEMS 35
133 vlc_object_t *p_object;
134 char *ppsz_varnames[MAX_POPUP_ITEMS];
135 int pi_objects[MAX_POPUP_ITEMS];
138 /* Initializations */
139 memset( pi_objects, 0, MAX_POPUP_ITEMS * sizeof(int) );
142 ppsz_varnames[i++] = _("Audio menu");
143 ppsz_varnames[i++] = NULL; /* Separator */
145 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
147 if( p_object != NULL )
149 ppsz_varnames[i] = "audio-device";
150 pi_objects[i++] = p_object->i_object_id;
151 ppsz_varnames[i] = "audio-channels";
152 pi_objects[i++] = p_object->i_object_id;
153 ppsz_varnames[i] = "visual";
154 pi_objects[i++] = p_object->i_object_id;
155 vlc_object_release( p_object );
159 ppsz_varnames[i++] = NULL; /* Separator */
160 ppsz_varnames[i++] = _("Video menu");
161 ppsz_varnames[i++] = NULL; /* Separator */
163 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
165 if( p_object != NULL )
167 vlc_object_t *p_dec_obj;
169 ppsz_varnames[i] = "fullscreen";
170 pi_objects[i++] = p_object->i_object_id;
171 ppsz_varnames[i] = "zoom";
172 pi_objects[i++] = p_object->i_object_id;
173 ppsz_varnames[i] = "deinterlace";
174 pi_objects[i++] = p_object->i_object_id;
175 ppsz_varnames[i] = "aspect-ratio";
176 pi_objects[i++] = p_object->i_object_id;
177 ppsz_varnames[i] = "crop";
178 pi_objects[i++] = p_object->i_object_id;
179 ppsz_varnames[i] = "video-on-top";
180 pi_objects[i++] = p_object->i_object_id;
181 ppsz_varnames[i] = "directx-wallpaper";
182 pi_objects[i++] = p_object->i_object_id;
184 p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
187 if( p_dec_obj != NULL )
189 ppsz_varnames[i] = "ffmpeg-pp-q";
190 pi_objects[i++] = p_dec_obj->i_object_id;
191 vlc_object_release( p_dec_obj );
194 vlc_object_release( p_object );
198 ppsz_varnames[i++] = NULL; /* Separator */
199 ppsz_varnames[i++] = _("Input menu");
200 ppsz_varnames[i++] = NULL; /* Separator */
202 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
204 if( p_object != NULL )
206 ppsz_varnames[i] = "bookmark";
207 pi_objects[i++] = p_object->i_object_id;
208 ppsz_varnames[i] = "title";
209 pi_objects[i++] = p_object->i_object_id;
210 ppsz_varnames[i] = "chapter";
211 pi_objects[i++] = p_object->i_object_id;
212 ppsz_varnames[i] = "program";
213 pi_objects[i++] = p_object->i_object_id;
214 ppsz_varnames[i] = "navigation";
215 pi_objects[i++] = p_object->i_object_id;
216 ppsz_varnames[i] = "dvd_menus";
217 pi_objects[i++] = p_object->i_object_id;
219 ppsz_varnames[i] = "video-es";
220 pi_objects[i++] = p_object->i_object_id;
221 ppsz_varnames[i] = "audio-es";
222 pi_objects[i++] = p_object->i_object_id;
223 ppsz_varnames[i] = "spu-es";
224 pi_objects[i++] = p_object->i_object_id;
226 vlc_object_release( p_object );
230 ppsz_varnames[i++] = NULL; /* Separator */
231 ppsz_varnames[i++] = _("Interface menu");
232 ppsz_varnames[i++] = NULL; /* Separator */
234 /* vlc_object_find is needed because of the dialogs provider case */
235 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INTF,
237 if( p_object != NULL )
239 ppsz_varnames[i] = "intf-switch";
240 pi_objects[i++] = p_object->i_object_id;
241 ppsz_varnames[i] = "intf-add";
242 pi_objects[i++] = p_object->i_object_id;
244 vlc_object_release( p_object );
248 Menu popupmenu( p_intf, PopupMenu_Events );
249 popupmenu.Populate( i, ppsz_varnames, pi_objects );
251 /* Add static entries */
252 popupmenu.AppendSeparator();
253 popupmenu.Append( MenuDummy_Event, wxU("Open..."),
254 OpenStreamMenu( p_intf ), wxT("") );
255 popupmenu.Append( Preferences_Event, wxU(_("&Preferences...")) );
257 p_intf->p_sys->p_popup_menu = &popupmenu;
258 p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
259 p_intf->p_sys->p_popup_menu = NULL;
262 wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
264 #define MAX_AUDIO_ITEMS 10
266 vlc_object_t *p_object;
267 char *ppsz_varnames[MAX_AUDIO_ITEMS];
268 int pi_objects[MAX_AUDIO_ITEMS];
271 /* Initializations */
272 memset( pi_objects, 0, MAX_AUDIO_ITEMS * sizeof(int) );
274 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
276 if( p_object != NULL )
278 ppsz_varnames[i] = "audio-es";
279 pi_objects[i++] = p_object->i_object_id;
280 vlc_object_release( p_object );
283 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_AOUT,
285 if( p_object != NULL )
287 ppsz_varnames[i] = "audio-device";
288 pi_objects[i++] = p_object->i_object_id;
289 ppsz_varnames[i] = "audio-channels";
290 pi_objects[i++] = p_object->i_object_id;
291 ppsz_varnames[i] = "visual";
292 pi_objects[i++] = p_object->i_object_id;
293 vlc_object_release( p_object );
297 Menu *p_vlc_menu = (Menu *)p_menu;
299 p_vlc_menu = new Menu( _p_intf, AudioMenu_Events );
303 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
308 wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
310 #define MAX_VIDEO_ITEMS 15
312 vlc_object_t *p_object;
313 char *ppsz_varnames[MAX_VIDEO_ITEMS];
314 int pi_objects[MAX_VIDEO_ITEMS];
317 /* Initializations */
318 memset( pi_objects, 0, MAX_VIDEO_ITEMS * sizeof(int) );
320 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
322 if( p_object != NULL )
324 ppsz_varnames[i] = "video-es";
325 pi_objects[i++] = p_object->i_object_id;
326 ppsz_varnames[i] = "spu-es";
327 pi_objects[i++] = p_object->i_object_id;
328 vlc_object_release( p_object );
331 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_VOUT,
333 if( p_object != NULL )
335 vlc_object_t *p_dec_obj;
337 ppsz_varnames[i] = "fullscreen";
338 pi_objects[i++] = p_object->i_object_id;
339 ppsz_varnames[i] = "zoom";
340 pi_objects[i++] = p_object->i_object_id;
341 ppsz_varnames[i] = "deinterlace";
342 pi_objects[i++] = p_object->i_object_id;
343 ppsz_varnames[i] = "aspect-ratio";
344 pi_objects[i++] = p_object->i_object_id;
345 ppsz_varnames[i] = "crop";
346 pi_objects[i++] = p_object->i_object_id;
347 ppsz_varnames[i] = "video-on-top";
348 pi_objects[i++] = p_object->i_object_id;
349 ppsz_varnames[i] = "directx-wallpaper";
350 pi_objects[i++] = p_object->i_object_id;
352 p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
355 if( p_dec_obj != NULL )
357 ppsz_varnames[i] = "ffmpeg-pp-q";
358 pi_objects[i++] = p_dec_obj->i_object_id;
359 vlc_object_release( p_dec_obj );
362 vlc_object_release( p_object );
366 Menu *p_vlc_menu = (Menu *)p_menu;
368 p_vlc_menu = new Menu( _p_intf, VideoMenu_Events );
372 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
377 wxMenu *NavigMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
379 #define MAX_NAVIG_ITEMS 10
381 vlc_object_t *p_object;
382 char *ppsz_varnames[MAX_NAVIG_ITEMS];
383 int pi_objects[MAX_NAVIG_ITEMS];
386 /* Initializations */
387 memset( pi_objects, 0, MAX_NAVIG_ITEMS * sizeof(int) );
389 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
391 if( p_object != NULL )
393 ppsz_varnames[i] = "bookmark";
394 pi_objects[i++] = p_object->i_object_id;
395 ppsz_varnames[i] = "title";
396 pi_objects[i++] = p_object->i_object_id;
397 ppsz_varnames[i] = "chapter";
398 pi_objects[i++] = p_object->i_object_id;
399 ppsz_varnames[i] = "program";
400 pi_objects[i++] = p_object->i_object_id;
401 ppsz_varnames[i] = "navigation";
402 pi_objects[i++] = p_object->i_object_id;
403 ppsz_varnames[i] = "dvd_menus";
404 pi_objects[i++] = p_object->i_object_id;
406 ppsz_varnames[i] = "prev-title";
407 pi_objects[i++] = p_object->i_object_id;
408 ppsz_varnames[i] = "next-title";
409 pi_objects[i++] = p_object->i_object_id;
410 ppsz_varnames[i] = "prev-chapter";
411 pi_objects[i++] = p_object->i_object_id;
412 ppsz_varnames[i] = "next-chapter";
413 pi_objects[i++] = p_object->i_object_id;
415 vlc_object_release( p_object );
419 Menu *p_vlc_menu = (Menu *)p_menu;
421 p_vlc_menu = new Menu( _p_intf, NavigMenu_Events );
425 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
430 wxMenu *SettingsMenu( intf_thread_t *_p_intf, wxWindow *p_parent,
433 #define MAX_SETTINGS_ITEMS 10
435 vlc_object_t *p_object;
436 char *ppsz_varnames[MAX_SETTINGS_ITEMS];
437 int pi_objects[MAX_SETTINGS_ITEMS];
440 /* Initializations */
441 memset( pi_objects, 0, MAX_SETTINGS_ITEMS * sizeof(int) );
443 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INTF,
445 if( p_object != NULL )
447 ppsz_varnames[i] = "intf-switch";
448 pi_objects[i++] = p_object->i_object_id;
449 ppsz_varnames[i] = "intf-add";
450 pi_objects[i++] = p_object->i_object_id;
451 vlc_object_release( p_object );
455 Menu *p_vlc_menu = (Menu *)p_menu;
457 p_vlc_menu = new Menu( _p_intf, SettingsMenu_Events );
461 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
466 /*****************************************************************************
468 *****************************************************************************/
469 Menu::Menu( intf_thread_t *_p_intf, int _i_start_id ) : wxMenu( )
471 /* Initializations */
473 i_start_id = _i_start_id;
480 /*****************************************************************************
482 *****************************************************************************/
483 void Menu::Populate( int i_count, char **ppsz_varnames, int *pi_objects )
485 vlc_object_t *p_object;
486 vlc_bool_t b_section_empty = VLC_FALSE;
489 i_item_id = i_start_id;
491 for( i = 0; i < i_count; i++ )
493 if( !ppsz_varnames[i] )
495 if( b_section_empty )
497 Append( MenuDummy_Event + i, wxU(_("Empty")) );
498 Enable( MenuDummy_Event + i, FALSE );
502 b_section_empty = VLC_TRUE;
508 Append( MenuDummy_Event, wxU(ppsz_varnames[i]) );
509 b_section_empty = VLC_FALSE;
513 p_object = (vlc_object_t *)vlc_object_get( p_intf, pi_objects[i] );
514 if( p_object == NULL ) continue;
516 b_section_empty = VLC_FALSE;
517 CreateMenuItem( this, ppsz_varnames[i], p_object );
518 vlc_object_release( p_object );
521 /* Special case for empty menus */
522 if( GetMenuItemCount() == 0 || b_section_empty )
524 Append( MenuDummy_Event + i, wxU(_("Empty")) );
525 Enable( MenuDummy_Event + i, FALSE );
529 /* Work-around helper for buggy wxGTK */
530 static void RecursiveDestroy( wxMenu *menu )
532 wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
535 wxMenuItem *item = node->GetData();
536 node = node->GetNext();
538 /* Delete the submenus */
539 wxMenu *submenu = item->GetSubMenu();
542 RecursiveDestroy( submenu );
544 menu->Delete( item );
550 RecursiveDestroy( this );
553 /*****************************************************************************
555 *****************************************************************************/
556 static bool IsMenuEmpty( char *psz_var, vlc_object_t *p_object,
559 vlc_value_t val, val_list;
560 int i_type, i_result, i;
562 /* Check the type of the object variable */
563 i_type = var_Type( p_object, psz_var );
565 /* Check if we want to display the variable */
566 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
568 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
569 if( val.i_int == 0 ) return TRUE;
571 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
573 if( val.i_int == 1 && b_root ) return TRUE;
577 /* Check children variables in case of VLC_VAR_VARIABLE */
578 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
583 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
585 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
593 /* clean up everything */
594 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
599 void Menu::CreateMenuItem( wxMenu *menu, char *psz_var,
600 vlc_object_t *p_object )
602 wxMenuItemExt *menuitem;
603 vlc_value_t val, text;
606 /* Check the type of the object variable */
607 i_type = var_Type( p_object, psz_var );
609 switch( i_type & VLC_VAR_TYPE )
613 case VLC_VAR_VARIABLE:
615 case VLC_VAR_INTEGER:
619 /* Variable doesn't exist or isn't handled */
623 /* Make sure we want to display the variable */
624 if( IsMenuEmpty( psz_var, p_object ) ) return;
626 /* Get the descriptive name of the variable */
627 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
629 if( i_type & VLC_VAR_HASCHOICE )
631 menu->Append( MenuDummy_Event,
632 wxU(text.psz_string ? text.psz_string : psz_var),
633 CreateChoicesMenu( psz_var, p_object, TRUE ),
634 wxT("")/* Nothing for now (maybe use a GETLONGTEXT) */ );
636 if( text.psz_string ) free( text.psz_string );
641 switch( i_type & VLC_VAR_TYPE )
644 var_Get( p_object, psz_var, &val );
645 menuitem = new wxMenuItemExt( menu, ++i_item_id,
646 wxU(text.psz_string ?
647 text.psz_string : psz_var),
648 wxT(""), wxITEM_NORMAL, strdup(psz_var),
649 p_object->i_object_id, val, i_type );
650 menu->Append( menuitem );
654 var_Get( p_object, psz_var, &val );
655 val.b_bool = !val.b_bool;
656 menuitem = new wxMenuItemExt( menu, ++i_item_id,
657 wxU(text.psz_string ?
658 text.psz_string : psz_var),
659 wxT(""), wxITEM_CHECK, strdup(psz_var),
660 p_object->i_object_id, val, i_type );
661 menu->Append( menuitem );
662 Check( i_item_id, val.b_bool ? FALSE : TRUE );
666 if( text.psz_string ) free( text.psz_string );
669 wxMenu *Menu::CreateChoicesMenu( char *psz_var, vlc_object_t *p_object,
672 vlc_value_t val, val_list, text_list;
675 /* Check the type of the object variable */
676 i_type = var_Type( p_object, psz_var );
678 /* Make sure we want to display the variable */
679 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return NULL;
681 switch( i_type & VLC_VAR_TYPE )
685 case VLC_VAR_VARIABLE:
687 case VLC_VAR_INTEGER:
691 /* Variable doesn't exist or isn't handled */
695 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
696 &val_list, &text_list ) < 0 )
701 wxMenu *menu = new wxMenu;
702 for( i = 0; i < val_list.p_list->i_count; i++ )
704 vlc_value_t another_val;
705 wxMenuItemExt *menuitem;
707 switch( i_type & VLC_VAR_TYPE )
709 case VLC_VAR_VARIABLE:
710 menu->Append( MenuDummy_Event,
711 wxU(text_list.p_list->p_values[i].psz_string ?
712 text_list.p_list->p_values[i].psz_string :
713 val_list.p_list->p_values[i].psz_string),
715 val_list.p_list->p_values[i].psz_string,
716 p_object, FALSE ), wxT("") );
720 var_Get( p_object, psz_var, &val );
722 another_val.psz_string =
723 strdup(val_list.p_list->p_values[i].psz_string);
725 new wxMenuItemExt( menu, ++i_item_id,
726 wxU(text_list.p_list->p_values[i].psz_string ?
727 text_list.p_list->p_values[i].psz_string :
728 another_val.psz_string), wxT(""),
729 i_type & VLC_VAR_ISCOMMAND ?
730 wxITEM_NORMAL : wxITEM_RADIO,
732 p_object->i_object_id, another_val, i_type );
734 menu->Append( menuitem );
736 if( !(i_type & VLC_VAR_ISCOMMAND) && val.psz_string &&
737 !strcmp( val.psz_string,
738 val_list.p_list->p_values[i].psz_string ) )
739 menu->Check( i_item_id, TRUE );
741 if( val.psz_string ) free( val.psz_string );
744 case VLC_VAR_INTEGER:
745 var_Get( p_object, psz_var, &val );
748 new wxMenuItemExt( menu, ++i_item_id,
749 text_list.p_list->p_values[i].psz_string ?
751 text_list.p_list->p_values[i].psz_string) :
752 wxString::Format(wxT("%d"),
753 val_list.p_list->p_values[i].i_int), wxT(""),
754 i_type & VLC_VAR_ISCOMMAND ?
755 wxITEM_NORMAL : wxITEM_RADIO,
757 p_object->i_object_id,
758 val_list.p_list->p_values[i], i_type );
760 menu->Append( menuitem );
762 if( !(i_type & VLC_VAR_ISCOMMAND) &&
763 val_list.p_list->p_values[i].i_int == val.i_int )
764 menu->Check( i_item_id, TRUE );
768 var_Get( p_object, psz_var, &val );
771 new wxMenuItemExt( menu, ++i_item_id,
772 text_list.p_list->p_values[i].psz_string ?
774 text_list.p_list->p_values[i].psz_string) :
775 wxString::Format(wxT("%.2f"),
776 val_list.p_list->p_values[i].f_float),wxT(""),
777 i_type & VLC_VAR_ISCOMMAND ?
778 wxITEM_NORMAL : wxITEM_RADIO,
780 p_object->i_object_id,
781 val_list.p_list->p_values[i], i_type );
783 menu->Append( menuitem );
785 if( !(i_type & VLC_VAR_ISCOMMAND) &&
786 val_list.p_list->p_values[i].f_float == val.f_float )
787 menu->Check( i_item_id, TRUE );
795 /* clean up everything */
796 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
801 /*****************************************************************************
802 * A small helper class which intercepts all popup menu events
803 *****************************************************************************/
804 MenuEvtHandler::MenuEvtHandler( intf_thread_t *_p_intf,
805 Interface *_p_main_interface )
807 /* Initializations */
809 p_main_interface = _p_main_interface;
812 MenuEvtHandler::~MenuEvtHandler()
816 void MenuEvtHandler::OnShowDialog( wxCommandEvent& event )
818 if( p_intf->p_sys->pf_show_dialog )
822 switch( event.GetId() )
824 case OpenFileSimple_Event:
825 i_id = INTF_DIALOG_FILE_SIMPLE;
828 i_id = INTF_DIALOG_FILE;
831 i_id = INTF_DIALOG_DISC;
834 i_id = INTF_DIALOG_NET;
836 case OpenCapture_Event:
837 i_id = INTF_DIALOG_CAPTURE;
839 case Preferences_Event:
840 i_id = INTF_DIALOG_PREFS;
843 i_id = INTF_DIALOG_FILE;
848 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
852 void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
854 wxMenuItem *p_menuitem = NULL;
855 int i_hotkey_event = p_intf->p_sys->i_first_hotkey_event;
856 int i_hotkeys = p_intf->p_sys->i_hotkeys;
858 /* Check if this is an auto generated menu item */
859 if( event.GetId() < FirstAutoGenerated_Event )
865 msg_Err( p_intf, "received event: %i", event.GetId() );
867 /* Check if this is an hotkey event */
868 if( event.GetId() >= i_hotkey_event &&
869 event.GetId() < i_hotkey_event + i_hotkeys )
874 p_intf->p_vlc->p_hotkeys[event.GetId() - i_hotkey_event].i_key;
876 /* Get the key combination and send it to the hotkey handler */
877 var_Set( p_intf->p_vlc, "key-pressed", val );
878 msg_Err( p_intf, "received key event: %i", event.GetId() );
882 if( !p_main_interface ||
883 (p_menuitem = p_main_interface->GetMenuBar()->FindItem(event.GetId()))
886 if( p_intf->p_sys->p_popup_menu )
889 p_intf->p_sys->p_popup_menu->FindItem( event.GetId() );
895 wxMenuItemExt *p_menuitemext = (wxMenuItemExt *)p_menuitem;
896 vlc_object_t *p_object;
898 p_object = (vlc_object_t *)vlc_object_get( p_intf,
899 p_menuitemext->i_object_id );
900 if( p_object == NULL ) return;
902 wxMutexGuiLeave(); // We don't want deadlocks
903 var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val );
906 vlc_object_release( p_object );
912 /*****************************************************************************
913 * A small helper class which encapsulate wxMenuitem with some other useful
915 *****************************************************************************/
916 wxMenuItemExt::wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
917 const wxString& helpString, wxItemKind kind,
918 char *_psz_var, int _i_object_id, vlc_value_t _val, int _i_val_type ):
919 wxMenuItem( parentMenu, id, text, helpString, kind )
921 /* Initializations */
923 i_val_type = _i_val_type;
924 i_object_id = _i_object_id;
928 wxMenuItemExt::~wxMenuItemExt()
930 if( psz_var ) free( psz_var );
931 if( ((i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
932 && val.psz_string ) free( val.psz_string );