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() */
41 /*****************************************************************************
43 *****************************************************************************/
45 /* IDs for the controls and the menu commands */
49 MenuDummy_Event = 1000,
50 OpenFileSimple_Event = 1100,
54 FirstAutoGenerated_Event = 1999,
55 SettingsMenu_Events = 2000,
56 AudioMenu_Events = 3000,
57 VideoMenu_Events = 4000,
58 NavigMenu_Events = 5000,
59 PopupMenu_Events = 6000
62 void RefreshAudioMenu( intf_thread_t *p_intf, HMENU hMenu )
64 #define MAX_AUDIO_ITEMS 10
66 vlc_object_t *p_object;
67 char *ppsz_varnames[MAX_AUDIO_ITEMS];
68 int pi_objects[MAX_AUDIO_ITEMS];
69 vector<MenuItemExt*>::iterator iter;
73 int count = wce_GetMenuItemCount( hMenu );
74 for( i = 0; i <= count; i++ ) RemoveMenu( hMenu, 0, MF_BYPOSITION );
76 if( p_intf->p_sys->p_audio_menu )
78 for( iter = p_intf->p_sys->p_audio_menu->begin();
79 iter != p_intf->p_sys->p_audio_menu->end(); iter++ )
81 p_intf->p_sys->p_audio_menu->clear();
83 else p_intf->p_sys->p_audio_menu = new vector<MenuItemExt*>;
86 memset( pi_objects, 0, MAX_AUDIO_ITEMS * sizeof(int) );
89 p_object = (vlc_object_t *)
90 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
91 if( p_object != NULL )
93 ppsz_varnames[i] = "audio-es";
94 pi_objects[i++] = p_object->i_object_id;
95 vlc_object_release( p_object );
98 p_object = (vlc_object_t *)
99 vlc_object_find( p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE );
100 if( p_object != NULL )
102 ppsz_varnames[i] = "audio-device";
103 pi_objects[i++] = p_object->i_object_id;
104 ppsz_varnames[i] = "audio-channels";
105 pi_objects[i++] = p_object->i_object_id;
106 ppsz_varnames[i] = "visual";
107 pi_objects[i++] = p_object->i_object_id;
108 vlc_object_release( p_object );
112 RefreshMenu( p_intf, p_intf->p_sys->p_audio_menu,
113 hMenu, i, ppsz_varnames, pi_objects, AudioMenu_Events );
116 void RefreshVideoMenu( intf_thread_t *p_intf, HMENU hMenu )
118 #define MAX_VIDEO_ITEMS 15
120 vlc_object_t *p_object;
121 char *ppsz_varnames[MAX_VIDEO_ITEMS];
122 int pi_objects[MAX_VIDEO_ITEMS];
123 vector<MenuItemExt*>::iterator iter;
126 /* Delete old menu */
127 int count = wce_GetMenuItemCount( hMenu );
128 for( i = 0; i <= count; i++ ) RemoveMenu( hMenu, 0, MF_BYPOSITION );
130 if( p_intf->p_sys->p_video_menu )
132 for( iter = p_intf->p_sys->p_video_menu->begin();
133 iter != p_intf->p_sys->p_video_menu->end(); iter++ )
135 p_intf->p_sys->p_video_menu->clear();
137 else p_intf->p_sys->p_video_menu = new vector<MenuItemExt*>;
139 /* Initializations */
140 memset( pi_objects, 0, MAX_VIDEO_ITEMS * sizeof(int) );
143 p_object = (vlc_object_t *)
144 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
145 if( p_object != NULL )
147 ppsz_varnames[i] = "video-es";
148 pi_objects[i++] = p_object->i_object_id;
149 ppsz_varnames[i] = "spu-es";
150 pi_objects[i++] = p_object->i_object_id;
151 vlc_object_release( p_object );
154 p_object = (vlc_object_t *)
155 vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
156 if( p_object != NULL )
158 vlc_object_t *p_dec_obj;
160 ppsz_varnames[i] = "fullscreen";
161 pi_objects[i++] = p_object->i_object_id;
163 ppsz_varnames[i] = "transform";
164 pi_objects[i++] = p_object->i_object_id;
166 ppsz_varnames[i] = "zoom";
167 pi_objects[i++] = p_object->i_object_id;
168 ppsz_varnames[i] = "deinterlace";
169 pi_objects[i++] = p_object->i_object_id;
170 ppsz_varnames[i] = "aspect-ratio";
171 pi_objects[i++] = p_object->i_object_id;
172 ppsz_varnames[i] = "crop";
173 pi_objects[i++] = p_object->i_object_id;
174 ppsz_varnames[i] = "directx-on-top";
175 pi_objects[i++] = p_object->i_object_id;
177 p_dec_obj = (vlc_object_t *)
178 vlc_object_find( p_object, VLC_OBJECT_DECODER, FIND_PARENT );
179 if( p_dec_obj != NULL )
181 ppsz_varnames[i] = "ffmpeg-pp-q";
182 pi_objects[i++] = p_dec_obj->i_object_id;
183 vlc_object_release( p_dec_obj );
186 vlc_object_release( p_object );
190 RefreshMenu( p_intf, p_intf->p_sys->p_video_menu, hMenu, i,
191 ppsz_varnames, pi_objects, VideoMenu_Events );
194 void RefreshNavigMenu( intf_thread_t *p_intf, HMENU hMenu )
196 #define MAX_NAVIG_ITEMS 10
198 vlc_object_t *p_object;
199 char *ppsz_varnames[MAX_NAVIG_ITEMS];
200 int pi_objects[MAX_NAVIG_ITEMS];
201 vector<MenuItemExt*>::iterator iter;
204 /* Delete old menu */
205 int count = wce_GetMenuItemCount( hMenu );
206 for( i = 0; i <= count; i++ ) RemoveMenu( hMenu, 0, MF_BYPOSITION );
208 if( p_intf->p_sys->p_navig_menu )
210 for( iter = p_intf->p_sys->p_navig_menu->begin();
211 iter != p_intf->p_sys->p_navig_menu->end(); iter++ )
213 p_intf->p_sys->p_navig_menu->clear();
215 else p_intf->p_sys->p_navig_menu = new vector<MenuItemExt*>;
217 /* Initializations */
218 memset( pi_objects, 0, MAX_NAVIG_ITEMS * sizeof(int) );
221 p_object = (vlc_object_t *)
222 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
223 if( p_object != NULL )
225 ppsz_varnames[i] = "title";
226 pi_objects[i++] = p_object->i_object_id;
227 ppsz_varnames[i] = "chapter";
228 pi_objects[i++] = p_object->i_object_id;
229 ppsz_varnames[i] = "program";
230 pi_objects[i++] = p_object->i_object_id;
231 ppsz_varnames[i] = "navigation";
232 pi_objects[i++] = p_object->i_object_id;
233 ppsz_varnames[i] = "dvd_menus";
234 pi_objects[i++] = p_object->i_object_id;
236 ppsz_varnames[i] = "prev-title";
237 pi_objects[i++] = p_object->i_object_id;
238 ppsz_varnames[i] = "next-title";
239 pi_objects[i++] = p_object->i_object_id;
240 ppsz_varnames[i] = "prev-chapter";
241 pi_objects[i++] = p_object->i_object_id;
242 ppsz_varnames[i] = "next-chapter";
243 pi_objects[i++] = p_object->i_object_id;
245 vlc_object_release( p_object );
249 RefreshMenu( p_intf, p_intf->p_sys->p_navig_menu, hMenu, i,
250 ppsz_varnames, pi_objects, NavigMenu_Events );
253 void RefreshSettingsMenu( intf_thread_t *p_intf, HMENU hMenu )
255 #define MAX_SETTINGS_ITEMS 10
257 vlc_object_t *p_object;
258 char *ppsz_varnames[MAX_SETTINGS_ITEMS];
259 int pi_objects[MAX_SETTINGS_ITEMS];
260 vector<MenuItemExt*>::iterator iter;
263 /* Delete old menu */
264 int count = wce_GetMenuItemCount( hMenu );
265 for( i = 0; i <= count; i++ ) RemoveMenu( hMenu, 0, MF_BYPOSITION );
267 if( p_intf->p_sys->p_settings_menu )
269 for( iter = p_intf->p_sys->p_settings_menu->begin();
270 iter != p_intf->p_sys->p_settings_menu->end(); iter++ )
272 p_intf->p_sys->p_settings_menu->clear();
274 else p_intf->p_sys->p_settings_menu = new vector<MenuItemExt*>;
276 /* Initializations */
277 memset( pi_objects, 0, MAX_SETTINGS_ITEMS * sizeof(int) );
280 AppendMenu( hMenu, MF_STRING, ID_SETTINGS_EXTEND, _T("&Extended GUI") );
281 AppendMenu( hMenu, MF_STRING, ID_SETTINGS_PREF, _T("&Preferences...") );
283 p_object = (vlc_object_t *)
284 vlc_object_find( p_intf, VLC_OBJECT_INTF, FIND_PARENT );
285 if( p_object != NULL )
287 ppsz_varnames[i] = "intf-switch";
288 pi_objects[i++] = p_object->i_object_id;
289 ppsz_varnames[i] = "intf-add";
290 pi_objects[i++] = p_object->i_object_id;
291 vlc_object_release( p_object );
295 RefreshMenu( p_intf, p_intf->p_sys->p_settings_menu, hMenu, i,
296 ppsz_varnames, pi_objects, SettingsMenu_Events );
299 /*****************************************************************************
301 *****************************************************************************/
302 void RefreshMenu( intf_thread_t *p_intf, vector<MenuItemExt*> *_p_menuList,
303 HMENU hMenu , int i_count, char **ppsz_varnames,
304 int *pi_objects, int i_start_id )
306 vlc_object_t *p_object;
307 vlc_bool_t b_section_empty = VLC_FALSE;
310 /* Initializations */
311 int i_item_id = i_start_id;
313 for( i = 0; i < i_count; i++ )
315 if( !ppsz_varnames[i] )
317 if( b_section_empty )
319 AppendMenu( hMenu, MF_GRAYED | MF_STRING,
320 MenuDummy_Event + i, _T("Empty") );
323 AppendMenu( hMenu, MF_SEPARATOR, 0, _T("") );
324 b_section_empty = VLC_TRUE;
330 AppendMenu( hMenu, MF_GRAYED | MF_STRING,
331 MenuDummy_Event, _FROMMB(ppsz_varnames[i]) );
333 b_section_empty = VLC_FALSE;
337 p_object = (vlc_object_t *)vlc_object_get( p_intf, pi_objects[i] );
338 if( p_object == NULL ) continue;
340 b_section_empty = VLC_FALSE;
341 CreateMenuItem( p_intf, _p_menuList, hMenu, ppsz_varnames[i],
342 p_object, &i_item_id );
343 vlc_object_release( p_object );
346 /* Special case for empty menus */
347 if( wce_GetMenuItemCount(hMenu) == 0 || b_section_empty )
349 AppendMenu( hMenu, MF_GRAYED | MF_STRING,
350 MenuDummy_Event + i, _T("Empty") );
354 /*****************************************************************************
356 *****************************************************************************/
357 void CreateMenuItem( intf_thread_t *p_intf, vector<MenuItemExt*> *_p_menuList,
358 HMENU hMenu, char *psz_var, vlc_object_t *p_object,
361 MenuItemExt *pMenuItemExt;
363 vlc_value_t val, text;
366 /* Check the type of the object variable */
367 i_type = var_Type( p_object, psz_var );
369 switch( i_type & VLC_VAR_TYPE )
373 case VLC_VAR_VARIABLE:
375 case VLC_VAR_INTEGER:
379 /* Variable doesn't exist or isn't handled */
383 /* Make sure we want to display the variable */
384 if( i_type & VLC_VAR_HASCHOICE )
386 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
387 if( val.i_int == 0 ) return;
388 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
392 /* Get the descriptive name of the variable */
393 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
395 var_Get( p_object, psz_var, &val );
397 if( i_type & VLC_VAR_HASCHOICE )
399 hMenuItem = CreateChoicesMenu( p_intf, _p_menuList, psz_var,
400 p_object, pi_item_id );
401 AppendMenu( hMenu, MF_STRING | MF_POPUP, (UINT)hMenuItem,
402 _FROMMB(text.psz_string ? text.psz_string : psz_var) );
403 if( text.psz_string ) free( text.psz_string );
407 switch( i_type & VLC_VAR_TYPE )
410 AppendMenu( hMenu, MF_STRING , ++(*pi_item_id),
411 _FROMMB(text.psz_string ? text.psz_string : psz_var) );
412 pMenuItemExt = new MenuItemExt( p_intf, *pi_item_id, psz_var,
413 p_object->i_object_id, val, i_type );
414 _p_menuList->push_back( pMenuItemExt );
418 val.b_bool = !val.b_bool;
419 AppendMenu( hMenu, MF_STRING | MF_CHECKED, ++(*pi_item_id),
420 _FROMMB(text.psz_string ? text.psz_string : psz_var) );
421 pMenuItemExt = new MenuItemExt( p_intf, *pi_item_id, psz_var,
422 p_object->i_object_id, val, i_type );
423 _p_menuList->push_back( pMenuItemExt );
424 CheckMenuItem( hMenu, *pi_item_id ,
425 ( val.b_bool ? MF_UNCHECKED : MF_CHECKED ) |
430 if( text.psz_string ) free( text.psz_string );
434 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
435 if( text.psz_string ) free( text.psz_string );
438 HMENU CreateChoicesMenu( intf_thread_t *p_intf,
439 vector<MenuItemExt*> *_p_menuList, char *psz_var,
440 vlc_object_t *p_object, int *pi_item_id )
442 MenuItemExt *pMenuItemExt;
443 vlc_value_t val, val_list, text_list;
445 HMENU hSubMenu = CreatePopupMenu();
447 /* Check the type of the object variable */
448 i_type = var_Type( p_object, psz_var );
450 /* Make sure we want to display the variable */
451 if( i_type & VLC_VAR_HASCHOICE )
453 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
454 if( val.i_int == 0 ) return NULL;
455 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
463 switch( i_type & VLC_VAR_TYPE )
467 case VLC_VAR_VARIABLE:
469 case VLC_VAR_INTEGER:
472 /* Variable doesn't exist or isn't handled */
476 if( var_Get( p_object, psz_var, &val ) < 0 ) return NULL;
478 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
479 &val_list, &text_list ) < 0 )
481 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
485 for( i = 0; i < val_list.p_list->i_count; i++ )
487 vlc_value_t another_val;
491 switch( i_type & VLC_VAR_TYPE )
493 case VLC_VAR_VARIABLE:
494 hMenuItem = CreateChoicesMenu( p_intf, _p_menuList,
495 val_list.p_list->p_values[i].psz_string, p_object, pi_item_id );
496 AppendMenu( hSubMenu, MF_STRING | MF_POPUP, (UINT)hMenuItem,
497 _FROMMB(text_list.p_list->p_values[i].psz_string ?
498 text_list.p_list->p_values[i].psz_string :
499 val_list.p_list->p_values[i].psz_string) );
503 another_val.psz_string =
504 strdup(val_list.p_list->p_values[i].psz_string);
505 AppendMenu( hSubMenu, MF_STRING, ++(*pi_item_id),
506 _FROMMB(text_list.p_list->p_values[i].psz_string ?
507 text_list.p_list->p_values[i].psz_string :
508 val_list.p_list->p_values[i].psz_string) );
509 pMenuItemExt = new MenuItemExt( p_intf, *pi_item_id, psz_var,
510 p_object->i_object_id, another_val, i_type );
511 _p_menuList->push_back( pMenuItemExt );
513 if( !(i_type & VLC_VAR_ISCOMMAND) && val.psz_string &&
514 !strcmp( val.psz_string,
515 val_list.p_list->p_values[i].psz_string ) )
516 CheckMenuItem( hSubMenu, *pi_item_id, MF_CHECKED | MF_BYCOMMAND);
519 case VLC_VAR_INTEGER:
520 asprintf( &psz_tmp, "%d", val_list.p_list->p_values[i].i_int );
521 AppendMenu( hSubMenu, MF_STRING, ++(*pi_item_id),
522 _FROMMB(text_list.p_list->p_values[i].psz_string ?
523 text_list.p_list->p_values[i].psz_string : psz_tmp));
524 pMenuItemExt = new MenuItemExt( p_intf, *pi_item_id, psz_var,
525 p_object->i_object_id, val_list.p_list->p_values[i], i_type );
526 _p_menuList->push_back( pMenuItemExt );
528 if( val_list.p_list->p_values[i].i_int == val.i_int )
529 CheckMenuItem( hSubMenu, *pi_item_id, MF_CHECKED | MF_BYCOMMAND);
537 /* Clean up everything */
538 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
539 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
544 int wce_GetMenuItemCount(HMENU hMenu)
546 const int MAX_NUM_ITEMS = 256;
550 memset( (char *)&mii, 0, sizeof(MENUITEMINFO) );
551 mii.cbSize = sizeof(MENUITEMINFO);
554 for( iPos = 0; iPos < MAX_NUM_ITEMS; iPos++ )
556 if( !GetMenuItemInfo(hMenu, (UINT)iPos, TRUE, &mii) ) break;
563 void OnMenuEvent( intf_thread_t *p_intf, int id )
565 MenuItemExt *p_menuitemext = NULL;
566 vector<MenuItemExt*>::iterator iter;
568 for( iter = p_intf->p_sys->p_settings_menu->begin();
569 iter != p_intf->p_sys->p_settings_menu->end(); iter++ )
570 if( (*iter)->id == id )
572 p_menuitemext = *iter;
575 for( iter = p_intf->p_sys->p_audio_menu->begin();
576 iter != p_intf->p_sys->p_audio_menu->end(); iter++ )
577 if( (*iter)->id == id )
579 p_menuitemext = *iter;
582 for( iter = p_intf->p_sys->p_video_menu->begin();
583 iter != p_intf->p_sys->p_video_menu->end(); iter++ )
584 if( (*iter)->id == id )
586 p_menuitemext = *iter;
589 for( iter = p_intf->p_sys->p_navig_menu->begin();
590 iter != p_intf->p_sys->p_navig_menu->end(); iter++ )
591 if( (*iter)->id == id )
593 p_menuitemext = *iter;
599 vlc_object_t *p_object = (vlc_object_t *)
600 vlc_object_get( p_intf, p_menuitemext->i_object_id );
601 if( p_object == NULL ) return;
603 var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val );
604 int i_type = var_Type( p_object, p_menuitemext->psz_var );
605 switch( i_type & VLC_VAR_TYPE )
609 case VLC_VAR_VARIABLE:
611 case VLC_VAR_INTEGER:
614 /* Variable doesn't exist or isn't handled */
618 vlc_object_release( p_object );
622 /*****************************************************************************
623 * A small helper class which encapsulate wxMenuitem with some other useful
625 *****************************************************************************/
626 MenuItemExt::MenuItemExt( intf_thread_t *p_intf, int _id, char *_psz_var,
627 int _i_object_id, vlc_value_t _val, int _i_val_type )
629 /* Initializations */
632 psz_var = strdup( _psz_var );
633 i_val_type = _i_val_type;
634 i_object_id = _i_object_id;
638 MenuItemExt::~MenuItemExt()
640 if( psz_var ) free( psz_var );
641 if( ((i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
642 && val.psz_string ) free( val.psz_string );