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,
102 FirstAutoGenerated_Event = wxID_HIGHEST + 1999,
103 SettingsMenu_Events = wxID_HIGHEST + 5000,
104 AudioMenu_Events = wxID_HIGHEST + 2000,
105 VideoMenu_Events = wxID_HIGHEST + 3000,
106 NavigMenu_Events = wxID_HIGHEST + 4000,
107 PopupMenu_Events = wxID_HIGHEST + 6000,
108 Hotkeys_Events = wxID_HIGHEST + 7000
111 BEGIN_EVENT_TABLE(Menu, wxMenu)
114 BEGIN_EVENT_TABLE(MenuEvtHandler, wxEvtHandler)
115 EVT_MENU(OpenFileSimple_Event, MenuEvtHandler::OnShowDialog)
116 EVT_MENU(OpenFile_Event, MenuEvtHandler::OnShowDialog)
117 EVT_MENU(OpenDisc_Event, MenuEvtHandler::OnShowDialog)
118 EVT_MENU(OpenNet_Event, MenuEvtHandler::OnShowDialog)
119 EVT_MENU(OpenCapture_Event, MenuEvtHandler::OnShowDialog)
120 EVT_MENU(MediaInfo_Event, MenuEvtHandler::OnShowDialog)
121 EVT_MENU(Messages_Event, MenuEvtHandler::OnShowDialog)
122 EVT_MENU(Preferences_Event, MenuEvtHandler::OnShowDialog)
123 EVT_MENU(-1, MenuEvtHandler::OnMenuEvent)
126 wxMenu *OpenStreamMenu( intf_thread_t *p_intf )
128 wxMenu *menu = new wxMenu;
129 menu->Append( OpenFileSimple_Event, wxU(_("Quick &Open File...")) );
130 menu->Append( OpenFile_Event, wxU(_("Open &File...")) );
131 menu->Append( OpenDisc_Event, wxU(_("Open &Disc...")) );
132 menu->Append( OpenNet_Event, wxU(_("Open &Network Stream...")) );
133 menu->Append( OpenCapture_Event, wxU(_("Open &Capture Device...")) );
137 wxMenu *MiscMenu( intf_thread_t *p_intf )
139 wxMenu *menu = new wxMenu;
140 menu->Append( MediaInfo_Event, wxU(_("Media &Info...")) );
141 menu->Append( Messages_Event, wxU(_("&Messages...")) );
142 menu->Append( Preferences_Event, wxU(_("&Preferences...")) );
146 void PopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
149 #define MAX_POPUP_ITEMS 45
151 vlc_object_t *p_object, *p_input;
152 char *ppsz_varnames[MAX_POPUP_ITEMS];
153 int pi_objects[MAX_POPUP_ITEMS];
154 int i = 0, i_last_separator = 0;
156 /* Initializations */
157 memset( pi_objects, 0, MAX_POPUP_ITEMS * sizeof(int) );
160 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
162 if( p_object != NULL )
164 ppsz_varnames[i] = "bookmark";
165 pi_objects[i++] = p_object->i_object_id;
166 ppsz_varnames[i] = "title";
167 pi_objects[i++] = p_object->i_object_id;
168 ppsz_varnames[i] = "chapter";
169 pi_objects[i++] = p_object->i_object_id;
170 ppsz_varnames[i] = "program";
171 pi_objects[i++] = p_object->i_object_id;
172 ppsz_varnames[i] = "navigation";
173 pi_objects[i++] = p_object->i_object_id;
174 ppsz_varnames[i] = "dvd_menus";
175 pi_objects[i++] = p_object->i_object_id;
177 ppsz_varnames[i] = "video-es";
178 pi_objects[i++] = p_object->i_object_id;
179 ppsz_varnames[i] = "audio-es";
180 pi_objects[i++] = p_object->i_object_id;
181 ppsz_varnames[i] = "spu-es";
182 pi_objects[i++] = p_object->i_object_id;
185 if( !p_input ) goto interfacemenu;
188 if( i != i_last_separator ) ppsz_varnames[i++] = NULL; /* Separator */
189 i_last_separator = i;
191 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
193 if( p_object != NULL )
195 vlc_object_t *p_dec_obj;
197 ppsz_varnames[i] = "fullscreen";
198 pi_objects[i++] = p_object->i_object_id;
199 ppsz_varnames[i] = "zoom";
200 pi_objects[i++] = p_object->i_object_id;
201 ppsz_varnames[i] = "deinterlace";
202 pi_objects[i++] = p_object->i_object_id;
203 ppsz_varnames[i] = "aspect-ratio";
204 pi_objects[i++] = p_object->i_object_id;
205 ppsz_varnames[i] = "crop";
206 pi_objects[i++] = p_object->i_object_id;
207 ppsz_varnames[i] = "video-on-top";
208 pi_objects[i++] = p_object->i_object_id;
209 ppsz_varnames[i] = "directx-wallpaper";
210 pi_objects[i++] = p_object->i_object_id;
211 ppsz_varnames[i] = "video-snapshot";
212 pi_objects[i++] = p_object->i_object_id;
214 p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
217 if( p_dec_obj != NULL )
219 ppsz_varnames[i] = "ffmpeg-pp-q";
220 pi_objects[i++] = p_dec_obj->i_object_id;
221 vlc_object_release( p_dec_obj );
224 vlc_object_release( p_object );
228 if( i != i_last_separator ) ppsz_varnames[i++] = NULL; /* Separator */
229 i_last_separator = i;
231 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
233 if( p_object != NULL )
235 ppsz_varnames[i] = "audio-device";
236 pi_objects[i++] = p_object->i_object_id;
237 ppsz_varnames[i] = "audio-channels";
238 pi_objects[i++] = p_object->i_object_id;
239 ppsz_varnames[i] = "visual";
240 pi_objects[i++] = p_object->i_object_id;
241 ppsz_varnames[i] = "equalizer";
242 pi_objects[i++] = p_object->i_object_id;
243 vlc_object_release( p_object );
248 if( i != i_last_separator ) ppsz_varnames[i++] = NULL; /* Separator */
249 i_last_separator = i;
251 /* vlc_object_find is needed because of the dialogs provider case */
252 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INTF,
254 if( p_object != NULL )
256 ppsz_varnames[i] = "intf-switch";
257 pi_objects[i++] = p_object->i_object_id;
258 ppsz_varnames[i] = "intf-add";
259 pi_objects[i++] = p_object->i_object_id;
260 ppsz_varnames[i] = "intf-skins";
261 pi_objects[i++] = p_object->i_object_id;
263 vlc_object_release( p_object );
267 Menu popupmenu( p_intf, PopupMenu_Events );
268 popupmenu.Populate( i, ppsz_varnames, pi_objects );
270 /* Add static entries */
271 if( p_input != NULL )
274 popupmenu.InsertSeparator( 0 );
275 popupmenu.Insert( 0, Stop_Event, wxU(_("Stop")) );
276 popupmenu.Insert( 0, Previous_Event, wxU(_("Previous")) );
277 popupmenu.Insert( 0, Next_Event, wxU(_("Next")) );
279 var_Get( p_input, "state", &val );
280 if( val.i_int == PAUSE_S )
281 popupmenu.Insert( 0, Play_Event, wxU(_("Play")) );
283 popupmenu.Insert( 0, Pause_Event, wxU(_("Pause")) );
285 vlc_object_release( p_input );
289 playlist_t * p_playlist =
290 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
292 if( p_playlist && p_playlist->i_size )
294 popupmenu.InsertSeparator( 0 );
295 popupmenu.Insert( 0, Play_Event, wxU(_("Play")) );
297 if( p_playlist ) vlc_object_release( p_playlist );
300 popupmenu.Append( MenuDummy_Event, wxU(_("Miscellaneous")),
301 MiscMenu( p_intf ), wxT("") );
302 popupmenu.Append( MenuDummy_Event, wxU(_("Open")),
303 OpenStreamMenu( p_intf ), wxT("") );
305 p_intf->p_sys->p_popup_menu = &popupmenu;
306 p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
307 p_intf->p_sys->p_popup_menu = NULL;
310 wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
312 #define MAX_AUDIO_ITEMS 10
314 vlc_object_t *p_object;
315 char *ppsz_varnames[MAX_AUDIO_ITEMS];
316 int pi_objects[MAX_AUDIO_ITEMS];
319 /* Initializations */
320 memset( pi_objects, 0, MAX_AUDIO_ITEMS * sizeof(int) );
322 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
324 if( p_object != NULL )
326 ppsz_varnames[i] = "audio-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_AOUT,
333 if( p_object != NULL )
335 ppsz_varnames[i] = "audio-device";
336 pi_objects[i++] = p_object->i_object_id;
337 ppsz_varnames[i] = "audio-channels";
338 pi_objects[i++] = p_object->i_object_id;
339 ppsz_varnames[i] = "visual";
340 pi_objects[i++] = p_object->i_object_id;
341 ppsz_varnames[i] = "equalizer";
342 pi_objects[i++] = p_object->i_object_id;
343 vlc_object_release( p_object );
347 Menu *p_vlc_menu = (Menu *)p_menu;
349 p_vlc_menu = new Menu( _p_intf, AudioMenu_Events );
353 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
358 wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
360 #define MAX_VIDEO_ITEMS 15
362 vlc_object_t *p_object;
363 char *ppsz_varnames[MAX_VIDEO_ITEMS];
364 int pi_objects[MAX_VIDEO_ITEMS];
367 /* Initializations */
368 memset( pi_objects, 0, MAX_VIDEO_ITEMS * sizeof(int) );
370 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
372 if( p_object != NULL )
374 ppsz_varnames[i] = "video-es";
375 pi_objects[i++] = p_object->i_object_id;
376 ppsz_varnames[i] = "spu-es";
377 pi_objects[i++] = p_object->i_object_id;
378 vlc_object_release( p_object );
381 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_VOUT,
383 if( p_object != NULL )
385 vlc_object_t *p_dec_obj;
387 ppsz_varnames[i] = "fullscreen";
388 pi_objects[i++] = p_object->i_object_id;
389 ppsz_varnames[i] = "zoom";
390 pi_objects[i++] = p_object->i_object_id;
391 ppsz_varnames[i] = "deinterlace";
392 pi_objects[i++] = p_object->i_object_id;
393 ppsz_varnames[i] = "aspect-ratio";
394 pi_objects[i++] = p_object->i_object_id;
395 ppsz_varnames[i] = "crop";
396 pi_objects[i++] = p_object->i_object_id;
397 ppsz_varnames[i] = "video-on-top";
398 pi_objects[i++] = p_object->i_object_id;
399 ppsz_varnames[i] = "directx-wallpaper";
400 pi_objects[i++] = p_object->i_object_id;
401 ppsz_varnames[i] = "video-snapshot";
402 pi_objects[i++] = p_object->i_object_id;
404 p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
407 if( p_dec_obj != NULL )
409 ppsz_varnames[i] = "ffmpeg-pp-q";
410 pi_objects[i++] = p_dec_obj->i_object_id;
411 vlc_object_release( p_dec_obj );
414 vlc_object_release( p_object );
418 Menu *p_vlc_menu = (Menu *)p_menu;
420 p_vlc_menu = new Menu( _p_intf, VideoMenu_Events );
424 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
429 wxMenu *NavigMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
431 #define MAX_NAVIG_ITEMS 15
433 vlc_object_t *p_object;
434 char *ppsz_varnames[MAX_NAVIG_ITEMS];
435 int pi_objects[MAX_NAVIG_ITEMS];
438 /* Initializations */
439 memset( pi_objects, 0, MAX_NAVIG_ITEMS * sizeof(int) );
441 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
443 if( p_object != NULL )
445 ppsz_varnames[i] = "bookmark";
446 pi_objects[i++] = p_object->i_object_id;
447 ppsz_varnames[i] = "title";
448 pi_objects[i++] = p_object->i_object_id;
449 ppsz_varnames[i] = "chapter";
450 pi_objects[i++] = p_object->i_object_id;
451 ppsz_varnames[i] = "program";
452 pi_objects[i++] = p_object->i_object_id;
453 ppsz_varnames[i] = "navigation";
454 pi_objects[i++] = p_object->i_object_id;
455 ppsz_varnames[i] = "dvd_menus";
456 pi_objects[i++] = p_object->i_object_id;
458 ppsz_varnames[i] = "prev-title";
459 pi_objects[i++] = p_object->i_object_id;
460 ppsz_varnames[i] = "next-title";
461 pi_objects[i++] = p_object->i_object_id;
462 ppsz_varnames[i] = "prev-chapter";
463 pi_objects[i++] = p_object->i_object_id;
464 ppsz_varnames[i] = "next-chapter";
465 pi_objects[i++] = p_object->i_object_id;
467 vlc_object_release( p_object );
471 Menu *p_vlc_menu = (Menu *)p_menu;
473 p_vlc_menu = new Menu( _p_intf, NavigMenu_Events );
477 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
482 wxMenu *SettingsMenu( intf_thread_t *_p_intf, wxWindow *p_parent,
485 #define MAX_SETTINGS_ITEMS 10
487 vlc_object_t *p_object;
488 char *ppsz_varnames[MAX_SETTINGS_ITEMS];
489 int pi_objects[MAX_SETTINGS_ITEMS];
492 /* Initializations */
493 memset( pi_objects, 0, MAX_SETTINGS_ITEMS * sizeof(int) );
495 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INTF,
497 if( p_object != NULL )
499 ppsz_varnames[i] = "intf-switch";
500 pi_objects[i++] = p_object->i_object_id;
501 ppsz_varnames[i] = "intf-add";
502 pi_objects[i++] = p_object->i_object_id;
503 vlc_object_release( p_object );
507 Menu *p_vlc_menu = (Menu *)p_menu;
509 p_vlc_menu = new Menu( _p_intf, SettingsMenu_Events );
513 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
518 /*****************************************************************************
520 *****************************************************************************/
521 Menu::Menu( intf_thread_t *_p_intf, int _i_start_id ) : wxMenu( )
523 /* Initializations */
525 i_start_id = _i_start_id;
532 /*****************************************************************************
534 *****************************************************************************/
535 void Menu::Populate( int i_count, char **ppsz_varnames, int *pi_objects )
537 vlc_object_t *p_object;
538 vlc_bool_t b_section_empty = VLC_FALSE;
541 i_item_id = i_start_id;
543 for( i = 0; i < i_count; i++ )
545 if( !ppsz_varnames[i] )
547 if( b_section_empty )
549 Append( MenuDummy_Event + i, wxU(_("Empty")) );
550 Enable( MenuDummy_Event + i, FALSE );
554 b_section_empty = VLC_TRUE;
560 Append( MenuDummy_Event, wxU(ppsz_varnames[i]) );
561 b_section_empty = VLC_FALSE;
565 p_object = (vlc_object_t *)vlc_object_get( p_intf, pi_objects[i] );
566 if( p_object == NULL ) continue;
568 b_section_empty = VLC_FALSE;
569 CreateMenuItem( this, ppsz_varnames[i], p_object );
570 vlc_object_release( p_object );
573 /* Special case for empty menus */
574 if( GetMenuItemCount() == 0 || b_section_empty )
576 Append( MenuDummy_Event + i, wxU(_("Empty")) );
577 Enable( MenuDummy_Event + i, FALSE );
581 /* Work-around helper for buggy wxGTK */
582 static void RecursiveDestroy( wxMenu *menu )
584 wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
587 wxMenuItem *item = node->GetData();
588 node = node->GetNext();
590 /* Delete the submenus */
591 wxMenu *submenu = item->GetSubMenu();
594 RecursiveDestroy( submenu );
596 menu->Delete( item );
602 RecursiveDestroy( this );
605 /*****************************************************************************
607 *****************************************************************************/
608 static bool IsMenuEmpty( char *psz_var, vlc_object_t *p_object,
611 vlc_value_t val, val_list;
612 int i_type, i_result, i;
614 /* Check the type of the object variable */
615 i_type = var_Type( p_object, psz_var );
617 /* Check if we want to display the variable */
618 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
620 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
621 if( val.i_int == 0 ) return TRUE;
623 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
625 if( val.i_int == 1 && b_root ) return TRUE;
629 /* Check children variables in case of VLC_VAR_VARIABLE */
630 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
635 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
637 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
645 /* clean up everything */
646 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
651 void Menu::CreateMenuItem( wxMenu *menu, char *psz_var,
652 vlc_object_t *p_object )
654 wxMenuItemExt *menuitem;
655 vlc_value_t val, text;
658 /* Check the type of the object variable */
659 i_type = var_Type( p_object, psz_var );
661 switch( i_type & VLC_VAR_TYPE )
665 case VLC_VAR_VARIABLE:
667 case VLC_VAR_INTEGER:
671 /* Variable doesn't exist or isn't handled */
675 /* Make sure we want to display the variable */
676 if( IsMenuEmpty( psz_var, p_object ) ) return;
678 /* Get the descriptive name of the variable */
679 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
681 if( i_type & VLC_VAR_HASCHOICE )
683 menu->Append( MenuDummy_Event,
684 wxU(text.psz_string ? text.psz_string : psz_var),
685 CreateChoicesMenu( psz_var, p_object, TRUE ),
686 wxT("")/* Nothing for now (maybe use a GETLONGTEXT) */ );
688 if( text.psz_string ) free( text.psz_string );
693 switch( i_type & VLC_VAR_TYPE )
696 var_Get( p_object, psz_var, &val );
697 menuitem = new wxMenuItemExt( menu, ++i_item_id,
698 wxU(text.psz_string ?
699 text.psz_string : psz_var),
700 wxT(""), wxITEM_NORMAL, strdup(psz_var),
701 p_object->i_object_id, val, i_type );
702 menu->Append( menuitem );
706 var_Get( p_object, psz_var, &val );
707 val.b_bool = !val.b_bool;
708 menuitem = new wxMenuItemExt( menu, ++i_item_id,
709 wxU(text.psz_string ?
710 text.psz_string : psz_var),
711 wxT(""), wxITEM_CHECK, strdup(psz_var),
712 p_object->i_object_id, val, i_type );
713 menu->Append( menuitem );
714 Check( i_item_id, val.b_bool ? FALSE : TRUE );
718 if( text.psz_string ) free( text.psz_string );
721 wxMenu *Menu::CreateChoicesMenu( char *psz_var, vlc_object_t *p_object,
724 vlc_value_t val, val_list, text_list;
727 /* Check the type of the object variable */
728 i_type = var_Type( p_object, psz_var );
730 /* Make sure we want to display the variable */
731 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return NULL;
733 switch( i_type & VLC_VAR_TYPE )
737 case VLC_VAR_VARIABLE:
739 case VLC_VAR_INTEGER:
743 /* Variable doesn't exist or isn't handled */
747 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
748 &val_list, &text_list ) < 0 )
753 wxMenu *menu = new wxMenu;
754 for( i = 0; i < val_list.p_list->i_count; i++ )
756 vlc_value_t another_val;
757 wxMenuItemExt *menuitem;
759 switch( i_type & VLC_VAR_TYPE )
761 case VLC_VAR_VARIABLE:
762 menu->Append( MenuDummy_Event,
763 wxU(text_list.p_list->p_values[i].psz_string ?
764 text_list.p_list->p_values[i].psz_string :
765 val_list.p_list->p_values[i].psz_string),
767 val_list.p_list->p_values[i].psz_string,
768 p_object, FALSE ), wxT("") );
772 var_Get( p_object, psz_var, &val );
774 another_val.psz_string =
775 strdup(val_list.p_list->p_values[i].psz_string);
777 new wxMenuItemExt( menu, ++i_item_id,
778 wxU(text_list.p_list->p_values[i].psz_string ?
779 text_list.p_list->p_values[i].psz_string :
780 another_val.psz_string), wxT(""),
781 i_type & VLC_VAR_ISCOMMAND ?
782 wxITEM_NORMAL : wxITEM_RADIO,
784 p_object->i_object_id, another_val, i_type );
786 menu->Append( menuitem );
788 if( !(i_type & VLC_VAR_ISCOMMAND) && val.psz_string &&
789 !strcmp( val.psz_string,
790 val_list.p_list->p_values[i].psz_string ) )
791 menu->Check( i_item_id, TRUE );
793 if( val.psz_string ) free( val.psz_string );
796 case VLC_VAR_INTEGER:
797 var_Get( p_object, psz_var, &val );
800 new wxMenuItemExt( menu, ++i_item_id,
801 text_list.p_list->p_values[i].psz_string ?
803 text_list.p_list->p_values[i].psz_string) :
804 wxString::Format(wxT("%d"),
805 val_list.p_list->p_values[i].i_int), wxT(""),
806 i_type & VLC_VAR_ISCOMMAND ?
807 wxITEM_NORMAL : wxITEM_RADIO,
809 p_object->i_object_id,
810 val_list.p_list->p_values[i], i_type );
812 menu->Append( menuitem );
814 if( !(i_type & VLC_VAR_ISCOMMAND) &&
815 val_list.p_list->p_values[i].i_int == val.i_int )
816 menu->Check( i_item_id, TRUE );
820 var_Get( p_object, psz_var, &val );
823 new wxMenuItemExt( menu, ++i_item_id,
824 text_list.p_list->p_values[i].psz_string ?
826 text_list.p_list->p_values[i].psz_string) :
827 wxString::Format(wxT("%.2f"),
828 val_list.p_list->p_values[i].f_float),wxT(""),
829 i_type & VLC_VAR_ISCOMMAND ?
830 wxITEM_NORMAL : wxITEM_RADIO,
832 p_object->i_object_id,
833 val_list.p_list->p_values[i], i_type );
835 menu->Append( menuitem );
837 if( !(i_type & VLC_VAR_ISCOMMAND) &&
838 val_list.p_list->p_values[i].f_float == val.f_float )
839 menu->Check( i_item_id, TRUE );
847 /* clean up everything */
848 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
853 /*****************************************************************************
854 * A small helper class which intercepts all popup menu events
855 *****************************************************************************/
856 MenuEvtHandler::MenuEvtHandler( intf_thread_t *_p_intf,
857 Interface *_p_main_interface )
859 /* Initializations */
861 p_main_interface = _p_main_interface;
864 MenuEvtHandler::~MenuEvtHandler()
868 void MenuEvtHandler::OnShowDialog( wxCommandEvent& event )
870 if( p_intf->p_sys->pf_show_dialog )
874 switch( event.GetId() )
876 case OpenFileSimple_Event:
877 i_id = INTF_DIALOG_FILE_SIMPLE;
880 i_id = INTF_DIALOG_FILE;
883 i_id = INTF_DIALOG_DISC;
886 i_id = INTF_DIALOG_NET;
888 case OpenCapture_Event:
889 i_id = INTF_DIALOG_CAPTURE;
891 case MediaInfo_Event:
892 i_id = INTF_DIALOG_FILEINFO;
895 i_id = INTF_DIALOG_MESSAGES;
897 case Preferences_Event:
898 i_id = INTF_DIALOG_PREFS;
901 i_id = INTF_DIALOG_FILE;
906 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
910 void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
912 wxMenuItem *p_menuitem = NULL;
913 int i_hotkey_event = p_intf->p_sys->i_first_hotkey_event;
914 int i_hotkeys = p_intf->p_sys->i_hotkeys;
916 if( event.GetId() >= Play_Event && event.GetId() <= Stop_Event )
918 input_thread_t *p_input;
919 playlist_t * p_playlist =
920 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
922 if( !p_playlist ) return;
924 switch( event.GetId() )
929 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
931 if( !p_input ) playlist_Play( p_playlist );
935 var_Get( p_input, "state", &val );
936 if( val.i_int != PAUSE_S ) val.i_int = PAUSE_S;
937 else val.i_int = PLAYING_S;
938 var_Set( p_input, "state", val );
939 vlc_object_release( p_input );
943 playlist_Stop( p_playlist );
946 playlist_Prev( p_playlist );
949 playlist_Next( p_playlist );
953 vlc_object_release( p_playlist );
957 /* Check if this is an auto generated menu item */
958 if( event.GetId() < FirstAutoGenerated_Event )
964 /* Check if this is an hotkey event */
965 if( event.GetId() >= i_hotkey_event &&
966 event.GetId() < i_hotkey_event + i_hotkeys )
971 p_intf->p_vlc->p_hotkeys[event.GetId() - i_hotkey_event].i_key;
973 /* Get the key combination and send it to the hotkey handler */
974 var_Set( p_intf->p_vlc, "key-pressed", val );
978 if( !p_main_interface ||
979 (p_menuitem = p_main_interface->GetMenuBar()->FindItem(event.GetId()))
982 if( p_intf->p_sys->p_popup_menu )
985 p_intf->p_sys->p_popup_menu->FindItem( event.GetId() );
991 wxMenuItemExt *p_menuitemext = (wxMenuItemExt *)p_menuitem;
992 vlc_object_t *p_object;
994 p_object = (vlc_object_t *)vlc_object_get( p_intf,
995 p_menuitemext->i_object_id );
996 if( p_object == NULL ) return;
998 wxMutexGuiLeave(); // We don't want deadlocks
999 var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val );
1002 vlc_object_release( p_object );
1008 /*****************************************************************************
1009 * A small helper class which encapsulate wxMenuitem with some other useful
1011 *****************************************************************************/
1012 wxMenuItemExt::wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
1013 const wxString& helpString, wxItemKind kind,
1014 char *_psz_var, int _i_object_id, vlc_value_t _val, int _i_val_type ):
1015 wxMenuItem( parentMenu, id, text, helpString, kind )
1017 /* Initializations */
1019 i_val_type = _i_val_type;
1020 i_object_id = _i_object_id;
1024 wxMenuItemExt::~wxMenuItemExt()
1026 if( psz_var ) free( psz_var );
1027 if( ((i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
1028 && val.psz_string ) free( val.psz_string );