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