1 /*****************************************************************************
2 * gtk_menu.c : functions to handle menu items.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: gtk_menu.c,v 1.23 2002/03/14 01:35:28 stef Exp $
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Stéphane Borel <stef@via.ecp.fr>
9 * Johan Bilien <jobi@via.ecp.fr>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
29 #include <sys/types.h> /* off_t */
32 #include <videolan/vlc.h>
34 #ifdef MODULE_NAME_IS_gnome
42 #include "stream_control.h"
43 #include "input_ext-intf.h"
45 #include "interface.h"
46 #include "intf_playlist.h"
49 #include "video_output.h"
50 #include "audio_output.h"
52 #include "gtk_callbacks.h"
53 #include "gtk_interface.h"
54 #include "gtk_support.h"
55 #include "gtk_playlist.h"
56 #include "gtk_common.h"
61 static gint GtkLanguageMenus( gpointer , GtkWidget *, es_descriptor_t *, gint,
62 void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) );
64 void GtkMenubarAudioToggle ( GtkCheckMenuItem *, gpointer );
65 void GtkPopupAudioToggle ( GtkCheckMenuItem *, gpointer );
66 void GtkMenubarSubtitleToggle( GtkCheckMenuItem *, gpointer );
67 void GtkPopupSubtitleToggle ( GtkCheckMenuItem *, gpointer );
68 static gint GtkTitleMenu( gpointer, GtkWidget *,
69 void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) );
70 static gint GtkRadioMenu( intf_thread_t *, GtkWidget *, GSList *,
72 void( *pf_toggle )( GtkCheckMenuItem *, gpointer ) );
74 gint GtkSetupMenus( intf_thread_t * p_intf );
76 /****************************************************************************
77 * Gtk*Toggle: callbacks to toggle the value of a checkmenuitem
78 ****************************************************************************
79 * We need separate functions for menubar and popup here since we can't use
80 * user_data to transmit intf_* and we need to refresh the other menu.
81 ****************************************************************************/
83 #define GTKLANGTOGGLE( intf, window, menu, type, callback, b_update ) \
84 intf_thread_t * p_intf; \
86 es_descriptor_t * p_es; \
88 p_intf = GetIntf( GTK_WIDGET(menuitem), (intf) ); \
90 if( !p_intf->p_sys->b_update ) \
92 p_menu = GTK_WIDGET( gtk_object_get_data( \
93 GTK_OBJECT( p_intf->p_sys->window ), (menu) ) ); \
94 p_es = (es_descriptor_t*)user_data; \
96 input_ToggleES( p_input_bank->pp_input[0], \
97 p_es, menuitem->active ); \
99 p_intf->p_sys->b_update = menuitem->active; \
101 if( p_intf->p_sys->b_update ) \
103 GtkLanguageMenus( p_intf, p_menu, p_es, type, callback ); \
106 p_intf->p_sys->b_update = 0; \
113 void GtkMenubarAudioToggle( GtkCheckMenuItem * menuitem, gpointer user_data )
115 GTKLANGTOGGLE( "intf_window", p_popup, "popup_audio", AUDIO_ES,
116 GtkPopupAudioToggle, b_audio_update );
119 void GtkPopupAudioToggle( GtkCheckMenuItem * menuitem, gpointer user_data )
121 GTKLANGTOGGLE( "intf_popup", p_window, "menubar_audio", AUDIO_ES,
122 GtkMenubarAudioToggle, b_audio_update );
129 void GtkMenubarSubtitleToggle( GtkCheckMenuItem * menuitem, gpointer user_data )
131 GTKLANGTOGGLE( "intf_window", p_popup, "popup_subpictures", SPU_ES,
132 GtkPopupSubtitleToggle, b_spu_update );
135 void GtkPopupSubtitleToggle( GtkCheckMenuItem * menuitem, gpointer user_data )
137 GTKLANGTOGGLE( "intf_popup", p_window, "menubar_subpictures", SPU_ES,
138 GtkMenubarSubtitleToggle, b_spu_update );
147 void GtkPopupNavigationToggle( GtkCheckMenuItem * menuitem,
150 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
152 if( menuitem->active &&
153 !p_intf->p_sys->b_title_update &&
154 !p_intf->p_sys->b_chapter_update )
156 input_area_t *p_area;
158 gint i_title = DATA2TITLE( user_data );
159 gint i_chapter = DATA2CHAPTER( user_data );
161 p_area = p_input_bank->pp_input[0]->stream.p_selected_area;
163 if( p_area != p_input_bank->pp_input[0]->stream.pp_areas[i_title] )
165 p_area = p_input_bank->pp_input[0]->stream.pp_areas[i_title];
166 p_intf->p_sys->b_title_update = 1;
169 p_area->i_part = i_chapter;
171 input_ChangeArea( p_input_bank->pp_input[0], (input_area_t*)p_area );
173 p_intf->p_sys->b_chapter_update = 1;
174 vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );
175 GtkSetupMenus( p_intf );
176 vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );
178 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
185 #define GTKPROGRAMTOGGLE( intf ) \
186 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), intf ); \
188 if( menuitem->active && !p_intf->p_sys->b_program_update ) \
190 u16 i_program_id = (ptrdiff_t)user_data; \
192 input_ChangeProgram( p_input_bank->pp_input[0], i_program_id ); \
194 p_intf->p_sys->b_program_update = 1; \
196 vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock ); \
197 GtkSetupMenus( p_intf ); \
198 vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock ); \
200 p_intf->p_sys->b_program_update = 0; \
202 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY ); \
205 void GtkMenubarProgramToggle( GtkCheckMenuItem * menuitem, gpointer user_data )
207 GTKPROGRAMTOGGLE( "intf_window" );
210 void GtkPopupProgramToggle( GtkCheckMenuItem * menuitem, gpointer user_data )
212 GTKPROGRAMTOGGLE( "intf_popup" );
219 void GtkMenubarTitleToggle( GtkCheckMenuItem * menuitem, gpointer user_data )
221 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
223 if( menuitem->active && !p_intf->p_sys->b_title_update )
225 gint i_title = (gint)((long)user_data);
226 input_ChangeArea( p_input_bank->pp_input[0],
227 p_input_bank->pp_input[0]->stream.pp_areas[i_title] );
229 p_intf->p_sys->b_title_update = 1;
230 vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );
231 GtkSetupMenus( p_intf );
232 vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );
233 p_intf->p_sys->b_title_update = 0;
235 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
244 void GtkMenubarChapterToggle( GtkCheckMenuItem * menuitem, gpointer user_data )
246 intf_thread_t * p_intf;
247 input_area_t * p_area;
249 GtkWidget * p_popup_menu;
251 p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
252 p_area = p_input_bank->pp_input[0]->stream.p_selected_area;
253 i_chapter = (gint)((long)user_data);
255 if( menuitem->active && !p_intf->p_sys->b_chapter_update )
257 p_area->i_part = i_chapter;
258 input_ChangeArea( p_input_bank->pp_input[0], (input_area_t*)p_area );
260 p_intf->p_sys->b_chapter_update = 1;
261 p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
262 p_intf->p_sys->p_popup ), "popup_navigation" ) );
264 vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );
265 GtkTitleMenu( p_intf, p_popup_menu, GtkPopupNavigationToggle );
266 vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );
268 p_intf->p_sys->b_chapter_update = 0;
270 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
275 /****************************************************************************
276 * Functions to generate menus
277 ****************************************************************************/
279 /*****************************************************************************
280 * GtkRadioMenu: update interactive menus of the interface
281 *****************************************************************************
282 * Sets up menus with information from input
283 * Warning: since this function is designed to be called by management
284 * function, the interface lock has to be taken
285 *****************************************************************************/
286 static gint GtkRadioMenu( intf_thread_t * p_intf,
287 GtkWidget * p_root, GSList * p_menu_group,
288 char * psz_item_name,
289 int i_nb, int i_selected,
290 void( *pf_toggle )( GtkCheckMenuItem *, gpointer ) )
292 char psz_name[ GTK_MENU_LABEL_SIZE ];
294 GtkWidget * p_submenu;
295 GtkWidget * p_item_group;
297 GtkWidget * p_item_selected;
301 /* temporary hack to avoid blank menu when an open menu is removed */
302 if( GTK_MENU_ITEM(p_root)->submenu != NULL )
304 gtk_menu_popdown( GTK_MENU( GTK_MENU_ITEM(p_root)->submenu ) );
306 /* removes previous menu */
307 gtk_menu_item_remove_submenu( GTK_MENU_ITEM( p_root ) );
308 gtk_widget_set_sensitive( p_root, FALSE );
312 p_item_selected = NULL;
313 p_group = p_menu_group;
315 p_menu = gtk_menu_new();
317 for( i_item = 0 ; i_item < i_nb ; i_item++ )
319 /* we group chapters in packets of ten for small screens */
320 if( ( i_item % 10 == 0 ) && ( i_nb > 20 ) )
324 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_item_group ),
326 gtk_menu_append( GTK_MENU( p_menu ), p_item_group );
329 snprintf( psz_name, GTK_MENU_LABEL_SIZE,
330 "%ss %d to %d", psz_item_name, i_item + 1, i_item + 10);
331 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
332 p_item_group = gtk_menu_item_new_with_label( psz_name );
333 gtk_widget_show( p_item_group );
334 p_submenu = gtk_menu_new();
337 snprintf( psz_name, GTK_MENU_LABEL_SIZE, "%s %d",
338 psz_item_name, i_item + 1 );
339 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
341 p_item = gtk_radio_menu_item_new_with_label( p_group, psz_name );
342 p_group = gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_item ) );
344 if( i_selected == i_item + 1 )
346 p_item_selected = p_item;
349 gtk_widget_show( p_item );
351 /* setup signal hanling */
352 gtk_signal_connect( GTK_OBJECT( p_item ),
354 GTK_SIGNAL_FUNC( pf_toggle ),
355 (gpointer)((long)(i_item + 1)) );
359 gtk_menu_append( GTK_MENU( p_submenu ), p_item );
363 gtk_menu_append( GTK_MENU( p_menu ), p_item );
369 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_item_group ), p_submenu );
370 gtk_menu_append( GTK_MENU( p_menu ), p_item_group );
373 /* link the new menu to the title menu item */
374 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_root ), p_menu );
376 /* toggle currently selected chapter
377 * We have to release the lock since input_ToggleES needs it */
378 if( p_item_selected != NULL )
380 gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( p_item_selected ),
384 /* be sure that menu is sensitive, if there are several items */
387 gtk_widget_set_sensitive( p_root, TRUE );
393 /*****************************************************************************
394 * GtkProgramMenu: update the programs menu of the interface
395 *****************************************************************************
396 * Builds the program menu according to what have been found in the PAT
397 * by the input. Usefull for multi-programs streams such as DVB ones.
398 *****************************************************************************/
399 static gint GtkProgramMenu( gpointer p_data,
401 pgrm_descriptor_t * p_pgrm,
402 void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) )
404 intf_thread_t * p_intf;
407 GtkWidget * p_item_active;
409 char psz_name[ GTK_MENU_LABEL_SIZE ];
413 p_intf = (intf_thread_t *)p_data;
415 /* temporary hack to avoid blank menu when an open menu is removed */
416 if( GTK_MENU_ITEM(p_root)->submenu != NULL )
418 gtk_menu_popdown( GTK_MENU( GTK_MENU_ITEM(p_root)->submenu ) );
420 /* removes previous menu */
421 gtk_menu_item_remove_submenu( GTK_MENU_ITEM( p_root ) );
422 gtk_widget_set_sensitive( p_root, FALSE );
427 p_menu = gtk_menu_new();
429 p_item_active = NULL;
431 /* create a set of program buttons and append them to the container */
432 for( i = 0 ; i < p_input_bank->pp_input[0]->stream.i_pgrm_number ; i++ )
434 snprintf( psz_name, GTK_MENU_LABEL_SIZE, "id %d",
435 p_input_bank->pp_input[0]->stream.pp_programs[i]->i_number );
436 psz_name[GTK_MENU_LABEL_SIZE-1] = '\0';
438 p_item = gtk_radio_menu_item_new_with_label( p_group, psz_name );
440 gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_item ) );
442 if( p_pgrm == p_input_bank->pp_input[0]->stream.pp_programs[i] )
444 /* don't lose p_item when we append into menu */
445 p_item_active = p_item;
448 gtk_widget_show( p_item );
450 /* setup signal hanling */
451 gtk_signal_connect( GTK_OBJECT( p_item ), "toggled",
452 GTK_SIGNAL_FUNC( pf_toggle ),
453 (gpointer)(ptrdiff_t)( p_input_bank->pp_input[0]->
454 stream.pp_programs[i]->i_number ) );
456 gtk_menu_append( GTK_MENU( p_menu ), p_item );
459 /* link the new menu to the menubar item */
460 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_root ), p_menu );
462 /* activation will call signals so we can only do it
463 * when submenu is attached to menu - to get intf_window
464 * We have to release the lock since input_ToggleES needs it */
465 if( p_item_active != NULL )
467 gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( p_item_active ),
471 /* be sure that menu is sensitive if more than 1 program */
472 if( p_input_bank->pp_input[0]->stream.i_pgrm_number > 1 )
474 gtk_widget_set_sensitive( p_root, TRUE );
480 /*****************************************************************************
481 * GtkLanguageMenus: update interactive menus of the interface
482 *****************************************************************************
483 * Sets up menus with information from input:
486 * Warning: since this function is designed to be called by management
487 * function, the interface lock has to be taken
488 *****************************************************************************/
489 static gint GtkLanguageMenus( gpointer p_data,
491 es_descriptor_t * p_es,
493 void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) )
495 intf_thread_t * p_intf;
497 GtkWidget * p_separator;
499 GtkWidget * p_item_active;
501 char psz_name[ GTK_MENU_LABEL_SIZE ];
508 p_intf = (intf_thread_t *)p_data;
510 /* temporary hack to avoid blank menu when an open menu is removed */
511 if( GTK_MENU_ITEM(p_root)->submenu != NULL )
513 gtk_menu_popdown( GTK_MENU( GTK_MENU_ITEM(p_root)->submenu ) );
515 /* removes previous menu */
516 gtk_menu_item_remove_submenu( GTK_MENU_ITEM( p_root ) );
517 gtk_widget_set_sensitive( p_root, FALSE );
522 p_menu = gtk_menu_new();
524 /* special case for "off" item */
525 snprintf( psz_name, GTK_MENU_LABEL_SIZE, "None" );
526 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
528 p_item = gtk_radio_menu_item_new_with_label( p_group, psz_name );
529 p_group = gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_item ) );
531 gtk_widget_show( p_item );
533 /* signal hanling for off */
534 gtk_signal_connect( GTK_OBJECT( p_item ), "toggled",
535 GTK_SIGNAL_FUNC ( pf_toggle ), NULL );
537 gtk_menu_append( GTK_MENU( p_menu ), p_item );
539 p_separator = gtk_menu_item_new();
540 gtk_widget_set_sensitive( p_separator, FALSE );
541 gtk_widget_show( p_separator );
542 gtk_menu_append( GTK_MENU( p_menu ), p_separator );
544 p_item_active = NULL;
547 vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );
549 #define ES p_input_bank->pp_input[0]->stream.pp_es[i]
550 /* create a set of language buttons and append them to the container */
551 for( i = 0 ; i < p_input_bank->pp_input[0]->stream.i_es_number ; i++ )
553 if( ( ES->i_cat == i_cat ) &&
556 p_input_bank->pp_input[0]->stream.p_selected_program ) )
560 p_input_bank->pp_input[0]->stream.pp_es[i]->psz_desc );
561 if( psz_name[0] == '\0' )
563 snprintf( psz_name, GTK_MENU_LABEL_SIZE,
564 "Language %d", i_item );
565 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
568 p_item = gtk_radio_menu_item_new_with_label( p_group, psz_name );
570 gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_item ) );
572 if( p_es == p_input_bank->pp_input[0]->stream.pp_es[i] )
574 /* don't lose p_item when we append into menu */
575 p_item_active = p_item;
578 gtk_widget_show( p_item );
580 /* setup signal hanling */
581 gtk_signal_connect( GTK_OBJECT( p_item ), "toggled",
582 GTK_SIGNAL_FUNC( pf_toggle ),
583 (gpointer)( p_input_bank->pp_input[0]->stream.pp_es[i] ) );
585 gtk_menu_append( GTK_MENU( p_menu ), p_item );
589 vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );
591 /* link the new menu to the menubar item */
592 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_root ), p_menu );
594 /* acitvation will call signals so we can only do it
595 * when submenu is attached to menu - to get intf_window
596 * We have to release the lock since input_ToggleES needs it */
597 if( p_item_active != NULL )
599 gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( p_item_active ),
603 /* be sure that menu is sensitive if non empty */
606 gtk_widget_set_sensitive( p_root, TRUE );
612 /*****************************************************************************
613 * GtkTitleMenu: sets menus for titles and chapters selection
614 *****************************************************************************
615 * Generates two types of menus:
616 * -simple list of titles
617 * -cascaded lists of chapters for each title
618 *****************************************************************************/
619 static gint GtkTitleMenu( gpointer p_data,
620 GtkWidget * p_navigation,
621 void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) )
623 intf_thread_t * p_intf;
624 char psz_name[ GTK_MENU_LABEL_SIZE ];
625 GtkWidget * p_title_menu;
626 GtkWidget * p_title_submenu;
627 GtkWidget * p_title_item;
628 GtkWidget * p_item_active;
629 GtkWidget * p_chapter_menu;
630 GtkWidget * p_chapter_submenu;
631 GtkWidget * p_title_menu_item;
632 GtkWidget * p_chapter_menu_item;
634 GSList * p_title_group;
635 GSList * p_chapter_group;
642 p_intf = (intf_thread_t*)p_data;
644 /* temporary hack to avoid blank menu when an open menu is removed */
645 if( GTK_MENU_ITEM(p_navigation)->submenu != NULL )
647 gtk_menu_popdown( GTK_MENU( GTK_MENU_ITEM(p_navigation)->submenu ) );
649 /* removes previous menu */
650 gtk_menu_item_remove_submenu( GTK_MENU_ITEM( p_navigation ) );
651 gtk_widget_set_sensitive( p_navigation, FALSE );
653 p_title_menu = gtk_menu_new();
654 p_title_group = NULL;
655 p_title_submenu = NULL;
656 p_title_menu_item = NULL;
657 p_chapter_group = NULL;
658 p_chapter_submenu = NULL;
659 p_chapter_menu_item = NULL;
660 p_item_active = NULL;
661 i_title_nb = p_input_bank->pp_input[0]->stream.i_area_nb;
664 for( i_title = 1 ; i_title < i_title_nb ; i_title++ )
666 /* we group titles in packets of ten for small screens */
667 if( ( i_title % 10 == 1 ) && ( i_title_nb > 20 ) )
671 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_title_menu_item ),
673 gtk_menu_append( GTK_MENU( p_title_menu ), p_title_menu_item );
676 snprintf( psz_name, GTK_MENU_LABEL_SIZE,
677 "%d - %d", i_title, i_title + 9 );
678 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
679 p_title_menu_item = gtk_menu_item_new_with_label( psz_name );
680 gtk_widget_show( p_title_menu_item );
681 p_title_submenu = gtk_menu_new();
684 snprintf( psz_name, GTK_MENU_LABEL_SIZE, "Title %d (%d)", i_title,
685 p_input_bank->pp_input[0]->stream.pp_areas[i_title]->i_part_nb );
686 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
688 if( pf_toggle == on_menubar_title_toggle )
690 p_title_item = gtk_radio_menu_item_new_with_label( p_title_group,
693 gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_title_item ) );
695 if( p_input_bank->pp_input[0]->stream.pp_areas[i_title] ==
696 p_input_bank->pp_input[0]->stream.p_selected_area )
698 p_item_active = p_title_item;
701 /* setup signal hanling */
702 gtk_signal_connect( GTK_OBJECT( p_title_item ),
704 GTK_SIGNAL_FUNC( pf_toggle ),
705 (gpointer)(p_input_bank->pp_input[0]->stream.pp_areas[i_title]) );
707 if( p_input_bank->pp_input[0]->stream.i_area_nb > 1 )
709 /* be sure that menu is sensitive */
710 gtk_widget_set_sensitive( p_navigation, TRUE );
716 p_title_item = gtk_menu_item_new_with_label( psz_name );
719 p_chapter_menu = gtk_menu_new();
721 p_input_bank->pp_input[0]->stream.pp_areas[i_title]->i_part_nb;
723 for( i_chapter = 0 ; i_chapter < i_chapter_nb ; i_chapter++ )
725 /* we group chapters in packets of ten for small screens */
726 if( ( i_chapter % 10 == 0 ) && ( i_chapter_nb > 20 ) )
730 gtk_menu_item_set_submenu(
731 GTK_MENU_ITEM( p_chapter_menu_item ),
733 gtk_menu_append( GTK_MENU( p_chapter_menu ),
734 p_chapter_menu_item );
737 snprintf( psz_name, GTK_MENU_LABEL_SIZE,
738 "%d - %d", i_chapter + 1, i_chapter + 10 );
739 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
740 p_chapter_menu_item =
741 gtk_menu_item_new_with_label( psz_name );
742 gtk_widget_show( p_chapter_menu_item );
743 p_chapter_submenu = gtk_menu_new();
746 snprintf( psz_name, GTK_MENU_LABEL_SIZE,
747 "Chapter %d", i_chapter + 1 );
748 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
750 p_item = gtk_radio_menu_item_new_with_label(
751 p_chapter_group, psz_name );
752 p_chapter_group = gtk_radio_menu_item_group(
753 GTK_RADIO_MENU_ITEM( p_item ) );
754 gtk_widget_show( p_item );
756 #define p_area p_input_bank->pp_input[0]->stream.pp_areas[i_title]
758 p_input_bank->pp_input[0]->stream.p_selected_area ) &&
759 ( p_area->i_part == i_chapter + 1 ) )
761 p_item_active = p_item;
765 /* setup signal hanling */
766 gtk_signal_connect( GTK_OBJECT( p_item ),
768 GTK_SIGNAL_FUNC( pf_toggle ),
769 (gpointer)POS2DATA( i_title, i_chapter + 1) );
771 if( i_chapter_nb > 20 )
773 gtk_menu_append( GTK_MENU( p_chapter_submenu ), p_item );
777 gtk_menu_append( GTK_MENU( p_chapter_menu ), p_item );
781 if( i_chapter_nb > 20 )
783 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_chapter_menu_item ),
785 gtk_menu_append( GTK_MENU( p_chapter_menu ),
786 p_chapter_menu_item );
789 /* link the new menu to the title menu item */
790 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_title_item ),
793 if( p_input_bank->pp_input[0]->stream.pp_areas[i_title]->i_part_nb > 1 )
795 /* be sure that menu is sensitive */
796 gtk_widget_set_sensitive( p_navigation, TRUE );
799 GtkRadioMenu( p_intf, p_title_item, p_chapter_group, "Chapter",
800 p_input_bank->pp_input[0]->stream.pp_areas[i_title]->i_part_nb,
802 p_input_bank->pp_input[0]->stream.p_selected_area->i_part +
803 p_input_bank->pp_input[0]->stream.p_selected_area->i_id *100,
808 gtk_widget_show( p_title_item );
810 if( i_title_nb > 20 )
812 gtk_menu_append( GTK_MENU( p_title_submenu ), p_title_item );
816 gtk_menu_append( GTK_MENU( p_title_menu ), p_title_item );
820 if( i_title_nb > 20 )
822 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_title_menu_item ),
824 gtk_menu_append( GTK_MENU( p_title_menu ), p_title_menu_item );
827 /* be sure that menu is sensitive */
828 gtk_widget_set_sensitive( p_title_menu, TRUE );
830 /* link the new menu to the menubar item */
831 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_navigation ), p_title_menu );
833 /* Default selected chapter
834 * We have to release the lock since input_ToggleES needs it */
835 if( p_item_active != NULL )
837 gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( p_item_active ),
841 if( p_input_bank->pp_input[0]->stream.i_area_nb > 1 )
843 /* be sure that menu is sensitive */
844 gtk_widget_set_sensitive( p_navigation, TRUE );
851 /*****************************************************************************
852 * GtkSetupMenus: function that generates title/chapter/audio/subpic
853 * menus with help from preceding functions
854 *****************************************************************************
855 * Function called with the lock on stream
856 *****************************************************************************/
857 gint GtkSetupMenus( intf_thread_t * p_intf )
859 es_descriptor_t * p_audio_es;
860 es_descriptor_t * p_spu_es;
861 GtkWidget * p_menubar_menu;
862 GtkWidget * p_popup_menu;
865 p_intf->p_sys->b_chapter_update |= p_intf->p_sys->b_title_update;
866 p_intf->p_sys->b_audio_update |= p_intf->p_sys->b_title_update |
867 p_intf->p_sys->b_program_update;
868 p_intf->p_sys->b_spu_update |= p_intf->p_sys->b_title_update |
869 p_intf->p_sys->b_program_update;
871 if( p_intf->p_sys->b_program_update )
873 pgrm_descriptor_t * p_pgrm;
875 if( p_input_bank->pp_input[0]->stream.p_new_program )
877 p_pgrm = p_input_bank->pp_input[0]->stream.p_new_program;
881 p_pgrm = p_input_bank->pp_input[0]->stream.p_selected_program;
884 p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
885 p_intf->p_sys->p_window ), "menubar_program" ) );
886 GtkProgramMenu( p_intf, p_menubar_menu, p_pgrm,
887 GtkMenubarProgramToggle );
889 p_intf->p_sys->b_program_update = 1;
890 p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
891 p_intf->p_sys->p_popup ), "popup_program" ) );
892 GtkProgramMenu( p_intf, p_popup_menu, p_pgrm,
893 GtkPopupProgramToggle );
895 p_intf->p_sys->b_program_update = 0;
898 if( p_intf->p_sys->b_title_update )
902 p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
903 p_intf->p_sys->p_window ), "menubar_title" ) );
904 GtkRadioMenu( p_intf, p_menubar_menu, NULL, "Title",
905 p_input_bank->pp_input[0]->stream.i_area_nb - 1,
906 p_input_bank->pp_input[0]->stream.p_selected_area->i_id,
907 GtkMenubarTitleToggle );
909 snprintf( psz_title, 4, "%d",
910 p_input_bank->pp_input[0]->stream.p_selected_area->i_id );
911 psz_title[ 4 ] = '\0';
912 gtk_label_set_text( p_intf->p_sys->p_label_title, psz_title );
914 p_intf->p_sys->b_title_update = 0;
917 if( p_intf->p_sys->b_chapter_update )
921 p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
922 p_intf->p_sys->p_popup ), "popup_navigation" ) );
923 GtkTitleMenu( p_intf, p_popup_menu, GtkPopupNavigationToggle );
925 GtkRadioMenu( p_intf, p_menubar_menu, NULL, "Title",
926 p_input_bank->pp_input[0]->stream.i_area_nb - 1,
927 p_input_bank->pp_input[0]->stream.p_selected_area->i_id,
928 on_menubar_chapter_toggle );
931 p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
932 p_intf->p_sys->p_window ), "menubar_chapter" ) );
934 GtkRadioMenu( p_intf, p_menubar_menu, NULL, "Chapter",
935 p_input_bank->pp_input[0]->stream.p_selected_area->i_part_nb,
936 p_input_bank->pp_input[0]->stream.p_selected_area->i_part,
937 GtkMenubarChapterToggle );
940 snprintf( psz_chapter, 4, "%d",
941 p_input_bank->pp_input[0]->stream.p_selected_area->i_part );
942 psz_chapter[ 4 ] = '\0';
943 gtk_label_set_text( p_intf->p_sys->p_label_chapter, psz_chapter );
945 p_intf->p_sys->i_part =
946 p_input_bank->pp_input[0]->stream.p_selected_area->i_part;
948 p_intf->p_sys->b_chapter_update = 0;
951 /* look for selected ES */
955 for( i = 0 ; i < p_input_bank->pp_input[0]->stream.i_selected_es_number ; i++ )
957 if( p_input_bank->pp_input[0]->stream.pp_selected_es[i]->i_cat == AUDIO_ES )
959 p_audio_es = p_input_bank->pp_input[0]->stream.pp_selected_es[i];
962 if( p_input_bank->pp_input[0]->stream.pp_selected_es[i]->i_cat == SPU_ES )
964 p_spu_es = p_input_bank->pp_input[0]->stream.pp_selected_es[i];
968 vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );
971 if( p_intf->p_sys->b_audio_update )
973 /* find audio root menu */
974 p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
975 p_intf->p_sys->p_window ), "menubar_audio" ) );
977 p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
978 p_intf->p_sys->p_popup ), "popup_audio" ) );
980 p_intf->p_sys->b_audio_update = 1;
981 GtkLanguageMenus( p_intf, p_menubar_menu, p_audio_es, AUDIO_ES,
982 GtkMenubarAudioToggle );
983 p_intf->p_sys->b_audio_update = 1;
984 GtkLanguageMenus( p_intf, p_popup_menu, p_audio_es, AUDIO_ES,
985 GtkPopupAudioToggle );
987 p_intf->p_sys->b_audio_update = 0;
990 /* sub picture menus */
991 if( p_intf->p_sys->b_spu_update )
993 /* find spu root menu */
994 p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
995 p_intf->p_sys->p_window ), "menubar_subpictures" ) );
997 p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
998 p_intf->p_sys->p_popup ), "popup_subpictures" ) );
1000 p_intf->p_sys->b_spu_update = 1;
1001 GtkLanguageMenus( p_intf, p_menubar_menu, p_spu_es, SPU_ES,
1002 GtkMenubarSubtitleToggle );
1003 p_intf->p_sys->b_spu_update = 1;
1004 GtkLanguageMenus( p_intf, p_popup_menu, p_spu_es, SPU_ES,
1005 GtkPopupSubtitleToggle );
1007 p_intf->p_sys->b_spu_update = 0;
1010 vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );