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.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 int minimal = config_GetInt( p_intf, "wx-minimal" );
153 vlc_object_t *p_object, *p_input;
154 char *ppsz_varnames[MAX_POPUP_ITEMS];
155 int pi_objects[MAX_POPUP_ITEMS];
156 int i = 0, i_last_separator = 0;
158 /* Initializations */
159 memset( pi_objects, 0, MAX_POPUP_ITEMS * sizeof(int) );
162 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
164 if( p_object != NULL )
166 ppsz_varnames[i] = "bookmark";
167 pi_objects[i++] = p_object->i_object_id;
168 ppsz_varnames[i] = "title";
169 pi_objects[i++] = p_object->i_object_id;
170 ppsz_varnames[i] = "chapter";
171 pi_objects[i++] = p_object->i_object_id;
172 ppsz_varnames[i] = "program";
173 pi_objects[i++] = p_object->i_object_id;
174 ppsz_varnames[i] = "navigation";
175 pi_objects[i++] = p_object->i_object_id;
176 ppsz_varnames[i] = "dvd_menus";
177 pi_objects[i++] = p_object->i_object_id;
179 ppsz_varnames[i] = "video-es";
180 pi_objects[i++] = p_object->i_object_id;
181 ppsz_varnames[i] = "audio-es";
182 pi_objects[i++] = p_object->i_object_id;
183 ppsz_varnames[i] = "spu-es";
184 pi_objects[i++] = p_object->i_object_id;
187 if( !p_input ) goto interfacemenu;
190 if( i != i_last_separator ) ppsz_varnames[i++] = NULL; /* Separator */
191 i_last_separator = i;
193 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
195 if( p_object != NULL )
197 vlc_object_t *p_dec_obj;
199 ppsz_varnames[i] = "fullscreen";
200 pi_objects[i++] = p_object->i_object_id;
201 ppsz_varnames[i] = "zoom";
202 pi_objects[i++] = p_object->i_object_id;
203 ppsz_varnames[i] = "deinterlace";
204 pi_objects[i++] = p_object->i_object_id;
205 ppsz_varnames[i] = "aspect-ratio";
206 pi_objects[i++] = p_object->i_object_id;
207 ppsz_varnames[i] = "crop";
208 pi_objects[i++] = p_object->i_object_id;
209 ppsz_varnames[i] = "video-on-top";
210 pi_objects[i++] = p_object->i_object_id;
211 ppsz_varnames[i] = "directx-wallpaper";
212 pi_objects[i++] = p_object->i_object_id;
213 ppsz_varnames[i] = "video-snapshot";
214 pi_objects[i++] = p_object->i_object_id;
216 p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
219 if( p_dec_obj != NULL )
221 ppsz_varnames[i] = "ffmpeg-pp-q";
222 pi_objects[i++] = p_dec_obj->i_object_id;
223 vlc_object_release( p_dec_obj );
226 vlc_object_release( p_object );
230 if( i != i_last_separator ) ppsz_varnames[i++] = NULL; /* Separator */
231 i_last_separator = i;
233 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
235 if( p_object != NULL )
237 ppsz_varnames[i] = "audio-device";
238 pi_objects[i++] = p_object->i_object_id;
239 ppsz_varnames[i] = "audio-channels";
240 pi_objects[i++] = p_object->i_object_id;
241 ppsz_varnames[i] = "visual";
242 pi_objects[i++] = p_object->i_object_id;
243 ppsz_varnames[i] = "equalizer";
244 pi_objects[i++] = p_object->i_object_id;
245 vlc_object_release( p_object );
250 if( i != i_last_separator ) ppsz_varnames[i++] = NULL; /* Separator */
251 i_last_separator = i;
253 /* vlc_object_find is needed because of the dialogs provider case */
254 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INTF,
256 if( p_object != NULL )
258 #if (wxCHECK_VERSION(2,5,0))
259 ppsz_varnames[i] = "intf-switch";
260 pi_objects[i++] = p_object->i_object_id;
262 ppsz_varnames[i] = "intf-add";
263 pi_objects[i++] = p_object->i_object_id;
264 ppsz_varnames[i] = "intf-skins";
265 pi_objects[i++] = p_object->i_object_id;
267 vlc_object_release( p_object );
271 Menu popupmenu( p_intf, PopupMenu_Events );
272 popupmenu.Populate( i, ppsz_varnames, pi_objects );
274 /* Add static entries */
275 if( p_input != NULL )
278 popupmenu.InsertSeparator( 0 );
281 popupmenu.Insert( 0, Stop_Event, wxU(_("Stop")) );
282 popupmenu.Insert( 0, Previous_Event, wxU(_("Previous")) );
283 popupmenu.Insert( 0, Next_Event, wxU(_("Next")) );
286 var_Get( p_input, "state", &val );
287 if( val.i_int == PAUSE_S )
288 popupmenu.Insert( 0, Play_Event, wxU(_("Play")) );
290 popupmenu.Insert( 0, Pause_Event, wxU(_("Pause")) );
292 vlc_object_release( p_input );
296 playlist_t * p_playlist =
297 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
299 if( p_playlist && p_playlist->i_size )
301 popupmenu.InsertSeparator( 0 );
302 popupmenu.Insert( 0, Play_Event, wxU(_("Play")) );
304 if( p_playlist ) vlc_object_release( p_playlist );
307 popupmenu.Append( MenuDummy_Event, wxU(_("Miscellaneous")),
308 MiscMenu( p_intf ), wxT("") );
311 popupmenu.Append( MenuDummy_Event, wxU(_("Open")),
312 OpenStreamMenu( p_intf ), wxT("") );
315 p_intf->p_sys->p_popup_menu = &popupmenu;
316 p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
317 p_intf->p_sys->p_popup_menu = NULL;
320 wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
322 #define MAX_AUDIO_ITEMS 10
324 vlc_object_t *p_object;
325 char *ppsz_varnames[MAX_AUDIO_ITEMS];
326 int pi_objects[MAX_AUDIO_ITEMS];
329 /* Initializations */
330 memset( pi_objects, 0, MAX_AUDIO_ITEMS * sizeof(int) );
332 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
334 if( p_object != NULL )
336 ppsz_varnames[i] = "audio-es";
337 pi_objects[i++] = p_object->i_object_id;
338 vlc_object_release( p_object );
341 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_AOUT,
343 if( p_object != NULL )
345 ppsz_varnames[i] = "audio-device";
346 pi_objects[i++] = p_object->i_object_id;
347 ppsz_varnames[i] = "audio-channels";
348 pi_objects[i++] = p_object->i_object_id;
349 ppsz_varnames[i] = "visual";
350 pi_objects[i++] = p_object->i_object_id;
351 ppsz_varnames[i] = "equalizer";
352 pi_objects[i++] = p_object->i_object_id;
353 vlc_object_release( p_object );
357 Menu *p_vlc_menu = (Menu *)p_menu;
359 p_vlc_menu = new Menu( _p_intf, AudioMenu_Events );
363 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
368 wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
370 #define MAX_VIDEO_ITEMS 15
372 vlc_object_t *p_object;
373 char *ppsz_varnames[MAX_VIDEO_ITEMS];
374 int pi_objects[MAX_VIDEO_ITEMS];
377 /* Initializations */
378 memset( pi_objects, 0, MAX_VIDEO_ITEMS * sizeof(int) );
380 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
382 if( p_object != NULL )
384 ppsz_varnames[i] = "video-es";
385 pi_objects[i++] = p_object->i_object_id;
386 ppsz_varnames[i] = "spu-es";
387 pi_objects[i++] = p_object->i_object_id;
388 vlc_object_release( p_object );
391 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_VOUT,
393 if( p_object != NULL )
395 vlc_object_t *p_dec_obj;
397 ppsz_varnames[i] = "fullscreen";
398 pi_objects[i++] = p_object->i_object_id;
399 ppsz_varnames[i] = "zoom";
400 pi_objects[i++] = p_object->i_object_id;
401 ppsz_varnames[i] = "deinterlace";
402 pi_objects[i++] = p_object->i_object_id;
403 ppsz_varnames[i] = "aspect-ratio";
404 pi_objects[i++] = p_object->i_object_id;
405 ppsz_varnames[i] = "crop";
406 pi_objects[i++] = p_object->i_object_id;
407 ppsz_varnames[i] = "video-on-top";
408 pi_objects[i++] = p_object->i_object_id;
409 ppsz_varnames[i] = "directx-wallpaper";
410 pi_objects[i++] = p_object->i_object_id;
411 ppsz_varnames[i] = "video-snapshot";
412 pi_objects[i++] = p_object->i_object_id;
414 p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
417 if( p_dec_obj != NULL )
419 ppsz_varnames[i] = "ffmpeg-pp-q";
420 pi_objects[i++] = p_dec_obj->i_object_id;
421 vlc_object_release( p_dec_obj );
424 vlc_object_release( p_object );
428 Menu *p_vlc_menu = (Menu *)p_menu;
430 p_vlc_menu = new Menu( _p_intf, VideoMenu_Events );
434 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
439 wxMenu *NavigMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
441 #define MAX_NAVIG_ITEMS 15
443 vlc_object_t *p_object;
444 char *ppsz_varnames[MAX_NAVIG_ITEMS];
445 int pi_objects[MAX_NAVIG_ITEMS];
448 /* Initializations */
449 memset( pi_objects, 0, MAX_NAVIG_ITEMS * sizeof(int) );
451 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
453 if( p_object != NULL )
455 ppsz_varnames[i] = "bookmark";
456 pi_objects[i++] = p_object->i_object_id;
457 ppsz_varnames[i] = "title";
458 pi_objects[i++] = p_object->i_object_id;
459 ppsz_varnames[i] = "chapter";
460 pi_objects[i++] = p_object->i_object_id;
461 ppsz_varnames[i] = "program";
462 pi_objects[i++] = p_object->i_object_id;
463 ppsz_varnames[i] = "navigation";
464 pi_objects[i++] = p_object->i_object_id;
465 ppsz_varnames[i] = "dvd_menus";
466 pi_objects[i++] = p_object->i_object_id;
468 ppsz_varnames[i] = "prev-title";
469 pi_objects[i++] = p_object->i_object_id;
470 ppsz_varnames[i] = "next-title";
471 pi_objects[i++] = p_object->i_object_id;
472 ppsz_varnames[i] = "prev-chapter";
473 pi_objects[i++] = p_object->i_object_id;
474 ppsz_varnames[i] = "next-chapter";
475 pi_objects[i++] = p_object->i_object_id;
477 vlc_object_release( p_object );
481 Menu *p_vlc_menu = (Menu *)p_menu;
483 p_vlc_menu = new Menu( _p_intf, NavigMenu_Events );
487 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
492 wxMenu *SettingsMenu( intf_thread_t *_p_intf, wxWindow *p_parent,
495 #define MAX_SETTINGS_ITEMS 10
497 vlc_object_t *p_object;
498 char *ppsz_varnames[MAX_SETTINGS_ITEMS];
499 int pi_objects[MAX_SETTINGS_ITEMS];
502 /* Initializations */
503 memset( pi_objects, 0, MAX_SETTINGS_ITEMS * sizeof(int) );
505 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INTF,
507 if( p_object != NULL )
509 #if (wxCHECK_VERSION(2,5,0))
510 ppsz_varnames[i] = "intf-switch";
511 pi_objects[i++] = p_object->i_object_id;
513 ppsz_varnames[i] = "intf-add";
514 pi_objects[i++] = p_object->i_object_id;
515 vlc_object_release( p_object );
519 Menu *p_vlc_menu = (Menu *)p_menu;
521 p_vlc_menu = new Menu( _p_intf, SettingsMenu_Events );
525 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
530 /*****************************************************************************
532 *****************************************************************************/
533 Menu::Menu( intf_thread_t *_p_intf, int _i_start_id ) : wxMenu( )
535 /* Initializations */
537 i_start_id = _i_start_id;
544 /*****************************************************************************
546 *****************************************************************************/
547 void Menu::Populate( int i_count, char **ppsz_varnames, int *pi_objects )
549 vlc_object_t *p_object;
550 vlc_bool_t b_section_empty = VLC_FALSE;
553 i_item_id = i_start_id;
555 for( i = 0; i < i_count; i++ )
557 if( !ppsz_varnames[i] )
559 if( b_section_empty )
561 Append( MenuDummy_Event + i, wxU(_("Empty")) );
562 Enable( MenuDummy_Event + i, FALSE );
566 b_section_empty = VLC_TRUE;
572 Append( MenuDummy_Event, wxU(ppsz_varnames[i]) );
573 b_section_empty = VLC_FALSE;
577 p_object = (vlc_object_t *)vlc_object_get( p_intf, pi_objects[i] );
578 if( p_object == NULL ) continue;
580 b_section_empty = VLC_FALSE;
581 CreateMenuItem( this, ppsz_varnames[i], p_object );
582 vlc_object_release( p_object );
585 /* Special case for empty menus */
586 if( GetMenuItemCount() == 0 || b_section_empty )
588 Append( MenuDummy_Event + i, wxU(_("Empty")) );
589 Enable( MenuDummy_Event + i, FALSE );
593 /* Work-around helper for buggy wxGTK */
594 static void RecursiveDestroy( wxMenu *menu )
596 wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
599 wxMenuItem *item = node->GetData();
600 node = node->GetNext();
602 /* Delete the submenus */
603 wxMenu *submenu = item->GetSubMenu();
606 RecursiveDestroy( submenu );
608 menu->Delete( item );
614 RecursiveDestroy( this );
617 /*****************************************************************************
619 *****************************************************************************/
620 static bool IsMenuEmpty( char *psz_var, vlc_object_t *p_object,
623 vlc_value_t val, val_list;
624 int i_type, i_result, i;
626 /* Check the type of the object variable */
627 i_type = var_Type( p_object, psz_var );
629 /* Check if we want to display the variable */
630 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
632 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
633 if( val.i_int == 0 ) return TRUE;
635 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
637 if( val.i_int == 1 && b_root ) return TRUE;
641 /* Check children variables in case of VLC_VAR_VARIABLE */
642 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
647 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
649 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
657 /* clean up everything */
658 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
663 void Menu::CreateMenuItem( wxMenu *menu, char *psz_var,
664 vlc_object_t *p_object )
666 wxMenuItemExt *menuitem;
667 vlc_value_t val, text;
670 /* Check the type of the object variable */
671 i_type = var_Type( p_object, psz_var );
673 switch( i_type & VLC_VAR_TYPE )
677 case VLC_VAR_VARIABLE:
679 case VLC_VAR_INTEGER:
683 /* Variable doesn't exist or isn't handled */
687 /* Make sure we want to display the variable */
688 if( IsMenuEmpty( psz_var, p_object ) ) return;
690 /* Get the descriptive name of the variable */
691 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
693 if( i_type & VLC_VAR_HASCHOICE )
695 menu->Append( MenuDummy_Event,
696 wxU(text.psz_string ? text.psz_string : psz_var),
697 CreateChoicesMenu( psz_var, p_object, TRUE ),
698 wxT("")/* Nothing for now (maybe use a GETLONGTEXT) */ );
700 if( text.psz_string ) free( text.psz_string );
705 switch( i_type & VLC_VAR_TYPE )
708 var_Get( p_object, psz_var, &val );
709 menuitem = new wxMenuItemExt( menu, ++i_item_id,
710 wxU(text.psz_string ?
711 text.psz_string : psz_var),
712 wxT(""), wxITEM_NORMAL, strdup(psz_var),
713 p_object->i_object_id, val, i_type );
714 menu->Append( menuitem );
718 var_Get( p_object, psz_var, &val );
719 val.b_bool = !val.b_bool;
720 menuitem = new wxMenuItemExt( menu, ++i_item_id,
721 wxU(text.psz_string ?
722 text.psz_string : psz_var),
723 wxT(""), wxITEM_CHECK, strdup(psz_var),
724 p_object->i_object_id, val, i_type );
725 menu->Append( menuitem );
726 Check( i_item_id, val.b_bool ? FALSE : TRUE );
730 if( text.psz_string ) free( text.psz_string );
733 wxMenu *Menu::CreateChoicesMenu( char *psz_var, vlc_object_t *p_object,
736 vlc_value_t val, val_list, text_list;
739 /* Check the type of the object variable */
740 i_type = var_Type( p_object, psz_var );
742 /* Make sure we want to display the variable */
743 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return NULL;
745 switch( i_type & VLC_VAR_TYPE )
749 case VLC_VAR_VARIABLE:
751 case VLC_VAR_INTEGER:
755 /* Variable doesn't exist or isn't handled */
759 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
760 &val_list, &text_list ) < 0 )
765 wxMenu *menu = new wxMenu;
766 for( i = 0; i < val_list.p_list->i_count; i++ )
768 vlc_value_t another_val;
769 wxMenuItemExt *menuitem;
771 switch( i_type & VLC_VAR_TYPE )
773 case VLC_VAR_VARIABLE:
774 menu->Append( MenuDummy_Event,
775 wxU(text_list.p_list->p_values[i].psz_string ?
776 text_list.p_list->p_values[i].psz_string :
777 val_list.p_list->p_values[i].psz_string),
779 val_list.p_list->p_values[i].psz_string,
780 p_object, FALSE ), wxT("") );
784 var_Get( p_object, psz_var, &val );
786 another_val.psz_string =
787 strdup(val_list.p_list->p_values[i].psz_string);
789 new wxMenuItemExt( menu, ++i_item_id,
790 wxU(text_list.p_list->p_values[i].psz_string ?
791 text_list.p_list->p_values[i].psz_string :
792 another_val.psz_string), wxT(""),
793 i_type & VLC_VAR_ISCOMMAND ?
794 wxITEM_NORMAL : wxITEM_RADIO,
796 p_object->i_object_id, another_val, i_type );
798 menu->Append( menuitem );
800 if( !(i_type & VLC_VAR_ISCOMMAND) && val.psz_string &&
801 !strcmp( val.psz_string,
802 val_list.p_list->p_values[i].psz_string ) )
803 menu->Check( i_item_id, TRUE );
805 if( val.psz_string ) free( val.psz_string );
808 case VLC_VAR_INTEGER:
809 var_Get( p_object, psz_var, &val );
812 new wxMenuItemExt( menu, ++i_item_id,
813 text_list.p_list->p_values[i].psz_string ?
815 text_list.p_list->p_values[i].psz_string) :
816 wxString::Format(wxT("%d"),
817 val_list.p_list->p_values[i].i_int), wxT(""),
818 i_type & VLC_VAR_ISCOMMAND ?
819 wxITEM_NORMAL : wxITEM_RADIO,
821 p_object->i_object_id,
822 val_list.p_list->p_values[i], i_type );
824 menu->Append( menuitem );
826 if( !(i_type & VLC_VAR_ISCOMMAND) &&
827 val_list.p_list->p_values[i].i_int == val.i_int )
828 menu->Check( i_item_id, TRUE );
832 var_Get( p_object, psz_var, &val );
835 new wxMenuItemExt( menu, ++i_item_id,
836 text_list.p_list->p_values[i].psz_string ?
838 text_list.p_list->p_values[i].psz_string) :
839 wxString::Format(wxT("%.2f"),
840 val_list.p_list->p_values[i].f_float),wxT(""),
841 i_type & VLC_VAR_ISCOMMAND ?
842 wxITEM_NORMAL : wxITEM_RADIO,
844 p_object->i_object_id,
845 val_list.p_list->p_values[i], i_type );
847 menu->Append( menuitem );
849 if( !(i_type & VLC_VAR_ISCOMMAND) &&
850 val_list.p_list->p_values[i].f_float == val.f_float )
851 menu->Check( i_item_id, TRUE );
859 /* clean up everything */
860 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
865 /*****************************************************************************
866 * A small helper class which intercepts all popup menu events
867 *****************************************************************************/
868 MenuEvtHandler::MenuEvtHandler( intf_thread_t *_p_intf,
869 Interface *_p_main_interface )
871 /* Initializations */
873 p_main_interface = _p_main_interface;
876 MenuEvtHandler::~MenuEvtHandler()
880 void MenuEvtHandler::OnShowDialog( wxCommandEvent& event )
882 if( p_intf->p_sys->pf_show_dialog )
886 switch( event.GetId() )
888 case OpenFileSimple_Event:
889 i_id = INTF_DIALOG_FILE_SIMPLE;
892 i_id = INTF_DIALOG_FILE;
895 i_id = INTF_DIALOG_DISC;
898 i_id = INTF_DIALOG_NET;
900 case OpenCapture_Event:
901 i_id = INTF_DIALOG_CAPTURE;
903 case MediaInfo_Event:
904 i_id = INTF_DIALOG_FILEINFO;
907 i_id = INTF_DIALOG_MESSAGES;
909 case Preferences_Event:
910 i_id = INTF_DIALOG_PREFS;
913 i_id = INTF_DIALOG_FILE;
918 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
922 void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
924 wxMenuItem *p_menuitem = NULL;
925 int i_hotkey_event = p_intf->p_sys->i_first_hotkey_event;
926 int i_hotkeys = p_intf->p_sys->i_hotkeys;
928 if( event.GetId() >= Play_Event && event.GetId() <= Stop_Event )
930 input_thread_t *p_input;
931 playlist_t * p_playlist =
932 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
934 if( !p_playlist ) return;
936 switch( event.GetId() )
941 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
943 if( !p_input ) playlist_Play( p_playlist );
947 var_Get( p_input, "state", &val );
948 if( val.i_int != PAUSE_S ) val.i_int = PAUSE_S;
949 else val.i_int = PLAYING_S;
950 var_Set( p_input, "state", val );
951 vlc_object_release( p_input );
955 playlist_Stop( p_playlist );
958 playlist_Prev( p_playlist );
961 playlist_Next( p_playlist );
965 vlc_object_release( p_playlist );
969 /* Check if this is an auto generated menu item */
970 if( event.GetId() < FirstAutoGenerated_Event )
976 /* Check if this is an hotkey event */
977 if( event.GetId() >= i_hotkey_event &&
978 event.GetId() < i_hotkey_event + i_hotkeys )
983 p_intf->p_vlc->p_hotkeys[event.GetId() - i_hotkey_event].i_key;
985 /* Get the key combination and send it to the hotkey handler */
986 var_Set( p_intf->p_vlc, "key-pressed", val );
990 if( !p_main_interface ||
991 (p_menuitem = p_main_interface->GetMenuBar()->FindItem(event.GetId()))
994 if( p_intf->p_sys->p_popup_menu )
997 p_intf->p_sys->p_popup_menu->FindItem( event.GetId() );
1003 wxMenuItemExt *p_menuitemext = (wxMenuItemExt *)p_menuitem;
1004 vlc_object_t *p_object;
1006 p_object = (vlc_object_t *)vlc_object_get( p_intf,
1007 p_menuitemext->i_object_id );
1008 if( p_object == NULL ) return;
1010 wxMutexGuiLeave(); // We don't want deadlocks
1011 var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val );
1012 //wxMutexGuiEnter();
1014 vlc_object_release( p_object );
1020 /*****************************************************************************
1021 * A small helper class which encapsulate wxMenuitem with some other useful
1023 *****************************************************************************/
1024 wxMenuItemExt::wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
1025 const wxString& helpString, wxItemKind kind,
1026 char *_psz_var, int _i_object_id, vlc_value_t _val, int _i_val_type ):
1027 wxMenuItem( parentMenu, id, text, helpString, kind )
1029 /* Initializations */
1031 i_val_type = _i_val_type;
1032 i_object_id = _i_object_id;
1036 wxMenuItemExt::~wxMenuItemExt()
1038 if( psz_var ) free( psz_var );
1039 if( ((i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
1040 && val.psz_string ) free( val.psz_string );