Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

menus.cpp

00001 /*****************************************************************************
00002  * menus.cpp : WinCE gui plugin for VLC
00003  *****************************************************************************
00004  * Copyright (C) 2000-2004 the VideoLAN team
00005  * $Id: menus.cpp 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Marodon Cedric <[email protected]>
00008  *          Gildas Bazin <[email protected]>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 /*****************************************************************************
00026  * Preamble
00027  *****************************************************************************/
00028 #include <stdlib.h>                                      /* malloc(), free() */
00029 #include <string.h>                                            /* strerror() */
00030 #include <stdio.h>
00031 #include <vlc/vlc.h>
00032 #include <vlc/intf.h>
00033 
00034 #include "wince.h"
00035 
00036 /*****************************************************************************
00037  * Event Table.
00038  *****************************************************************************/
00039 
00040 /* IDs for the controls and the menu commands */
00041 enum
00042 {
00043     /* menu items */
00044     MenuDummy_Event = 1000,
00045     OpenFileSimple_Event = 1100,
00046     OpenFile_Event,
00047     OpenDisc_Event,
00048     OpenNet_Event,
00049     FirstAutoGenerated_Event = 1999,
00050     SettingsMenu_Events = 2000,
00051     AudioMenu_Events = 3000,
00052     VideoMenu_Events = 4000,
00053     NavigMenu_Events = 5000,
00054     PopupMenu_Events = 6000
00055 };
00056 
00057 HMENU OpenStreamMenu( intf_thread_t *p_intf )
00058 {
00059     HMENU hmenu = CreatePopupMenu();
00060     AppendMenu( hmenu, MF_STRING, ID_FILE_QUICKOPEN,
00061                 _T("Quick &Open File...") );
00062     AppendMenu( hmenu, MF_STRING, ID_FILE_OPENFILE,
00063                 _T("Open &File...") );
00064     AppendMenu( hmenu, MF_STRING, ID_FILE_OPENNET,
00065                 _T("Open &Network Stream...") );
00066     return hmenu;
00067 }
00068 
00069 HMENU MiscMenu( intf_thread_t *p_intf )
00070 {
00071     HMENU hmenu = CreatePopupMenu();
00072     AppendMenu( hmenu, MF_STRING, ID_VIEW_STREAMINFO, _T("Media &Info...") );
00073     AppendMenu( hmenu, MF_STRING, ID_VIEW_MESSAGES, _T("&Messages...") );
00074     AppendMenu( hmenu, MF_STRING, ID_PREFERENCES, _T("&Preferences...") );
00075     return hmenu;
00076 }
00077 
00078 void PopupMenu( intf_thread_t *p_intf, HWND p_parent, POINT point )
00079 {
00080 #define MAX_POPUP_ITEMS 45
00081 
00082     vlc_object_t *p_object, *p_input;
00083     char *ppsz_varnames[MAX_POPUP_ITEMS];
00084     int pi_objects[MAX_POPUP_ITEMS];
00085     int i = 0, i_last_separator = 0;
00086 
00087     /* Initializations */
00088     memset( pi_objects, 0, MAX_POPUP_ITEMS * sizeof(int) );
00089 
00090     ppsz_varnames[i] = "VLC media player";
00091     pi_objects[i++] = 0;
00092     ppsz_varnames[i++] = NULL; /* Separator */
00093     i_last_separator = i;
00094 
00095     /* Input menu */
00096     p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
00097                                                 FIND_ANYWHERE );
00098     if( p_object != NULL )
00099     {
00100         ppsz_varnames[i] = "bookmark";
00101         pi_objects[i++] = p_object->i_object_id;
00102         ppsz_varnames[i] = "title";
00103         pi_objects[i++] = p_object->i_object_id;
00104         ppsz_varnames[i] = "chapter";
00105         pi_objects[i++] = p_object->i_object_id;
00106         ppsz_varnames[i] = "program";
00107         pi_objects[i++] = p_object->i_object_id;
00108         ppsz_varnames[i] = "navigation";
00109         pi_objects[i++] = p_object->i_object_id;
00110         ppsz_varnames[i] = "dvd_menus";
00111         pi_objects[i++] = p_object->i_object_id;
00112 
00113         ppsz_varnames[i] = "video-es";
00114         pi_objects[i++] = p_object->i_object_id;
00115         ppsz_varnames[i] = "audio-es";
00116         pi_objects[i++] = p_object->i_object_id;
00117         ppsz_varnames[i] = "spu-es";
00118         pi_objects[i++] = p_object->i_object_id;
00119     }
00120     p_input = p_object;
00121     if( !p_input ) goto interfacemenu;
00122 
00123     /* Video menu */
00124     if( i != i_last_separator ) ppsz_varnames[i++] = NULL; /* Separator */
00125     i_last_separator = i;
00126 
00127     p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
00128                                                 FIND_ANYWHERE );
00129     if( p_object != NULL )
00130     {
00131         vlc_object_t *p_dec_obj;
00132 
00133         ppsz_varnames[i] = "fullscreen";
00134         pi_objects[i++] = p_object->i_object_id;
00135         ppsz_varnames[i] = "zoom";
00136         pi_objects[i++] = p_object->i_object_id;
00137         ppsz_varnames[i] = "deinterlace";
00138         pi_objects[i++] = p_object->i_object_id;
00139         ppsz_varnames[i] = "aspect-ratio";
00140         pi_objects[i++] = p_object->i_object_id;
00141         ppsz_varnames[i] = "crop";
00142         pi_objects[i++] = p_object->i_object_id;
00143         ppsz_varnames[i] = "video-on-top";
00144         pi_objects[i++] = p_object->i_object_id;
00145         ppsz_varnames[i] = "directx-wallpaper";
00146         pi_objects[i++] = p_object->i_object_id;
00147         ppsz_varnames[i] = "video-snapshot";
00148         pi_objects[i++] = p_object->i_object_id;
00149 
00150         p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
00151                                                      VLC_OBJECT_DECODER,
00152                                                      FIND_PARENT );
00153         if( p_dec_obj != NULL )
00154         {
00155             ppsz_varnames[i] = "ffmpeg-pp-q";
00156             pi_objects[i++] = p_dec_obj->i_object_id;
00157             vlc_object_release( p_dec_obj );
00158         }
00159 
00160         vlc_object_release( p_object );
00161     }
00162 
00163     /* Audio menu */
00164     if( i != i_last_separator ) ppsz_varnames[i++] = NULL; /* Separator */
00165     i_last_separator  = i;
00166 
00167     p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
00168                                                 FIND_ANYWHERE );
00169     if( p_object != NULL )
00170     {
00171         ppsz_varnames[i] = "audio-device";
00172         pi_objects[i++] = p_object->i_object_id;
00173         ppsz_varnames[i] = "audio-channels";
00174         pi_objects[i++] = p_object->i_object_id;
00175         ppsz_varnames[i] = "visual";
00176         pi_objects[i++] = p_object->i_object_id;
00177         ppsz_varnames[i] = "equalizer";
00178         pi_objects[i++] = p_object->i_object_id;
00179         vlc_object_release( p_object );
00180     }
00181 
00182  interfacemenu:
00183     /* Interface menu */
00184     if( i != i_last_separator ) ppsz_varnames[i++] = NULL; /* Separator */
00185     i_last_separator = i;
00186 
00187     /* vlc_object_find is needed because of the dialogs provider case */
00188     p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INTF,
00189                                                 FIND_PARENT );
00190     if( p_object != NULL )
00191     {
00192         /* Nothing for now */
00193         vlc_object_release( p_object );
00194     }
00195 
00196     /* Build menu */
00197     vector<MenuItemExt*> popup_menu;
00198     HMENU hmenu = CreatePopupMenu();
00199     RefreshMenu( p_intf, &popup_menu, hmenu, i,
00200                  ppsz_varnames, pi_objects, PopupMenu_Events );
00201     MenuItemExt::ClearList( &popup_menu );
00202 
00203 
00204     /* Add static entries */
00205     if( p_input != NULL )
00206     {
00207         vlc_value_t val;
00208         AppendMenu( hmenu, MF_SEPARATOR, 0, _T("") );
00209         AppendMenu( hmenu, MF_STRING, StopStream_Event, _T("Stop") );
00210         AppendMenu( hmenu, MF_STRING, PrevStream_Event, _T("Previous") );
00211         AppendMenu( hmenu, MF_STRING, NextStream_Event, _T("Next") );
00212 
00213         var_Get( p_input, "state", &val );
00214         if( val.i_int == PAUSE_S )
00215             AppendMenu( hmenu, MF_STRING, PlayStream_Event, _T("Play") );
00216         else
00217             AppendMenu( hmenu, MF_STRING, PlayStream_Event, _T("Pause") );
00218 
00219         vlc_object_release( p_input );
00220     }
00221     else
00222     {
00223         playlist_t * p_playlist =
00224             (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
00225                                            FIND_ANYWHERE );
00226         if( p_playlist && p_playlist->i_size )
00227         {
00228             AppendMenu( hmenu, MF_SEPARATOR, 0, _T("") );
00229             AppendMenu( hmenu, MF_STRING, PlayStream_Event, _T("Play") );
00230         }
00231         if( p_playlist ) vlc_object_release( p_playlist );
00232     }
00233 
00234     AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)MiscMenu( p_intf ),
00235                 _T("Miscellaneous") );
00236     AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)OpenStreamMenu( p_intf ),
00237                 _T("Open") );
00238 
00239     TrackPopupMenu( hmenu, 0, point.x, point.y, 0, p_parent, 0 );
00240     PostMessage( p_parent, WM_NULL, 0, 0 );
00241     DestroyMenu( hmenu );
00242 }
00243 
00244 void RefreshAudioMenu( intf_thread_t *p_intf, HMENU hMenu )
00245 {
00246 #define MAX_AUDIO_ITEMS 10
00247 
00248     vlc_object_t *p_object;
00249     char *ppsz_varnames[MAX_AUDIO_ITEMS];
00250     int pi_objects[MAX_AUDIO_ITEMS];
00251     int i;
00252 
00253     /* Delete old menu */
00254     int count = wce_GetMenuItemCount( hMenu );
00255     for( i = 0; i <= count; i++ ) RemoveMenu( hMenu, 0, MF_BYPOSITION );
00256 
00257     if( p_intf->p_sys->p_audio_menu )
00258         MenuItemExt::ClearList( p_intf->p_sys->p_audio_menu );
00259     else p_intf->p_sys->p_audio_menu = new vector<MenuItemExt*>;
00260 
00261 
00262     /* Initializations */
00263     memset( pi_objects, 0, MAX_AUDIO_ITEMS * sizeof(int) );
00264     i = 0;
00265 
00266     p_object = (vlc_object_t *)
00267         vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
00268     if( p_object != NULL )
00269     {
00270         ppsz_varnames[i] = "audio-es";
00271         pi_objects[i++] = p_object->i_object_id;
00272         vlc_object_release( p_object );
00273     }
00274 
00275     p_object = (vlc_object_t *)
00276         vlc_object_find( p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE );
00277     if( p_object != NULL )
00278     {
00279         ppsz_varnames[i] = "audio-device";
00280         pi_objects[i++] = p_object->i_object_id;
00281         ppsz_varnames[i] = "audio-channels";
00282         pi_objects[i++] = p_object->i_object_id;
00283         ppsz_varnames[i] = "visual";
00284         pi_objects[i++] = p_object->i_object_id;
00285         vlc_object_release( p_object );
00286     }
00287 
00288     /* Build menu */
00289     RefreshMenu( p_intf, p_intf->p_sys->p_audio_menu,
00290                  hMenu, i, ppsz_varnames, pi_objects, AudioMenu_Events );
00291 }
00292 
00293 void RefreshVideoMenu( intf_thread_t *p_intf, HMENU hMenu )
00294 {
00295 #define MAX_VIDEO_ITEMS 15
00296 
00297     vlc_object_t *p_object;
00298     char *ppsz_varnames[MAX_VIDEO_ITEMS];
00299     int pi_objects[MAX_VIDEO_ITEMS];
00300     int i;
00301 
00302     /* Delete old menu */
00303     int count = wce_GetMenuItemCount( hMenu );
00304     for( i = 0; i <= count; i++ ) RemoveMenu( hMenu, 0, MF_BYPOSITION );
00305 
00306     if( p_intf->p_sys->p_video_menu )
00307         MenuItemExt::ClearList( p_intf->p_sys->p_video_menu );
00308     else p_intf->p_sys->p_video_menu = new vector<MenuItemExt*>;
00309 
00310     /* Initializations */
00311     memset( pi_objects, 0, MAX_VIDEO_ITEMS * sizeof(int) );
00312     i = 0;
00313 
00314     p_object = (vlc_object_t *)
00315         vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
00316     if( p_object != NULL )
00317     {
00318         ppsz_varnames[i] = "video-es";
00319         pi_objects[i++] = p_object->i_object_id;
00320         ppsz_varnames[i] = "spu-es";
00321         pi_objects[i++] = p_object->i_object_id;
00322         vlc_object_release( p_object );
00323     }
00324 
00325     p_object = (vlc_object_t *)
00326         vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
00327     if( p_object != NULL )
00328     {
00329         vlc_object_t *p_dec_obj;
00330 
00331         ppsz_varnames[i] = "fullscreen";
00332         pi_objects[i++] = p_object->i_object_id;
00333 #ifdef WINCE
00334         ppsz_varnames[i] = "transform";
00335         pi_objects[i++] = p_object->i_object_id;
00336 #endif
00337         ppsz_varnames[i] = "zoom";
00338         pi_objects[i++] = p_object->i_object_id;
00339         ppsz_varnames[i] = "deinterlace";
00340         pi_objects[i++] = p_object->i_object_id;
00341         ppsz_varnames[i] = "aspect-ratio";
00342         pi_objects[i++] = p_object->i_object_id;
00343         ppsz_varnames[i] = "crop";
00344         pi_objects[i++] = p_object->i_object_id;
00345         ppsz_varnames[i] = "directx-on-top";
00346         pi_objects[i++] = p_object->i_object_id;
00347 
00348         p_dec_obj = (vlc_object_t *)
00349             vlc_object_find( p_object, VLC_OBJECT_DECODER, FIND_PARENT );
00350         if( p_dec_obj != NULL )
00351         {
00352             ppsz_varnames[i] = "ffmpeg-pp-q";
00353             pi_objects[i++] = p_dec_obj->i_object_id;
00354             vlc_object_release( p_dec_obj );
00355         }
00356 
00357         vlc_object_release( p_object );
00358     }
00359 
00360     /* Build menu */
00361     RefreshMenu( p_intf, p_intf->p_sys->p_video_menu, hMenu, i,
00362                  ppsz_varnames, pi_objects, VideoMenu_Events );
00363 }
00364 
00365 void RefreshNavigMenu( intf_thread_t *p_intf, HMENU hMenu )
00366 {
00367 #define MAX_NAVIG_ITEMS 10
00368 
00369     vlc_object_t *p_object;
00370     char *ppsz_varnames[MAX_NAVIG_ITEMS];
00371     int pi_objects[MAX_NAVIG_ITEMS];
00372     int i;
00373 
00374     /* Delete old menu */
00375     int count = wce_GetMenuItemCount( hMenu );
00376     for( i = 0; i <= count; i++ ) RemoveMenu( hMenu, 0, MF_BYPOSITION );
00377         
00378     if( p_intf->p_sys->p_navig_menu )
00379         MenuItemExt::ClearList( p_intf->p_sys->p_navig_menu );
00380     else p_intf->p_sys->p_navig_menu = new vector<MenuItemExt*>;
00381 
00382     /* Initializations */
00383     memset( pi_objects, 0, MAX_NAVIG_ITEMS * sizeof(int) );
00384     i = 0;
00385 
00386     p_object = (vlc_object_t *)
00387         vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
00388     if( p_object != NULL )
00389     {
00390         ppsz_varnames[i] = "title";
00391         pi_objects[i++] = p_object->i_object_id;
00392         ppsz_varnames[i] = "chapter";
00393         pi_objects[i++] = p_object->i_object_id;
00394         ppsz_varnames[i] = "program";
00395         pi_objects[i++] = p_object->i_object_id;
00396         ppsz_varnames[i] = "navigation";
00397         pi_objects[i++] = p_object->i_object_id;
00398         ppsz_varnames[i] = "dvd_menus";
00399         pi_objects[i++] = p_object->i_object_id;
00400 
00401         ppsz_varnames[i] = "prev-title";
00402         pi_objects[i++] = p_object->i_object_id;
00403         ppsz_varnames[i] = "next-title";
00404         pi_objects[i++] = p_object->i_object_id;
00405         ppsz_varnames[i] = "prev-chapter";
00406         pi_objects[i++] = p_object->i_object_id;
00407         ppsz_varnames[i] = "next-chapter";
00408         pi_objects[i++] = p_object->i_object_id;
00409 
00410         vlc_object_release( p_object );
00411     }
00412 
00413     /* Build menu */
00414     RefreshMenu( p_intf, p_intf->p_sys->p_navig_menu, hMenu, i,
00415                  ppsz_varnames, pi_objects, NavigMenu_Events );
00416 }
00417 
00418 void RefreshSettingsMenu( intf_thread_t *p_intf, HMENU hMenu )
00419 {
00420 #define MAX_SETTINGS_ITEMS 10
00421 
00422     vlc_object_t *p_object;
00423     char *ppsz_varnames[MAX_SETTINGS_ITEMS];
00424     int pi_objects[MAX_SETTINGS_ITEMS];
00425     int i;
00426 
00427     /* Delete old menu */
00428     int count = wce_GetMenuItemCount( hMenu );
00429     for( i = 0; i <= count; i++ ) RemoveMenu( hMenu, 0, MF_BYPOSITION );
00430 
00431     if( p_intf->p_sys->p_settings_menu )
00432         MenuItemExt::ClearList( p_intf->p_sys->p_settings_menu );
00433     else p_intf->p_sys->p_settings_menu = new vector<MenuItemExt*>;
00434 
00435     /* Initializations */
00436     memset( pi_objects, 0, MAX_SETTINGS_ITEMS * sizeof(int) );
00437     i = 0;
00438 
00439     AppendMenu( hMenu, MF_STRING, ID_PREFERENCES, _T("&Preferences...") );
00440 
00441     p_object = (vlc_object_t *)
00442         vlc_object_find( p_intf, VLC_OBJECT_INTF, FIND_PARENT );
00443     if( p_object != NULL )
00444     {
00445         ppsz_varnames[i] = "intf-switch";
00446         pi_objects[i++] = p_object->i_object_id;
00447         ppsz_varnames[i] = "intf-add";
00448         pi_objects[i++] = p_object->i_object_id;
00449         vlc_object_release( p_object );
00450     }
00451 
00452     /* Build menu */
00453     RefreshMenu( p_intf, p_intf->p_sys->p_settings_menu, hMenu, i,
00454                  ppsz_varnames, pi_objects, SettingsMenu_Events );
00455 }
00456 
00457 /*****************************************************************************
00458  * Refresh the menu.
00459  *****************************************************************************/
00460 void RefreshMenu( intf_thread_t *p_intf, vector<MenuItemExt*> *p_menu_list,
00461                   HMENU hMenu , int i_count, char **ppsz_varnames, 
00462                   int *pi_objects, int i_start_id )
00463 {
00464     vlc_object_t *p_object;
00465     vlc_bool_t b_section_empty = VLC_FALSE;
00466     int i;
00467 
00468     /* Initializations */
00469     int i_item_id = i_start_id;
00470 
00471     for( i = 0; i < i_count; i++ )
00472     {
00473         if( !ppsz_varnames[i] )
00474         {
00475             if( b_section_empty )
00476             {
00477                 AppendMenu( hMenu, MF_GRAYED | MF_STRING,
00478                             MenuDummy_Event + i, _T("Empty") );
00479             }
00480 
00481             AppendMenu( hMenu, MF_SEPARATOR, 0, _T("") );
00482             b_section_empty = VLC_TRUE;
00483             continue;
00484         }
00485 
00486         if( !pi_objects[i] )
00487         {
00488             AppendMenu( hMenu, MF_GRAYED | MF_STRING,
00489                         MenuDummy_Event, _FROMMB(ppsz_varnames[i]) );
00490 
00491             b_section_empty = VLC_FALSE;
00492             continue;
00493         }
00494 
00495         p_object = (vlc_object_t *)vlc_object_get( p_intf, pi_objects[i] );
00496         if( p_object == NULL ) continue;
00497 
00498         b_section_empty = VLC_FALSE;
00499         CreateMenuItem( p_intf, p_menu_list, hMenu, ppsz_varnames[i],
00500                         p_object, &i_item_id );
00501         vlc_object_release( p_object );
00502     }
00503 
00504     /* Special case for empty menus */
00505     if( wce_GetMenuItemCount(hMenu) == 0 || b_section_empty )
00506     {
00507         AppendMenu( hMenu, MF_GRAYED | MF_STRING,
00508                     MenuDummy_Event + i, _T("Empty") );
00509     }
00510 }
00511 
00512 /*****************************************************************************
00513  * Private methods.
00514  *****************************************************************************/
00515 void CreateMenuItem( intf_thread_t *p_intf, vector<MenuItemExt*> *p_menu_list,
00516                      HMENU hMenu, char *psz_var, vlc_object_t *p_object,
00517                      int *pi_item_id )
00518 {
00519     MenuItemExt *pMenuItemExt;
00520     HMENU hMenuItem;
00521     vlc_value_t val, text;
00522     int i_type;
00523 
00524     /* Check the type of the object variable */
00525     i_type = var_Type( p_object, psz_var );
00526 
00527     switch( i_type & VLC_VAR_TYPE )
00528     {
00529     case VLC_VAR_VOID:
00530     case VLC_VAR_BOOL:
00531     case VLC_VAR_VARIABLE:
00532     case VLC_VAR_STRING:
00533     case VLC_VAR_INTEGER:
00534     case VLC_VAR_FLOAT:
00535         break;
00536     default:
00537         /* Variable doesn't exist or isn't handled */
00538         return;
00539     }
00540 
00541     /* Make sure we want to display the variable */
00542     if( i_type & VLC_VAR_HASCHOICE )
00543     {
00544         var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
00545         if( val.i_int == 0 ) return;
00546         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
00547             return;
00548     }
00549 
00550     /* Get the descriptive name of the variable */
00551     var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
00552 
00553     var_Get( p_object, psz_var, &val );
00554 
00555     if( i_type & VLC_VAR_HASCHOICE )
00556     {
00557         hMenuItem = CreateChoicesMenu( p_intf, p_menu_list, psz_var,
00558                                        p_object, pi_item_id );
00559         AppendMenu( hMenu, MF_STRING | MF_POPUP, (UINT)hMenuItem,
00560                     _FROMMB(text.psz_string ? text.psz_string : psz_var) );
00561         if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
00562         if( text.psz_string ) free( text.psz_string );
00563         return;
00564     }
00565 
00566     switch( i_type & VLC_VAR_TYPE )
00567     {
00568     case VLC_VAR_VOID:
00569         AppendMenu( hMenu, MF_STRING , ++(*pi_item_id),
00570                     _FROMMB(text.psz_string ? text.psz_string : psz_var) );
00571         pMenuItemExt = new MenuItemExt( p_intf, *pi_item_id, psz_var,
00572                                         p_object->i_object_id, val, i_type );
00573         p_menu_list->push_back( pMenuItemExt );
00574         break;
00575 
00576     case VLC_VAR_BOOL:
00577         val.b_bool = !val.b_bool;
00578         AppendMenu( hMenu, MF_STRING | MF_CHECKED, ++(*pi_item_id),
00579                     _FROMMB(text.psz_string ? text.psz_string : psz_var) );
00580         pMenuItemExt = new MenuItemExt( p_intf, *pi_item_id, psz_var,
00581                                         p_object->i_object_id, val, i_type );
00582         p_menu_list->push_back( pMenuItemExt );
00583         CheckMenuItem( hMenu, *pi_item_id ,
00584                        ( val.b_bool ? MF_UNCHECKED : MF_CHECKED ) |
00585                        MF_BYCOMMAND ); 
00586         break;
00587 
00588     default:
00589         if( text.psz_string ) free( text.psz_string );
00590         return;
00591     }
00592 
00593     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
00594     if( text.psz_string ) free( text.psz_string );
00595 }
00596 
00597 HMENU CreateChoicesMenu( intf_thread_t *p_intf,
00598                          vector<MenuItemExt*> *p_menu_list, char *psz_var, 
00599                          vlc_object_t *p_object, int *pi_item_id )
00600 {
00601     MenuItemExt *pMenuItemExt;
00602     vlc_value_t val, val_list, text_list;
00603     int i_type, i;
00604     HMENU hSubMenu = CreatePopupMenu();
00605 
00606     /* Check the type of the object variable */
00607     i_type = var_Type( p_object, psz_var );
00608 
00609     /* Make sure we want to display the variable */
00610     if( i_type & VLC_VAR_HASCHOICE )
00611     {
00612         var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
00613         if( val.i_int == 0 ) return NULL;
00614         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
00615             return NULL;
00616     }
00617     else
00618     {
00619         return NULL;
00620     }
00621 
00622     switch( i_type & VLC_VAR_TYPE )
00623     {
00624     case VLC_VAR_VOID:
00625     case VLC_VAR_BOOL:
00626     case VLC_VAR_VARIABLE:
00627     case VLC_VAR_STRING:
00628     case VLC_VAR_INTEGER:
00629         break;
00630     default:
00631         /* Variable doesn't exist or isn't handled */
00632         return NULL;
00633     }
00634 
00635     if( var_Get( p_object, psz_var, &val ) < 0 ) return NULL;
00636 
00637     if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
00638                     &val_list, &text_list ) < 0 )
00639     {
00640         if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
00641         return NULL;
00642     }
00643 
00644     for( i = 0; i < val_list.p_list->i_count; i++ )
00645     {
00646         vlc_value_t another_val;
00647         HMENU hMenuItem;
00648         char *psz_tmp;
00649 
00650         switch( i_type & VLC_VAR_TYPE )
00651         {
00652         case VLC_VAR_VARIABLE:
00653             hMenuItem = CreateChoicesMenu( p_intf, p_menu_list,
00654               val_list.p_list->p_values[i].psz_string, p_object, pi_item_id );
00655             AppendMenu( hSubMenu, MF_STRING | MF_POPUP, (UINT)hMenuItem,
00656                         _FROMMB(text_list.p_list->p_values[i].psz_string ?
00657                           text_list.p_list->p_values[i].psz_string :
00658                           val_list.p_list->p_values[i].psz_string) );
00659             break;
00660 
00661         case VLC_VAR_STRING:
00662             another_val.psz_string =
00663                 strdup(val_list.p_list->p_values[i].psz_string);
00664             AppendMenu( hSubMenu, MF_STRING, ++(*pi_item_id),
00665                         _FROMMB(text_list.p_list->p_values[i].psz_string ?
00666                           text_list.p_list->p_values[i].psz_string :
00667                           val_list.p_list->p_values[i].psz_string) );
00668             pMenuItemExt = new MenuItemExt( p_intf, *pi_item_id, psz_var,
00669                           p_object->i_object_id, another_val, i_type );
00670             p_menu_list->push_back( pMenuItemExt );
00671 
00672             if( !(i_type & VLC_VAR_ISCOMMAND) && val.psz_string &&
00673                 !strcmp( val.psz_string,
00674                          val_list.p_list->p_values[i].psz_string ) )
00675               CheckMenuItem( hSubMenu, *pi_item_id, MF_CHECKED | MF_BYCOMMAND);
00676             break;
00677 
00678         case VLC_VAR_INTEGER:
00679             asprintf( &psz_tmp, "%d", val_list.p_list->p_values[i].i_int );
00680             AppendMenu( hSubMenu, MF_STRING, ++(*pi_item_id),
00681                         _FROMMB(text_list.p_list->p_values[i].psz_string ?
00682                           text_list.p_list->p_values[i].psz_string : psz_tmp));
00683             pMenuItemExt = new MenuItemExt( p_intf, *pi_item_id, psz_var,
00684                 p_object->i_object_id, val_list.p_list->p_values[i], i_type );
00685             p_menu_list->push_back( pMenuItemExt );
00686 
00687             if( val_list.p_list->p_values[i].i_int == val.i_int )
00688               CheckMenuItem( hSubMenu, *pi_item_id, MF_CHECKED | MF_BYCOMMAND);
00689             break;
00690 
00691         default:
00692             break;
00693         }
00694     }
00695 
00696     /* Clean up everything */
00697     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
00698     var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
00699 
00700     return hSubMenu;
00701 }
00702 
00703 int wce_GetMenuItemCount(HMENU hMenu)
00704 {
00705     const int MAX_NUM_ITEMS = 256;
00706     int iPos, iCount;
00707 
00708     MENUITEMINFO mii;
00709     memset( (char *)&mii, 0, sizeof(MENUITEMINFO) );
00710     mii.cbSize = sizeof(MENUITEMINFO);
00711 
00712     iCount = 0;
00713     for( iPos = 0; iPos < MAX_NUM_ITEMS; iPos++ )
00714     {
00715         if( !GetMenuItemInfo(hMenu, (UINT)iPos, TRUE, &mii) ) break;
00716         iCount++;
00717     }
00718 
00719     return iCount;
00720 }
00721 
00722 void OnMenuEvent( intf_thread_t *p_intf, int id )
00723 {
00724     MenuItemExt *p_menuitemext = NULL;
00725     vector<MenuItemExt*>::iterator iter;
00726 
00727     if( p_intf->p_sys->p_settings_menu )
00728     for( iter = p_intf->p_sys->p_settings_menu->begin();
00729          iter != p_intf->p_sys->p_settings_menu->end(); iter++ )
00730         if( (*iter)->id == id )
00731         {
00732             p_menuitemext = *iter;
00733             break;
00734         }
00735 
00736     if( p_intf->p_sys->p_audio_menu && !p_menuitemext )
00737     for( iter = p_intf->p_sys->p_audio_menu->begin();
00738          iter != p_intf->p_sys->p_audio_menu->end(); iter++ ) 
00739         if( (*iter)->id == id )
00740         {
00741             p_menuitemext = *iter;
00742             break;
00743         }
00744 
00745     if( p_intf->p_sys->p_video_menu && !p_menuitemext )
00746     for( iter = p_intf->p_sys->p_video_menu->begin();
00747          iter != p_intf->p_sys->p_video_menu->end(); iter++ )
00748         if( (*iter)->id == id )
00749         {
00750             p_menuitemext = *iter;
00751             break;
00752         }
00753 
00754     if( p_intf->p_sys->p_navig_menu && !p_menuitemext )
00755     for( iter = p_intf->p_sys->p_navig_menu->begin();
00756          iter != p_intf->p_sys->p_navig_menu->end(); iter++ )
00757         if( (*iter)->id == id )
00758         {
00759             p_menuitemext = *iter;
00760             break;
00761         }
00762 
00763     if( p_menuitemext )
00764     {
00765         vlc_object_t *p_object = (vlc_object_t *)
00766             vlc_object_get( p_intf, p_menuitemext->i_object_id );
00767         if( p_object == NULL ) return;
00768 
00769         var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val );
00770         int i_type = var_Type( p_object, p_menuitemext->psz_var );
00771         switch( i_type & VLC_VAR_TYPE )
00772         {
00773         case VLC_VAR_VOID:
00774         case VLC_VAR_BOOL:
00775         case VLC_VAR_VARIABLE:
00776         case VLC_VAR_STRING:
00777         case VLC_VAR_INTEGER:
00778             break;
00779         default:
00780             /* Variable doesn't exist or isn't handled */
00781             return;
00782         }
00783 
00784         vlc_object_release( p_object );
00785     }
00786 }
00787 
00788 /*****************************************************************************
00789  * A small helper class which encapsulate wxMenuitem with some other useful
00790  * things.
00791  *****************************************************************************/
00792 MenuItemExt::MenuItemExt( intf_thread_t *p_intf, int _id, char *_psz_var,
00793                           int _i_object_id, vlc_value_t _val, int _i_val_type )
00794 {
00795     /* Initializations */
00796     id = _id;
00797     p_intf = p_intf;
00798     psz_var = strdup( _psz_var );
00799     i_val_type = _i_val_type;
00800     i_object_id = _i_object_id;
00801     val = _val;
00802 };
00803 
00804 MenuItemExt::~MenuItemExt()
00805 {
00806     if( psz_var ) free( psz_var );
00807     if( ((i_val_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
00808         && val.psz_string ) free( val.psz_string );
00809 };
00810 
00811 void MenuItemExt::ClearList( vector<MenuItemExt*> *p_menu_list )
00812 {
00813     vector<MenuItemExt*>::iterator iter;
00814 
00815     if( !p_menu_list ) return;
00816     for( iter = p_menu_list->begin(); iter != p_menu_list->end(); iter++ )
00817     {
00818         delete *iter;
00819     }
00820     p_menu_list->clear();
00821 }

Generated on Tue Dec 20 10:14:45 2005 for vlc-0.8.4a by  doxygen 1.4.2