1 /*****************************************************************************
2 * menus.cpp : wxWidgets plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 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 "wxwidgets.hpp"
36 #include "interface.hpp"
38 class wxMenuItemExt: public wxMenuItem
42 wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
43 const wxString& helpString, wxItemKind kind,
44 char *_psz_var, int _i_object_id, vlc_value_t _val,
47 virtual ~wxMenuItemExt();
58 class Menu: public wxMenu
62 Menu( intf_thread_t *p_intf, int i_start_id );
65 void Populate( int i_count, char **ppsz_names, int *pi_objects );
69 wxMenu *Menu::CreateDummyMenu();
70 void Menu::CreateMenuItem( wxMenu *, char *, vlc_object_t * );
71 wxMenu *Menu::CreateChoicesMenu( char *, vlc_object_t *, bool );
73 DECLARE_EVENT_TABLE();
75 intf_thread_t *p_intf;
81 /*****************************************************************************
83 *****************************************************************************/
85 /* IDs for the controls and the menu commands */
89 MenuDummy_Event = wxID_HIGHEST + 1000,
90 OpenFileSimple_Event = wxID_HIGHEST + 1100,
104 FirstAutoGenerated_Event = wxID_HIGHEST + 1999,
105 SettingsMenu_Events = wxID_HIGHEST + 5000,
106 AudioMenu_Events = wxID_HIGHEST + 2000,
107 VideoMenu_Events = wxID_HIGHEST + 3000,
108 NavigMenu_Events = wxID_HIGHEST + 4000,
109 PopupMenu_Events = wxID_HIGHEST + 6000,
110 Hotkeys_Events = wxID_HIGHEST + 7000
113 BEGIN_EVENT_TABLE(Menu, wxMenu)
116 BEGIN_EVENT_TABLE(MenuEvtHandler, wxEvtHandler)
117 EVT_MENU(OpenFileSimple_Event, MenuEvtHandler::OnShowDialog)
118 EVT_MENU(OpenFile_Event, MenuEvtHandler::OnShowDialog)
119 EVT_MENU(OpenDirectory_Event, MenuEvtHandler::OnShowDialog)
120 EVT_MENU(OpenDisc_Event, MenuEvtHandler::OnShowDialog)
121 EVT_MENU(OpenNet_Event, MenuEvtHandler::OnShowDialog)
122 EVT_MENU(OpenCapture_Event, MenuEvtHandler::OnShowDialog)
123 EVT_MENU(MediaInfo_Event, MenuEvtHandler::OnShowDialog)
124 EVT_MENU(Messages_Event, MenuEvtHandler::OnShowDialog)
125 EVT_MENU(Preferences_Event, MenuEvtHandler::OnShowDialog)
126 EVT_MENU(-1, MenuEvtHandler::OnMenuEvent)
129 wxMenu *OpenStreamMenu( intf_thread_t *p_intf )
131 wxMenu *menu = new wxMenu;
132 menu->Append( OpenFileSimple_Event, wxU(_("Quick &Open File...")) );
133 menu->Append( OpenFile_Event, wxU(_("Open &File...")) );
134 menu->Append( OpenDirectory_Event, wxU(_("Open D&irectory...")) );
135 menu->Append( OpenDisc_Event, wxU(_("Open &Disc...")) );
136 menu->Append( OpenNet_Event, wxU(_("Open &Network Stream...")) );
137 menu->Append( OpenCapture_Event, wxU(_("Open &Capture Device...")) );
141 wxMenu *MiscMenu( intf_thread_t *p_intf )
143 wxMenu *menu = new wxMenu;
144 menu->Append( MediaInfo_Event, wxU(_("Media &Info...")) );
145 menu->Append( Messages_Event, wxU(_("&Messages...")) );
146 menu->Append( Preferences_Event, wxU(_("&Preferences...")) );
150 void PopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
153 #define MAX_POPUP_ITEMS 45
155 int minimal = config_GetInt( p_intf, "wx-minimal" );
157 vlc_object_t *p_object, *p_input;
158 char *ppsz_varnames[MAX_POPUP_ITEMS];
159 int pi_objects[MAX_POPUP_ITEMS];
160 int i = 0, i_last_separator = 0;
162 /* Initializations */
163 memset( pi_objects, 0, MAX_POPUP_ITEMS * sizeof(int) );
166 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
168 if( p_object != NULL )
170 ppsz_varnames[i] = "bookmark";
171 pi_objects[i++] = p_object->i_object_id;
172 ppsz_varnames[i] = "title";
173 pi_objects[i++] = p_object->i_object_id;
174 ppsz_varnames[i] = "chapter";
175 pi_objects[i++] = p_object->i_object_id;
176 ppsz_varnames[i] = "program";
177 pi_objects[i++] = p_object->i_object_id;
178 ppsz_varnames[i] = "navigation";
179 pi_objects[i++] = p_object->i_object_id;
180 ppsz_varnames[i] = "dvd_menus";
181 pi_objects[i++] = p_object->i_object_id;
183 ppsz_varnames[i] = "video-es";
184 pi_objects[i++] = p_object->i_object_id;
185 ppsz_varnames[i] = "audio-es";
186 pi_objects[i++] = p_object->i_object_id;
187 ppsz_varnames[i] = "spu-es";
188 pi_objects[i++] = p_object->i_object_id;
191 if( !p_input ) goto interfacemenu;
194 if( i != i_last_separator ) ppsz_varnames[i++] = NULL; /* Separator */
195 i_last_separator = i;
197 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
199 if( p_object != NULL )
201 vlc_object_t *p_dec_obj;
203 ppsz_varnames[i] = "fullscreen";
204 pi_objects[i++] = p_object->i_object_id;
205 ppsz_varnames[i] = "zoom";
206 pi_objects[i++] = p_object->i_object_id;
207 ppsz_varnames[i] = "deinterlace";
208 pi_objects[i++] = p_object->i_object_id;
209 ppsz_varnames[i] = "aspect-ratio";
210 pi_objects[i++] = p_object->i_object_id;
211 ppsz_varnames[i] = "crop";
212 pi_objects[i++] = p_object->i_object_id;
213 ppsz_varnames[i] = "video-on-top";
214 pi_objects[i++] = p_object->i_object_id;
215 ppsz_varnames[i] = "directx-wallpaper";
216 pi_objects[i++] = p_object->i_object_id;
217 ppsz_varnames[i] = "video-snapshot";
218 pi_objects[i++] = p_object->i_object_id;
220 p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
223 if( p_dec_obj != NULL )
225 ppsz_varnames[i] = "ffmpeg-pp-q";
226 pi_objects[i++] = p_dec_obj->i_object_id;
227 vlc_object_release( p_dec_obj );
230 vlc_object_release( p_object );
234 if( i != i_last_separator ) ppsz_varnames[i++] = NULL; /* Separator */
235 i_last_separator = i;
237 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
239 if( p_object != NULL )
241 ppsz_varnames[i] = "audio-device";
242 pi_objects[i++] = p_object->i_object_id;
243 ppsz_varnames[i] = "audio-channels";
244 pi_objects[i++] = p_object->i_object_id;
245 ppsz_varnames[i] = "visual";
246 pi_objects[i++] = p_object->i_object_id;
247 ppsz_varnames[i] = "equalizer";
248 pi_objects[i++] = p_object->i_object_id;
249 vlc_object_release( p_object );
254 if( i != i_last_separator ) ppsz_varnames[i++] = NULL; /* Separator */
255 i_last_separator = i;
257 /* vlc_object_find is needed because of the dialogs provider case */
258 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INTF,
260 if( p_object != NULL )
262 #if (wxCHECK_VERSION(2,5,0))
263 ppsz_varnames[i] = "intf-switch";
264 pi_objects[i++] = p_object->i_object_id;
266 ppsz_varnames[i] = "intf-add";
267 pi_objects[i++] = p_object->i_object_id;
268 ppsz_varnames[i] = "intf-skins";
269 pi_objects[i++] = p_object->i_object_id;
271 vlc_object_release( p_object );
275 Menu popupmenu( p_intf, PopupMenu_Events );
276 popupmenu.Populate( i, ppsz_varnames, pi_objects );
278 /* Add static entries */
279 if( p_input != NULL )
282 popupmenu.InsertSeparator( 0 );
285 popupmenu.Insert( 0, Stop_Event, wxU(_("Stop")) );
286 popupmenu.Insert( 0, Previous_Event, wxU(_("Previous")) );
287 popupmenu.Insert( 0, Next_Event, wxU(_("Next")) );
290 var_Get( p_input, "state", &val );
291 if( val.i_int == PAUSE_S )
292 popupmenu.Insert( 0, Play_Event, wxU(_("Play")) );
294 popupmenu.Insert( 0, Pause_Event, wxU(_("Pause")) );
296 vlc_object_release( p_input );
300 playlist_t * p_playlist =
301 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
303 if( p_playlist && p_playlist->i_size )
305 popupmenu.InsertSeparator( 0 );
306 popupmenu.Insert( 0, Play_Event, wxU(_("Play")) );
308 if( p_playlist ) vlc_object_release( p_playlist );
311 popupmenu.Append( MenuDummy_Event, wxU(_("Miscellaneous")),
312 MiscMenu( p_intf ), wxT("") );
315 popupmenu.Append( MenuDummy_Event, wxU(_("Open")),
316 OpenStreamMenu( p_intf ), wxT("") );
319 p_intf->p_sys->p_popup_menu = &popupmenu;
320 p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
321 p_intf->p_sys->p_popup_menu = NULL;
324 wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
326 #define MAX_AUDIO_ITEMS 10
328 vlc_object_t *p_object;
329 char *ppsz_varnames[MAX_AUDIO_ITEMS];
330 int pi_objects[MAX_AUDIO_ITEMS];
333 /* Initializations */
334 memset( pi_objects, 0, MAX_AUDIO_ITEMS * sizeof(int) );
336 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
338 if( p_object != NULL )
340 ppsz_varnames[i] = "audio-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_AOUT,
347 if( p_object != NULL )
349 ppsz_varnames[i] = "audio-device";
350 pi_objects[i++] = p_object->i_object_id;
351 ppsz_varnames[i] = "audio-channels";
352 pi_objects[i++] = p_object->i_object_id;
353 ppsz_varnames[i] = "visual";
354 pi_objects[i++] = p_object->i_object_id;
355 ppsz_varnames[i] = "equalizer";
356 pi_objects[i++] = p_object->i_object_id;
357 vlc_object_release( p_object );
361 Menu *p_vlc_menu = (Menu *)p_menu;
363 p_vlc_menu = new Menu( _p_intf, AudioMenu_Events );
367 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
372 wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
374 #define MAX_VIDEO_ITEMS 15
376 vlc_object_t *p_object;
377 char *ppsz_varnames[MAX_VIDEO_ITEMS];
378 int pi_objects[MAX_VIDEO_ITEMS];
381 /* Initializations */
382 memset( pi_objects, 0, MAX_VIDEO_ITEMS * sizeof(int) );
384 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
386 if( p_object != NULL )
388 ppsz_varnames[i] = "video-es";
389 pi_objects[i++] = p_object->i_object_id;
390 ppsz_varnames[i] = "spu-es";
391 pi_objects[i++] = p_object->i_object_id;
392 vlc_object_release( p_object );
395 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_VOUT,
397 if( p_object != NULL )
399 vlc_object_t *p_dec_obj;
401 ppsz_varnames[i] = "fullscreen";
402 pi_objects[i++] = p_object->i_object_id;
403 ppsz_varnames[i] = "zoom";
404 pi_objects[i++] = p_object->i_object_id;
405 ppsz_varnames[i] = "deinterlace";
406 pi_objects[i++] = p_object->i_object_id;
407 ppsz_varnames[i] = "aspect-ratio";
408 pi_objects[i++] = p_object->i_object_id;
409 ppsz_varnames[i] = "crop";
410 pi_objects[i++] = p_object->i_object_id;
411 ppsz_varnames[i] = "video-on-top";
412 pi_objects[i++] = p_object->i_object_id;
413 ppsz_varnames[i] = "directx-wallpaper";
414 pi_objects[i++] = p_object->i_object_id;
415 ppsz_varnames[i] = "video-snapshot";
416 pi_objects[i++] = p_object->i_object_id;
418 p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
421 if( p_dec_obj != NULL )
423 ppsz_varnames[i] = "ffmpeg-pp-q";
424 pi_objects[i++] = p_dec_obj->i_object_id;
425 vlc_object_release( p_dec_obj );
428 vlc_object_release( p_object );
432 Menu *p_vlc_menu = (Menu *)p_menu;
434 p_vlc_menu = new Menu( _p_intf, VideoMenu_Events );
438 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
443 wxMenu *NavigMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
445 #define MAX_NAVIG_ITEMS 15
447 vlc_object_t *p_object;
448 char *ppsz_varnames[MAX_NAVIG_ITEMS];
449 int pi_objects[MAX_NAVIG_ITEMS];
452 /* Initializations */
453 memset( pi_objects, 0, MAX_NAVIG_ITEMS * sizeof(int) );
455 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
457 if( p_object != NULL )
459 ppsz_varnames[i] = "bookmark";
460 pi_objects[i++] = p_object->i_object_id;
461 ppsz_varnames[i] = "title";
462 pi_objects[i++] = p_object->i_object_id;
463 ppsz_varnames[i] = "chapter";
464 pi_objects[i++] = p_object->i_object_id;
465 ppsz_varnames[i] = "program";
466 pi_objects[i++] = p_object->i_object_id;
467 ppsz_varnames[i] = "navigation";
468 pi_objects[i++] = p_object->i_object_id;
469 ppsz_varnames[i] = "dvd_menus";
470 pi_objects[i++] = p_object->i_object_id;
472 ppsz_varnames[i] = "prev-title";
473 pi_objects[i++] = p_object->i_object_id;
474 ppsz_varnames[i] = "next-title";
475 pi_objects[i++] = p_object->i_object_id;
476 ppsz_varnames[i] = "prev-chapter";
477 pi_objects[i++] = p_object->i_object_id;
478 ppsz_varnames[i] = "next-chapter";
479 pi_objects[i++] = p_object->i_object_id;
481 vlc_object_release( p_object );
485 Menu *p_vlc_menu = (Menu *)p_menu;
487 p_vlc_menu = new Menu( _p_intf, NavigMenu_Events );
491 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
496 wxMenu *SettingsMenu( intf_thread_t *_p_intf, wxWindow *p_parent,
499 #define MAX_SETTINGS_ITEMS 10
501 vlc_object_t *p_object;
502 char *ppsz_varnames[MAX_SETTINGS_ITEMS];
503 int pi_objects[MAX_SETTINGS_ITEMS];
506 /* Initializations */
507 memset( pi_objects, 0, MAX_SETTINGS_ITEMS * sizeof(int) );
509 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INTF,
511 if( p_object != NULL )
513 #if (wxCHECK_VERSION(2,5,0))
514 ppsz_varnames[i] = "intf-switch";
515 pi_objects[i++] = p_object->i_object_id;
517 ppsz_varnames[i] = "intf-add";
518 pi_objects[i++] = p_object->i_object_id;
519 vlc_object_release( p_object );
523 Menu *p_vlc_menu = (Menu *)p_menu;
525 p_vlc_menu = new Menu( _p_intf, SettingsMenu_Events );
529 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
534 /*****************************************************************************
536 *****************************************************************************/
537 Menu::Menu( intf_thread_t *_p_intf, int _i_start_id ) : wxMenu( )
539 /* Initializations */
541 i_start_id = _i_start_id;
548 /*****************************************************************************
550 *****************************************************************************/
551 void Menu::Populate( int i_count, char **ppsz_varnames, int *pi_objects )
553 vlc_object_t *p_object;
554 vlc_bool_t b_section_empty = VLC_FALSE;
557 i_item_id = i_start_id;
559 for( i = 0; i < i_count; i++ )
561 if( !ppsz_varnames[i] )
563 if( b_section_empty )
565 Append( MenuDummy_Event + i, wxU(_("Empty")) );
566 Enable( MenuDummy_Event + i, FALSE );
570 b_section_empty = VLC_TRUE;
576 Append( MenuDummy_Event, wxU(ppsz_varnames[i]) );
577 b_section_empty = VLC_FALSE;
581 p_object = (vlc_object_t *)vlc_object_get( p_intf, pi_objects[i] );
582 if( p_object == NULL ) continue;
584 b_section_empty = VLC_FALSE;
585 CreateMenuItem( this, ppsz_varnames[i], p_object );
586 vlc_object_release( p_object );
589 /* Special case for empty menus */
590 if( GetMenuItemCount() == 0 || b_section_empty )
592 Append( MenuDummy_Event + i, wxU(_("Empty")) );
593 Enable( MenuDummy_Event + i, FALSE );
597 /* Work-around helper for buggy wxGTK */
598 static void RecursiveDestroy( wxMenu *menu )
600 wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
603 wxMenuItem *item = node->GetData();
604 node = node->GetNext();
606 /* Delete the submenus */
607 wxMenu *submenu = item->GetSubMenu();
610 RecursiveDestroy( submenu );
612 menu->Delete( item );
618 RecursiveDestroy( this );
621 /*****************************************************************************
623 *****************************************************************************/
624 static bool IsMenuEmpty( char *psz_var, vlc_object_t *p_object,
627 vlc_value_t val, val_list;
628 int i_type, i_result, i;
630 /* Check the type of the object variable */
631 i_type = var_Type( p_object, psz_var );
633 /* Check if we want to display the variable */
634 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
636 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
637 if( val.i_int == 0 ) return TRUE;
639 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
641 if( val.i_int == 1 && b_root ) return TRUE;
645 /* Check children variables in case of VLC_VAR_VARIABLE */
646 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
651 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
653 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
661 /* clean up everything */
662 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
667 void Menu::CreateMenuItem( wxMenu *menu, char *psz_var,
668 vlc_object_t *p_object )
670 wxMenuItemExt *menuitem;
671 vlc_value_t val, text;
674 /* Check the type of the object variable */
675 i_type = var_Type( p_object, psz_var );
677 switch( i_type & VLC_VAR_TYPE )
681 case VLC_VAR_VARIABLE:
683 case VLC_VAR_INTEGER:
687 /* Variable doesn't exist or isn't handled */
691 /* Make sure we want to display the variable */
692 if( IsMenuEmpty( psz_var, p_object ) ) return;
694 /* Get the descriptive name of the variable */
695 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
697 if( i_type & VLC_VAR_HASCHOICE )
699 menu->Append( MenuDummy_Event,
700 wxU(text.psz_string ? text.psz_string : psz_var),
701 CreateChoicesMenu( psz_var, p_object, TRUE ),
702 wxT("")/* Nothing for now (maybe use a GETLONGTEXT) */ );
704 if( text.psz_string ) free( text.psz_string );
709 switch( i_type & VLC_VAR_TYPE )
712 var_Get( p_object, psz_var, &val );
713 menuitem = new wxMenuItemExt( menu, ++i_item_id,
714 wxU(text.psz_string ?
715 text.psz_string : psz_var),
716 wxT(""), wxITEM_NORMAL, strdup(psz_var),
717 p_object->i_object_id, val, i_type );
718 menu->Append( menuitem );
722 var_Get( p_object, psz_var, &val );
723 val.b_bool = !val.b_bool;
724 menuitem = new wxMenuItemExt( menu, ++i_item_id,
725 wxU(text.psz_string ?
726 text.psz_string : psz_var),
727 wxT(""), wxITEM_CHECK, strdup(psz_var),
728 p_object->i_object_id, val, i_type );
729 menu->Append( menuitem );
730 Check( i_item_id, val.b_bool ? FALSE : TRUE );
734 if( text.psz_string ) free( text.psz_string );
737 wxMenu *Menu::CreateChoicesMenu( char *psz_var, vlc_object_t *p_object,
740 vlc_value_t val, val_list, text_list;
743 /* Check the type of the object variable */
744 i_type = var_Type( p_object, psz_var );
746 /* Make sure we want to display the variable */
747 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return NULL;
749 switch( i_type & VLC_VAR_TYPE )
753 case VLC_VAR_VARIABLE:
755 case VLC_VAR_INTEGER:
759 /* Variable doesn't exist or isn't handled */
763 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
764 &val_list, &text_list ) < 0 )
769 wxMenu *menu = new wxMenu;
770 for( i = 0; i < val_list.p_list->i_count; i++ )
772 vlc_value_t another_val;
773 wxMenuItemExt *menuitem;
775 switch( i_type & VLC_VAR_TYPE )
777 case VLC_VAR_VARIABLE:
778 menu->Append( MenuDummy_Event,
779 wxU(text_list.p_list->p_values[i].psz_string ?
780 text_list.p_list->p_values[i].psz_string :
781 val_list.p_list->p_values[i].psz_string),
783 val_list.p_list->p_values[i].psz_string,
784 p_object, FALSE ), wxT("") );
788 var_Get( p_object, psz_var, &val );
790 another_val.psz_string =
791 strdup(val_list.p_list->p_values[i].psz_string);
793 new wxMenuItemExt( menu, ++i_item_id,
794 wxU(text_list.p_list->p_values[i].psz_string ?
795 text_list.p_list->p_values[i].psz_string :
796 another_val.psz_string), wxT(""),
797 i_type & VLC_VAR_ISCOMMAND ?
798 wxITEM_NORMAL : wxITEM_RADIO,
800 p_object->i_object_id, another_val, i_type );
802 menu->Append( menuitem );
804 if( !(i_type & VLC_VAR_ISCOMMAND) && val.psz_string &&
805 !strcmp( val.psz_string,
806 val_list.p_list->p_values[i].psz_string ) )
807 menu->Check( i_item_id, TRUE );
809 if( val.psz_string ) free( val.psz_string );
812 case VLC_VAR_INTEGER:
813 var_Get( p_object, psz_var, &val );
816 new wxMenuItemExt( menu, ++i_item_id,
817 text_list.p_list->p_values[i].psz_string ?
819 text_list.p_list->p_values[i].psz_string) :
820 wxString::Format(wxT("%d"),
821 val_list.p_list->p_values[i].i_int), wxT(""),
822 i_type & VLC_VAR_ISCOMMAND ?
823 wxITEM_NORMAL : wxITEM_RADIO,
825 p_object->i_object_id,
826 val_list.p_list->p_values[i], i_type );
828 menu->Append( menuitem );
830 if( !(i_type & VLC_VAR_ISCOMMAND) &&
831 val_list.p_list->p_values[i].i_int == val.i_int )
832 menu->Check( i_item_id, TRUE );
836 var_Get( p_object, psz_var, &val );
839 new wxMenuItemExt( menu, ++i_item_id,
840 text_list.p_list->p_values[i].psz_string ?
842 text_list.p_list->p_values[i].psz_string) :
843 wxString::Format(wxT("%.2f"),
844 val_list.p_list->p_values[i].f_float),wxT(""),
845 i_type & VLC_VAR_ISCOMMAND ?
846 wxITEM_NORMAL : wxITEM_RADIO,
848 p_object->i_object_id,
849 val_list.p_list->p_values[i], i_type );
851 menu->Append( menuitem );
853 if( !(i_type & VLC_VAR_ISCOMMAND) &&
854 val_list.p_list->p_values[i].f_float == val.f_float )
855 menu->Check( i_item_id, TRUE );
863 /* clean up everything */
864 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
869 /*****************************************************************************
870 * A small helper class which intercepts all popup menu events
871 *****************************************************************************/
872 MenuEvtHandler::MenuEvtHandler( intf_thread_t *_p_intf,
873 Interface *_p_main_interface )
875 /* Initializations */
877 p_main_interface = _p_main_interface;
880 MenuEvtHandler::~MenuEvtHandler()
884 void MenuEvtHandler::OnShowDialog( wxCommandEvent& event )
886 if( p_intf->p_sys->pf_show_dialog )
890 switch( event.GetId() )
892 case OpenFileSimple_Event:
893 i_id = INTF_DIALOG_FILE_SIMPLE;
896 i_id = INTF_DIALOG_FILE;
898 case OpenDirectory_Event:
899 i_id = INTF_DIALOG_DIRECTORY;
902 i_id = INTF_DIALOG_DISC;
905 i_id = INTF_DIALOG_NET;
907 case OpenCapture_Event:
908 i_id = INTF_DIALOG_CAPTURE;
910 case MediaInfo_Event:
911 i_id = INTF_DIALOG_FILEINFO;
914 i_id = INTF_DIALOG_MESSAGES;
916 case Preferences_Event:
917 i_id = INTF_DIALOG_PREFS;
920 i_id = INTF_DIALOG_FILE;
925 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
929 void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
931 wxMenuItem *p_menuitem = NULL;
932 int i_hotkey_event = p_intf->p_sys->i_first_hotkey_event;
933 int i_hotkeys = p_intf->p_sys->i_hotkeys;
935 if( event.GetId() >= Play_Event && event.GetId() <= Stop_Event )
937 input_thread_t *p_input;
938 playlist_t * p_playlist =
939 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
941 if( !p_playlist ) return;
943 switch( event.GetId() )
948 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
950 if( !p_input ) playlist_Play( p_playlist );
954 var_Get( p_input, "state", &val );
955 if( val.i_int != PAUSE_S ) val.i_int = PAUSE_S;
956 else val.i_int = PLAYING_S;
957 var_Set( p_input, "state", val );
958 vlc_object_release( p_input );
962 playlist_Stop( p_playlist );
965 playlist_Prev( p_playlist );
968 playlist_Next( p_playlist );
972 vlc_object_release( p_playlist );
976 /* Check if this is an auto generated menu item */
977 if( event.GetId() < FirstAutoGenerated_Event )
983 /* Check if this is an hotkey event */
984 if( event.GetId() >= i_hotkey_event &&
985 event.GetId() < i_hotkey_event + i_hotkeys )
990 p_intf->p_vlc->p_hotkeys[event.GetId() - i_hotkey_event].i_key;
992 /* Get the key combination and send it to the hotkey handler */
993 var_Set( p_intf->p_vlc, "key-pressed", val );
997 if( !p_main_interface ||
998 (p_menuitem = p_main_interface->GetMenuBar()->FindItem(event.GetId()))
1001 if( p_intf->p_sys->p_popup_menu )
1004 p_intf->p_sys->p_popup_menu->FindItem( event.GetId() );
1010 wxMenuItemExt *p_menuitemext = (wxMenuItemExt *)p_menuitem;
1011 vlc_object_t *p_object;
1013 p_object = (vlc_object_t *)vlc_object_get( p_intf,
1014 p_menuitemext->i_object_id );
1015 if( p_object == NULL ) return;
1017 wxMutexGuiLeave(); // We don't want deadlocks
1018 var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val );
1019 //wxMutexGuiEnter();
1021 vlc_object_release( p_object );
1027 /*****************************************************************************
1028 * A small helper class which encapsulate wxMenuitem with some other useful
1030 *****************************************************************************/
1031 wxMenuItemExt::wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
1032 const wxString& helpString, wxItemKind kind,
1033 char *_psz_var, int _i_object_id, vlc_value_t _val, int _i_val_type ):
1034 wxMenuItem( parentMenu, id, text, helpString, kind )
1036 /* Initializations */
1038 i_val_type = _i_val_type;
1039 i_object_id = _i_object_id;
1043 wxMenuItemExt::~wxMenuItemExt()
1045 if( psz_var ) free( psz_var );
1046 if( ((i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
1047 && val.psz_string ) free( val.psz_string );