1 /*****************************************************************************
2 * menus.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004 VideoLAN
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <errno.h> /* ENOMEM */
29 #include <string.h> /* strerror() */
35 #include "wxwindows.h"
37 class wxMenuItemExt: public wxMenuItem
41 wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
42 const wxString& helpString, wxItemKind kind,
43 char *_psz_var, int _i_object_id, vlc_value_t _val,
46 virtual ~wxMenuItemExt();
57 class Menu: public wxMenu
61 Menu( intf_thread_t *p_intf, int i_start_id );
64 void Populate( int i_count, char **ppsz_names, int *pi_objects );
68 wxMenu *Menu::CreateDummyMenu();
69 void Menu::CreateMenuItem( wxMenu *, char *, vlc_object_t * );
70 wxMenu *Menu::CreateChoicesMenu( char *, vlc_object_t *, bool );
72 DECLARE_EVENT_TABLE();
74 intf_thread_t *p_intf;
80 /*****************************************************************************
82 *****************************************************************************/
84 /* IDs for the controls and the menu commands */
88 MenuDummy_Event = wxID_HIGHEST + 1000,
89 OpenFileSimple_Event = wxID_HIGHEST + 1100,
95 FirstAutoGenerated_Event = wxID_HIGHEST + 1999,
96 SettingsMenu_Events = wxID_HIGHEST + 5000,
97 AudioMenu_Events = wxID_HIGHEST + 2000,
98 VideoMenu_Events = wxID_HIGHEST + 3000,
99 NavigMenu_Events = wxID_HIGHEST + 4000,
100 PopupMenu_Events = wxID_HIGHEST + 6000
103 BEGIN_EVENT_TABLE(Menu, wxMenu)
106 BEGIN_EVENT_TABLE(MenuEvtHandler, wxEvtHandler)
107 EVT_MENU(OpenFileSimple_Event, MenuEvtHandler::OnShowDialog)
108 EVT_MENU(OpenFile_Event, MenuEvtHandler::OnShowDialog)
109 EVT_MENU(OpenDisc_Event, MenuEvtHandler::OnShowDialog)
110 EVT_MENU(OpenNet_Event, MenuEvtHandler::OnShowDialog)
111 EVT_MENU(OpenCapture_Event, MenuEvtHandler::OnShowDialog)
112 EVT_MENU(Preferences_Event, MenuEvtHandler::OnShowDialog)
113 EVT_MENU(-1, MenuEvtHandler::OnMenuEvent)
116 wxMenu *OpenStreamMenu( intf_thread_t *p_intf )
118 wxMenu *menu = new wxMenu;
119 menu->Append( OpenFileSimple_Event, wxU(_("Quick &Open File...")) );
120 menu->Append( OpenFile_Event, wxU(_("Open &File...")) );
121 menu->Append( OpenDisc_Event, wxU(_("Open &Disc...")) );
122 menu->Append( OpenNet_Event, wxU(_("Open &Network Stream...")) );
123 menu->Append( OpenCapture_Event, wxU(_("Open &Capture Device...")) );
127 void PopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
130 #define MAX_POPUP_ITEMS 35
132 vlc_object_t *p_object;
133 char *ppsz_varnames[MAX_POPUP_ITEMS];
134 int pi_objects[MAX_POPUP_ITEMS];
137 /* Initializations */
138 memset( pi_objects, 0, MAX_POPUP_ITEMS * sizeof(int) );
141 ppsz_varnames[i++] = _("Audio menu");
142 ppsz_varnames[i++] = NULL; /* Separator */
144 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
146 if( p_object != NULL )
148 ppsz_varnames[i] = "audio-device";
149 pi_objects[i++] = p_object->i_object_id;
150 ppsz_varnames[i] = "audio-channels";
151 pi_objects[i++] = p_object->i_object_id;
152 ppsz_varnames[i] = "visual";
153 pi_objects[i++] = p_object->i_object_id;
154 vlc_object_release( p_object );
158 ppsz_varnames[i++] = NULL; /* Separator */
159 ppsz_varnames[i++] = _("Video menu");
160 ppsz_varnames[i++] = NULL; /* Separator */
162 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
164 if( p_object != NULL )
166 vlc_object_t *p_dec_obj;
168 ppsz_varnames[i] = "fullscreen";
169 pi_objects[i++] = p_object->i_object_id;
170 ppsz_varnames[i] = "zoom";
171 pi_objects[i++] = p_object->i_object_id;
172 ppsz_varnames[i] = "deinterlace";
173 pi_objects[i++] = p_object->i_object_id;
174 ppsz_varnames[i] = "aspect-ratio";
175 pi_objects[i++] = p_object->i_object_id;
176 ppsz_varnames[i] = "crop";
177 pi_objects[i++] = p_object->i_object_id;
178 ppsz_varnames[i] = "video-on-top";
179 pi_objects[i++] = p_object->i_object_id;
181 p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
184 if( p_dec_obj != NULL )
186 ppsz_varnames[i] = "ffmpeg-pp-q";
187 pi_objects[i++] = p_dec_obj->i_object_id;
188 vlc_object_release( p_dec_obj );
191 vlc_object_release( p_object );
195 ppsz_varnames[i++] = NULL; /* Separator */
196 ppsz_varnames[i++] = _("Input menu");
197 ppsz_varnames[i++] = NULL; /* Separator */
199 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
201 if( p_object != NULL )
203 ppsz_varnames[i] = "bookmark";
204 pi_objects[i++] = p_object->i_object_id;
205 ppsz_varnames[i] = "title";
206 pi_objects[i++] = p_object->i_object_id;
207 ppsz_varnames[i] = "chapter";
208 pi_objects[i++] = p_object->i_object_id;
209 ppsz_varnames[i] = "program";
210 pi_objects[i++] = p_object->i_object_id;
211 ppsz_varnames[i] = "navigation";
212 pi_objects[i++] = p_object->i_object_id;
213 ppsz_varnames[i] = "dvd_menus";
214 pi_objects[i++] = p_object->i_object_id;
216 ppsz_varnames[i] = "video-es";
217 pi_objects[i++] = p_object->i_object_id;
218 ppsz_varnames[i] = "audio-es";
219 pi_objects[i++] = p_object->i_object_id;
220 ppsz_varnames[i] = "spu-es";
221 pi_objects[i++] = p_object->i_object_id;
223 vlc_object_release( p_object );
227 ppsz_varnames[i++] = NULL; /* Separator */
228 ppsz_varnames[i++] = _("Interface menu");
229 ppsz_varnames[i++] = NULL; /* Separator */
231 /* vlc_object_find is needed because of the dialogs provider case */
232 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INTF,
234 if( p_object != NULL )
236 ppsz_varnames[i] = "intf-switch";
237 pi_objects[i++] = p_object->i_object_id;
238 ppsz_varnames[i] = "intf-add";
239 pi_objects[i++] = p_object->i_object_id;
241 vlc_object_release( p_object );
245 Menu popupmenu( p_intf, PopupMenu_Events );
246 popupmenu.Populate( i, ppsz_varnames, pi_objects );
248 /* Add static entries */
249 popupmenu.AppendSeparator();
250 popupmenu.Append( MenuDummy_Event, wxU("Open..."),
251 OpenStreamMenu( p_intf ), wxT("") );
252 popupmenu.Append( Preferences_Event, wxU(_("&Preferences...")) );
254 p_intf->p_sys->p_popup_menu = &popupmenu;
255 p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
256 p_intf->p_sys->p_popup_menu = NULL;
259 wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
261 #define MAX_AUDIO_ITEMS 10
263 vlc_object_t *p_object;
264 char *ppsz_varnames[MAX_AUDIO_ITEMS];
265 int pi_objects[MAX_AUDIO_ITEMS];
268 /* Initializations */
269 memset( pi_objects, 0, MAX_AUDIO_ITEMS * sizeof(int) );
271 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
273 if( p_object != NULL )
275 ppsz_varnames[i] = "audio-es";
276 pi_objects[i++] = p_object->i_object_id;
277 vlc_object_release( p_object );
280 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_AOUT,
282 if( p_object != NULL )
284 ppsz_varnames[i] = "audio-device";
285 pi_objects[i++] = p_object->i_object_id;
286 ppsz_varnames[i] = "audio-channels";
287 pi_objects[i++] = p_object->i_object_id;
288 ppsz_varnames[i] = "visual";
289 pi_objects[i++] = p_object->i_object_id;
290 vlc_object_release( p_object );
294 Menu *p_vlc_menu = (Menu *)p_menu;
296 p_vlc_menu = new Menu( _p_intf, AudioMenu_Events );
300 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
305 wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
307 #define MAX_VIDEO_ITEMS 15
309 vlc_object_t *p_object;
310 char *ppsz_varnames[MAX_VIDEO_ITEMS];
311 int pi_objects[MAX_VIDEO_ITEMS];
314 /* Initializations */
315 memset( pi_objects, 0, MAX_VIDEO_ITEMS * sizeof(int) );
317 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
319 if( p_object != NULL )
321 ppsz_varnames[i] = "video-es";
322 pi_objects[i++] = p_object->i_object_id;
323 ppsz_varnames[i] = "spu-es";
324 pi_objects[i++] = p_object->i_object_id;
325 vlc_object_release( p_object );
328 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_VOUT,
330 if( p_object != NULL )
332 vlc_object_t *p_dec_obj;
334 ppsz_varnames[i] = "fullscreen";
335 pi_objects[i++] = p_object->i_object_id;
336 ppsz_varnames[i] = "zoom";
337 pi_objects[i++] = p_object->i_object_id;
338 ppsz_varnames[i] = "deinterlace";
339 pi_objects[i++] = p_object->i_object_id;
340 ppsz_varnames[i] = "aspect-ratio";
341 pi_objects[i++] = p_object->i_object_id;
342 ppsz_varnames[i] = "crop";
343 pi_objects[i++] = p_object->i_object_id;
344 ppsz_varnames[i] = "video-on-top";
345 pi_objects[i++] = p_object->i_object_id;
347 p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
350 if( p_dec_obj != NULL )
352 ppsz_varnames[i] = "ffmpeg-pp-q";
353 pi_objects[i++] = p_dec_obj->i_object_id;
354 vlc_object_release( p_dec_obj );
357 vlc_object_release( p_object );
361 Menu *p_vlc_menu = (Menu *)p_menu;
363 p_vlc_menu = new Menu( _p_intf, VideoMenu_Events );
367 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
372 wxMenu *NavigMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
374 #define MAX_NAVIG_ITEMS 10
376 vlc_object_t *p_object;
377 char *ppsz_varnames[MAX_NAVIG_ITEMS];
378 int pi_objects[MAX_NAVIG_ITEMS];
381 /* Initializations */
382 memset( pi_objects, 0, MAX_NAVIG_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] = "bookmark";
389 pi_objects[i++] = p_object->i_object_id;
390 ppsz_varnames[i] = "title";
391 pi_objects[i++] = p_object->i_object_id;
392 ppsz_varnames[i] = "chapter";
393 pi_objects[i++] = p_object->i_object_id;
394 ppsz_varnames[i] = "program";
395 pi_objects[i++] = p_object->i_object_id;
396 ppsz_varnames[i] = "navigation";
397 pi_objects[i++] = p_object->i_object_id;
398 ppsz_varnames[i] = "dvd_menus";
399 pi_objects[i++] = p_object->i_object_id;
401 ppsz_varnames[i] = "prev-title";
402 pi_objects[i++] = p_object->i_object_id;
403 ppsz_varnames[i] = "next-title";
404 pi_objects[i++] = p_object->i_object_id;
405 ppsz_varnames[i] = "prev-chapter";
406 pi_objects[i++] = p_object->i_object_id;
407 ppsz_varnames[i] = "next-chapter";
408 pi_objects[i++] = p_object->i_object_id;
410 vlc_object_release( p_object );
414 Menu *p_vlc_menu = (Menu *)p_menu;
416 p_vlc_menu = new Menu( _p_intf, NavigMenu_Events );
420 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
425 wxMenu *SettingsMenu( intf_thread_t *_p_intf, wxWindow *p_parent,
428 #define MAX_SETTINGS_ITEMS 10
430 vlc_object_t *p_object;
431 char *ppsz_varnames[MAX_SETTINGS_ITEMS];
432 int pi_objects[MAX_SETTINGS_ITEMS];
435 /* Initializations */
436 memset( pi_objects, 0, MAX_SETTINGS_ITEMS * sizeof(int) );
438 p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INTF,
440 if( p_object != NULL )
442 ppsz_varnames[i] = "intf-switch";
443 pi_objects[i++] = p_object->i_object_id;
444 ppsz_varnames[i] = "intf-add";
445 pi_objects[i++] = p_object->i_object_id;
446 vlc_object_release( p_object );
450 Menu *p_vlc_menu = (Menu *)p_menu;
452 p_vlc_menu = new Menu( _p_intf, SettingsMenu_Events );
456 p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
461 /*****************************************************************************
463 *****************************************************************************/
464 Menu::Menu( intf_thread_t *_p_intf, int _i_start_id ) : wxMenu( )
466 /* Initializations */
468 i_start_id = _i_start_id;
475 /*****************************************************************************
477 *****************************************************************************/
478 void Menu::Populate( int i_count, char **ppsz_varnames, int *pi_objects )
480 vlc_object_t *p_object;
481 vlc_bool_t b_section_empty = VLC_FALSE;
484 i_item_id = i_start_id;
486 for( i = 0; i < i_count; i++ )
488 if( !ppsz_varnames[i] )
490 if( b_section_empty )
492 Append( MenuDummy_Event + i, wxU(_("Empty")) );
493 Enable( MenuDummy_Event + i, FALSE );
497 b_section_empty = VLC_TRUE;
503 Append( MenuDummy_Event, wxU(ppsz_varnames[i]) );
504 b_section_empty = VLC_FALSE;
508 p_object = (vlc_object_t *)vlc_object_get( p_intf, pi_objects[i] );
509 if( p_object == NULL ) continue;
511 b_section_empty = VLC_FALSE;
512 CreateMenuItem( this, ppsz_varnames[i], p_object );
513 vlc_object_release( p_object );
516 /* Special case for empty menus */
517 if( GetMenuItemCount() == 0 || b_section_empty )
519 Append( MenuDummy_Event + i, wxU(_("Empty")) );
520 Enable( MenuDummy_Event + i, FALSE );
524 /* Work-around helper for buggy wxGTK */
525 static void RecursiveDestroy( wxMenu *menu )
527 wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
530 wxMenuItem *item = node->GetData();
531 node = node->GetNext();
533 /* Delete the submenus */
534 wxMenu *submenu = item->GetSubMenu();
537 RecursiveDestroy( submenu );
539 menu->Delete( item );
545 RecursiveDestroy( this );
548 /*****************************************************************************
550 *****************************************************************************/
551 static bool IsMenuEmpty( char *psz_var, vlc_object_t *p_object,
554 vlc_value_t val, val_list;
555 int i_type, i_result, i;
557 /* Check the type of the object variable */
558 i_type = var_Type( p_object, psz_var );
560 /* Check if we want to display the variable */
561 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
563 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
564 if( val.i_int == 0 ) return TRUE;
566 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
568 if( val.i_int == 1 && b_root ) return TRUE;
572 /* Check children variables in case of VLC_VAR_VARIABLE */
573 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
578 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
580 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
588 /* clean up everything */
589 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
594 void Menu::CreateMenuItem( wxMenu *menu, char *psz_var,
595 vlc_object_t *p_object )
597 wxMenuItemExt *menuitem;
598 vlc_value_t val, text;
601 /* Check the type of the object variable */
602 i_type = var_Type( p_object, psz_var );
604 switch( i_type & VLC_VAR_TYPE )
608 case VLC_VAR_VARIABLE:
610 case VLC_VAR_INTEGER:
614 /* Variable doesn't exist or isn't handled */
618 /* Make sure we want to display the variable */
619 if( IsMenuEmpty( psz_var, p_object ) ) return;
621 /* Get the descriptive name of the variable */
622 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
624 if( i_type & VLC_VAR_HASCHOICE )
626 menu->Append( MenuDummy_Event,
627 wxU(text.psz_string ? text.psz_string : psz_var),
628 CreateChoicesMenu( psz_var, p_object, TRUE ),
629 wxT("")/* Nothing for now (maybe use a GETLONGTEXT) */ );
631 if( text.psz_string ) free( text.psz_string );
636 switch( i_type & VLC_VAR_TYPE )
639 var_Get( p_object, psz_var, &val );
640 menuitem = new wxMenuItemExt( menu, ++i_item_id,
641 wxU(text.psz_string ?
642 text.psz_string : psz_var),
643 wxT(""), wxITEM_NORMAL, strdup(psz_var),
644 p_object->i_object_id, val, i_type );
645 menu->Append( menuitem );
649 var_Get( p_object, psz_var, &val );
650 val.b_bool = !val.b_bool;
651 menuitem = new wxMenuItemExt( menu, ++i_item_id,
652 wxU(text.psz_string ?
653 text.psz_string : psz_var),
654 wxT(""), wxITEM_CHECK, strdup(psz_var),
655 p_object->i_object_id, val, i_type );
656 menu->Append( menuitem );
657 Check( i_item_id, val.b_bool ? FALSE : TRUE );
661 if( text.psz_string ) free( text.psz_string );
664 wxMenu *Menu::CreateChoicesMenu( char *psz_var, vlc_object_t *p_object,
667 vlc_value_t val, val_list, text_list;
670 /* Check the type of the object variable */
671 i_type = var_Type( p_object, psz_var );
673 /* Make sure we want to display the variable */
674 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return NULL;
676 switch( i_type & VLC_VAR_TYPE )
680 case VLC_VAR_VARIABLE:
682 case VLC_VAR_INTEGER:
686 /* Variable doesn't exist or isn't handled */
690 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
691 &val_list, &text_list ) < 0 )
696 wxMenu *menu = new wxMenu;
697 for( i = 0; i < val_list.p_list->i_count; i++ )
699 vlc_value_t another_val;
700 wxMenuItemExt *menuitem;
702 switch( i_type & VLC_VAR_TYPE )
704 case VLC_VAR_VARIABLE:
705 menu->Append( MenuDummy_Event,
706 wxU(text_list.p_list->p_values[i].psz_string ?
707 text_list.p_list->p_values[i].psz_string :
708 val_list.p_list->p_values[i].psz_string),
710 val_list.p_list->p_values[i].psz_string,
711 p_object, FALSE ), wxT("") );
715 var_Get( p_object, psz_var, &val );
717 another_val.psz_string =
718 strdup(val_list.p_list->p_values[i].psz_string);
720 new wxMenuItemExt( menu, ++i_item_id,
721 wxU(text_list.p_list->p_values[i].psz_string ?
722 text_list.p_list->p_values[i].psz_string :
723 another_val.psz_string), wxT(""),
724 i_type & VLC_VAR_ISCOMMAND ?
725 wxITEM_NORMAL : wxITEM_RADIO,
727 p_object->i_object_id, another_val, i_type );
729 menu->Append( menuitem );
731 if( !(i_type & VLC_VAR_ISCOMMAND) && val.psz_string &&
732 !strcmp( val.psz_string,
733 val_list.p_list->p_values[i].psz_string ) )
734 menu->Check( i_item_id, TRUE );
736 if( val.psz_string ) free( val.psz_string );
739 case VLC_VAR_INTEGER:
740 var_Get( p_object, psz_var, &val );
743 new wxMenuItemExt( menu, ++i_item_id,
744 text_list.p_list->p_values[i].psz_string ?
746 text_list.p_list->p_values[i].psz_string) :
747 wxString::Format(wxT("%d"),
748 val_list.p_list->p_values[i].i_int), wxT(""),
749 i_type & VLC_VAR_ISCOMMAND ?
750 wxITEM_NORMAL : wxITEM_RADIO,
752 p_object->i_object_id,
753 val_list.p_list->p_values[i], i_type );
755 menu->Append( menuitem );
757 if( !(i_type & VLC_VAR_ISCOMMAND) &&
758 val_list.p_list->p_values[i].i_int == val.i_int )
759 menu->Check( i_item_id, TRUE );
763 var_Get( p_object, psz_var, &val );
766 new wxMenuItemExt( menu, ++i_item_id,
767 text_list.p_list->p_values[i].psz_string ?
769 text_list.p_list->p_values[i].psz_string) :
770 wxString::Format(wxT("%.2f"),
771 val_list.p_list->p_values[i].f_float),wxT(""),
772 i_type & VLC_VAR_ISCOMMAND ?
773 wxITEM_NORMAL : wxITEM_RADIO,
775 p_object->i_object_id,
776 val_list.p_list->p_values[i], i_type );
778 menu->Append( menuitem );
780 if( !(i_type & VLC_VAR_ISCOMMAND) &&
781 val_list.p_list->p_values[i].f_float == val.f_float )
782 menu->Check( i_item_id, TRUE );
790 /* clean up everything */
791 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
796 /*****************************************************************************
797 * A small helper class which intercepts all popup menu events
798 *****************************************************************************/
799 MenuEvtHandler::MenuEvtHandler( intf_thread_t *_p_intf,
800 Interface *_p_main_interface )
802 /* Initializations */
804 p_main_interface = _p_main_interface;
807 MenuEvtHandler::~MenuEvtHandler()
811 void MenuEvtHandler::OnShowDialog( wxCommandEvent& event )
813 if( p_intf->p_sys->pf_show_dialog )
817 switch( event.GetId() )
819 case OpenFileSimple_Event:
820 i_id = INTF_DIALOG_FILE_SIMPLE;
823 i_id = INTF_DIALOG_FILE;
826 i_id = INTF_DIALOG_DISC;
829 i_id = INTF_DIALOG_NET;
831 case OpenCapture_Event:
832 i_id = INTF_DIALOG_CAPTURE;
834 case Preferences_Event:
835 i_id = INTF_DIALOG_PREFS;
838 i_id = INTF_DIALOG_FILE;
843 p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
847 void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
849 wxMenuItem *p_menuitem = NULL;
851 /* Check if this is an auto generated menu item */
852 if( event.GetId() < FirstAutoGenerated_Event )
858 if( !p_main_interface ||
859 (p_menuitem = p_main_interface->GetMenuBar()->FindItem(event.GetId()))
862 if( p_intf->p_sys->p_popup_menu )
865 p_intf->p_sys->p_popup_menu->FindItem( event.GetId() );
871 wxMenuItemExt *p_menuitemext = (wxMenuItemExt *)p_menuitem;
872 vlc_object_t *p_object;
874 p_object = (vlc_object_t *)vlc_object_get( p_intf,
875 p_menuitemext->i_object_id );
876 if( p_object == NULL ) return;
878 var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val );
880 vlc_object_release( p_object );
886 /*****************************************************************************
887 * A small helper class which encapsulate wxMenuitem with some other useful
889 *****************************************************************************/
890 wxMenuItemExt::wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
891 const wxString& helpString, wxItemKind kind,
892 char *_psz_var, int _i_object_id, vlc_value_t _val, int _i_val_type ):
893 wxMenuItem( parentMenu, id, text, helpString, kind )
895 /* Initializations */
897 i_val_type = _i_val_type;
898 i_object_id = _i_object_id;
902 wxMenuItemExt::~wxMenuItemExt()
904 if( psz_var ) free( psz_var );
905 if( ((i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
906 && val.psz_string ) free( val.psz_string );