]> git.sesse.net Git - vlc/blob - modules/gui/wince/menus.cpp
Don't include config.h from the headers - refs #297.
[vlc] / modules / gui / wince / menus.cpp
1 /*****************************************************************************
2  * menus.cpp : WinCE gui plugin for VLC
3  *****************************************************************************
4  * Copyright (C) 2000-2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Marodon Cedric <cedric_marodon@yahoo.fr>
8  *          Gildas Bazin <gbazin@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <vlc/vlc.h>
33 #include <vlc_interface.h>
34
35 #include "wince.h"
36
37 /*****************************************************************************
38  * Event Table.
39  *****************************************************************************/
40
41 /* IDs for the controls and the menu commands */
42 enum
43 {
44     /* menu items */
45     MenuDummy_Event = 1000,
46     OpenFileSimple_Event = 1100,
47     OpenFile_Event,
48     OpenDisc_Event,
49     OpenNet_Event,
50     FirstAutoGenerated_Event = 1999,
51     SettingsMenu_Events = 2000,
52     AudioMenu_Events = 3000,
53     VideoMenu_Events = 4000,
54     NavigMenu_Events = 5000,
55     PopupMenu_Events = 6000
56 };
57
58 HMENU OpenStreamMenu( intf_thread_t *p_intf )
59 {
60     HMENU hmenu = CreatePopupMenu();
61     AppendMenu( hmenu, MF_STRING, ID_FILE_QUICKOPEN,
62                 _T("Quick &Open File...") );
63     AppendMenu( hmenu, MF_STRING, ID_FILE_OPENFILE,
64                 _T("Open &File...") );
65     AppendMenu( hmenu, MF_STRING, ID_FILE_OPENNET,
66                 _T("Open &Network Stream...") );
67     return hmenu;
68 }
69
70 HMENU MiscMenu( intf_thread_t *p_intf )
71 {
72     HMENU hmenu = CreatePopupMenu();
73     AppendMenu( hmenu, MF_STRING, ID_VIEW_STREAMINFO, _T("Media &Info...") );
74     AppendMenu( hmenu, MF_STRING, ID_VIEW_MESSAGES, _T("&Messages...") );
75     AppendMenu( hmenu, MF_STRING, ID_PREFERENCES, _T("&Preferences...") );
76     return hmenu;
77 }
78
79 void PopupMenu( intf_thread_t *p_intf, HWND p_parent, POINT point )
80 {
81 #define MAX_POPUP_ITEMS 45
82
83     vlc_object_t *p_object, *p_input;
84     char *ppsz_varnames[MAX_POPUP_ITEMS];
85     int pi_objects[MAX_POPUP_ITEMS];
86     int i = 0, i_last_separator = 0;
87
88     /* Initializations */
89     memset( pi_objects, 0, MAX_POPUP_ITEMS * sizeof(int) );
90
91     ppsz_varnames[i] = "VLC media player";
92     pi_objects[i++] = 0;
93     ppsz_varnames[i++] = NULL; /* Separator */
94     i_last_separator = i;
95
96     /* Input menu */
97     p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
98                                                 FIND_ANYWHERE );
99     if( p_object != NULL )
100     {
101         ppsz_varnames[i] = "bookmark";
102         pi_objects[i++] = p_object->i_object_id;
103         ppsz_varnames[i] = "title";
104         pi_objects[i++] = p_object->i_object_id;
105         ppsz_varnames[i] = "chapter";
106         pi_objects[i++] = p_object->i_object_id;
107         ppsz_varnames[i] = "program";
108         pi_objects[i++] = p_object->i_object_id;
109         ppsz_varnames[i] = "navigation";
110         pi_objects[i++] = p_object->i_object_id;
111         ppsz_varnames[i] = "dvd_menus";
112         pi_objects[i++] = p_object->i_object_id;
113
114         ppsz_varnames[i] = "video-es";
115         pi_objects[i++] = p_object->i_object_id;
116         ppsz_varnames[i] = "audio-es";
117         pi_objects[i++] = p_object->i_object_id;
118         ppsz_varnames[i] = "spu-es";
119         pi_objects[i++] = p_object->i_object_id;
120     }
121     p_input = p_object;
122     if( !p_input ) goto interfacemenu;
123
124     /* Video menu */
125     if( i != i_last_separator ) ppsz_varnames[i++] = NULL; /* Separator */
126     i_last_separator = i;
127
128     p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
129                                                 FIND_ANYWHERE );
130     if( p_object != NULL )
131     {
132         vlc_object_t *p_dec_obj;
133
134         ppsz_varnames[i] = "fullscreen";
135         pi_objects[i++] = p_object->i_object_id;
136         ppsz_varnames[i] = "zoom";
137         pi_objects[i++] = p_object->i_object_id;
138         ppsz_varnames[i] = "deinterlace";
139         pi_objects[i++] = p_object->i_object_id;
140         ppsz_varnames[i] = "aspect-ratio";
141         pi_objects[i++] = p_object->i_object_id;
142         ppsz_varnames[i] = "crop";
143         pi_objects[i++] = p_object->i_object_id;
144         ppsz_varnames[i] = "video-on-top";
145         pi_objects[i++] = p_object->i_object_id;
146         ppsz_varnames[i] = "directx-wallpaper";
147         pi_objects[i++] = p_object->i_object_id;
148         ppsz_varnames[i] = "video-snapshot";
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     /* Audio menu */
165     if( i != i_last_separator ) ppsz_varnames[i++] = NULL; /* Separator */
166     i_last_separator  = i;
167
168     p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
169                                                 FIND_ANYWHERE );
170     if( p_object != NULL )
171     {
172         ppsz_varnames[i] = "audio-device";
173         pi_objects[i++] = p_object->i_object_id;
174         ppsz_varnames[i] = "audio-channels";
175         pi_objects[i++] = p_object->i_object_id;
176         ppsz_varnames[i] = "visual";
177         pi_objects[i++] = p_object->i_object_id;
178         ppsz_varnames[i] = "equalizer";
179         pi_objects[i++] = p_object->i_object_id;
180         vlc_object_release( p_object );
181     }
182
183  interfacemenu:
184     /* Interface menu */
185     if( i != i_last_separator ) ppsz_varnames[i++] = NULL; /* Separator */
186     i_last_separator = i;
187
188     /* vlc_object_find is needed because of the dialogs provider case */
189     p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INTF,
190                                                 FIND_PARENT );
191     if( p_object != NULL )
192     {
193         /* Nothing for now */
194         vlc_object_release( p_object );
195     }
196
197     /* Build menu */
198     vector<MenuItemExt*> popup_menu;
199     HMENU hmenu = CreatePopupMenu();
200     RefreshMenu( p_intf, &popup_menu, hmenu, i,
201                  ppsz_varnames, pi_objects, PopupMenu_Events );
202     MenuItemExt::ClearList( &popup_menu );
203
204
205     /* Add static entries */
206     if( p_input != NULL )
207     {
208         vlc_value_t val;
209         AppendMenu( hmenu, MF_SEPARATOR, 0, _T("") );
210         AppendMenu( hmenu, MF_STRING, StopStream_Event, _T("Stop") );
211         AppendMenu( hmenu, MF_STRING, PrevStream_Event, _T("Previous") );
212         AppendMenu( hmenu, MF_STRING, NextStream_Event, _T("Next") );
213
214         var_Get( p_input, "state", &val );
215         if( val.i_int == PAUSE_S )
216             AppendMenu( hmenu, MF_STRING, PlayStream_Event, _T("Play") );
217         else
218             AppendMenu( hmenu, MF_STRING, PlayStream_Event, _T("Pause") );
219
220         vlc_object_release( p_input );
221     }
222     else
223     {
224         playlist_t * p_playlist =
225             (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
226                                            FIND_ANYWHERE );
227         if( p_playlist && p_playlist->i_size )
228         {
229             AppendMenu( hmenu, MF_SEPARATOR, 0, _T("") );
230             AppendMenu( hmenu, MF_STRING, PlayStream_Event, _T("Play") );
231         }
232         if( p_playlist ) vlc_object_release( p_playlist );
233     }
234
235     AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)MiscMenu( p_intf ),
236                 _T("Miscellaneous") );
237     AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)OpenStreamMenu( p_intf ),
238                 _T("Open") );
239
240     TrackPopupMenu( hmenu, 0, point.x, point.y, 0, p_parent, 0 );
241     PostMessage( p_parent, WM_NULL, 0, 0 );
242     DestroyMenu( hmenu );
243 }
244
245 void RefreshAudioMenu( intf_thread_t *p_intf, HMENU hMenu )
246 {
247 #define MAX_AUDIO_ITEMS 10
248
249     vlc_object_t *p_object;
250     char *ppsz_varnames[MAX_AUDIO_ITEMS];
251     int pi_objects[MAX_AUDIO_ITEMS];
252     int i;
253
254     /* Delete old menu */
255     int count = wce_GetMenuItemCount( hMenu );
256     for( i = 0; i <= count; i++ ) RemoveMenu( hMenu, 0, MF_BYPOSITION );
257
258     if( p_intf->p_sys->p_audio_menu )
259         MenuItemExt::ClearList( p_intf->p_sys->p_audio_menu );
260     else p_intf->p_sys->p_audio_menu = new vector<MenuItemExt*>;
261
262
263     /* Initializations */
264     memset( pi_objects, 0, MAX_AUDIO_ITEMS * sizeof(int) );
265     i = 0;
266
267     p_object = (vlc_object_t *)
268         vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
269     if( p_object != NULL )
270     {
271         ppsz_varnames[i] = "audio-es";
272         pi_objects[i++] = p_object->i_object_id;
273         vlc_object_release( p_object );
274     }
275
276     p_object = (vlc_object_t *)
277         vlc_object_find( p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE );
278     if( p_object != NULL )
279     {
280         ppsz_varnames[i] = "audio-device";
281         pi_objects[i++] = p_object->i_object_id;
282         ppsz_varnames[i] = "audio-channels";
283         pi_objects[i++] = p_object->i_object_id;
284         ppsz_varnames[i] = "visual";
285         pi_objects[i++] = p_object->i_object_id;
286         vlc_object_release( p_object );
287     }
288
289     /* Build menu */
290     RefreshMenu( p_intf, p_intf->p_sys->p_audio_menu,
291                  hMenu, i, ppsz_varnames, pi_objects, AudioMenu_Events );
292 }
293
294 void RefreshVideoMenu( intf_thread_t *p_intf, HMENU hMenu )
295 {
296 #define MAX_VIDEO_ITEMS 15
297
298     vlc_object_t *p_object;
299     char *ppsz_varnames[MAX_VIDEO_ITEMS];
300     int pi_objects[MAX_VIDEO_ITEMS];
301     int i;
302
303     /* Delete old menu */
304     int count = wce_GetMenuItemCount( hMenu );
305     for( i = 0; i <= count; i++ ) RemoveMenu( hMenu, 0, MF_BYPOSITION );
306
307     if( p_intf->p_sys->p_video_menu )
308         MenuItemExt::ClearList( p_intf->p_sys->p_video_menu );
309     else p_intf->p_sys->p_video_menu = new vector<MenuItemExt*>;
310
311     /* Initializations */
312     memset( pi_objects, 0, MAX_VIDEO_ITEMS * sizeof(int) );
313     i = 0;
314
315     p_object = (vlc_object_t *)
316         vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
317     if( p_object != NULL )
318     {
319         ppsz_varnames[i] = "video-es";
320         pi_objects[i++] = p_object->i_object_id;
321         ppsz_varnames[i] = "spu-es";
322         pi_objects[i++] = p_object->i_object_id;
323         vlc_object_release( p_object );
324     }
325
326     p_object = (vlc_object_t *)
327         vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
328     if( p_object != NULL )
329     {
330         vlc_object_t *p_dec_obj;
331
332         ppsz_varnames[i] = "fullscreen";
333         pi_objects[i++] = p_object->i_object_id;
334 #ifdef WINCE
335         ppsz_varnames[i] = "transform";
336         pi_objects[i++] = p_object->i_object_id;
337 #endif
338         ppsz_varnames[i] = "zoom";
339         pi_objects[i++] = p_object->i_object_id;
340         ppsz_varnames[i] = "deinterlace";
341         pi_objects[i++] = p_object->i_object_id;
342         ppsz_varnames[i] = "aspect-ratio";
343         pi_objects[i++] = p_object->i_object_id;
344         ppsz_varnames[i] = "crop";
345         pi_objects[i++] = p_object->i_object_id;
346         ppsz_varnames[i] = "directx-on-top";
347         pi_objects[i++] = p_object->i_object_id;
348
349         p_dec_obj = (vlc_object_t *)
350             vlc_object_find( p_object, VLC_OBJECT_DECODER, FIND_PARENT );
351         if( p_dec_obj != NULL )
352         {
353             ppsz_varnames[i] = "ffmpeg-pp-q";
354             pi_objects[i++] = p_dec_obj->i_object_id;
355             vlc_object_release( p_dec_obj );
356         }
357
358         vlc_object_release( p_object );
359     }
360
361     /* Build menu */
362     RefreshMenu( p_intf, p_intf->p_sys->p_video_menu, hMenu, i,
363                  ppsz_varnames, pi_objects, VideoMenu_Events );
364 }
365
366 void RefreshNavigMenu( intf_thread_t *p_intf, HMENU hMenu )
367 {
368 #define MAX_NAVIG_ITEMS 10
369
370     vlc_object_t *p_object;
371     char *ppsz_varnames[MAX_NAVIG_ITEMS];
372     int pi_objects[MAX_NAVIG_ITEMS];
373     int i;
374
375     /* Delete old menu */
376     int count = wce_GetMenuItemCount( hMenu );
377     for( i = 0; i <= count; i++ ) RemoveMenu( hMenu, 0, MF_BYPOSITION );
378  
379     if( p_intf->p_sys->p_navig_menu )
380         MenuItemExt::ClearList( p_intf->p_sys->p_navig_menu );
381     else p_intf->p_sys->p_navig_menu = new vector<MenuItemExt*>;
382
383     /* Initializations */
384     memset( pi_objects, 0, MAX_NAVIG_ITEMS * sizeof(int) );
385     i = 0;
386
387     p_object = (vlc_object_t *)
388         vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
389     if( p_object != NULL )
390     {
391         ppsz_varnames[i] = "title";
392         pi_objects[i++] = p_object->i_object_id;
393         ppsz_varnames[i] = "chapter";
394         pi_objects[i++] = p_object->i_object_id;
395         ppsz_varnames[i] = "program";
396         pi_objects[i++] = p_object->i_object_id;
397         ppsz_varnames[i] = "navigation";
398         pi_objects[i++] = p_object->i_object_id;
399         ppsz_varnames[i] = "dvd_menus";
400         pi_objects[i++] = p_object->i_object_id;
401
402         ppsz_varnames[i] = "prev-title";
403         pi_objects[i++] = p_object->i_object_id;
404         ppsz_varnames[i] = "next-title";
405         pi_objects[i++] = p_object->i_object_id;
406         ppsz_varnames[i] = "prev-chapter";
407         pi_objects[i++] = p_object->i_object_id;
408         ppsz_varnames[i] = "next-chapter";
409         pi_objects[i++] = p_object->i_object_id;
410
411         vlc_object_release( p_object );
412     }
413
414     /* Build menu */
415     RefreshMenu( p_intf, p_intf->p_sys->p_navig_menu, hMenu, i,
416                  ppsz_varnames, pi_objects, NavigMenu_Events );
417 }
418
419 void RefreshSettingsMenu( intf_thread_t *p_intf, HMENU hMenu )
420 {
421 #define MAX_SETTINGS_ITEMS 10
422
423     vlc_object_t *p_object;
424     char *ppsz_varnames[MAX_SETTINGS_ITEMS];
425     int pi_objects[MAX_SETTINGS_ITEMS];
426     int i;
427
428     /* Delete old menu */
429     int count = wce_GetMenuItemCount( hMenu );
430     for( i = 0; i <= count; i++ ) RemoveMenu( hMenu, 0, MF_BYPOSITION );
431
432     if( p_intf->p_sys->p_settings_menu )
433         MenuItemExt::ClearList( p_intf->p_sys->p_settings_menu );
434     else p_intf->p_sys->p_settings_menu = new vector<MenuItemExt*>;
435
436     /* Initializations */
437     memset( pi_objects, 0, MAX_SETTINGS_ITEMS * sizeof(int) );
438     i = 0;
439
440     AppendMenu( hMenu, MF_STRING, ID_PREFERENCES, _T("&Preferences...") );
441
442     p_object = (vlc_object_t *)
443         vlc_object_find( p_intf, VLC_OBJECT_INTF, FIND_PARENT );
444     if( p_object != NULL )
445     {
446         ppsz_varnames[i] = "intf-switch";
447         pi_objects[i++] = p_object->i_object_id;
448         ppsz_varnames[i] = "intf-add";
449         pi_objects[i++] = p_object->i_object_id;
450         vlc_object_release( p_object );
451     }
452
453     /* Build menu */
454     RefreshMenu( p_intf, p_intf->p_sys->p_settings_menu, hMenu, i,
455                  ppsz_varnames, pi_objects, SettingsMenu_Events );
456 }
457
458 /*****************************************************************************
459  * Refresh the menu.
460  *****************************************************************************/
461 void RefreshMenu( intf_thread_t *p_intf, vector<MenuItemExt*> *p_menu_list,
462                   HMENU hMenu , int i_count, char **ppsz_varnames,
463                   int *pi_objects, int i_start_id )
464 {
465     vlc_object_t *p_object;
466     vlc_bool_t b_section_empty = VLC_FALSE;
467     int i;
468
469     /* Initializations */
470     int i_item_id = i_start_id;
471
472     for( i = 0; i < i_count; i++ )
473     {
474         if( !ppsz_varnames[i] )
475         {
476             if( b_section_empty )
477             {
478                 AppendMenu( hMenu, MF_GRAYED | MF_STRING,
479                             MenuDummy_Event + i, _T("Empty") );
480             }
481
482             AppendMenu( hMenu, MF_SEPARATOR, 0, _T("") );
483             b_section_empty = VLC_TRUE;
484             continue;
485         }
486
487         if( !pi_objects[i] )
488         {
489             AppendMenu( hMenu, MF_GRAYED | MF_STRING,
490                         MenuDummy_Event, _FROMMB(ppsz_varnames[i]) );
491
492             b_section_empty = VLC_FALSE;
493             continue;
494         }
495
496         p_object = (vlc_object_t *)vlc_object_get( p_intf, pi_objects[i] );
497         if( p_object == NULL ) continue;
498
499         b_section_empty = VLC_FALSE;
500         CreateMenuItem( p_intf, p_menu_list, hMenu, ppsz_varnames[i],
501                         p_object, &i_item_id );
502         vlc_object_release( p_object );
503     }
504
505     /* Special case for empty menus */
506     if( wce_GetMenuItemCount(hMenu) == 0 || b_section_empty )
507     {
508         AppendMenu( hMenu, MF_GRAYED | MF_STRING,
509                     MenuDummy_Event + i, _T("Empty") );
510     }
511 }
512
513 /*****************************************************************************
514  * Private methods.
515  *****************************************************************************/
516 void CreateMenuItem( intf_thread_t *p_intf, vector<MenuItemExt*> *p_menu_list,
517                      HMENU hMenu, char *psz_var, vlc_object_t *p_object,
518                      int *pi_item_id )
519 {
520     MenuItemExt *pMenuItemExt;
521     HMENU hMenuItem;
522     vlc_value_t val, text;
523     int i_type;
524
525     /* Check the type of the object variable */
526     i_type = var_Type( p_object, psz_var );
527
528     switch( i_type & VLC_VAR_TYPE )
529     {
530     case VLC_VAR_VOID:
531     case VLC_VAR_BOOL:
532     case VLC_VAR_VARIABLE:
533     case VLC_VAR_STRING:
534     case VLC_VAR_INTEGER:
535     case VLC_VAR_FLOAT:
536         break;
537     default:
538         /* Variable doesn't exist or isn't handled */
539         return;
540     }
541
542     /* Make sure we want to display the variable */
543     if( i_type & VLC_VAR_HASCHOICE )
544     {
545         var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
546         if( val.i_int == 0 ) return;
547         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
548             return;
549     }
550
551     /* Get the descriptive name of the variable */
552     var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
553
554     var_Get( p_object, psz_var, &val );
555
556     if( i_type & VLC_VAR_HASCHOICE )
557     {
558         hMenuItem = CreateChoicesMenu( p_intf, p_menu_list, psz_var,
559                                        p_object, pi_item_id );
560         AppendMenu( hMenu, MF_STRING | MF_POPUP, (UINT)hMenuItem,
561                     _FROMMB(text.psz_string ? text.psz_string : psz_var) );
562         if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
563         if( text.psz_string ) free( text.psz_string );
564         return;
565     }
566
567     switch( i_type & VLC_VAR_TYPE )
568     {
569     case VLC_VAR_VOID:
570         AppendMenu( hMenu, MF_STRING , ++(*pi_item_id),
571                     _FROMMB(text.psz_string ? text.psz_string : psz_var) );
572         pMenuItemExt = new MenuItemExt( p_intf, *pi_item_id, psz_var,
573                                         p_object->i_object_id, val, i_type );
574         p_menu_list->push_back( pMenuItemExt );
575         break;
576
577     case VLC_VAR_BOOL:
578         val.b_bool = !val.b_bool;
579         AppendMenu( hMenu, MF_STRING | MF_CHECKED, ++(*pi_item_id),
580                     _FROMMB(text.psz_string ? text.psz_string : psz_var) );
581         pMenuItemExt = new MenuItemExt( p_intf, *pi_item_id, psz_var,
582                                         p_object->i_object_id, val, i_type );
583         p_menu_list->push_back( pMenuItemExt );
584         CheckMenuItem( hMenu, *pi_item_id ,
585                        ( val.b_bool ? MF_UNCHECKED : MF_CHECKED ) |
586                        MF_BYCOMMAND );
587         break;
588
589     default:
590         if( text.psz_string ) free( text.psz_string );
591         return;
592     }
593
594     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
595     if( text.psz_string ) free( text.psz_string );
596 }
597
598 HMENU CreateChoicesMenu( intf_thread_t *p_intf,
599                          vector<MenuItemExt*> *p_menu_list, char *psz_var,
600                          vlc_object_t *p_object, int *pi_item_id )
601 {
602     MenuItemExt *pMenuItemExt;
603     vlc_value_t val, val_list, text_list;
604     int i_type, i;
605     HMENU hSubMenu = CreatePopupMenu();
606
607     /* Check the type of the object variable */
608     i_type = var_Type( p_object, psz_var );
609
610     /* Make sure we want to display the variable */
611     if( i_type & VLC_VAR_HASCHOICE )
612     {
613         var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
614         if( val.i_int == 0 ) return NULL;
615         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
616             return NULL;
617     }
618     else
619     {
620         return NULL;
621     }
622
623     switch( i_type & VLC_VAR_TYPE )
624     {
625     case VLC_VAR_VOID:
626     case VLC_VAR_BOOL:
627     case VLC_VAR_VARIABLE:
628     case VLC_VAR_STRING:
629     case VLC_VAR_INTEGER:
630         break;
631     default:
632         /* Variable doesn't exist or isn't handled */
633         return NULL;
634     }
635
636     if( var_Get( p_object, psz_var, &val ) < 0 ) return NULL;
637
638     if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
639                     &val_list, &text_list ) < 0 )
640     {
641         if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
642         return NULL;
643     }
644
645     for( i = 0; i < val_list.p_list->i_count; i++ )
646     {
647         vlc_value_t another_val;
648         HMENU hMenuItem;
649         char *psz_tmp;
650
651         switch( i_type & VLC_VAR_TYPE )
652         {
653         case VLC_VAR_VARIABLE:
654             hMenuItem = CreateChoicesMenu( p_intf, p_menu_list,
655               val_list.p_list->p_values[i].psz_string, p_object, pi_item_id );
656             AppendMenu( hSubMenu, MF_STRING | MF_POPUP, (UINT)hMenuItem,
657                         _FROMMB(text_list.p_list->p_values[i].psz_string ?
658                           text_list.p_list->p_values[i].psz_string :
659                           val_list.p_list->p_values[i].psz_string) );
660             break;
661
662         case VLC_VAR_STRING:
663             another_val.psz_string =
664                 strdup(val_list.p_list->p_values[i].psz_string);
665             AppendMenu( hSubMenu, MF_STRING, ++(*pi_item_id),
666                         _FROMMB(text_list.p_list->p_values[i].psz_string ?
667                           text_list.p_list->p_values[i].psz_string :
668                           val_list.p_list->p_values[i].psz_string) );
669             pMenuItemExt = new MenuItemExt( p_intf, *pi_item_id, psz_var,
670                           p_object->i_object_id, another_val, i_type );
671             p_menu_list->push_back( pMenuItemExt );
672
673             if( !(i_type & VLC_VAR_ISCOMMAND) && val.psz_string &&
674                 !strcmp( val.psz_string,
675                          val_list.p_list->p_values[i].psz_string ) )
676               CheckMenuItem( hSubMenu, *pi_item_id, MF_CHECKED | MF_BYCOMMAND);
677             break;
678
679         case VLC_VAR_INTEGER:
680             asprintf( &psz_tmp, "%d", val_list.p_list->p_values[i].i_int );
681             AppendMenu( hSubMenu, MF_STRING, ++(*pi_item_id),
682                         _FROMMB(text_list.p_list->p_values[i].psz_string ?
683                           text_list.p_list->p_values[i].psz_string : psz_tmp));
684             pMenuItemExt = new MenuItemExt( p_intf, *pi_item_id, psz_var,
685                 p_object->i_object_id, val_list.p_list->p_values[i], i_type );
686             p_menu_list->push_back( pMenuItemExt );
687
688             if( val_list.p_list->p_values[i].i_int == val.i_int )
689               CheckMenuItem( hSubMenu, *pi_item_id, MF_CHECKED | MF_BYCOMMAND);
690             break;
691
692         default:
693             break;
694         }
695     }
696
697     /* Clean up everything */
698     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
699     var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
700
701     return hSubMenu;
702 }
703
704 int wce_GetMenuItemCount(HMENU hMenu)
705 {
706     const int MAX_NUM_ITEMS = 256;
707     int iPos, iCount;
708
709     MENUITEMINFO mii;
710     memset( (char *)&mii, 0, sizeof(MENUITEMINFO) );
711     mii.cbSize = sizeof(MENUITEMINFO);
712
713     iCount = 0;
714     for( iPos = 0; iPos < MAX_NUM_ITEMS; iPos++ )
715     {
716         if( !GetMenuItemInfo(hMenu, (UINT)iPos, TRUE, &mii) ) break;
717         iCount++;
718     }
719
720     return iCount;
721 }
722
723 void OnMenuEvent( intf_thread_t *p_intf, int id )
724 {
725     MenuItemExt *p_menuitemext = NULL;
726     vector<MenuItemExt*>::iterator iter;
727
728     if( p_intf->p_sys->p_settings_menu )
729     for( iter = p_intf->p_sys->p_settings_menu->begin();
730          iter != p_intf->p_sys->p_settings_menu->end(); iter++ )
731         if( (*iter)->id == id )
732         {
733             p_menuitemext = *iter;
734             break;
735         }
736
737     if( p_intf->p_sys->p_audio_menu && !p_menuitemext )
738     for( iter = p_intf->p_sys->p_audio_menu->begin();
739          iter != p_intf->p_sys->p_audio_menu->end(); iter++ )
740         if( (*iter)->id == id )
741         {
742             p_menuitemext = *iter;
743             break;
744         }
745
746     if( p_intf->p_sys->p_video_menu && !p_menuitemext )
747     for( iter = p_intf->p_sys->p_video_menu->begin();
748          iter != p_intf->p_sys->p_video_menu->end(); iter++ )
749         if( (*iter)->id == id )
750         {
751             p_menuitemext = *iter;
752             break;
753         }
754
755     if( p_intf->p_sys->p_navig_menu && !p_menuitemext )
756     for( iter = p_intf->p_sys->p_navig_menu->begin();
757          iter != p_intf->p_sys->p_navig_menu->end(); iter++ )
758         if( (*iter)->id == id )
759         {
760             p_menuitemext = *iter;
761             break;
762         }
763
764     if( p_menuitemext )
765     {
766         vlc_object_t *p_object = (vlc_object_t *)
767             vlc_object_get( p_intf, p_menuitemext->i_object_id );
768         if( p_object == NULL ) return;
769
770         var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val );
771         int i_type = var_Type( p_object, p_menuitemext->psz_var );
772         switch( i_type & VLC_VAR_TYPE )
773         {
774         case VLC_VAR_VOID:
775         case VLC_VAR_BOOL:
776         case VLC_VAR_VARIABLE:
777         case VLC_VAR_STRING:
778         case VLC_VAR_INTEGER:
779             break;
780         default:
781             /* Variable doesn't exist or isn't handled */
782             return;
783         }
784
785         vlc_object_release( p_object );
786     }
787 }
788
789 /*****************************************************************************
790  * A small helper class which encapsulate wxMenuitem with some other useful
791  * things.
792  *****************************************************************************/
793 MenuItemExt::MenuItemExt( intf_thread_t *p_intf, int _id, char *_psz_var,
794                           int _i_object_id, vlc_value_t _val, int _i_val_type )
795 {
796     /* Initializations */
797     id = _id;
798     p_intf = p_intf;
799     psz_var = strdup( _psz_var );
800     i_val_type = _i_val_type;
801     i_object_id = _i_object_id;
802     val = _val;
803 };
804
805 MenuItemExt::~MenuItemExt()
806 {
807     if( psz_var ) free( psz_var );
808     if( ((i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
809         && val.psz_string ) free( val.psz_string );
810 };
811
812 void MenuItemExt::ClearList( vector<MenuItemExt*> *p_menu_list )
813 {
814     vector<MenuItemExt*>::iterator iter;
815
816     if( !p_menu_list ) return;
817     for( iter = p_menu_list->begin(); iter != p_menu_list->end(); iter++ )
818     {
819         delete *iter;
820     }
821     p_menu_list->clear();
822 }