1 /*****************************************************************************
2 * menus.cpp : WinCE gui plugin for VLC
3 *****************************************************************************
4 * Copyright (C) 2000-2004 VideoLAN
7 * Authors: Marodon Cedric <cedric_marodon@yahoo.fr>
8 * Gildas Bazin <gbazin@videolan.org>
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
29 #include <string.h> /* strerror() */
36 /*****************************************************************************
38 *****************************************************************************/
40 /* IDs for the controls and the menu commands */
44 MenuDummy_Event = 1000,
45 OpenFileSimple_Event = 1100,
49 FirstAutoGenerated_Event = 1999,
50 SettingsMenu_Events = 2000,
51 AudioMenu_Events = 3000,
52 VideoMenu_Events = 4000,
53 NavigMenu_Events = 5000,
54 PopupMenu_Events = 6000
57 void RefreshAudioMenu( intf_thread_t *p_intf, HMENU hMenu )
59 #define MAX_AUDIO_ITEMS 10
61 vlc_object_t *p_object;
62 char *ppsz_varnames[MAX_AUDIO_ITEMS];
63 int pi_objects[MAX_AUDIO_ITEMS];
64 vector<MenuItemExt*>::iterator iter;
68 int count = wce_GetMenuItemCount( hMenu );
69 for( i = 0; i <= count; i++ ) RemoveMenu( hMenu, 0, MF_BYPOSITION );
71 if( p_intf->p_sys->p_audio_menu )
73 for( iter = p_intf->p_sys->p_audio_menu->begin();
74 iter != p_intf->p_sys->p_audio_menu->end(); iter++ )
76 p_intf->p_sys->p_audio_menu->clear();
78 else p_intf->p_sys->p_audio_menu = new vector<MenuItemExt*>;
81 memset( pi_objects, 0, MAX_AUDIO_ITEMS * sizeof(int) );
84 p_object = (vlc_object_t *)
85 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
86 if( p_object != NULL )
88 ppsz_varnames[i] = "audio-es";
89 pi_objects[i++] = p_object->i_object_id;
90 vlc_object_release( p_object );
93 p_object = (vlc_object_t *)
94 vlc_object_find( p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE );
95 if( p_object != NULL )
97 ppsz_varnames[i] = "audio-device";
98 pi_objects[i++] = p_object->i_object_id;
99 ppsz_varnames[i] = "audio-channels";
100 pi_objects[i++] = p_object->i_object_id;
101 ppsz_varnames[i] = "visual";
102 pi_objects[i++] = p_object->i_object_id;
103 vlc_object_release( p_object );
107 RefreshMenu( p_intf, p_intf->p_sys->p_audio_menu,
108 hMenu, i, ppsz_varnames, pi_objects, AudioMenu_Events );
111 void RefreshVideoMenu( intf_thread_t *p_intf, HMENU hMenu )
113 #define MAX_VIDEO_ITEMS 15
115 vlc_object_t *p_object;
116 char *ppsz_varnames[MAX_VIDEO_ITEMS];
117 int pi_objects[MAX_VIDEO_ITEMS];
118 vector<MenuItemExt*>::iterator iter;
121 /* Delete old menu */
122 int count = wce_GetMenuItemCount( hMenu );
123 for( i = 0; i <= count; i++ ) RemoveMenu( hMenu, 0, MF_BYPOSITION );
125 if( p_intf->p_sys->p_video_menu )
127 for( iter = p_intf->p_sys->p_video_menu->begin();
128 iter != p_intf->p_sys->p_video_menu->end(); iter++ )
130 p_intf->p_sys->p_video_menu->clear();
132 else p_intf->p_sys->p_video_menu = new vector<MenuItemExt*>;
134 /* Initializations */
135 memset( pi_objects, 0, MAX_VIDEO_ITEMS * sizeof(int) );
138 p_object = (vlc_object_t *)
139 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
140 if( p_object != NULL )
142 ppsz_varnames[i] = "video-es";
143 pi_objects[i++] = p_object->i_object_id;
144 ppsz_varnames[i] = "spu-es";
145 pi_objects[i++] = p_object->i_object_id;
146 vlc_object_release( p_object );
149 p_object = (vlc_object_t *)
150 vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
151 if( p_object != NULL )
153 vlc_object_t *p_dec_obj;
155 ppsz_varnames[i] = "fullscreen";
156 pi_objects[i++] = p_object->i_object_id;
158 ppsz_varnames[i] = "transform";
159 pi_objects[i++] = p_object->i_object_id;
161 ppsz_varnames[i] = "zoom";
162 pi_objects[i++] = p_object->i_object_id;
163 ppsz_varnames[i] = "deinterlace";
164 pi_objects[i++] = p_object->i_object_id;
165 ppsz_varnames[i] = "aspect-ratio";
166 pi_objects[i++] = p_object->i_object_id;
167 ppsz_varnames[i] = "crop";
168 pi_objects[i++] = p_object->i_object_id;
169 ppsz_varnames[i] = "directx-on-top";
170 pi_objects[i++] = p_object->i_object_id;
172 p_dec_obj = (vlc_object_t *)
173 vlc_object_find( p_object, VLC_OBJECT_DECODER, FIND_PARENT );
174 if( p_dec_obj != NULL )
176 ppsz_varnames[i] = "ffmpeg-pp-q";
177 pi_objects[i++] = p_dec_obj->i_object_id;
178 vlc_object_release( p_dec_obj );
181 vlc_object_release( p_object );
185 RefreshMenu( p_intf, p_intf->p_sys->p_video_menu, hMenu, i,
186 ppsz_varnames, pi_objects, VideoMenu_Events );
189 void RefreshNavigMenu( intf_thread_t *p_intf, HMENU hMenu )
191 #define MAX_NAVIG_ITEMS 10
193 vlc_object_t *p_object;
194 char *ppsz_varnames[MAX_NAVIG_ITEMS];
195 int pi_objects[MAX_NAVIG_ITEMS];
196 vector<MenuItemExt*>::iterator iter;
199 /* Delete old menu */
200 int count = wce_GetMenuItemCount( hMenu );
201 for( i = 0; i <= count; i++ ) RemoveMenu( hMenu, 0, MF_BYPOSITION );
203 if( p_intf->p_sys->p_navig_menu )
205 for( iter = p_intf->p_sys->p_navig_menu->begin();
206 iter != p_intf->p_sys->p_navig_menu->end(); iter++ )
208 p_intf->p_sys->p_navig_menu->clear();
210 else p_intf->p_sys->p_navig_menu = new vector<MenuItemExt*>;
212 /* Initializations */
213 memset( pi_objects, 0, MAX_NAVIG_ITEMS * sizeof(int) );
216 p_object = (vlc_object_t *)
217 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
218 if( p_object != NULL )
220 ppsz_varnames[i] = "title";
221 pi_objects[i++] = p_object->i_object_id;
222 ppsz_varnames[i] = "chapter";
223 pi_objects[i++] = p_object->i_object_id;
224 ppsz_varnames[i] = "program";
225 pi_objects[i++] = p_object->i_object_id;
226 ppsz_varnames[i] = "navigation";
227 pi_objects[i++] = p_object->i_object_id;
228 ppsz_varnames[i] = "dvd_menus";
229 pi_objects[i++] = p_object->i_object_id;
231 ppsz_varnames[i] = "prev-title";
232 pi_objects[i++] = p_object->i_object_id;
233 ppsz_varnames[i] = "next-title";
234 pi_objects[i++] = p_object->i_object_id;
235 ppsz_varnames[i] = "prev-chapter";
236 pi_objects[i++] = p_object->i_object_id;
237 ppsz_varnames[i] = "next-chapter";
238 pi_objects[i++] = p_object->i_object_id;
240 vlc_object_release( p_object );
244 RefreshMenu( p_intf, p_intf->p_sys->p_navig_menu, hMenu, i,
245 ppsz_varnames, pi_objects, NavigMenu_Events );
248 void RefreshSettingsMenu( intf_thread_t *p_intf, HMENU hMenu )
250 #define MAX_SETTINGS_ITEMS 10
252 vlc_object_t *p_object;
253 char *ppsz_varnames[MAX_SETTINGS_ITEMS];
254 int pi_objects[MAX_SETTINGS_ITEMS];
255 vector<MenuItemExt*>::iterator iter;
258 /* Delete old menu */
259 int count = wce_GetMenuItemCount( hMenu );
260 for( i = 0; i <= count; i++ ) RemoveMenu( hMenu, 0, MF_BYPOSITION );
262 if( p_intf->p_sys->p_settings_menu )
264 for( iter = p_intf->p_sys->p_settings_menu->begin();
265 iter != p_intf->p_sys->p_settings_menu->end(); iter++ )
267 p_intf->p_sys->p_settings_menu->clear();
269 else p_intf->p_sys->p_settings_menu = new vector<MenuItemExt*>;
271 /* Initializations */
272 memset( pi_objects, 0, MAX_SETTINGS_ITEMS * sizeof(int) );
275 AppendMenu( hMenu, MF_STRING, ID_SETTINGS_EXTEND, _T("&Extended GUI") );
276 AppendMenu( hMenu, MF_STRING, ID_SETTINGS_PREF, _T("&Preferences...") );
278 p_object = (vlc_object_t *)
279 vlc_object_find( p_intf, VLC_OBJECT_INTF, FIND_PARENT );
280 if( p_object != NULL )
282 ppsz_varnames[i] = "intf-switch";
283 pi_objects[i++] = p_object->i_object_id;
284 ppsz_varnames[i] = "intf-add";
285 pi_objects[i++] = p_object->i_object_id;
286 vlc_object_release( p_object );
290 RefreshMenu( p_intf, p_intf->p_sys->p_settings_menu, hMenu, i,
291 ppsz_varnames, pi_objects, SettingsMenu_Events );
294 /*****************************************************************************
296 *****************************************************************************/
297 void RefreshMenu( intf_thread_t *p_intf, vector<MenuItemExt*> *_p_menuList,
298 HMENU hMenu , int i_count, char **ppsz_varnames,
299 int *pi_objects, int i_start_id )
301 vlc_object_t *p_object;
302 vlc_bool_t b_section_empty = VLC_FALSE;
305 /* Initializations */
306 int i_item_id = i_start_id;
308 for( i = 0; i < i_count; i++ )
310 if( !ppsz_varnames[i] )
312 if( b_section_empty )
314 AppendMenu( hMenu, MF_GRAYED | MF_STRING,
315 MenuDummy_Event + i, _T("Empty") );
318 AppendMenu( hMenu, MF_SEPARATOR, 0, _T("") );
319 b_section_empty = VLC_TRUE;
325 AppendMenu( hMenu, MF_GRAYED | MF_STRING,
326 MenuDummy_Event, _FROMMB(ppsz_varnames[i]) );
328 b_section_empty = VLC_FALSE;
332 p_object = (vlc_object_t *)vlc_object_get( p_intf, pi_objects[i] );
333 if( p_object == NULL ) continue;
335 b_section_empty = VLC_FALSE;
336 CreateMenuItem( p_intf, _p_menuList, hMenu, ppsz_varnames[i],
337 p_object, &i_item_id );
338 vlc_object_release( p_object );
341 /* Special case for empty menus */
342 if( wce_GetMenuItemCount(hMenu) == 0 || b_section_empty )
344 AppendMenu( hMenu, MF_GRAYED | MF_STRING,
345 MenuDummy_Event + i, _T("Empty") );
349 /*****************************************************************************
351 *****************************************************************************/
352 void CreateMenuItem( intf_thread_t *p_intf, vector<MenuItemExt*> *_p_menuList,
353 HMENU hMenu, char *psz_var, vlc_object_t *p_object,
356 MenuItemExt *pMenuItemExt;
358 vlc_value_t val, text;
361 /* Check the type of the object variable */
362 i_type = var_Type( p_object, psz_var );
364 switch( i_type & VLC_VAR_TYPE )
368 case VLC_VAR_VARIABLE:
370 case VLC_VAR_INTEGER:
374 /* Variable doesn't exist or isn't handled */
378 /* Make sure we want to display the variable */
379 if( i_type & VLC_VAR_HASCHOICE )
381 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
382 if( val.i_int == 0 ) return;
383 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
387 /* Get the descriptive name of the variable */
388 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
390 var_Get( p_object, psz_var, &val );
392 if( i_type & VLC_VAR_HASCHOICE )
394 hMenuItem = CreateChoicesMenu( p_intf, _p_menuList, psz_var,
395 p_object, pi_item_id );
396 AppendMenu( hMenu, MF_STRING | MF_POPUP, (UINT)hMenuItem,
397 _FROMMB(text.psz_string ? text.psz_string : psz_var) );
398 if( text.psz_string ) free( text.psz_string );
402 switch( i_type & VLC_VAR_TYPE )
405 AppendMenu( hMenu, MF_STRING , ++(*pi_item_id),
406 _FROMMB(text.psz_string ? text.psz_string : psz_var) );
407 pMenuItemExt = new MenuItemExt( p_intf, *pi_item_id, psz_var,
408 p_object->i_object_id, val, i_type );
409 _p_menuList->push_back( pMenuItemExt );
413 val.b_bool = !val.b_bool;
414 AppendMenu( hMenu, MF_STRING | MF_CHECKED, ++(*pi_item_id),
415 _FROMMB(text.psz_string ? text.psz_string : psz_var) );
416 pMenuItemExt = new MenuItemExt( p_intf, *pi_item_id, psz_var,
417 p_object->i_object_id, val, i_type );
418 _p_menuList->push_back( pMenuItemExt );
419 CheckMenuItem( hMenu, *pi_item_id ,
420 ( val.b_bool ? MF_UNCHECKED : MF_CHECKED ) |
425 if( text.psz_string ) free( text.psz_string );
429 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
430 if( text.psz_string ) free( text.psz_string );
433 HMENU CreateChoicesMenu( intf_thread_t *p_intf,
434 vector<MenuItemExt*> *_p_menuList, char *psz_var,
435 vlc_object_t *p_object, int *pi_item_id )
437 MenuItemExt *pMenuItemExt;
438 vlc_value_t val, val_list, text_list;
440 HMENU hSubMenu = CreatePopupMenu();
442 /* Check the type of the object variable */
443 i_type = var_Type( p_object, psz_var );
445 /* Make sure we want to display the variable */
446 if( i_type & VLC_VAR_HASCHOICE )
448 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
449 if( val.i_int == 0 ) return NULL;
450 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
458 switch( i_type & VLC_VAR_TYPE )
462 case VLC_VAR_VARIABLE:
464 case VLC_VAR_INTEGER:
467 /* Variable doesn't exist or isn't handled */
471 if( var_Get( p_object, psz_var, &val ) < 0 ) return NULL;
473 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
474 &val_list, &text_list ) < 0 )
476 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
480 for( i = 0; i < val_list.p_list->i_count; i++ )
482 vlc_value_t another_val;
486 switch( i_type & VLC_VAR_TYPE )
488 case VLC_VAR_VARIABLE:
489 hMenuItem = CreateChoicesMenu( p_intf, _p_menuList,
490 val_list.p_list->p_values[i].psz_string, p_object, pi_item_id );
491 AppendMenu( hSubMenu, MF_STRING | MF_POPUP, (UINT)hMenuItem,
492 _FROMMB(text_list.p_list->p_values[i].psz_string ?
493 text_list.p_list->p_values[i].psz_string :
494 val_list.p_list->p_values[i].psz_string) );
498 another_val.psz_string =
499 strdup(val_list.p_list->p_values[i].psz_string);
500 AppendMenu( hSubMenu, MF_STRING, ++(*pi_item_id),
501 _FROMMB(text_list.p_list->p_values[i].psz_string ?
502 text_list.p_list->p_values[i].psz_string :
503 val_list.p_list->p_values[i].psz_string) );
504 pMenuItemExt = new MenuItemExt( p_intf, *pi_item_id, psz_var,
505 p_object->i_object_id, another_val, i_type );
506 _p_menuList->push_back( pMenuItemExt );
508 if( !(i_type & VLC_VAR_ISCOMMAND) && val.psz_string &&
509 !strcmp( val.psz_string,
510 val_list.p_list->p_values[i].psz_string ) )
511 CheckMenuItem( hSubMenu, *pi_item_id, MF_CHECKED | MF_BYCOMMAND);
514 case VLC_VAR_INTEGER:
515 asprintf( &psz_tmp, "%d", val_list.p_list->p_values[i].i_int );
516 AppendMenu( hSubMenu, MF_STRING, ++(*pi_item_id),
517 _FROMMB(text_list.p_list->p_values[i].psz_string ?
518 text_list.p_list->p_values[i].psz_string : psz_tmp));
519 pMenuItemExt = new MenuItemExt( p_intf, *pi_item_id, psz_var,
520 p_object->i_object_id, val_list.p_list->p_values[i], i_type );
521 _p_menuList->push_back( pMenuItemExt );
523 if( val_list.p_list->p_values[i].i_int == val.i_int )
524 CheckMenuItem( hSubMenu, *pi_item_id, MF_CHECKED | MF_BYCOMMAND);
532 /* Clean up everything */
533 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
534 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
539 int wce_GetMenuItemCount(HMENU hMenu)
541 const int MAX_NUM_ITEMS = 256;
545 memset( (char *)&mii, 0, sizeof(MENUITEMINFO) );
546 mii.cbSize = sizeof(MENUITEMINFO);
549 for( iPos = 0; iPos < MAX_NUM_ITEMS; iPos++ )
551 if( !GetMenuItemInfo(hMenu, (UINT)iPos, TRUE, &mii) ) break;
558 void OnMenuEvent( intf_thread_t *p_intf, int id )
560 MenuItemExt *p_menuitemext = NULL;
561 vector<MenuItemExt*>::iterator iter;
563 for( iter = p_intf->p_sys->p_settings_menu->begin();
564 iter != p_intf->p_sys->p_settings_menu->end(); iter++ )
565 if( (*iter)->id == id )
567 p_menuitemext = *iter;
570 for( iter = p_intf->p_sys->p_audio_menu->begin();
571 iter != p_intf->p_sys->p_audio_menu->end(); iter++ )
572 if( (*iter)->id == id )
574 p_menuitemext = *iter;
577 for( iter = p_intf->p_sys->p_video_menu->begin();
578 iter != p_intf->p_sys->p_video_menu->end(); iter++ )
579 if( (*iter)->id == id )
581 p_menuitemext = *iter;
584 for( iter = p_intf->p_sys->p_navig_menu->begin();
585 iter != p_intf->p_sys->p_navig_menu->end(); iter++ )
586 if( (*iter)->id == id )
588 p_menuitemext = *iter;
594 vlc_object_t *p_object = (vlc_object_t *)
595 vlc_object_get( p_intf, p_menuitemext->i_object_id );
596 if( p_object == NULL ) return;
598 var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val );
599 int i_type = var_Type( p_object, p_menuitemext->psz_var );
600 switch( i_type & VLC_VAR_TYPE )
604 case VLC_VAR_VARIABLE:
606 case VLC_VAR_INTEGER:
609 /* Variable doesn't exist or isn't handled */
613 vlc_object_release( p_object );
617 /*****************************************************************************
618 * A small helper class which encapsulate wxMenuitem with some other useful
620 *****************************************************************************/
621 MenuItemExt::MenuItemExt( intf_thread_t *p_intf, int _id, char *_psz_var,
622 int _i_object_id, vlc_value_t _val, int _i_val_type )
624 /* Initializations */
627 psz_var = strdup( _psz_var );
628 i_val_type = _i_val_type;
629 i_object_id = _i_object_id;
633 MenuItemExt::~MenuItemExt()
635 if( psz_var ) free( psz_var );
636 if( ((i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
637 && val.psz_string ) free( val.psz_string );