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