]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/menus.cpp
* string review
[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.30 2004/01/25 03:29:01 hartman 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 void Menu::CreateMenuItem( wxMenu *menu, char *psz_var,
463                            vlc_object_t *p_object )
464 {
465     wxMenuItemExt *menuitem;
466     vlc_value_t val, text;
467     int i_type;
468
469     /* Check the type of the object variable */
470     i_type = var_Type( p_object, psz_var );
471
472     switch( i_type & VLC_VAR_TYPE )
473     {
474     case VLC_VAR_VOID:
475     case VLC_VAR_BOOL:
476     case VLC_VAR_VARIABLE:
477     case VLC_VAR_STRING:
478     case VLC_VAR_INTEGER:
479         break;
480     default:
481         /* Variable doesn't exist or isn't handled */
482         return;
483     }
484
485     /* Make sure we want to display the variable */
486     if( i_type & VLC_VAR_HASCHOICE )
487     {
488         var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
489         if( val.i_int == 0 ) return;
490         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
491             return;
492     }
493
494     /* Get the descriptive name of the variable */
495     var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
496
497     var_Get( p_object, psz_var, &val );
498
499     if( i_type & VLC_VAR_HASCHOICE )
500     {
501         menu->Append( MenuDummy_Event,
502                       wxU(text.psz_string ? text.psz_string : psz_var),
503                       CreateChoicesMenu( psz_var, p_object ),
504                       wxT("")/* Nothing for now (maybe use a GETLONGTEXT) */ );
505
506         if( text.psz_string ) free( text.psz_string );
507         return;
508     }
509
510
511     switch( i_type & VLC_VAR_TYPE )
512     {
513     case VLC_VAR_VOID:
514         menuitem = new wxMenuItemExt( menu, ++i_item_id,
515                                       wxU(text.psz_string ?
516                                         text.psz_string : psz_var),
517                                       wxT(""), wxITEM_NORMAL, strdup(psz_var),
518                                       p_object->i_object_id, val, i_type );
519         menu->Append( menuitem );
520         break;
521
522     case VLC_VAR_BOOL:
523         val.b_bool = !val.b_bool;
524         menuitem = new wxMenuItemExt( menu, ++i_item_id,
525                                       wxU(text.psz_string ?
526                                         text.psz_string : psz_var),
527                                       wxT(""), wxITEM_CHECK, strdup(psz_var),
528                                       p_object->i_object_id, val, i_type );
529         menu->Append( menuitem );
530         Check( i_item_id, val.b_bool ? FALSE : TRUE );
531         break;
532
533     default:
534         if( text.psz_string ) free( text.psz_string );
535         return;
536     }
537
538     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
539     if( text.psz_string ) free( text.psz_string );
540 }
541
542 wxMenu *Menu::CreateChoicesMenu( char *psz_var, vlc_object_t *p_object )
543 {
544     vlc_value_t val, val_list, text_list;
545     int i_type, i;
546
547     /* Check the type of the object variable */
548     i_type = var_Type( p_object, psz_var );
549
550     /* Make sure we want to display the variable */
551     if( i_type & VLC_VAR_HASCHOICE )
552     {
553         var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
554         if( val.i_int == 0 ) return NULL;
555         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
556             return NULL;
557     }
558     else
559     {
560         return NULL;
561     }
562
563     switch( i_type & VLC_VAR_TYPE )
564     {
565     case VLC_VAR_VOID:
566     case VLC_VAR_BOOL:
567     case VLC_VAR_VARIABLE:
568     case VLC_VAR_STRING:
569     case VLC_VAR_INTEGER:
570         break;
571     default:
572         /* Variable doesn't exist or isn't handled */
573         return NULL;
574     }
575
576     if( var_Get( p_object, psz_var, &val ) < 0 )
577     {
578         return NULL;
579     }
580
581     if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
582                     &val_list, &text_list ) < 0 )
583     {
584         if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
585         return NULL;
586     }
587
588     wxMenu *menu = new wxMenu;
589     for( i = 0; i < val_list.p_list->i_count; i++ )
590     {
591         vlc_value_t another_val;
592         wxMenuItemExt *menuitem;
593
594         switch( i_type & VLC_VAR_TYPE )
595         {
596         case VLC_VAR_VARIABLE:
597           menu->Append( MenuDummy_Event,
598                         wxU(text_list.p_list->p_values[i].psz_string ?
599                         text_list.p_list->p_values[i].psz_string :
600                         val_list.p_list->p_values[i].psz_string),
601                         CreateChoicesMenu(
602                             val_list.p_list->p_values[i].psz_string,
603                             p_object ), wxT("") );
604           break;
605
606         case VLC_VAR_STRING:
607           another_val.psz_string =
608               strdup(val_list.p_list->p_values[i].psz_string);
609           menuitem =
610               new wxMenuItemExt( menu, ++i_item_id,
611                                  wxU(text_list.p_list->p_values[i].psz_string ?
612                                  text_list.p_list->p_values[i].psz_string :
613                                  another_val.psz_string), wxT(""),
614                                  i_type & VLC_VAR_ISCOMMAND ?
615                                    wxITEM_NORMAL : wxITEM_RADIO,
616                                  strdup(psz_var),
617                                  p_object->i_object_id, another_val, i_type );
618
619           menu->Append( menuitem );
620
621           if( !strcmp( val.psz_string,
622                        val_list.p_list->p_values[i].psz_string ) )
623               menu->Check( i_item_id, TRUE );
624           break;
625
626         case VLC_VAR_INTEGER:
627           menuitem =
628               new wxMenuItemExt( menu, ++i_item_id,
629                                  text_list.p_list->p_values[i].psz_string ?
630                                  (wxString)wxU(
631                                    text_list.p_list->p_values[i].psz_string) :
632                                  wxString::Format(wxT("%d"),
633                                  val_list.p_list->p_values[i].i_int), wxT(""),
634                                  i_type & VLC_VAR_ISCOMMAND ?
635                                    wxITEM_NORMAL : wxITEM_RADIO,
636                                  strdup(psz_var),
637                                  p_object->i_object_id,
638                                  val_list.p_list->p_values[i], i_type );
639
640           menu->Append( menuitem );
641
642           if( val_list.p_list->p_values[i].i_int == val.i_int )
643               menu->Check( i_item_id, TRUE );
644           break;
645
646         default:
647           break;
648         }
649     }
650
651     /* clean up everything */
652     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
653     var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
654
655     return menu;
656 }
657
658 void Menu::OnShowDialog( wxCommandEvent& event )
659 {
660     if( p_intf->p_sys->pf_show_dialog )
661     {
662         int i_id;
663
664         switch( event.GetId() )
665         {
666         case OpenFileSimple_Event:
667             i_id = INTF_DIALOG_FILE_SIMPLE;
668             break;
669         case OpenFile_Event:
670             i_id = INTF_DIALOG_FILE;
671             break;
672         case OpenDisc_Event:
673             i_id = INTF_DIALOG_DISC;
674             break;
675         case OpenNet_Event:
676             i_id = INTF_DIALOG_NET;
677             break;
678         default:
679             i_id = INTF_DIALOG_FILE;
680             break;
681
682         }
683
684         p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
685     }
686 }
687
688 /*****************************************************************************
689  * A small helper class which intercepts all popup menu events
690  *****************************************************************************/
691 MenuEvtHandler::MenuEvtHandler( intf_thread_t *_p_intf,
692                                 Interface *_p_main_interface )
693 {
694     /* Initializations */
695     p_intf = _p_intf;
696     p_main_interface = _p_main_interface;
697 }
698
699 MenuEvtHandler::~MenuEvtHandler()
700 {
701 }
702
703 void MenuEvtHandler::OnShowDialog( wxCommandEvent& event )
704 {
705     if( p_intf->p_sys->pf_show_dialog )
706     {
707         int i_id;
708
709         switch( event.GetId() )
710         {
711         case OpenFileSimple_Event:
712             i_id = INTF_DIALOG_FILE_SIMPLE;
713             break;
714         case OpenFile_Event:
715             i_id = INTF_DIALOG_FILE;
716             break;
717         case OpenDisc_Event:
718             i_id = INTF_DIALOG_DISC;
719             break;
720         case OpenNet_Event:
721             i_id = INTF_DIALOG_NET;
722             break;
723         default:
724             i_id = INTF_DIALOG_FILE;
725             break;
726
727         }
728
729         p_intf->p_sys->pf_show_dialog( p_intf, i_id, 1, 0 );
730     }
731 }
732
733 void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
734 {
735     wxMenuItem *p_menuitem = NULL;
736
737     /* Check if this is an auto generated menu item */
738     if( event.GetId() < FirstAutoGenerated_Event )
739     {
740         event.Skip();
741         return;
742     }
743
744     if( !p_main_interface ||
745         (p_menuitem = p_main_interface->GetMenuBar()->FindItem(event.GetId()))
746         == NULL )
747     {
748         if( p_intf->p_sys->p_popup_menu )
749         {
750             p_menuitem = 
751                 p_intf->p_sys->p_popup_menu->FindItem( event.GetId() );
752         }
753     }
754
755     if( p_menuitem )
756     {
757         wxMenuItemExt *p_menuitemext = (wxMenuItemExt *)p_menuitem;
758         vlc_object_t *p_object;
759
760         p_object = (vlc_object_t *)vlc_object_get( p_intf,
761                                        p_menuitemext->i_object_id );
762         if( p_object == NULL ) return;
763
764         var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val );
765
766         vlc_object_release( p_object );
767     }
768     else
769         event.Skip();
770 }
771
772 /*****************************************************************************
773  * A small helper class which encapsulate wxMenuitem with some other useful
774  * things.
775  *****************************************************************************/
776 wxMenuItemExt::wxMenuItemExt( wxMenu* parentMenu, int id, const wxString& text,
777     const wxString& helpString, wxItemKind kind,
778     char *_psz_var, int _i_object_id, vlc_value_t _val, int _i_val_type ):
779     wxMenuItem( parentMenu, id, text, helpString, kind )
780 {
781     /* Initializations */
782     psz_var = _psz_var;
783     i_val_type = _i_val_type;
784     i_object_id = _i_object_id;
785     val = _val;
786 };
787
788 wxMenuItemExt::~wxMenuItemExt()
789 {
790     if( psz_var ) free( psz_var );
791     if( ((i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
792         && val.psz_string ) free( val.psz_string );
793 };