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