1 /*****************************************************************************
2 * gtk_menu.c : functions to handle menu items.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: gtk_menu.c,v 1.22 2002/03/06 01:20:56 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;
250 GtkWidget * p_popup_menu;
252 p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
253 p_area = p_input_bank->pp_input[0]->stream.p_selected_area;
254 i_chapter = (gint)((long)user_data);
256 if( menuitem->active && !p_intf->p_sys->b_chapter_update )
258 p_area->i_part = i_chapter;
259 input_ChangeArea( p_input_bank->pp_input[0], (input_area_t*)p_area );
261 snprintf( psz_chapter, 4, "%02d", p_area->i_part );
262 psz_chapter[ 4 ] = '\0';
263 gtk_label_set_text( p_intf->p_sys->p_label_chapter, psz_chapter );
265 p_intf->p_sys->b_chapter_update = 1;
266 p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
267 p_intf->p_sys->p_popup ), "popup_navigation" ) );
269 vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );
270 GtkTitleMenu( p_intf, p_popup_menu, GtkPopupNavigationToggle );
271 vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );
273 p_intf->p_sys->b_chapter_update = 0;
275 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
280 /****************************************************************************
281 * Functions to generate menus
282 ****************************************************************************/
284 /*****************************************************************************
285 * GtkRadioMenu: update interactive menus of the interface
286 *****************************************************************************
287 * Sets up menus with information from input
288 * Warning: since this function is designed to be called by management
289 * function, the interface lock has to be taken
290 *****************************************************************************/
291 static gint GtkRadioMenu( intf_thread_t * p_intf,
292 GtkWidget * p_root, GSList * p_menu_group,
293 char * psz_item_name,
294 int i_nb, int i_selected,
295 void( *pf_toggle )( GtkCheckMenuItem *, gpointer ) )
297 char psz_name[ GTK_MENU_LABEL_SIZE ];
299 GtkWidget * p_submenu;
300 GtkWidget * p_item_group;
302 GtkWidget * p_item_selected;
306 /* temporary hack to avoid blank menu when an open menu is removed */
307 if( GTK_MENU_ITEM(p_root)->submenu != NULL )
309 gtk_menu_popdown( GTK_MENU( GTK_MENU_ITEM(p_root)->submenu ) );
311 /* removes previous menu */
312 gtk_menu_item_remove_submenu( GTK_MENU_ITEM( p_root ) );
313 gtk_widget_set_sensitive( p_root, FALSE );
317 p_item_selected = NULL;
318 p_group = p_menu_group;
320 p_menu = gtk_menu_new();
322 for( i_item = 0 ; i_item < i_nb ; i_item++ )
324 /* we group chapters in packets of ten for small screens */
325 if( ( i_item % 10 == 0 ) && ( i_nb > 20 ) )
329 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_item_group ),
331 gtk_menu_append( GTK_MENU( p_menu ), p_item_group );
334 snprintf( psz_name, GTK_MENU_LABEL_SIZE,
335 "%ss %d to %d", psz_item_name, i_item + 1, i_item + 10);
336 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
337 p_item_group = gtk_menu_item_new_with_label( psz_name );
338 gtk_widget_show( p_item_group );
339 p_submenu = gtk_menu_new();
342 snprintf( psz_name, GTK_MENU_LABEL_SIZE, "%s %d",
343 psz_item_name, i_item + 1 );
344 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
346 p_item = gtk_radio_menu_item_new_with_label( p_group, psz_name );
347 p_group = gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_item ) );
349 if( i_selected == i_item + 1 )
351 p_item_selected = p_item;
354 gtk_widget_show( p_item );
356 /* setup signal hanling */
357 gtk_signal_connect( GTK_OBJECT( p_item ),
359 GTK_SIGNAL_FUNC( pf_toggle ),
360 (gpointer)((long)(i_item + 1)) );
364 gtk_menu_append( GTK_MENU( p_submenu ), p_item );
368 gtk_menu_append( GTK_MENU( p_menu ), p_item );
374 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_item_group ), p_submenu );
375 gtk_menu_append( GTK_MENU( p_menu ), p_item_group );
378 /* link the new menu to the title menu item */
379 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_root ), p_menu );
381 /* toggle currently selected chapter
382 * We have to release the lock since input_ToggleES needs it */
383 if( p_item_selected != NULL )
385 vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );
386 gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( p_item_selected ),
388 vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );
391 /* be sure that menu is sensitive, if there are several items */
394 gtk_widget_set_sensitive( p_root, TRUE );
400 /*****************************************************************************
401 * GtkProgramMenu: update the programs menu of the interface
402 *****************************************************************************
403 * Builds the program menu according to what have been found in the PAT
404 * by the input. Usefull for multi-programs streams such as DVB ones.
405 *****************************************************************************/
406 static gint GtkProgramMenu( gpointer p_data,
408 pgrm_descriptor_t * p_pgrm,
409 void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) )
411 intf_thread_t * p_intf;
414 GtkWidget * p_item_active;
416 char psz_name[ GTK_MENU_LABEL_SIZE ];
420 p_intf = (intf_thread_t *)p_data;
422 /* temporary hack to avoid blank menu when an open menu is removed */
423 if( GTK_MENU_ITEM(p_root)->submenu != NULL )
425 gtk_menu_popdown( GTK_MENU( GTK_MENU_ITEM(p_root)->submenu ) );
427 /* removes previous menu */
428 gtk_menu_item_remove_submenu( GTK_MENU_ITEM( p_root ) );
429 gtk_widget_set_sensitive( p_root, FALSE );
434 p_menu = gtk_menu_new();
436 p_item_active = NULL;
438 /* create a set of program buttons and append them to the container */
439 for( i = 0 ; i < p_input_bank->pp_input[0]->stream.i_pgrm_number ; i++ )
441 snprintf( psz_name, GTK_MENU_LABEL_SIZE, "id %d",
442 p_input_bank->pp_input[0]->stream.pp_programs[i]->i_number );
443 psz_name[GTK_MENU_LABEL_SIZE-1] = '\0';
445 p_item = gtk_radio_menu_item_new_with_label( p_group, psz_name );
447 gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_item ) );
449 if( p_pgrm == p_input_bank->pp_input[0]->stream.pp_programs[i] )
451 /* don't lose p_item when we append into menu */
452 p_item_active = p_item;
455 gtk_widget_show( p_item );
457 /* setup signal hanling */
458 gtk_signal_connect( GTK_OBJECT( p_item ), "toggled",
459 GTK_SIGNAL_FUNC( pf_toggle ),
460 (gpointer)(ptrdiff_t)( p_input_bank->pp_input[0]->
461 stream.pp_programs[i]->i_number ) );
463 gtk_menu_append( GTK_MENU( p_menu ), p_item );
466 /* link the new menu to the menubar item */
467 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_root ), p_menu );
469 /* activation will call signals so we can only do it
470 * when submenu is attached to menu - to get intf_window
471 * We have to release the lock since input_ToggleES needs it */
472 if( p_item_active != NULL )
474 gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( p_item_active ),
478 /* be sure that menu is sensitive if more than 1 program */
479 if( p_input_bank->pp_input[0]->stream.i_pgrm_number > 1 )
481 gtk_widget_set_sensitive( p_root, TRUE );
487 /*****************************************************************************
488 * GtkLanguageMenus: update interactive menus of the interface
489 *****************************************************************************
490 * Sets up menus with information from input:
493 * Warning: since this function is designed to be called by management
494 * function, the interface lock has to be taken
495 *****************************************************************************/
496 static gint GtkLanguageMenus( gpointer p_data,
498 es_descriptor_t * p_es,
500 void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) )
502 intf_thread_t * p_intf;
504 GtkWidget * p_separator;
506 GtkWidget * p_item_active;
508 char psz_name[ GTK_MENU_LABEL_SIZE ];
515 p_intf = (intf_thread_t *)p_data;
517 /* temporary hack to avoid blank menu when an open menu is removed */
518 if( GTK_MENU_ITEM(p_root)->submenu != NULL )
520 gtk_menu_popdown( GTK_MENU( GTK_MENU_ITEM(p_root)->submenu ) );
522 /* removes previous menu */
523 gtk_menu_item_remove_submenu( GTK_MENU_ITEM( p_root ) );
524 gtk_widget_set_sensitive( p_root, FALSE );
529 p_menu = gtk_menu_new();
531 /* special case for "off" item */
532 snprintf( psz_name, GTK_MENU_LABEL_SIZE, "None" );
533 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
535 p_item = gtk_radio_menu_item_new_with_label( p_group, psz_name );
536 p_group = gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_item ) );
538 gtk_widget_show( p_item );
540 /* signal hanling for off */
541 gtk_signal_connect( GTK_OBJECT( p_item ), "toggled",
542 GTK_SIGNAL_FUNC ( pf_toggle ), NULL );
544 gtk_menu_append( GTK_MENU( p_menu ), p_item );
546 p_separator = gtk_menu_item_new();
547 gtk_widget_set_sensitive( p_separator, FALSE );
548 gtk_widget_show( p_separator );
549 gtk_menu_append( GTK_MENU( p_menu ), p_separator );
551 p_item_active = NULL;
554 vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );
556 #define ES p_input_bank->pp_input[0]->stream.pp_es[i]
557 /* create a set of language buttons and append them to the container */
558 for( i = 0 ; i < p_input_bank->pp_input[0]->stream.i_es_number ; i++ )
560 if( ( ES->i_cat == i_cat ) &&
563 p_input_bank->pp_input[0]->stream.p_selected_program ) )
567 p_input_bank->pp_input[0]->stream.pp_es[i]->psz_desc );
568 if( psz_name[0] == '\0' )
570 snprintf( psz_name, GTK_MENU_LABEL_SIZE,
571 "Language %d", i_item );
572 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
575 p_item = gtk_radio_menu_item_new_with_label( p_group, psz_name );
577 gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_item ) );
579 if( p_es == p_input_bank->pp_input[0]->stream.pp_es[i] )
581 /* don't lose p_item when we append into menu */
582 p_item_active = p_item;
585 gtk_widget_show( p_item );
587 /* setup signal hanling */
588 gtk_signal_connect( GTK_OBJECT( p_item ), "toggled",
589 GTK_SIGNAL_FUNC( pf_toggle ),
590 (gpointer)( p_input_bank->pp_input[0]->stream.pp_es[i] ) );
592 gtk_menu_append( GTK_MENU( p_menu ), p_item );
596 vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );
598 /* link the new menu to the menubar item */
599 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_root ), p_menu );
601 /* acitvation will call signals so we can only do it
602 * when submenu is attached to menu - to get intf_window
603 * We have to release the lock since input_ToggleES needs it */
604 if( p_item_active != NULL )
606 gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( p_item_active ),
610 /* be sure that menu is sensitive if non empty */
613 gtk_widget_set_sensitive( p_root, TRUE );
619 /*****************************************************************************
620 * GtkTitleMenu: sets menus for titles and chapters selection
621 *****************************************************************************
622 * Generates two types of menus:
623 * -simple list of titles
624 * -cascaded lists of chapters for each title
625 *****************************************************************************/
626 static gint GtkTitleMenu( gpointer p_data,
627 GtkWidget * p_navigation,
628 void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) )
630 intf_thread_t * p_intf;
631 char psz_name[ GTK_MENU_LABEL_SIZE ];
632 GtkWidget * p_title_menu;
633 GtkWidget * p_title_submenu;
634 GtkWidget * p_title_item;
635 GtkWidget * p_item_active;
636 GtkWidget * p_chapter_menu;
637 GtkWidget * p_chapter_submenu;
638 GtkWidget * p_title_menu_item;
639 GtkWidget * p_chapter_menu_item;
641 GSList * p_title_group;
642 GSList * p_chapter_group;
649 p_intf = (intf_thread_t*)p_data;
651 /* temporary hack to avoid blank menu when an open menu is removed */
652 if( GTK_MENU_ITEM(p_navigation)->submenu != NULL )
654 gtk_menu_popdown( GTK_MENU( GTK_MENU_ITEM(p_navigation)->submenu ) );
656 /* removes previous menu */
657 gtk_menu_item_remove_submenu( GTK_MENU_ITEM( p_navigation ) );
658 gtk_widget_set_sensitive( p_navigation, FALSE );
660 p_title_menu = gtk_menu_new();
661 p_title_group = NULL;
662 p_title_submenu = NULL;
663 p_title_menu_item = NULL;
664 p_chapter_group = NULL;
665 p_chapter_submenu = NULL;
666 p_chapter_menu_item = NULL;
667 p_item_active = NULL;
668 i_title_nb = p_input_bank->pp_input[0]->stream.i_area_nb;
671 for( i_title = 1 ; i_title < i_title_nb ; i_title++ )
673 /* we group titles in packets of ten for small screens */
674 if( ( i_title % 10 == 1 ) && ( i_title_nb > 20 ) )
678 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_title_menu_item ),
680 gtk_menu_append( GTK_MENU( p_title_menu ), p_title_menu_item );
683 snprintf( psz_name, GTK_MENU_LABEL_SIZE,
684 "%d - %d", i_title, i_title + 9 );
685 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
686 p_title_menu_item = gtk_menu_item_new_with_label( psz_name );
687 gtk_widget_show( p_title_menu_item );
688 p_title_submenu = gtk_menu_new();
691 snprintf( psz_name, GTK_MENU_LABEL_SIZE, "Title %d (%d)", i_title,
692 p_input_bank->pp_input[0]->stream.pp_areas[i_title]->i_part_nb );
693 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
695 if( pf_toggle == on_menubar_title_toggle )
697 p_title_item = gtk_radio_menu_item_new_with_label( p_title_group,
700 gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_title_item ) );
702 if( p_input_bank->pp_input[0]->stream.pp_areas[i_title] ==
703 p_input_bank->pp_input[0]->stream.p_selected_area )
705 p_item_active = p_title_item;
708 /* setup signal hanling */
709 gtk_signal_connect( GTK_OBJECT( p_title_item ),
711 GTK_SIGNAL_FUNC( pf_toggle ),
712 (gpointer)(p_input_bank->pp_input[0]->stream.pp_areas[i_title]) );
714 if( p_input_bank->pp_input[0]->stream.i_area_nb > 1 )
716 /* be sure that menu is sensitive */
717 gtk_widget_set_sensitive( p_navigation, TRUE );
723 p_title_item = gtk_menu_item_new_with_label( psz_name );
726 p_chapter_menu = gtk_menu_new();
728 p_input_bank->pp_input[0]->stream.pp_areas[i_title]->i_part_nb;
730 for( i_chapter = 0 ; i_chapter < i_chapter_nb ; i_chapter++ )
732 /* we group chapters in packets of ten for small screens */
733 if( ( i_chapter % 10 == 0 ) && ( i_chapter_nb > 20 ) )
737 gtk_menu_item_set_submenu(
738 GTK_MENU_ITEM( p_chapter_menu_item ),
740 gtk_menu_append( GTK_MENU( p_chapter_menu ),
741 p_chapter_menu_item );
744 snprintf( psz_name, GTK_MENU_LABEL_SIZE,
745 "%d - %d", i_chapter + 1, i_chapter + 10 );
746 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
747 p_chapter_menu_item =
748 gtk_menu_item_new_with_label( psz_name );
749 gtk_widget_show( p_chapter_menu_item );
750 p_chapter_submenu = gtk_menu_new();
753 snprintf( psz_name, GTK_MENU_LABEL_SIZE,
754 "Chapter %d", i_chapter + 1 );
755 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
757 p_item = gtk_radio_menu_item_new_with_label(
758 p_chapter_group, psz_name );
759 p_chapter_group = gtk_radio_menu_item_group(
760 GTK_RADIO_MENU_ITEM( p_item ) );
761 gtk_widget_show( p_item );
763 #define p_area p_input_bank->pp_input[0]->stream.pp_areas[i_title]
765 p_input_bank->pp_input[0]->stream.p_selected_area ) &&
766 ( p_area->i_part == i_chapter + 1 ) )
768 p_item_active = p_item;
772 /* setup signal hanling */
773 gtk_signal_connect( GTK_OBJECT( p_item ),
775 GTK_SIGNAL_FUNC( pf_toggle ),
776 (gpointer)POS2DATA( i_title, i_chapter + 1) );
778 if( i_chapter_nb > 20 )
780 gtk_menu_append( GTK_MENU( p_chapter_submenu ), p_item );
784 gtk_menu_append( GTK_MENU( p_chapter_menu ), p_item );
788 if( i_chapter_nb > 20 )
790 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_chapter_menu_item ),
792 gtk_menu_append( GTK_MENU( p_chapter_menu ),
793 p_chapter_menu_item );
796 /* link the new menu to the title menu item */
797 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_title_item ),
800 if( p_input_bank->pp_input[0]->stream.pp_areas[i_title]->i_part_nb > 1 )
802 /* be sure that menu is sensitive */
803 gtk_widget_set_sensitive( p_navigation, TRUE );
806 GtkRadioMenu( p_intf, p_title_item, p_chapter_group, "Chapter",
807 p_input_bank->pp_input[0]->stream.pp_areas[i_title]->i_part_nb,
809 p_input_bank->pp_input[0]->stream.p_selected_area->i_part +
810 p_input_bank->pp_input[0]->stream.p_selected_area->i_id *100,
815 gtk_widget_show( p_title_item );
817 if( i_title_nb > 20 )
819 gtk_menu_append( GTK_MENU( p_title_submenu ), p_title_item );
823 gtk_menu_append( GTK_MENU( p_title_menu ), p_title_item );
827 if( i_title_nb > 20 )
829 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_title_menu_item ),
831 gtk_menu_append( GTK_MENU( p_title_menu ), p_title_menu_item );
834 /* be sure that menu is sensitive */
835 gtk_widget_set_sensitive( p_title_menu, TRUE );
837 /* link the new menu to the menubar item */
838 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_navigation ), p_title_menu );
840 /* Default selected chapter
841 * We have to release the lock since input_ToggleES needs it */
842 if( p_item_active != NULL )
844 vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );
845 gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( p_item_active ),
847 vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );
850 if( p_input_bank->pp_input[0]->stream.i_area_nb > 1 )
852 /* be sure that menu is sensitive */
853 gtk_widget_set_sensitive( p_navigation, TRUE );
860 /*****************************************************************************
861 * GtkSetupMenus: function that generates title/chapter/audio/subpic
862 * menus with help from preceding functions
863 *****************************************************************************
864 * Function called with the lock on stream
865 *****************************************************************************/
866 gint GtkSetupMenus( intf_thread_t * p_intf )
868 es_descriptor_t * p_audio_es;
869 es_descriptor_t * p_spu_es;
870 GtkWidget * p_menubar_menu;
871 GtkWidget * p_popup_menu;
874 p_intf->p_sys->b_chapter_update |= p_intf->p_sys->b_title_update;
875 p_intf->p_sys->b_audio_update |= p_intf->p_sys->b_title_update |
876 p_intf->p_sys->b_program_update;
877 p_intf->p_sys->b_spu_update |= p_intf->p_sys->b_title_update |
878 p_intf->p_sys->b_program_update;
880 if( p_intf->p_sys->b_program_update )
882 pgrm_descriptor_t * p_pgrm;
884 if( p_input_bank->pp_input[0]->stream.p_new_program )
886 p_pgrm = p_input_bank->pp_input[0]->stream.p_new_program;
890 p_pgrm = p_input_bank->pp_input[0]->stream.p_selected_program;
893 p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
894 p_intf->p_sys->p_window ), "menubar_program" ) );
895 GtkProgramMenu( p_intf, p_menubar_menu, p_pgrm,
896 GtkMenubarProgramToggle );
898 p_intf->p_sys->b_program_update = 1;
899 p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
900 p_intf->p_sys->p_popup ), "popup_program" ) );
901 GtkProgramMenu( p_intf, p_popup_menu, p_pgrm,
902 GtkPopupProgramToggle );
904 p_intf->p_sys->b_program_update = 0;
907 if( p_intf->p_sys->b_title_update )
911 p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
912 p_intf->p_sys->p_window ), "menubar_title" ) );
913 GtkRadioMenu( p_intf, p_menubar_menu, NULL, "Title",
914 p_input_bank->pp_input[0]->stream.i_area_nb - 1,
915 p_input_bank->pp_input[0]->stream.p_selected_area->i_id,
916 GtkMenubarTitleToggle );
918 snprintf( psz_title, 4, "%d",
919 p_input_bank->pp_input[0]->stream.p_selected_area->i_id );
920 psz_title[ 4 ] = '\0';
921 gtk_label_set_text( p_intf->p_sys->p_label_title, psz_title );
923 p_intf->p_sys->b_title_update = 0;
926 if( p_intf->p_sys->b_chapter_update )
930 p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
931 p_intf->p_sys->p_popup ), "popup_navigation" ) );
932 GtkTitleMenu( p_intf, p_popup_menu, GtkPopupNavigationToggle );
934 GtkRadioMenu( p_intf, p_menubar_menu, NULL, "Title",
935 p_input_bank->pp_input[0]->stream.i_area_nb - 1,
936 p_input_bank->pp_input[0]->stream.p_selected_area->i_id,
937 on_menubar_chapter_toggle );
940 p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
941 p_intf->p_sys->p_window ), "menubar_chapter" ) );
943 GtkRadioMenu( p_intf, p_menubar_menu, NULL, "Chapter",
944 p_input_bank->pp_input[0]->stream.p_selected_area->i_part_nb,
945 p_input_bank->pp_input[0]->stream.p_selected_area->i_part,
946 GtkMenubarChapterToggle );
949 snprintf( psz_chapter, 4, "%d",
950 p_input_bank->pp_input[0]->stream.p_selected_area->i_part );
951 psz_chapter[ 4 ] = '\0';
952 gtk_label_set_text( p_intf->p_sys->p_label_chapter, psz_chapter );
954 p_intf->p_sys->i_part =
955 p_input_bank->pp_input[0]->stream.p_selected_area->i_part;
957 p_intf->p_sys->b_chapter_update = 0;
960 /* look for selected ES */
964 for( i = 0 ; i < p_input_bank->pp_input[0]->stream.i_selected_es_number ; i++ )
966 if( p_input_bank->pp_input[0]->stream.pp_selected_es[i]->i_cat == AUDIO_ES )
968 p_audio_es = p_input_bank->pp_input[0]->stream.pp_selected_es[i];
971 if( p_input_bank->pp_input[0]->stream.pp_selected_es[i]->i_cat == SPU_ES )
973 p_spu_es = p_input_bank->pp_input[0]->stream.pp_selected_es[i];
977 vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );
980 if( p_intf->p_sys->b_audio_update )
982 /* find audio root menu */
983 p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
984 p_intf->p_sys->p_window ), "menubar_audio" ) );
986 p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
987 p_intf->p_sys->p_popup ), "popup_audio" ) );
989 p_intf->p_sys->b_audio_update = 1;
990 GtkLanguageMenus( p_intf, p_menubar_menu, p_audio_es, AUDIO_ES,
991 GtkMenubarAudioToggle );
992 p_intf->p_sys->b_audio_update = 1;
993 GtkLanguageMenus( p_intf, p_popup_menu, p_audio_es, AUDIO_ES,
994 GtkPopupAudioToggle );
996 p_intf->p_sys->b_audio_update = 0;
999 /* sub picture menus */
1000 if( p_intf->p_sys->b_spu_update )
1002 /* find spu root menu */
1003 p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1004 p_intf->p_sys->p_window ), "menubar_subpictures" ) );
1006 p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
1007 p_intf->p_sys->p_popup ), "popup_subpictures" ) );
1009 p_intf->p_sys->b_spu_update = 1;
1010 GtkLanguageMenus( p_intf, p_menubar_menu, p_spu_es, SPU_ES,
1011 GtkMenubarSubtitleToggle );
1012 p_intf->p_sys->b_spu_update = 1;
1013 GtkLanguageMenus( p_intf, p_popup_menu, p_spu_es, SPU_ES,
1014 GtkPopupSubtitleToggle );
1016 p_intf->p_sys->b_spu_update = 0;
1019 vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );