]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/menus.cpp
* modules/gui/wxwindows/menus.cpp: moved audio/video track menu to the top.
[vlc] / modules / gui / wxwindows / menus.cpp
1 /*****************************************************************************
2  * menus.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2001 VideoLAN
5  * $Id: menus.cpp,v 1.28 2003/11/29 16:36:56 gbazin Exp $
6  *
7  * Authors: Gildas Bazin <gbazin@netcourrier.com>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <string.h>                                            /* strerror() */
30 #include <stdio.h>
31
32 #include <vlc/vlc.h>
33 #include <vlc/intf.h>
34
35 #include "wxwindows.h"
36 #include <wx/listctrl.h>
37
38 class wxMenuItemExt: public wxMenuItem
39 {
40 public:
41     /* Constructor */
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,
45                    int _i_val_type );
46
47     virtual ~wxMenuItemExt();
48
49     char *psz_var;
50     int  i_val_type;
51     int  i_object_id;
52     vlc_value_t val;
53
54 private:
55
56 };
57
58 /*****************************************************************************
59  * Event Table.
60  *****************************************************************************/
61
62 /* IDs for the controls and the menu commands */
63 enum
64 {
65     /* menu items */
66     MenuDummy_Event = wxID_HIGHEST + 1000,
67     OpenFileSimple_Event = wxID_HIGHEST + 1100,
68     OpenFile_Event,
69     OpenDisc_Event,
70     OpenNet_Event,
71     FirstAutoGenerated_Event = wxID_HIGHEST + 1999,
72     SettingsMenu_Events = wxID_HIGHEST + 5000,
73     AudioMenu_Events = wxID_HIGHEST + 2000,
74     VideoMenu_Events = wxID_HIGHEST + 3000,
75     NavigMenu_Events = wxID_HIGHEST + 4000,
76     PopupMenu_Events = wxID_HIGHEST + 6000
77 };
78
79 BEGIN_EVENT_TABLE(Menu, wxMenu)
80 END_EVENT_TABLE()
81
82 BEGIN_EVENT_TABLE(MenuEvtHandler, wxEvtHandler)
83     EVT_MENU(OpenFileSimple_Event, MenuEvtHandler::OnShowDialog)
84     EVT_MENU(OpenFile_Event, MenuEvtHandler::OnShowDialog)
85     EVT_MENU(OpenDisc_Event, MenuEvtHandler::OnShowDialog)
86     EVT_MENU(OpenNet_Event, MenuEvtHandler::OnShowDialog)
87     EVT_MENU(-1, MenuEvtHandler::OnMenuEvent)
88 END_EVENT_TABLE()
89
90 wxMenu *OpenStreamMenu( intf_thread_t *p_intf )
91 {
92     wxMenu *menu = new wxMenu;
93     menu->Append( OpenFileSimple_Event, wxU(_("Simple &Open ...")) );
94     menu->Append( OpenFile_Event, wxU(_("Open &File...")) );
95     menu->Append( OpenDisc_Event, wxU(_("Open &Disc...")) );
96     menu->Append( OpenNet_Event, wxU(_("Open &Network Stream...")) );
97     return menu;
98 }
99
100 void PopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
101                 const wxPoint& pos )
102 {
103 #define MAX_POPUP_ITEMS 35
104
105     vlc_object_t *p_object;
106     char *ppsz_varnames[MAX_POPUP_ITEMS];
107     int pi_objects[MAX_POPUP_ITEMS];
108     int i = 0;
109
110     /* Initializations */
111     memset( pi_objects, 0, MAX_POPUP_ITEMS * sizeof(int) );
112
113     /* Audio menu */
114     ppsz_varnames[i++] = _("Audio menu");
115     ppsz_varnames[i++] = NULL; /* Separator */
116
117     p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
118                                                 FIND_ANYWHERE );
119     if( p_object != NULL )
120     {
121         ppsz_varnames[i] = "audio-device";
122         pi_objects[i++] = p_object->i_object_id;
123         ppsz_varnames[i] = "audio-channels";
124         pi_objects[i++] = p_object->i_object_id;
125         ppsz_varnames[i] = "visual";
126         pi_objects[i++] = p_object->i_object_id;
127         vlc_object_release( p_object );
128     }
129
130     /* Video menu */
131     ppsz_varnames[i++] = NULL; /* Separator */
132     ppsz_varnames[i++] = _("Video menu");
133     ppsz_varnames[i++] = NULL; /* Separator */
134
135     p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
136                                                 FIND_ANYWHERE );
137     if( p_object != NULL )
138     {
139         vlc_object_t *p_dec_obj;
140
141         ppsz_varnames[i] = "fullscreen";
142         pi_objects[i++] = p_object->i_object_id;
143         ppsz_varnames[i] = "deinterlace";
144         pi_objects[i++] = p_object->i_object_id;
145         ppsz_varnames[i] = "aspect-ratio";
146         pi_objects[i++] = p_object->i_object_id;
147         ppsz_varnames[i] = "crop";
148         pi_objects[i++] = p_object->i_object_id;
149         ppsz_varnames[i] = "directx-on-top";
150         pi_objects[i++] = p_object->i_object_id;
151         ppsz_varnames[i] = "xvideo-on-top";
152         pi_objects[i++] = p_object->i_object_id;
153         ppsz_varnames[i] = "x11-on-top";
154         pi_objects[i++] = p_object->i_object_id;
155
156         p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
157                                                      VLC_OBJECT_DECODER,
158                                                      FIND_PARENT );
159         if( p_dec_obj != NULL )
160         {
161             ppsz_varnames[i] = "ffmpeg-pp-q";
162             pi_objects[i++] = p_dec_obj->i_object_id;
163             vlc_object_release( p_dec_obj );
164         }
165
166         vlc_object_release( p_object );
167     }
168
169     /* Input menu */
170     ppsz_varnames[i++] = NULL; /* Separator */
171     ppsz_varnames[i++] = _("Input menu");
172     ppsz_varnames[i++] = NULL; /* Separator */
173
174     p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
175                                                 FIND_ANYWHERE );
176     if( p_object != NULL )
177     {
178         ppsz_varnames[i] = "title";
179         pi_objects[i++] = p_object->i_object_id;
180         ppsz_varnames[i] = "chapter";
181         pi_objects[i++] = p_object->i_object_id;
182         ppsz_varnames[i] = "program";
183         pi_objects[i++] = p_object->i_object_id;
184         ppsz_varnames[i] = "navigation";
185         pi_objects[i++] = p_object->i_object_id;
186         ppsz_varnames[i] = "dvd_menus";
187         pi_objects[i++] = p_object->i_object_id;
188
189         ppsz_varnames[i] = "video-es";
190         pi_objects[i++] = p_object->i_object_id;
191         ppsz_varnames[i] = "audio-es";
192         pi_objects[i++] = p_object->i_object_id;
193         ppsz_varnames[i] = "spu-es";
194         pi_objects[i++] = p_object->i_object_id;
195
196         vlc_object_release( p_object );
197     }
198
199     /* Interface menu */
200     ppsz_varnames[i++] = NULL; /* Separator */
201     ppsz_varnames[i++] = _("Interface menu");
202     ppsz_varnames[i++] = NULL; /* Separator */
203
204     /* vlc_object_find is needed because of the dialogs provider case */
205     p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INTF,
206                                                 FIND_PARENT );
207     if( p_object != NULL )
208     {
209         ppsz_varnames[i] = "intf-switch";
210         pi_objects[i++] = p_object->i_object_id;
211         ppsz_varnames[i] = "intf-add";
212         pi_objects[i++] = p_object->i_object_id;
213
214         vlc_object_release( p_object );
215     }
216
217     /* Build menu */
218     Menu popupmenu( p_intf, p_parent, i,
219                      ppsz_varnames, pi_objects, PopupMenu_Events );
220
221 #if 1
222     /* Add static entries */
223     popupmenu.AppendSeparator();
224     popupmenu.Append( MenuDummy_Event, wxU("Open"),
225                       OpenStreamMenu( p_intf ), wxT("") );
226 #endif
227
228     p_intf->p_sys->p_popup_menu = &popupmenu;
229     p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
230     p_intf->p_sys->p_popup_menu = NULL;
231 }
232
233 wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent )
234 {
235 #define MAX_AUDIO_ITEMS 10
236
237     vlc_object_t *p_object;
238     char *ppsz_varnames[MAX_AUDIO_ITEMS];
239     int pi_objects[MAX_AUDIO_ITEMS];
240     int i = 0;
241
242     /* Initializations */
243     memset( pi_objects, 0, MAX_AUDIO_ITEMS * sizeof(int) );
244
245     p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
246                                                 FIND_ANYWHERE );
247     if( p_object != NULL )
248     {
249         ppsz_varnames[i] = "audio-es";
250         pi_objects[i++] = p_object->i_object_id;
251         vlc_object_release( p_object );
252     }
253
254     p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_AOUT,
255                                                 FIND_ANYWHERE );
256     if( p_object != NULL )
257     {
258         ppsz_varnames[i] = "audio-device";
259         pi_objects[i++] = p_object->i_object_id;
260         ppsz_varnames[i] = "audio-channels";
261         pi_objects[i++] = p_object->i_object_id;
262         ppsz_varnames[i] = "visual";
263         pi_objects[i++] = p_object->i_object_id;
264         vlc_object_release( p_object );
265     }
266
267     /* Build menu */
268     return new Menu( _p_intf, p_parent, i,
269                      ppsz_varnames, pi_objects, AudioMenu_Events );
270 }
271
272 wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent )
273 {
274 #define MAX_VIDEO_ITEMS 15
275
276     vlc_object_t *p_object;
277     char *ppsz_varnames[MAX_VIDEO_ITEMS];
278     int pi_objects[MAX_VIDEO_ITEMS];
279     int i = 0;
280
281     /* Initializations */
282     memset( pi_objects, 0, MAX_VIDEO_ITEMS * sizeof(int) );
283
284     p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
285                                                 FIND_ANYWHERE );
286     if( p_object != NULL )
287     {
288         ppsz_varnames[i] = "video-es";
289         pi_objects[i++] = p_object->i_object_id;
290         ppsz_varnames[i] = "spu-es";
291         pi_objects[i++] = p_object->i_object_id;
292         vlc_object_release( p_object );
293     }
294
295     p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_VOUT,
296                                                 FIND_ANYWHERE );
297     if( p_object != NULL )
298     {
299         vlc_object_t *p_dec_obj;
300
301         ppsz_varnames[i] = "fullscreen";
302         pi_objects[i++] = p_object->i_object_id;
303         ppsz_varnames[i] = "deinterlace";
304         pi_objects[i++] = p_object->i_object_id;
305         ppsz_varnames[i] = "aspect-ratio";
306         pi_objects[i++] = p_object->i_object_id;
307         ppsz_varnames[i] = "crop";
308         pi_objects[i++] = p_object->i_object_id;
309         ppsz_varnames[i] = "directx-on-top";
310         pi_objects[i++] = p_object->i_object_id;
311         ppsz_varnames[i] = "xvideo-on-top";
312         pi_objects[i++] = p_object->i_object_id;
313         ppsz_varnames[i] = "x11-on-top";
314         pi_objects[i++] = p_object->i_object_id;
315
316         p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
317                                                      VLC_OBJECT_DECODER,
318                                                      FIND_PARENT );
319         if( p_dec_obj != NULL )
320         {
321             ppsz_varnames[i] = "ffmpeg-pp-q";
322             pi_objects[i++] = p_dec_obj->i_object_id;
323             vlc_object_release( p_dec_obj );
324         }
325
326         vlc_object_release( p_object );
327     }
328
329     /* Build menu */
330     return new Menu( _p_intf, p_parent, i,
331                      ppsz_varnames, pi_objects, VideoMenu_Events );
332 }
333
334 wxMenu *NavigMenu( intf_thread_t *_p_intf, wxWindow *p_parent )
335 {
336 #define MAX_NAVIG_ITEMS 10
337
338     vlc_object_t *p_object;
339     char *ppsz_varnames[MAX_NAVIG_ITEMS];
340     int pi_objects[MAX_NAVIG_ITEMS];
341     int i = 0;
342
343     /* Initializations */
344     memset( pi_objects, 0, MAX_NAVIG_ITEMS * sizeof(int) );
345
346     p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INPUT,
347                                                 FIND_ANYWHERE );
348     if( p_object != NULL )
349     {
350         ppsz_varnames[i] = "title";
351         pi_objects[i++] = p_object->i_object_id;
352         ppsz_varnames[i] = "chapter";
353         pi_objects[i++] = p_object->i_object_id;
354         ppsz_varnames[i] = "program";
355         pi_objects[i++] = p_object->i_object_id;
356         ppsz_varnames[i] = "navigation";
357         pi_objects[i++] = p_object->i_object_id;
358         ppsz_varnames[i] = "dvd_menus";
359         pi_objects[i++] = p_object->i_object_id;
360
361         ppsz_varnames[i] = "prev-title";
362         pi_objects[i++] = p_object->i_object_id;
363         ppsz_varnames[i] = "next-title";
364         pi_objects[i++] = p_object->i_object_id;
365         ppsz_varnames[i] = "prev-chapter";
366         pi_objects[i++] = p_object->i_object_id;
367         ppsz_varnames[i] = "next-chapter";
368         pi_objects[i++] = p_object->i_object_id;
369
370         vlc_object_release( p_object );
371     }
372
373     /* Build menu */
374     return new Menu( _p_intf, p_parent, i,
375                      ppsz_varnames, pi_objects, NavigMenu_Events );
376 }
377
378 wxMenu *SettingsMenu( intf_thread_t *_p_intf, wxWindow *p_parent )
379 {
380 #define MAX_SETTINGS_ITEMS 10
381
382     vlc_object_t *p_object;
383     char *ppsz_varnames[MAX_SETTINGS_ITEMS];
384     int pi_objects[MAX_SETTINGS_ITEMS];
385     int i = 0;
386
387     /* Initializations */
388     memset( pi_objects, 0, MAX_SETTINGS_ITEMS * sizeof(int) );
389
390     p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INTF,
391                                                 FIND_PARENT );
392     if( p_object != NULL )
393     {
394         ppsz_varnames[i] = "intf-switch";
395         pi_objects[i++] = p_object->i_object_id;
396         ppsz_varnames[i] = "intf-add";
397         pi_objects[i++] = p_object->i_object_id;
398         vlc_object_release( p_object );
399     }
400
401     /* Build menu */
402     return new Menu( _p_intf, p_parent, i,
403                      ppsz_varnames, pi_objects, SettingsMenu_Events );
404 }
405
406 /*****************************************************************************
407  * Constructor.
408  *****************************************************************************/
409 Menu::Menu( intf_thread_t *_p_intf, wxWindow *p_parent,
410             int i_count, char **ppsz_varnames, int *pi_objects,
411             int i_start_id ): wxMenu( )
412 {
413     vlc_object_t *p_object;
414     vlc_bool_t b_section_empty = VLC_FALSE;
415     int i;
416
417     /* Initializations */
418     p_intf = _p_intf;
419
420     i_item_id = i_start_id;
421
422     for( i = 0; i < i_count; i++ )
423     {
424         if( !ppsz_varnames[i] )
425         {
426             if( b_section_empty )
427             {
428                 Append( MenuDummy_Event + i, wxU(_("Empty")) );
429                 Enable( MenuDummy_Event + i, FALSE );
430             }
431
432             AppendSeparator();
433             b_section_empty = VLC_TRUE;
434             continue;
435         }
436
437         if( !pi_objects[i] )
438         {
439             Append( MenuDummy_Event, wxU(ppsz_varnames[i]) );
440             b_section_empty = VLC_FALSE;
441             continue;
442         }
443
444         p_object = (vlc_object_t *)vlc_object_get( p_intf, pi_objects[i] );
445         if( p_object == NULL ) continue;
446
447         b_section_empty = VLC_FALSE;
448         CreateMenuItem( this, ppsz_varnames[i], p_object );
449         vlc_object_release( p_object );
450     }
451
452     /* Special case for empty menus */
453     if( GetMenuItemCount() == 0 || b_section_empty )
454     {
455         Append( MenuDummy_Event + i, wxU(_("Empty")) );
456         Enable( MenuDummy_Event + i, FALSE );
457     }
458 }
459
460 Menu::~Menu()
461 {
462 }
463
464 /*****************************************************************************
465  * Private methods.
466  *****************************************************************************/
467 void Menu::CreateMenuItem( wxMenu *menu, char *psz_var,
468                            vlc_object_t *p_object )
469 {
470     wxMenuItemExt *menuitem;
471     vlc_value_t val, text;
472     int i_type;
473
474     /* Check the type of the object variable */
475     i_type = var_Type( p_object, psz_var );
476
477     switch( i_type & VLC_VAR_TYPE )
478     {
479     case VLC_VAR_VOID:
480     case VLC_VAR_BOOL:
481     case VLC_VAR_VARIABLE:
482     case VLC_VAR_STRING:
483     case VLC_VAR_INTEGER:
484         break;
485     default:
486         /* Variable doesn't exist or isn't handled */
487         return;
488     }
489
490     /* Make sure we want to display the variable */
491     if( i_type & VLC_VAR_HASCHOICE )
492     {
493         var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
494         if( val.i_int == 0 ) return;
495         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
496             return;
497     }
498
499     /* Get the descriptive name of the variable */
500     var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
501
502     var_Get( p_object, psz_var, &val );
503
504     if( i_type & VLC_VAR_HASCHOICE )
505     {
506         menu->Append( MenuDummy_Event,
507                       wxU(text.psz_string ? text.psz_string : psz_var),
508                       CreateChoicesMenu( psz_var, p_object ),
509                       wxT("")/* Nothing for now (maybe use a GETLONGTEXT) */ );
510
511         if( text.psz_string ) free( text.psz_string );
512         return;
513     }
514
515
516     switch( i_type & VLC_VAR_TYPE )
517     {
518     case VLC_VAR_VOID:
519         menuitem = new wxMenuItemExt( menu, ++i_item_id,
520                                       wxU(text.psz_string ?
521                                         text.psz_string : psz_var),
522                                       wxT(""), wxITEM_NORMAL, strdup(psz_var),
523                                       p_object->i_object_id, val, i_type );
524         menu->Append( menuitem );
525         break;
526
527     case VLC_VAR_BOOL:
528         val.b_bool = !val.b_bool;
529         menuitem = new wxMenuItemExt( menu, ++i_item_id,
530                                       wxU(text.psz_string ?
531                                         text.psz_string : psz_var),
532                                       wxT(""), wxITEM_CHECK, strdup(psz_var),
533                                       p_object->i_object_id, val, i_type );
534         menu->Append( menuitem );
535         Check( i_item_id, val.b_bool ? FALSE : TRUE );
536         break;
537
538     default:
539         if( text.psz_string ) free( text.psz_string );
540         return;
541     }
542
543     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
544     if( text.psz_string ) free( text.psz_string );
545 }
546
547 wxMenu *Menu::CreateChoicesMenu( char *psz_var, vlc_object_t *p_object )
548 {
549     vlc_value_t val, val_list, text_list;
550     int i_type, i;
551
552     /* Check the type of the object variable */
553     i_type = var_Type( p_object, psz_var );
554
555     /* Make sure we want to display the variable */
556     if( i_type & VLC_VAR_HASCHOICE )
557     {
558         var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
559         if( val.i_int == 0 ) return NULL;
560         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
561             return NULL;
562     }
563     else
564     {
565         return NULL;
566     }
567
568     switch( i_type & VLC_VAR_TYPE )
569     {
570     case VLC_VAR_VOID:
571     case VLC_VAR_BOOL:
572     case VLC_VAR_VARIABLE:
573     case VLC_VAR_STRING:
574     case VLC_VAR_INTEGER:
575         break;
576     default:
577         /* Variable doesn't exist or isn't handled */
578         return NULL;
579     }
580
581     if( var_Get( p_object, psz_var, &val ) < 0 )
582     {
583         return NULL;
584     }
585
586     if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
587                     &val_list, &text_list ) < 0 )
588     {
589         if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
590         return NULL;
591     }
592
593     wxMenu *menu = new wxMenu;
594     for( i = 0; i < val_list.p_list->i_count; i++ )
595     {
596         vlc_value_t another_val;
597         wxMenuItemExt *menuitem;
598
599         switch( i_type & VLC_VAR_TYPE )
600         {
601         case VLC_VAR_VARIABLE:
602           menu->Append( MenuDummy_Event,
603                         wxU(text_list.p_list->p_values[i].psz_string ?
604                         text_list.p_list->p_values[i].psz_string :
605                         val_list.p_list->p_values[i].psz_string),
606                         CreateChoicesMenu(
607                             val_list.p_list->p_values[i].psz_string,
608                             p_object ), wxT("") );
609           break;
610
611         case VLC_VAR_STRING:
612           another_val.psz_string =
613               strdup(val_list.p_list->p_values[i].psz_string);
614           menuitem =
615               new wxMenuItemExt( menu, ++i_item_id,
616                                  wxU(text_list.p_list->p_values[i].psz_string ?
617                                  text_list.p_list->p_values[i].psz_string :
618                                  another_val.psz_string), wxT(""),
619                                  i_type & VLC_VAR_ISCOMMAND ?
620                                    wxITEM_NORMAL : wxITEM_RADIO,
621                                  strdup(psz_var),
622                                  p_object->i_object_id, another_val, i_type );
623
624           menu->Append( menuitem );
625
626           if( !strcmp( val.psz_string,
627                        val_list.p_list->p_values[i].psz_string ) )
628               menu->Check( i_item_id, TRUE );
629           break;
630
631         case VLC_VAR_INTEGER:
632           menuitem =
633               new wxMenuItemExt( menu, ++i_item_id,
634                                  text_list.p_list->p_values[i].psz_string ?
635                                  (wxString)wxU(
636                                    text_list.p_list->p_values[i].psz_string) :
637                                  wxString::Format(wxT("%d"),
638                                  val_list.p_list->p_values[i].i_int), wxT(""),
639                                  i_type & VLC_VAR_ISCOMMAND ?
640                                    wxITEM_NORMAL : wxITEM_RADIO,
641                                  strdup(psz_var),
642                                  p_object->i_object_id,
643                                  val_list.p_list->p_values[i], i_type );
644
645           menu->Append( menuitem );
646
647           if( val_list.p_list->p_values[i].i_int == val.i_int )
648               menu->Check( i_item_id, TRUE );
649           break;
650
651         default:
652           break;
653         }
654     }
655
656     /* clean up everything */
657     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
658     var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
659
660     return menu;
661 }
662
663 void Menu::OnShowDialog( wxCommandEvent& event )
664 {
665     if( p_intf->p_sys->pf_show_dialog )
666     {
667         int i_id;
668
669         switch( event.GetId() )
670         {
671         case OpenFileSimple_Event:
672             i_id = INTF_DIALOG_FILE_SIMPLE;
673             break;
674         case OpenFile_Event:
675             i_id = INTF_DIALOG_FILE;
676             break;
677         case OpenDisc_Event:
678             i_id = INTF_DIALOG_DISC;
679             break;
680         case OpenNet_Event:
681             i_id = INTF_DIALOG_NET;
682             break;
683         default:
684             i_id = INTF_DIALOG_FILE;
685             break;
686
687         }
688
689         p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
690     }
691 }
692
693 /*****************************************************************************
694  * A small helper class which intercepts all popup menu events
695  *****************************************************************************/
696 MenuEvtHandler::MenuEvtHandler( intf_thread_t *_p_intf,
697                                 Interface *_p_main_interface )
698 {
699     /* Initializations */
700     p_intf = _p_intf;
701     p_main_interface = _p_main_interface;
702 }
703
704 MenuEvtHandler::~MenuEvtHandler()
705 {
706 }
707
708 void MenuEvtHandler::OnShowDialog( wxCommandEvent& event )
709 {
710     if( p_intf->p_sys->pf_show_dialog )
711     {
712         int i_id;
713
714         switch( event.GetId() )
715         {
716         case OpenFileSimple_Event:
717             i_id = INTF_DIALOG_FILE_SIMPLE;
718             break;
719         case OpenFile_Event:
720             i_id = INTF_DIALOG_FILE;
721             break;
722         case OpenDisc_Event:
723             i_id = INTF_DIALOG_DISC;
724             break;
725         case OpenNet_Event:
726             i_id = INTF_DIALOG_NET;
727             break;
728         default:
729             i_id = INTF_DIALOG_FILE;
730             break;
731
732         }
733
734         p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
735     }
736 }
737
738 void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
739 {
740     wxMenuItem *p_menuitem = NULL;
741
742     /* Check if this is an auto generated menu item */
743     if( event.GetId() < FirstAutoGenerated_Event )
744     {
745         event.Skip();
746         return;
747     }
748
749     if( !p_main_interface ||
750         (p_menuitem = p_main_interface->GetMenuBar()->FindItem(event.GetId()))
751         == NULL )
752     {
753         if( p_intf->p_sys->p_popup_menu )
754         {
755             p_menuitem = 
756                 p_intf->p_sys->p_popup_menu->FindItem( event.GetId() );
757         }
758     }
759
760     if( p_menuitem )
761     {
762         wxMenuItemExt *p_menuitemext = (wxMenuItemExt *)p_menuitem;
763         vlc_object_t *p_object;
764
765         p_object = (vlc_object_t *)vlc_object_get( p_intf,
766                                        p_menuitemext->i_object_id );
767         if( p_object == NULL ) return;
768
769         var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val );
770
771         vlc_object_release( p_object );
772     }
773     else
774         event.Skip();
775 }
776
777 /*****************************************************************************
778  * A small helper class which encapsulate wxMenuitem with some other useful
779  * things.
780  *****************************************************************************/
781 wxMenuItemExt::wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
782     const wxString& helpString, wxItemKind kind,
783     char *_psz_var, int _i_object_id, vlc_value_t _val, int _i_val_type ):
784     wxMenuItem( parentMenu, id, text, helpString, kind )
785 {
786     /* Initializations */
787     psz_var = _psz_var;
788     i_val_type = _i_val_type;
789     i_object_id = _i_object_id;
790     val = _val;
791 };
792
793 wxMenuItemExt::~wxMenuItemExt()
794 {
795     if( psz_var ) free( psz_var );
796     if( ((i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
797         && val.psz_string ) free( val.psz_string );
798 };