1 /*****************************************************************************
2 * menu.cpp: functions to handle menu items
3 *****************************************************************************
4 * Copyright (C) 2002-2003 VideoLAN
5 * $Id: menu.cpp,v 1.5 2003/01/16 09:02:46 sam Exp $
7 * Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
30 #include "win32_common.h"
32 /*****************************************************************************
33 * TMenusGen::*Click: callbacks for the menuitems
34 ****************************************************************************/
40 /* variables of the audio output */
41 void __fastcall TMenusGen::AoutVarClick( TObject *Sender )
43 TMenuItem * Item = (TMenuItem *)Sender;
45 vlc_object_t * p_aout;
46 p_aout = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
50 msg_Warn( p_intf, "cannot set variable (%s)", Item->Caption.c_str() );
54 if( Item->Parent == MenuADevice || Item->Parent == PopupADevice )
56 VarChange( p_aout, "audio-device", MenuADevice, PopupADevice, Item );
58 else if( Item->Parent == MenuChannel || Item->Parent == PopupChannel )
60 VarChange( p_aout, "audio-channels", MenuChannel, PopupChannel, Item );
63 vlc_object_release( p_aout );
66 /* variables of the video output */
67 void __fastcall TMenusGen::VoutVarClick( TObject *Sender )
69 TMenuItem * Item = (TMenuItem *)Sender;
71 vlc_object_t * p_vout;
72 p_vout = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
76 msg_Warn( p_intf, "cannot set variable (%s)", Item->Caption.c_str() );
80 if( Item->Parent == MenuVDevice || Item->Parent == PopupVDevice )
82 VarChange( p_vout, "video-device", MenuVDevice, PopupVDevice, Item );
85 vlc_object_release( p_vout );
92 void __fastcall TMenusGen::MenuLanguageClick( TObject *Sender )
94 LangChange( MenuLanguage, (TMenuItem *)Sender, PopupLanguage, AUDIO_ES );
97 void __fastcall TMenusGen::PopupLanguageClick( TObject *Sender )
99 LangChange( PopupLanguage, (TMenuItem *)Sender, MenuLanguage, AUDIO_ES );
106 void __fastcall TMenusGen::MenuSubtitleClick( TObject *Sender )
108 LangChange( MenuSubtitles, (TMenuItem *)Sender, PopupSubtitles, SPU_ES );
111 void __fastcall TMenusGen::PopupSubtitleClick( TObject *Sender )
113 LangChange( PopupSubtitles, (TMenuItem *)Sender, MenuSubtitles, SPU_ES );
120 void __fastcall TMenusGen::MenuProgramClick( TObject *Sender )
122 ProgramChange( (TMenuItem *)Sender, PopupProgram );
125 void __fastcall TMenusGen::PopupProgramClick( TObject *Sender )
127 ProgramChange( (TMenuItem *)Sender, MenuProgram );
134 void __fastcall TMenusGen::MenuTitleClick( TObject *Sender )
136 TMenuItem * Item = (TMenuItem *)Sender;
137 TMenuItem * ItemTitle;
138 int i_title = Item->Tag;
140 input_ChangeArea( p_intf->p_sys->p_input,
141 p_intf->p_sys->p_input->stream.pp_areas[i_title] );
142 Item->Checked = true;
143 ItemTitle = Index2Item( PopupNavigation, i_title - 1, false );
144 Index2Item( ItemTitle, 0, false )->Checked = true;
146 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
153 void __fastcall TMenusGen::MenuChapterClick( TObject *Sender )
155 TMenuItem * Item = (TMenuItem *)Sender;
156 TMenuItem * ItemTitle;
157 input_area_t * p_area;
159 int i_chapter = Item->Tag;
161 p_area = p_intf->p_sys->p_input->stream.p_selected_area;
162 p_area->i_part = i_chapter;
164 input_ChangeArea( p_intf->p_sys->p_input, (input_area_t*)p_area );
166 i_title = p_intf->p_sys->p_input->stream.p_selected_area->i_id;
167 ItemTitle = Index2Item( PopupNavigation, i_title - 1, false );
168 Index2Item( ItemTitle, i_chapter - 1, false )->Checked = true;
170 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
177 void __fastcall TMenusGen::PopupNavigationClick( TObject *Sender )
179 TMenuItem * Item = (TMenuItem *)Sender;
180 TMenuItem * ItemTitle;
181 input_area_t * p_area;
182 int i_title = Data2Title( Item->Tag );
183 int i_chapter = Data2Chapter( Item->Tag );
185 p_area = p_intf->p_sys->p_input->stream.pp_areas[i_title];
186 p_area->i_part = i_chapter;
188 input_ChangeArea( p_intf->p_sys->p_input, (input_area_t*)p_area );
190 Item->Checked = true;
191 ItemTitle = Index2Item( MenuTitle, i_title - 1, false );
192 if( ItemTitle->Checked )
194 /* same title, new chapter */
195 Index2Item( MenuChapter, i_chapter - 1, false )->Checked = true;
199 /* new title => we must rebuild the chapter menu */
200 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
202 MenuChapter, "Chapter",
203 p_intf->p_sys->p_input->stream.p_selected_area->i_part_nb,
204 i_chapter, MenuChapterClick );
205 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
208 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
212 __fastcall TMenusGen::TMenusGen( intf_thread_t *_p_intf ) : TObject()
216 /* Initialize local pointers to menu items of the main window */
217 TMainFrameDlg * p_window = p_intf->p_sys->p_window;
218 if( p_window == NULL )
220 msg_Warn( p_intf, "Main window wasn't created, expect problems..." );
224 MenuChannel = p_window->MenuChannel;
225 PopupChannel = p_window->PopupChannel;
226 MenuADevice = p_window->MenuADevice;
227 PopupADevice = p_window->PopupADevice;
228 MenuVDevice = p_window->MenuVDevice;
229 PopupVDevice = p_window->PopupVDevice;
230 MenuLanguage = p_window->MenuLanguage;
231 PopupLanguage = p_window->PopupLanguage;
232 MenuSubtitles = p_window->MenuSubtitles;
233 PopupSubtitles = p_window->PopupSubtitles;
234 MenuProgram = p_window->MenuProgram;
235 PopupProgram = p_window->PopupProgram;
236 MenuTitle = p_window->MenuTitle;
237 MenuChapter = p_window->MenuChapter;
238 PopupNavigation = p_window->PopupNavigation;
242 /*****************************************************************************
243 * SetupMenus: This function dynamically generates some menus
244 *****************************************************************************
245 * The lock on p_input->stream must be taken before you call this function
246 *****************************************************************************/
247 void __fastcall TMenusGen::SetupMenus()
249 TMainFrameDlg * p_window = p_intf->p_sys->p_window;
250 input_thread_t * p_input = p_intf->p_sys->p_input;
251 es_descriptor_t * p_audio_es;
252 es_descriptor_t * p_spu_es;
254 p_intf->p_sys->b_chapter_update |= p_intf->p_sys->b_title_update;
255 p_intf->p_sys->b_audio_update |= p_intf->p_sys->b_program_update |
256 p_intf->p_sys->b_title_update;
257 p_intf->p_sys->b_spu_update |= p_intf->p_sys->b_program_update |
258 p_intf->p_sys->b_title_update;
260 if( p_intf->p_sys->b_program_update )
262 pgrm_descriptor_t * p_pgrm;
264 if( p_input->stream.p_new_program )
266 p_pgrm = p_input->stream.p_new_program;
270 p_pgrm = p_input->stream.p_selected_program;
273 ProgramMenu( MenuProgram, p_pgrm, MenuProgramClick );
274 ProgramMenu( PopupProgram, p_pgrm, PopupProgramClick );
276 p_intf->p_sys->b_program_update = 0;
279 if( p_intf->p_sys->b_title_update )
282 RadioMenu( MenuTitle, "Title",
283 p_input->stream.i_area_nb - 1,
284 p_input->stream.p_selected_area->i_id,
287 AnsiString CurrentTitle;
288 CurrentTitle.sprintf( "%d", p_input->stream.p_selected_area->i_id );
289 p_window->LabelTitleCurrent->Caption = CurrentTitle;
291 p_intf->p_sys->b_title_update = 0;
294 if( p_intf->p_sys->b_chapter_update )
296 RadioMenu( MenuChapter, "Chapter",
297 p_input->stream.p_selected_area->i_part_nb,
298 p_input->stream.p_selected_area->i_part,
301 NavigationMenu( PopupNavigation, PopupNavigationClick );
303 AnsiString CurrentChapter;
304 CurrentChapter.sprintf( "%d", p_input->stream.p_selected_area->i_part );
305 p_window->LabelChapterCurrent->Caption = CurrentChapter;
307 p_intf->p_sys->i_part = p_input->stream.p_selected_area->i_part;
309 p_intf->p_sys->b_chapter_update = 0;
312 /* look for selected ES */
316 for( unsigned int i = 0; i < p_input->stream.i_selected_es_number; i++ )
318 if( p_input->stream.pp_selected_es[i]->i_cat == AUDIO_ES )
320 p_audio_es = p_input->stream.pp_selected_es[i];
323 if( p_input->stream.pp_selected_es[i]->i_cat == SPU_ES )
325 p_spu_es = p_input->stream.pp_selected_es[i];
328 this->p_audio_es_old = p_audio_es;
329 this->p_spu_es_old = p_spu_es;
331 vlc_mutex_unlock( &p_input->stream.stream_lock );
334 if( p_intf->p_sys->b_audio_update )
336 LanguageMenu( MenuLanguage, p_audio_es, AUDIO_ES, MenuLanguageClick );
337 LanguageMenu( PopupLanguage, p_audio_es, AUDIO_ES, PopupLanguageClick );
339 p_intf->p_sys->b_audio_update = 0;
342 /* sub picture menus */
343 if( p_intf->p_sys->b_spu_update )
345 LanguageMenu( PopupSubtitles, p_spu_es, SPU_ES, PopupSubtitleClick );
346 LanguageMenu( MenuSubtitles, p_spu_es, SPU_ES, MenuSubtitleClick );
348 p_intf->p_sys->b_spu_update = 0;
351 if( p_intf->p_sys->b_aout_update )
353 aout_instance_t * p_aout;
354 p_aout = (aout_instance_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
362 var_Set( (vlc_object_t *)p_aout, "intf-change", val );
364 SetupVarMenu( (vlc_object_t *)p_aout, "audio-channels",
365 MenuChannel, AoutVarClick );
366 SetupVarMenu( (vlc_object_t *)p_aout, "audio-channels",
367 PopupChannel, AoutVarClick );
369 SetupVarMenu( (vlc_object_t *)p_aout, "audio-device",
370 MenuADevice, AoutVarClick );
371 SetupVarMenu( (vlc_object_t *)p_aout, "audio-device",
372 PopupADevice, AoutVarClick );
374 vlc_object_release( (vlc_object_t *)p_aout );
377 p_intf->p_sys->b_aout_update = 0;
380 if( p_intf->p_sys->b_vout_update )
382 vout_thread_t * p_vout;
383 p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
391 var_Set( (vlc_object_t *)p_vout, "intf-change", val );
393 SetupVarMenu( (vlc_object_t *)p_vout, "video-device",
394 MenuVDevice, VoutVarClick );
395 SetupVarMenu( (vlc_object_t *)p_vout, "video-device",
396 PopupVDevice, VoutVarClick );
398 vlc_object_release( (vlc_object_t *)p_vout );
401 p_intf->p_sys->b_vout_update = 0;
404 vlc_mutex_lock( &p_input->stream.stream_lock );
408 /*****************************************************************************
410 *****************************************************************************/
411 TMenuItem * TMenusGen::Index2Item( TMenuItem *Root, int i_index,
414 if( SingleColumn || ( i_index < 20 ) )
415 return Root->Items[i_index];
417 return Root->Items[i_index / 10]->Items[i_index % 10];
420 int TMenusGen::Item2Index( TMenuItem *Root, TMenuItem *Item )
422 if( Item->Parent == Root )
423 return Item->MenuIndex;
425 return( 10 * Item->Parent->MenuIndex + Item->MenuIndex );
428 int __fastcall TMenusGen::Data2Title( int data )
430 return (int) (data >> 16 );
433 int __fastcall TMenusGen::Data2Chapter( int data )
435 return (int) (data & 0xffff);
438 int __fastcall TMenusGen::Pos2Data( int title, int chapter )
440 return (int) (( title << 16 ) | ( chapter & 0xffff ));
443 /****************************************************************************
444 * VarChange: change a variable in a vlc_object_t
445 ****************************************************************************
446 * Change the variable and update the menuitems.
447 ****************************************************************************/
448 void __fastcall TMenusGen::VarChange( vlc_object_t *p_object,
449 const char *psz_variable, TMenuItem *RootMenu, TMenuItem *RootPopup,
455 /* We must delete all the '&' characters in the caption string, because
456 * Borland automatically adds one when (and only when!) you click on
457 * the menuitem. Grrrrr... */
458 AnsiString Caption = Item->Caption;
459 while( Caption.LastDelimiter( "&" ) != 0 )
461 Caption.Delete( Caption.LastDelimiter( "&" ), 1 );
\r
463 val.psz_string = Caption.c_str();
465 /* set the new value */
466 if( var_Set( p_object, psz_variable, val ) < 0 )
468 msg_Warn( p_object, "cannot set variable (%s)", val.psz_string );
471 i_index = Item->MenuIndex;
472 RootMenu->Items[i_index]->Checked = true;
473 RootPopup->Items[i_index]->Checked = true;
476 /****************************************************************************
477 * LangChange: change audio or subtitles languages
478 ****************************************************************************
479 * Toggle the language, and update the selected menuitems.
480 ****************************************************************************/
481 void __fastcall TMenusGen::LangChange( TMenuItem *RootCurrent, TMenuItem *Item,
482 TMenuItem *RootOther, int i_cat )
484 es_descriptor_t * p_es;
485 es_descriptor_t * p_es_old;
489 /* find the selected ES */
492 /* find selected menu item */
493 i_index = Item2Index( RootCurrent, Item ) - 1;
496 /* 'None' was selected */
501 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
502 p_es = p_intf->p_sys->p_input->stream.pp_es[i_es];
503 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
506 /* find the current ES */
507 if( i_cat == AUDIO_ES )
509 p_es_old = this->p_audio_es_old;
510 this->p_audio_es_old = p_es;
514 p_es_old = this->p_spu_es_old;
515 this->p_spu_es_old = p_es;
519 input_ToggleES( p_intf->p_sys->p_input, p_es_old, false );
520 input_ToggleES( p_intf->p_sys->p_input, p_es, true );
522 Item->Checked = true;
523 Index2Item( RootOther, i_index + 1, true )->Checked = true;
526 /****************************************************************************
527 * ProgramChange: change the program
528 ****************************************************************************
529 * Toggle the program, and update the selected menuitems.
530 ****************************************************************************/
531 void __fastcall TMenusGen::ProgramChange( TMenuItem *Item,
532 TMenuItem *RootOther )
534 int i_program = Item->Tag;
536 /* toggle the program */
537 input_ChangeProgram( p_intf->p_sys->p_input, (uint16_t)i_program );
539 /* check selected menu items */
540 Item->Checked = true;
541 Index2Item( RootOther, i_program - 1, true )->Checked = true;
543 /* update audio/subtitles menus */
544 p_intf->p_sys->b_audio_update = 1;
545 p_intf->p_sys->b_spu_update = 1;
546 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
548 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
549 p_intf->p_sys->b_audio_update = 0;
550 p_intf->p_sys->b_spu_update = 0;
552 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
555 /*****************************************************************************
556 * SetupVarMenu: build a menu allowing to change a variable
557 *****************************************************************************/
558 void __fastcall TMenusGen::SetupVarMenu( vlc_object_t *p_object,
559 const char *psz_variable, TMenuItem *Root, TNotifyEvent MenuItemClick )
563 char * psz_value = NULL;
566 /* remove previous menu */
569 /* get the current value */
570 if( var_Get( p_object, psz_variable, &val ) < 0 )
574 psz_value = val.psz_string;
576 if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST, &val ) < 0 )
582 /* append a menuitem for each option */
583 for( i = 0; i < val.p_list->i_count; i++ )
585 Item = new TMenuItem( Root );
586 Item->Caption = val.p_list->p_values[i].psz_string;
587 Item->Hint = val.p_list->p_values[i].psz_string;
588 Item->RadioItem = true;
589 Item->OnClick = MenuItemClick;
590 if( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
591 Item->Checked = true;
593 /* Add the item to the submenu */
597 /* enable the menu if there is at least 1 item */
598 Root->Enabled = ( val.p_list->i_count > 0 );
600 /* clean up everything */
601 var_Change( p_object, psz_variable, VLC_VAR_FREELIST, &val );
602 // free( psz_value );
605 /*****************************************************************************
606 * ProgramMenu: update the programs menu of the interface
607 *****************************************************************************
608 * Builds the program menu according to what have been found in the PAT
609 * by the input. Useful for multi-programs streams such as DVB ones.
610 *****************************************************************************/
611 void __fastcall TMenusGen::ProgramMenu( TMenuItem *Root,
612 pgrm_descriptor_t *p_pgrm, TNotifyEvent MenuItemClick )
616 /* remove previous menu */
618 Root->Enabled = false;
620 /* create a set of program buttons and append them to the container */
621 for( unsigned int i = 0; i < p_intf->p_sys->p_input->stream.i_pgrm_number;
625 Name.sprintf( "id %d",
626 p_intf->p_sys->p_input->stream.pp_programs[i]->i_number );
628 Item = new TMenuItem( Root );
629 Item->Caption = Name;
631 Item->RadioItem = true;
632 Item->OnClick = MenuItemClick;
634 /* FIXME: temporary hack to save the program id with the Item
635 * It will be used in the callback. */
638 /* check the currently selected program */
639 if( p_pgrm == p_intf->p_sys->p_input->stream.pp_programs[i] )
641 Item->Checked = true;
644 /* add the item to the submenu */
648 /* be sure that menu is enabled if more than 1 program */
649 if( p_intf->p_sys->p_input->stream.i_pgrm_number > 1 )
651 Root->Enabled = true;
655 /*****************************************************************************
656 * RadioMenu: update interactive menus of the interface
657 *****************************************************************************
658 * Sets up menus with information from input
659 * Warning: since this function is designed to be called by management
660 * function, the interface lock has to be taken
661 *****************************************************************************/
662 void __fastcall TMenusGen::RadioMenu( TMenuItem *Root, AnsiString ItemName,
663 int i_nb, int i_selected, TNotifyEvent MenuItemClick )
665 TMenuItem * ItemGroup;
669 /* remove previous menu */
670 Root->Enabled = false;
673 for( int i_item = 0; i_item < i_nb; i_item++ )
675 /* we group titles/chapters in packets of ten for small screens */
676 if( ( i_item % 10 == 0 ) && ( i_nb > 20 ) )
680 Root->Add( ItemGroup );
683 Name.sprintf( "%ss %d to %d", ItemName, i_item + 1, i_item + 10 );
684 ItemGroup = new TMenuItem( Root );
685 ItemGroup->Hint = Name;
686 ItemGroup->RadioItem = true;
688 /* set the accelerator character */
689 Name.Insert( "&", Name.Length() - 1 );
690 ItemGroup->Caption = Name;
693 Name.sprintf( "%s %d", ItemName, i_item + 1 );
694 Item = new TMenuItem( Root );
695 Item->RadioItem = true;
698 /* set the accelerator character */
699 Name.Insert( "&", Name.Length() );
700 Item->Caption = Name;
702 /* FIXME: temporary hack to save i_item with the Item
703 * It will be used in the callback. */
704 Item->Tag = i_item + 1;
706 /* check the currently selected chapter */
707 if( i_selected == i_item + 1 )
709 Item->Checked = true;
712 /* setup signal handling */
713 Item->OnClick = MenuItemClick;
716 ItemGroup->Add( Item );
721 // if( ( i_nb > 20 ) && ( i_item % 10 ) ) ?
724 Root->Add( ItemGroup );
727 /* be sure that menu is enabled, if there are several items */
730 Root->Enabled = true;
734 /*****************************************************************************
735 * LanguageMenus: update interactive menus of the interface
736 *****************************************************************************
737 * Sets up menus with information from input:
740 * Warning: since this function is designed to be called by management
741 * function, the interface lock has to be taken
742 *****************************************************************************/
743 void __fastcall TMenusGen::LanguageMenu( TMenuItem *Root, es_descriptor_t *p_es,
744 int i_cat, TNotifyEvent MenuItemClick )
746 TMenuItem * Separator;
750 /* remove previous menu */
752 Root->Enabled = false;
754 /* special case for "off" item */
756 Item = new TMenuItem( Root );
757 Item->RadioItem = true;
759 Item->Caption = Name;
760 Item->OnClick = MenuItemClick;
765 Separator = new TMenuItem( Root );
766 Separator->Caption = "-";
767 Root->Add( Separator );
771 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
773 #define ES p_intf->p_sys->p_input->stream.pp_es[i]
774 /* create a set of language buttons and append them to the Root */
775 for( unsigned int i = 0; i < p_intf->p_sys->p_input->stream.i_es_number;
778 if( ( ES->i_cat == i_cat ) &&
781 p_intf->p_sys->p_input->stream.p_selected_program ) )
784 Name = p_intf->p_sys->p_input->stream.pp_es[i]->psz_desc;
787 Name.sprintf( "Language %d", i_item );
790 Item = new TMenuItem( Root );
791 Item->RadioItem = true;
793 Item->Caption = Name;
796 /* check the currently selected item */
797 if( p_es == p_intf->p_sys->p_input->stream.pp_es[i] )
799 Item->Checked = true;
802 /* setup signal hanling */
803 Item->OnClick = MenuItemClick;
809 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
811 /* be sure that menu is enabled if non empty */
814 Root->Enabled = true;
818 /*****************************************************************************
819 * NavigationMenu: sets menus for titles and chapters selection
820 *****************************************************************************
821 * Generates two types of menus:
822 * -simple list of titles
823 * -cascaded lists of chapters for each title
824 *****************************************************************************/
825 void __fastcall TMenusGen::NavigationMenu( TMenuItem *Root,
826 TNotifyEvent MenuItemClick )
828 TMenuItem * TitleGroup;
829 TMenuItem * TitleItem;
830 TMenuItem * ChapterGroup;
831 TMenuItem * ChapterItem;
833 unsigned int i_title_nb;
834 unsigned int i_chapter_nb;
837 /* remove previous menu */
838 Root->Enabled = false;
841 i_title_nb = p_intf->p_sys->p_input->stream.i_area_nb;
844 for( unsigned int i_title = 1; i_title < i_title_nb; i_title++ )
846 /* we group titles in packets of ten for small screens */
847 if( ( i_title % 10 == 1 ) && ( i_title_nb > 20 ) )
851 Root->Add( TitleGroup );
854 Name.sprintf( "%d - %d", i_title, i_title + 9 );
855 TitleGroup = new TMenuItem( Root );
856 TitleGroup->RadioItem = true;
857 TitleGroup->Hint = Name;
858 TitleGroup->Caption = Name;
861 Name.sprintf( "Title %d (%d)", i_title,
862 p_intf->p_sys->p_input->stream.pp_areas[i_title]->i_part_nb );
864 TitleItem = new TMenuItem( Root );
865 TitleItem->RadioItem = true;
866 TitleItem->Hint = Name;
867 TitleItem->Caption = Name;
870 p_intf->p_sys->p_input->stream.pp_areas[i_title]->i_part_nb;
872 /* loop on chapters */
873 for( unsigned int i_chapter = 0; i_chapter < i_chapter_nb;
876 /* we group chapters in packets of ten for small screens */
877 if( ( i_chapter % 10 == 0 ) && ( i_chapter_nb > 20 ) )
881 TitleItem->Add( ChapterGroup );
884 Name.sprintf( "%d - %d", i_chapter + 1, i_chapter + 10 );
885 ChapterGroup = new TMenuItem( TitleItem );
886 ChapterGroup->RadioItem = true;
887 ChapterGroup->Hint = Name;
888 ChapterGroup->Caption = Name;
891 Name.sprintf( "Chapter %d", i_chapter + 1 );
893 ChapterItem = new TMenuItem( TitleItem );
894 ChapterItem->RadioItem = true;
895 ChapterItem->Hint = Name;
896 ChapterItem->Caption = Name;
898 /* FIXME: temporary hack to save i_title and i_chapter with
899 * ChapterItem, since we will need them in the callback */
900 ChapterItem->Tag = Pos2Data( i_title, i_chapter + 1 );
902 #define p_area p_intf->p_sys->p_input->stream.pp_areas[i_title]
903 /* check the currently selected chapter */
905 p_intf->p_sys->p_input->stream.p_selected_area ) &&
906 ( p_area->i_part == i_chapter + 1 ) )
908 ChapterItem->Checked = true;
912 /* setup signal handling */
913 ChapterItem->OnClick = MenuItemClick;
915 if( i_chapter_nb > 20 )
916 ChapterGroup->Add( ChapterItem );
918 TitleItem->Add( ChapterItem );
921 if( i_chapter_nb > 20 )
923 TitleItem->Add( ChapterGroup );
926 if( p_intf->p_sys->p_input->stream.pp_areas[i_title]->i_part_nb
929 /* be sure that menu is sensitive */
930 Root->Enabled = true;
934 if( i_title_nb > 20 )
935 TitleGroup->Add( TitleItem );
937 Root->Add( TitleItem );
940 if( i_title_nb > 20 )
942 Root->Add( TitleGroup );
945 /* be sure that menu is sensitive */
946 Root->Enabled = true;