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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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 *CreateDummyMenu();
70 void CreateMenuItem( wxMenu *, char *, vlc_object_t * );
71 wxMenu *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 )
263 #if (wxCHECK_VERSION(2,5,0))
264 ppsz_varnames[i] = "intf-switch";
265 pi_objects[i++] = p_object->i_object_id;
268 ppsz_varnames[i] = "intf-add";
269 pi_objects[i++] = p_object->i_object_id;
270 ppsz_varnames[i] = "intf-skins";
271 pi_objects[i++] = p_object->i_object_id;
273 vlc_object_release( p_object );
277 Menu popupmenu( p_intf, PopupMenu_Events );
278 popupmenu.Populate( i, ppsz_varnames, pi_objects );
280 /* Add static entries */
281 if( p_input != NULL )
284 popupmenu.InsertSeparator( 0 );
287 popupmenu.Insert( 0, Stop_Event, wxU(_("Stop")) );
288 popupmenu.Insert( 0, Previous_Event, wxU(_("Previous")) );
289 popupmenu.Insert( 0, Next_Event, wxU(_("Next")) );
292 var_Get( p_input, "state", &val );
293 if( val.i_int == PAUSE_S )
294 popupmenu.Insert( 0, Play_Event, wxU(_("Play")) );
296 popupmenu.Insert( 0, Pause_Event, wxU(_("Pause")) );
298 vlc_object_release( p_input );
302 playlist_t * p_playlist =
303 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
305 if( p_playlist && p_playlist->i_size )
307 popupmenu.InsertSeparator( 0 );
308 popupmenu.Insert( 0, Play_Event, wxU(_("Play")) );
310 if( p_playlist ) vlc_object_release( p_playlist );
313 popupmenu.Append( MenuDummy_Event, wxU(_("Miscellaneous")),
314 MiscMenu( p_intf ), wxT("") );
317 popupmenu.Append( MenuDummy_Event, wxU(_("Open")),
318 OpenStreamMenu( p_intf ), wxT("") );
321 p_intf->p_sys->p_popup_menu = &popupmenu;
322 p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
323 p_intf->p_sys->p_popup_menu = NULL;
326 wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
328 #define MAX_AUDIO_ITEMS 10
330 vlc_object_t *p_object;
331 char *ppsz_varnames[MAX_AUDIO_ITEMS];
332 int pi_objects[MAX_AUDIO_ITEMS];
335 /* Initializations */
336 memset( pi_objects, 0, MAX_AUDIO_ITEMS * sizeof(int) );
338 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
340 if( p_object != NULL )
342 ppsz_varnames[i] = "audio-es";
343 pi_objects[i++] = p_object->i_object_id;
344 vlc_object_release( p_object );
347 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_AOUT,
349 if( p_object != NULL )
351 ppsz_varnames[i] = "audio-device";
352 pi_objects[i++] = p_object->i_object_id;
353 ppsz_varnames[i] = "audio-channels";
354 pi_objects[i++] = p_object->i_object_id;
355 ppsz_varnames[i] = "visual";
356 pi_objects[i++] = p_object->i_object_id;
357 ppsz_varnames[i] = "equalizer";
358 pi_objects[i++] = p_object->i_object_id;
359 vlc_object_release( p_object );
363 Menu *p_vlc_menu = (Menu *)p_menu;
365 p_vlc_menu = new Menu( _p_intf, AudioMenu_Events );
369 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
374 wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
376 #define MAX_VIDEO_ITEMS 15
378 vlc_object_t *p_object;
379 char *ppsz_varnames[MAX_VIDEO_ITEMS];
380 int pi_objects[MAX_VIDEO_ITEMS];
383 /* Initializations */
384 memset( pi_objects, 0, MAX_VIDEO_ITEMS * sizeof(int) );
386 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
388 if( p_object != NULL )
390 ppsz_varnames[i] = "video-es";
391 pi_objects[i++] = p_object->i_object_id;
392 ppsz_varnames[i] = "spu-es";
393 pi_objects[i++] = p_object->i_object_id;
394 vlc_object_release( p_object );
397 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_VOUT,
399 if( p_object != NULL )
401 vlc_object_t *p_dec_obj;
403 ppsz_varnames[i] = "fullscreen";
404 pi_objects[i++] = p_object->i_object_id;
405 ppsz_varnames[i] = "zoom";
406 pi_objects[i++] = p_object->i_object_id;
407 ppsz_varnames[i] = "deinterlace";
408 pi_objects[i++] = p_object->i_object_id;
409 ppsz_varnames[i] = "aspect-ratio";
410 pi_objects[i++] = p_object->i_object_id;
411 ppsz_varnames[i] = "crop";
412 pi_objects[i++] = p_object->i_object_id;
413 ppsz_varnames[i] = "video-on-top";
414 pi_objects[i++] = p_object->i_object_id;
415 ppsz_varnames[i] = "directx-wallpaper";
416 pi_objects[i++] = p_object->i_object_id;
417 ppsz_varnames[i] = "video-snapshot";
418 pi_objects[i++] = p_object->i_object_id;
420 p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
423 if( p_dec_obj != NULL )
425 ppsz_varnames[i] = "ffmpeg-pp-q";
426 pi_objects[i++] = p_dec_obj->i_object_id;
427 vlc_object_release( p_dec_obj );
430 vlc_object_release( p_object );
434 Menu *p_vlc_menu = (Menu *)p_menu;
436 p_vlc_menu = new Menu( _p_intf, VideoMenu_Events );
440 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
445 wxMenu *NavigMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
447 #define MAX_NAVIG_ITEMS 15
449 vlc_object_t *p_object;
450 char *ppsz_varnames[MAX_NAVIG_ITEMS];
451 int pi_objects[MAX_NAVIG_ITEMS];
454 /* Initializations */
455 memset( pi_objects, 0, MAX_NAVIG_ITEMS * sizeof(int) );
457 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
459 if( p_object != NULL )
461 ppsz_varnames[i] = "bookmark";
462 pi_objects[i++] = p_object->i_object_id;
463 ppsz_varnames[i] = "title";
464 pi_objects[i++] = p_object->i_object_id;
465 ppsz_varnames[i] = "chapter";
466 pi_objects[i++] = p_object->i_object_id;
467 ppsz_varnames[i] = "program";
468 pi_objects[i++] = p_object->i_object_id;
469 ppsz_varnames[i] = "navigation";
470 pi_objects[i++] = p_object->i_object_id;
471 ppsz_varnames[i] = "dvd_menus";
472 pi_objects[i++] = p_object->i_object_id;
474 ppsz_varnames[i] = "prev-title";
475 pi_objects[i++] = p_object->i_object_id;
476 ppsz_varnames[i] = "next-title";
477 pi_objects[i++] = p_object->i_object_id;
478 ppsz_varnames[i] = "prev-chapter";
479 pi_objects[i++] = p_object->i_object_id;
480 ppsz_varnames[i] = "next-chapter";
481 pi_objects[i++] = p_object->i_object_id;
483 vlc_object_release( p_object );
487 Menu *p_vlc_menu = (Menu *)p_menu;
489 p_vlc_menu = new Menu( _p_intf, NavigMenu_Events );
493 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
498 wxMenu *SettingsMenu( intf_thread_t *_p_intf, wxWindow *p_parent,
501 #define MAX_SETTINGS_ITEMS 10
503 vlc_object_t *p_object;
504 char *ppsz_varnames[MAX_SETTINGS_ITEMS];
505 int pi_objects[MAX_SETTINGS_ITEMS];
508 /* Initializations */
509 memset( pi_objects, 0, MAX_SETTINGS_ITEMS * sizeof(int) );
511 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INTF,
513 if( p_object != NULL )
516 #if (wxCHECK_VERSION(2,5,0))
517 ppsz_varnames[i] = "intf-switch";
518 pi_objects[i++] = p_object->i_object_id;
521 ppsz_varnames[i] = "intf-add";
522 pi_objects[i++] = p_object->i_object_id;
523 vlc_object_release( p_object );
527 Menu *p_vlc_menu = (Menu *)p_menu;
529 p_vlc_menu = new Menu( _p_intf, SettingsMenu_Events );
533 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
538 /*****************************************************************************
540 *****************************************************************************/
541 Menu::Menu( intf_thread_t *_p_intf, int _i_start_id ) : wxMenu( )
543 /* Initializations */
545 i_start_id = _i_start_id;
552 /*****************************************************************************
554 *****************************************************************************/
555 void Menu::Populate( int i_count, char **ppsz_varnames, int *pi_objects )
557 vlc_object_t *p_object;
558 vlc_bool_t b_section_empty = VLC_FALSE;
561 i_item_id = i_start_id;
563 for( i = 0; i < i_count; i++ )
565 if( !ppsz_varnames[i] )
567 if( b_section_empty )
569 Append( MenuDummy_Event + i, wxU(_("Empty")) );
570 Enable( MenuDummy_Event + i, FALSE );
574 b_section_empty = VLC_TRUE;
580 Append( MenuDummy_Event, wxU(ppsz_varnames[i]) );
581 b_section_empty = VLC_FALSE;
585 p_object = (vlc_object_t *)vlc_object_get( p_intf, pi_objects[i] );
586 if( p_object == NULL ) continue;
588 b_section_empty = VLC_FALSE;
589 CreateMenuItem( this, ppsz_varnames[i], p_object );
590 vlc_object_release( p_object );
593 /* Special case for empty menus */
594 if( GetMenuItemCount() == 0 || b_section_empty )
596 Append( MenuDummy_Event + i, wxU(_("Empty")) );
597 Enable( MenuDummy_Event + i, FALSE );
601 /* Work-around helper for buggy wxGTK */
602 static void RecursiveDestroy( wxMenu *menu )
604 wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
607 wxMenuItem *item = node->GetData();
608 node = node->GetNext();
610 /* Delete the submenus */
611 wxMenu *submenu = item->GetSubMenu();
614 RecursiveDestroy( submenu );
616 menu->Delete( item );
622 RecursiveDestroy( this );
625 /*****************************************************************************
627 *****************************************************************************/
628 static bool IsMenuEmpty( char *psz_var, vlc_object_t *p_object,
631 vlc_value_t val, val_list;
632 int i_type, i_result, i;
634 /* Check the type of the object variable */
635 i_type = var_Type( p_object, psz_var );
637 /* Check if we want to display the variable */
638 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
640 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
641 if( val.i_int == 0 ) return TRUE;
643 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
645 if( val.i_int == 1 && b_root ) return TRUE;
649 /* Check children variables in case of VLC_VAR_VARIABLE */
650 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
655 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
657 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
665 /* clean up everything */
666 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
671 void Menu::CreateMenuItem( wxMenu *menu, char *psz_var,
672 vlc_object_t *p_object )
674 wxMenuItemExt *menuitem;
675 vlc_value_t val, text;
678 /* Check the type of the object variable */
679 i_type = var_Type( p_object, psz_var );
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 /* Make sure we want to display the variable */
696 if( IsMenuEmpty( psz_var, p_object ) ) return;
698 /* Get the descriptive name of the variable */
699 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
701 if( i_type & VLC_VAR_HASCHOICE )
703 menu->Append( MenuDummy_Event,
704 wxU(text.psz_string ? text.psz_string : psz_var),
705 CreateChoicesMenu( psz_var, p_object, TRUE ),
706 wxT("")/* Nothing for now (maybe use a GETLONGTEXT) */ );
708 if( text.psz_string ) free( text.psz_string );
713 switch( i_type & VLC_VAR_TYPE )
716 var_Get( p_object, psz_var, &val );
717 menuitem = new wxMenuItemExt( menu, ++i_item_id,
718 wxU(text.psz_string ?
719 text.psz_string : psz_var),
720 wxT(""), wxITEM_NORMAL, strdup(psz_var),
721 p_object->i_object_id, val, i_type );
722 menu->Append( menuitem );
726 var_Get( p_object, psz_var, &val );
727 val.b_bool = !val.b_bool;
728 menuitem = new wxMenuItemExt( menu, ++i_item_id,
729 wxU(text.psz_string ?
730 text.psz_string : psz_var),
731 wxT(""), wxITEM_CHECK, strdup(psz_var),
732 p_object->i_object_id, val, i_type );
733 menu->Append( menuitem );
734 Check( i_item_id, val.b_bool ? FALSE : TRUE );
738 if( text.psz_string ) free( text.psz_string );
741 wxMenu *Menu::CreateChoicesMenu( char *psz_var, vlc_object_t *p_object,
744 vlc_value_t val, val_list, text_list;
747 /* Check the type of the object variable */
748 i_type = var_Type( p_object, psz_var );
750 /* Make sure we want to display the variable */
751 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return NULL;
753 switch( i_type & VLC_VAR_TYPE )
757 case VLC_VAR_VARIABLE:
759 case VLC_VAR_INTEGER:
763 /* Variable doesn't exist or isn't handled */
767 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
768 &val_list, &text_list ) < 0 )
773 wxMenu *menu = new wxMenu;
774 for( i = 0; i < val_list.p_list->i_count; i++ )
776 vlc_value_t another_val;
777 wxMenuItemExt *menuitem;
779 switch( i_type & VLC_VAR_TYPE )
781 case VLC_VAR_VARIABLE:
782 menu->Append( MenuDummy_Event,
783 wxU(text_list.p_list->p_values[i].psz_string ?
784 text_list.p_list->p_values[i].psz_string :
785 val_list.p_list->p_values[i].psz_string),
787 val_list.p_list->p_values[i].psz_string,
788 p_object, FALSE ), wxT("") );
792 var_Get( p_object, psz_var, &val );
794 another_val.psz_string =
795 strdup(val_list.p_list->p_values[i].psz_string);
797 new wxMenuItemExt( menu, ++i_item_id,
798 wxU(text_list.p_list->p_values[i].psz_string ?
799 text_list.p_list->p_values[i].psz_string :
800 another_val.psz_string), wxT(""),
801 i_type & VLC_VAR_ISCOMMAND ?
802 wxITEM_NORMAL : wxITEM_RADIO,
804 p_object->i_object_id, another_val, i_type );
806 menu->Append( menuitem );
808 if( !(i_type & VLC_VAR_ISCOMMAND) && val.psz_string &&
809 !strcmp( val.psz_string,
810 val_list.p_list->p_values[i].psz_string ) )
811 menu->Check( i_item_id, TRUE );
813 if( val.psz_string ) free( val.psz_string );
816 case VLC_VAR_INTEGER:
817 var_Get( p_object, psz_var, &val );
820 new wxMenuItemExt( menu, ++i_item_id,
821 text_list.p_list->p_values[i].psz_string ?
823 text_list.p_list->p_values[i].psz_string) :
824 wxString::Format(wxT("%d"),
825 val_list.p_list->p_values[i].i_int), wxT(""),
826 i_type & VLC_VAR_ISCOMMAND ?
827 wxITEM_NORMAL : wxITEM_RADIO,
829 p_object->i_object_id,
830 val_list.p_list->p_values[i], i_type );
832 menu->Append( menuitem );
834 if( !(i_type & VLC_VAR_ISCOMMAND) &&
835 val_list.p_list->p_values[i].i_int == val.i_int )
836 menu->Check( i_item_id, TRUE );
840 var_Get( p_object, psz_var, &val );
843 new wxMenuItemExt( menu, ++i_item_id,
844 text_list.p_list->p_values[i].psz_string ?
846 text_list.p_list->p_values[i].psz_string) :
847 wxString::Format(wxT("%.2f"),
848 val_list.p_list->p_values[i].f_float),wxT(""),
849 i_type & VLC_VAR_ISCOMMAND ?
850 wxITEM_NORMAL : wxITEM_RADIO,
852 p_object->i_object_id,
853 val_list.p_list->p_values[i], i_type );
855 menu->Append( menuitem );
857 if( !(i_type & VLC_VAR_ISCOMMAND) &&
858 val_list.p_list->p_values[i].f_float == val.f_float )
859 menu->Check( i_item_id, TRUE );
867 /* clean up everything */
868 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
873 /*****************************************************************************
874 * A small helper class which intercepts all popup menu events
875 *****************************************************************************/
876 MenuEvtHandler::MenuEvtHandler( intf_thread_t *_p_intf,
877 Interface *_p_main_interface )
879 /* Initializations */
881 p_main_interface = _p_main_interface;
884 MenuEvtHandler::~MenuEvtHandler()
888 void MenuEvtHandler::OnShowDialog( wxCommandEvent& event )
890 if( p_intf->p_sys->pf_show_dialog )
894 switch( event.GetId() )
896 case OpenFileSimple_Event:
897 i_id = INTF_DIALOG_FILE_SIMPLE;
900 i_id = INTF_DIALOG_FILE;
902 case OpenDirectory_Event:
903 i_id = INTF_DIALOG_DIRECTORY;
906 i_id = INTF_DIALOG_DISC;
909 i_id = INTF_DIALOG_NET;
911 case OpenCapture_Event:
912 i_id = INTF_DIALOG_CAPTURE;
914 case MediaInfo_Event:
915 i_id = INTF_DIALOG_FILEINFO;
918 i_id = INTF_DIALOG_MESSAGES;
920 case Preferences_Event:
921 i_id = INTF_DIALOG_PREFS;
924 i_id = INTF_DIALOG_FILE;
929 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
933 void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
935 wxMenuItem *p_menuitem = NULL;
936 int i_hotkey_event = p_intf->p_sys->i_first_hotkey_event;
937 int i_hotkeys = p_intf->p_sys->i_hotkeys;
939 if( event.GetId() >= Play_Event && event.GetId() <= Stop_Event )
941 input_thread_t *p_input;
942 playlist_t * p_playlist =
943 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
945 if( !p_playlist ) return;
947 switch( event.GetId() )
952 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
954 if( !p_input ) playlist_Play( p_playlist );
958 var_Get( p_input, "state", &val );
959 if( val.i_int != PAUSE_S ) val.i_int = PAUSE_S;
960 else val.i_int = PLAYING_S;
961 var_Set( p_input, "state", val );
962 vlc_object_release( p_input );
966 playlist_Stop( p_playlist );
969 playlist_Prev( p_playlist );
972 playlist_Next( p_playlist );
976 vlc_object_release( p_playlist );
980 /* Check if this is an auto generated menu item */
981 if( event.GetId() < FirstAutoGenerated_Event )
987 /* Check if this is an hotkey event */
988 if( event.GetId() >= i_hotkey_event &&
989 event.GetId() < i_hotkey_event + i_hotkeys )
994 p_intf->p_vlc->p_hotkeys[event.GetId() - i_hotkey_event].i_key;
996 /* Get the key combination and send it to the hotkey handler */
997 var_Set( p_intf->p_vlc, "key-pressed", val );
1001 if( !p_main_interface ||
1002 (p_menuitem = p_main_interface->GetMenuBar()->FindItem(event.GetId()))
1005 if( p_intf->p_sys->p_popup_menu )
1008 p_intf->p_sys->p_popup_menu->FindItem( event.GetId() );
1014 wxMenuItemExt *p_menuitemext = (wxMenuItemExt *)p_menuitem;
1015 vlc_object_t *p_object;
1017 p_object = (vlc_object_t *)vlc_object_get( p_intf,
1018 p_menuitemext->i_object_id );
1019 if( p_object == NULL ) return;
1021 wxMutexGuiLeave(); // We don't want deadlocks
1022 var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val );
1023 //wxMutexGuiEnter();
1025 vlc_object_release( p_object );
1031 /*****************************************************************************
1032 * A small helper class which encapsulate wxMenuitem with some other useful
1034 *****************************************************************************/
1035 wxMenuItemExt::wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
1036 const wxString& helpString, wxItemKind kind,
1037 char *_psz_var, int _i_object_id, vlc_value_t _val, int _i_val_type ):
1038 wxMenuItem( parentMenu, id, text, helpString, kind )
1040 /* Initializations */
1042 i_val_type = _i_val_type;
1043 i_object_id = _i_object_id;
1047 wxMenuItemExt::~wxMenuItemExt()
1049 if( psz_var ) free( psz_var );
1050 if( ((i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
1051 && val.psz_string ) free( val.psz_string );