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