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