1 /*****************************************************************************
2 * gtk_menu.c : functions to handle menu items.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: gtk_menu.c,v 1.26 2002/06/01 12:31:59 sam 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 */
35 #ifdef MODULE_NAME_IS_gnome
43 #include "gtk_callbacks.h"
44 #include "gtk_interface.h"
45 #include "gtk_support.h"
46 #include "gtk_playlist.h"
47 #include "gtk_common.h"
52 static gint GtkLanguageMenus( gpointer , GtkWidget *, es_descriptor_t *, gint,
53 void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) );
55 void GtkMenubarAudioToggle ( GtkCheckMenuItem *, gpointer );
56 void GtkPopupAudioToggle ( GtkCheckMenuItem *, gpointer );
57 void GtkMenubarSubtitleToggle( GtkCheckMenuItem *, gpointer );
58 void GtkPopupSubtitleToggle ( GtkCheckMenuItem *, gpointer );
59 static gint GtkTitleMenu( gpointer, GtkWidget *,
60 void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) );
61 static gint GtkRadioMenu( intf_thread_t *, GtkWidget *, GSList *,
63 void( *pf_toggle )( GtkCheckMenuItem *, gpointer ) );
65 gint GtkSetupMenus( intf_thread_t * p_intf );
67 /****************************************************************************
68 * Gtk*Toggle: callbacks to toggle the value of a checkmenuitem
69 ****************************************************************************
70 * We need separate functions for menubar and popup here since we can't use
71 * user_data to transmit intf_* and we need to refresh the other menu.
72 ****************************************************************************/
74 #define GTKLANGTOGGLE( intf, window, menu, type, callback, b_update ) \
75 intf_thread_t * p_intf; \
77 es_descriptor_t * p_es; \
79 p_intf = GetIntf( GTK_WIDGET(menuitem), (intf) ); \
81 if( !p_intf->p_sys->b_update ) \
83 p_menu = GTK_WIDGET( gtk_object_get_data( \
84 GTK_OBJECT( p_intf->p_sys->window ), (menu) ) ); \
85 p_es = (es_descriptor_t*)user_data; \
87 input_ToggleES( p_intf->p_sys->p_input, \
88 p_es, menuitem->active ); \
90 p_intf->p_sys->b_update = menuitem->active; \
92 if( p_intf->p_sys->b_update ) \
94 GtkLanguageMenus( p_intf, p_menu, p_es, type, callback ); \
97 p_intf->p_sys->b_update = 0; \
104 void GtkMenubarAudioToggle( GtkCheckMenuItem * menuitem, gpointer user_data )
106 GTKLANGTOGGLE( "intf_window", p_popup, "popup_audio", AUDIO_ES,
107 GtkPopupAudioToggle, b_audio_update );
110 void GtkPopupAudioToggle( GtkCheckMenuItem * menuitem, gpointer user_data )
112 GTKLANGTOGGLE( "intf_popup", p_window, "menubar_audio", AUDIO_ES,
113 GtkMenubarAudioToggle, b_audio_update );
120 void GtkMenubarSubtitleToggle( GtkCheckMenuItem * menuitem, gpointer user_data )
122 GTKLANGTOGGLE( "intf_window", p_popup, "popup_subpictures", SPU_ES,
123 GtkPopupSubtitleToggle, b_spu_update );
126 void GtkPopupSubtitleToggle( GtkCheckMenuItem * menuitem, gpointer user_data )
128 GTKLANGTOGGLE( "intf_popup", p_window, "menubar_subpictures", SPU_ES,
129 GtkMenubarSubtitleToggle, b_spu_update );
138 void GtkPopupNavigationToggle( GtkCheckMenuItem * menuitem,
141 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
143 if( menuitem->active &&
144 !p_intf->p_sys->b_title_update &&
145 !p_intf->p_sys->b_chapter_update )
147 input_area_t *p_area;
149 gint i_title = DATA2TITLE( user_data );
150 gint i_chapter = DATA2CHAPTER( user_data );
152 p_area = p_intf->p_sys->p_input->stream.p_selected_area;
154 if( p_area != p_intf->p_sys->p_input->stream.pp_areas[i_title] )
156 p_area = p_intf->p_sys->p_input->stream.pp_areas[i_title];
157 p_intf->p_sys->b_title_update = 1;
160 p_area->i_part = i_chapter;
162 input_ChangeArea( p_intf->p_sys->p_input, (input_area_t*)p_area );
164 p_intf->p_sys->b_chapter_update = 1;
165 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
166 GtkSetupMenus( p_intf );
167 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
169 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
176 #define GTKPROGRAMTOGGLE( intf ) \
177 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), intf ); \
179 if( menuitem->active && !p_intf->p_sys->b_program_update ) \
181 u16 i_program_id = (ptrdiff_t)user_data; \
183 input_ChangeProgram( p_intf->p_sys->p_input, i_program_id ); \
185 p_intf->p_sys->b_program_update = 1; \
187 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock ); \
188 GtkSetupMenus( p_intf ); \
189 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock ); \
191 p_intf->p_sys->b_program_update = 0; \
193 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY ); \
196 void GtkMenubarProgramToggle( GtkCheckMenuItem * menuitem, gpointer user_data )
198 GTKPROGRAMTOGGLE( "intf_window" );
201 void GtkPopupProgramToggle( GtkCheckMenuItem * menuitem, gpointer user_data )
203 GTKPROGRAMTOGGLE( "intf_popup" );
210 void GtkMenubarTitleToggle( GtkCheckMenuItem * menuitem, gpointer user_data )
212 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
214 if( menuitem->active && !p_intf->p_sys->b_title_update )
216 gint i_title = (gint)((long)user_data);
217 input_ChangeArea( p_intf->p_sys->p_input,
218 p_intf->p_sys->p_input->stream.pp_areas[i_title] );
220 p_intf->p_sys->b_title_update = 1;
221 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
222 GtkSetupMenus( p_intf );
223 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
224 p_intf->p_sys->b_title_update = 0;
226 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
235 void GtkMenubarChapterToggle( GtkCheckMenuItem * menuitem, gpointer user_data )
237 intf_thread_t * p_intf;
238 input_area_t * p_area;
240 GtkWidget * p_popup_menu;
242 p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
243 p_area = p_intf->p_sys->p_input->stream.p_selected_area;
244 i_chapter = (gint)((long)user_data);
246 if( menuitem->active && !p_intf->p_sys->b_chapter_update )
248 p_area->i_part = i_chapter;
249 input_ChangeArea( p_intf->p_sys->p_input, (input_area_t*)p_area );
251 p_intf->p_sys->b_chapter_update = 1;
252 p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
253 p_intf->p_sys->p_popup ), "popup_navigation" ) );
255 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
256 GtkTitleMenu( p_intf, p_popup_menu, GtkPopupNavigationToggle );
257 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
259 p_intf->p_sys->b_chapter_update = 0;
261 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
266 /****************************************************************************
267 * Functions to generate menus
268 ****************************************************************************/
270 /*****************************************************************************
271 * GtkRadioMenu: update interactive menus of the interface
272 *****************************************************************************
273 * Sets up menus with information from input
274 * Warning: since this function is designed to be called by management
275 * function, the interface lock has to be taken
276 *****************************************************************************/
277 static gint GtkRadioMenu( intf_thread_t * p_intf,
278 GtkWidget * p_root, GSList * p_menu_group,
279 char * psz_item_name,
280 int i_nb, int i_selected,
281 void( *pf_toggle )( GtkCheckMenuItem *, gpointer ) )
283 char psz_name[ GTK_MENU_LABEL_SIZE ];
285 GtkWidget * p_submenu;
286 GtkWidget * p_item_group;
288 GtkWidget * p_item_selected;
292 /* temporary hack to avoid blank menu when an open menu is removed */
293 if( GTK_MENU_ITEM(p_root)->submenu != NULL )
295 gtk_menu_popdown( GTK_MENU( GTK_MENU_ITEM(p_root)->submenu ) );
297 /* removes previous menu */
298 gtk_menu_item_remove_submenu( GTK_MENU_ITEM( p_root ) );
299 gtk_widget_set_sensitive( p_root, FALSE );
303 p_item_selected = NULL;
304 p_group = p_menu_group;
306 p_menu = gtk_menu_new();
308 for( i_item = 0 ; i_item < i_nb ; i_item++ )
310 /* we group chapters in packets of ten for small screens */
311 if( ( i_item % 10 == 0 ) && ( i_nb > 20 ) )
315 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_item_group ),
317 gtk_menu_append( GTK_MENU( p_menu ), p_item_group );
320 snprintf( psz_name, GTK_MENU_LABEL_SIZE,
321 "%ss %d to %d", psz_item_name, i_item + 1, i_item + 10);
322 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
323 p_item_group = gtk_menu_item_new_with_label( psz_name );
324 gtk_widget_show( p_item_group );
325 p_submenu = gtk_menu_new();
328 snprintf( psz_name, GTK_MENU_LABEL_SIZE, "%s %d",
329 psz_item_name, i_item + 1 );
330 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
332 p_item = gtk_radio_menu_item_new_with_label( p_group, psz_name );
333 p_group = gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_item ) );
335 if( i_selected == i_item + 1 )
337 p_item_selected = p_item;
340 gtk_widget_show( p_item );
342 /* setup signal hanling */
343 gtk_signal_connect( GTK_OBJECT( p_item ),
345 GTK_SIGNAL_FUNC( pf_toggle ),
346 (gpointer)((long)(i_item + 1)) );
350 gtk_menu_append( GTK_MENU( p_submenu ), p_item );
354 gtk_menu_append( GTK_MENU( p_menu ), p_item );
360 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_item_group ), p_submenu );
361 gtk_menu_append( GTK_MENU( p_menu ), p_item_group );
364 /* link the new menu to the title menu item */
365 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_root ), p_menu );
367 /* toggle currently selected chapter
368 * We have to release the lock since input_ToggleES needs it */
369 if( p_item_selected != NULL )
371 gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( p_item_selected ),
375 /* be sure that menu is sensitive, if there are several items */
378 gtk_widget_set_sensitive( p_root, TRUE );
384 /*****************************************************************************
385 * GtkProgramMenu: update the programs menu of the interface
386 *****************************************************************************
387 * Builds the program menu according to what have been found in the PAT
388 * by the input. Usefull for multi-programs streams such as DVB ones.
389 *****************************************************************************/
390 static gint GtkProgramMenu( gpointer p_data,
392 pgrm_descriptor_t * p_pgrm,
393 void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) )
395 intf_thread_t * p_intf;
398 GtkWidget * p_item_active;
400 char psz_name[ GTK_MENU_LABEL_SIZE ];
404 p_intf = (intf_thread_t *)p_data;
406 /* temporary hack to avoid blank menu when an open menu is removed */
407 if( GTK_MENU_ITEM(p_root)->submenu != NULL )
409 gtk_menu_popdown( GTK_MENU( GTK_MENU_ITEM(p_root)->submenu ) );
411 /* removes previous menu */
412 gtk_menu_item_remove_submenu( GTK_MENU_ITEM( p_root ) );
413 gtk_widget_set_sensitive( p_root, FALSE );
418 p_menu = gtk_menu_new();
420 p_item_active = NULL;
422 /* create a set of program buttons and append them to the container */
423 for( i = 0 ; i < p_intf->p_sys->p_input->stream.i_pgrm_number ; i++ )
425 snprintf( psz_name, GTK_MENU_LABEL_SIZE, "id %d",
426 p_intf->p_sys->p_input->stream.pp_programs[i]->i_number );
427 psz_name[GTK_MENU_LABEL_SIZE-1] = '\0';
429 p_item = gtk_radio_menu_item_new_with_label( p_group, psz_name );
431 gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_item ) );
433 if( p_pgrm == p_intf->p_sys->p_input->stream.pp_programs[i] )
435 /* don't lose p_item when we append into menu */
436 p_item_active = p_item;
439 gtk_widget_show( p_item );
441 /* setup signal hanling */
442 gtk_signal_connect( GTK_OBJECT( p_item ), "toggled",
443 GTK_SIGNAL_FUNC( pf_toggle ),
444 (gpointer)(ptrdiff_t)( p_intf->p_sys->p_input->
445 stream.pp_programs[i]->i_number ) );
447 gtk_menu_append( GTK_MENU( p_menu ), p_item );
450 /* link the new menu to the menubar item */
451 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_root ), p_menu );
453 /* activation will call signals so we can only do it
454 * when submenu is attached to menu - to get intf_window
455 * We have to release the lock since input_ToggleES needs it */
456 if( p_item_active != NULL )
458 gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( p_item_active ),
462 /* be sure that menu is sensitive if more than 1 program */
463 if( p_intf->p_sys->p_input->stream.i_pgrm_number > 1 )
465 gtk_widget_set_sensitive( p_root, TRUE );
471 /*****************************************************************************
472 * GtkLanguageMenus: update interactive menus of the interface
473 *****************************************************************************
474 * Sets up menus with information from input:
477 * Warning: since this function is designed to be called by management
478 * function, the interface lock has to be taken
479 *****************************************************************************/
480 static gint GtkLanguageMenus( gpointer p_data,
482 es_descriptor_t * p_es,
484 void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) )
486 intf_thread_t * p_intf;
488 GtkWidget * p_separator;
490 GtkWidget * p_item_active;
492 char psz_name[ GTK_MENU_LABEL_SIZE ];
496 p_intf = (intf_thread_t *)p_data;
498 /* temporary hack to avoid blank menu when an open menu is removed */
499 if( GTK_MENU_ITEM(p_root)->submenu != NULL )
501 gtk_menu_popdown( GTK_MENU( GTK_MENU_ITEM(p_root)->submenu ) );
503 /* removes previous menu */
504 gtk_menu_item_remove_submenu( GTK_MENU_ITEM( p_root ) );
505 gtk_widget_set_sensitive( p_root, FALSE );
510 p_menu = gtk_menu_new();
512 /* special case for "off" item */
513 snprintf( psz_name, GTK_MENU_LABEL_SIZE, _("None") );
514 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
516 p_item = gtk_radio_menu_item_new_with_label( p_group, psz_name );
517 p_group = gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_item ) );
519 gtk_widget_show( p_item );
521 /* signal hanling for off */
522 gtk_signal_connect( GTK_OBJECT( p_item ), "toggled",
523 GTK_SIGNAL_FUNC ( pf_toggle ), NULL );
525 gtk_menu_append( GTK_MENU( p_menu ), p_item );
527 p_separator = gtk_menu_item_new();
528 gtk_widget_set_sensitive( p_separator, FALSE );
529 gtk_widget_show( p_separator );
530 gtk_menu_append( GTK_MENU( p_menu ), p_separator );
532 p_item_active = NULL;
535 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
537 #define ES p_intf->p_sys->p_input->stream.pp_es[i]
538 /* create a set of language buttons and append them to the container */
539 for( i = 0 ; i < p_intf->p_sys->p_input->stream.i_es_number ; i++ )
541 if( ( ES->i_cat == i_cat ) &&
544 p_intf->p_sys->p_input->stream.p_selected_program ) )
548 p_intf->p_sys->p_input->stream.pp_es[i]->psz_desc );
549 if( psz_name[0] == '\0' )
551 snprintf( psz_name, GTK_MENU_LABEL_SIZE,
552 "Language %d", i_item );
553 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
556 p_item = gtk_radio_menu_item_new_with_label( p_group, psz_name );
558 gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_item ) );
560 if( p_es == p_intf->p_sys->p_input->stream.pp_es[i] )
562 /* don't lose p_item when we append into menu */
563 p_item_active = p_item;
566 gtk_widget_show( p_item );
568 /* setup signal hanling */
569 gtk_signal_connect( GTK_OBJECT( p_item ), "toggled",
570 GTK_SIGNAL_FUNC( pf_toggle ),
571 (gpointer)( p_intf->p_sys->p_input->stream.pp_es[i] ) );
573 gtk_menu_append( GTK_MENU( p_menu ), p_item );
577 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
579 /* link the new menu to the menubar item */
580 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_root ), p_menu );
582 /* acitvation will call signals so we can only do it
583 * when submenu is attached to menu - to get intf_window
584 * We have to release the lock since input_ToggleES needs it */
585 if( p_item_active != NULL )
587 gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( p_item_active ),
591 /* be sure that menu is sensitive if non empty */
594 gtk_widget_set_sensitive( p_root, TRUE );
600 /*****************************************************************************
601 * GtkTitleMenu: sets menus for titles and chapters selection
602 *****************************************************************************
603 * Generates two types of menus:
604 * -simple list of titles
605 * -cascaded lists of chapters for each title
606 *****************************************************************************/
607 static gint GtkTitleMenu( gpointer p_data,
608 GtkWidget * p_navigation,
609 void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) )
611 intf_thread_t * p_intf;
612 char psz_name[ GTK_MENU_LABEL_SIZE ];
613 GtkWidget * p_title_menu;
614 GtkWidget * p_title_submenu;
615 GtkWidget * p_title_item;
616 GtkWidget * p_item_active;
617 GtkWidget * p_chapter_menu;
618 GtkWidget * p_chapter_submenu;
619 GtkWidget * p_title_menu_item;
620 GtkWidget * p_chapter_menu_item;
622 GSList * p_title_group;
623 GSList * p_chapter_group;
630 p_intf = (intf_thread_t*)p_data;
632 /* temporary hack to avoid blank menu when an open menu is removed */
633 if( GTK_MENU_ITEM(p_navigation)->submenu != NULL )
635 gtk_menu_popdown( GTK_MENU( GTK_MENU_ITEM(p_navigation)->submenu ) );
637 /* removes previous menu */
638 gtk_menu_item_remove_submenu( GTK_MENU_ITEM( p_navigation ) );
639 gtk_widget_set_sensitive( p_navigation, FALSE );
641 p_title_menu = gtk_menu_new();
642 p_title_group = NULL;
643 p_title_submenu = NULL;
644 p_title_menu_item = NULL;
645 p_chapter_group = NULL;
646 p_chapter_submenu = NULL;
647 p_chapter_menu_item = NULL;
648 p_item_active = NULL;
649 i_title_nb = p_intf->p_sys->p_input->stream.i_area_nb;
652 for( i_title = 1 ; i_title < i_title_nb ; i_title++ )
654 /* we group titles in packets of ten for small screens */
655 if( ( i_title % 10 == 1 ) && ( i_title_nb > 20 ) )
659 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_title_menu_item ),
661 gtk_menu_append( GTK_MENU( p_title_menu ), p_title_menu_item );
664 snprintf( psz_name, GTK_MENU_LABEL_SIZE,
665 "%d - %d", i_title, i_title + 9 );
666 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
667 p_title_menu_item = gtk_menu_item_new_with_label( psz_name );
668 gtk_widget_show( p_title_menu_item );
669 p_title_submenu = gtk_menu_new();
672 snprintf( psz_name, GTK_MENU_LABEL_SIZE, _("Title %d (%d)"), i_title,
673 p_intf->p_sys->p_input->stream.pp_areas[i_title]->i_part_nb );
674 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
676 if( pf_toggle == on_menubar_title_toggle )
678 p_title_item = gtk_radio_menu_item_new_with_label( p_title_group,
681 gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_title_item ) );
683 if( p_intf->p_sys->p_input->stream.pp_areas[i_title] ==
684 p_intf->p_sys->p_input->stream.p_selected_area )
686 p_item_active = p_title_item;
689 /* setup signal hanling */
690 gtk_signal_connect( GTK_OBJECT( p_title_item ),
692 GTK_SIGNAL_FUNC( pf_toggle ),
693 (gpointer)(p_intf->p_sys->p_input->stream.pp_areas[i_title]) );
695 if( p_intf->p_sys->p_input->stream.i_area_nb > 1 )
697 /* be sure that menu is sensitive */
698 gtk_widget_set_sensitive( p_navigation, TRUE );
704 p_title_item = gtk_menu_item_new_with_label( psz_name );
707 p_chapter_menu = gtk_menu_new();
709 p_intf->p_sys->p_input->stream.pp_areas[i_title]->i_part_nb;
711 for( i_chapter = 0 ; i_chapter < i_chapter_nb ; i_chapter++ )
713 /* we group chapters in packets of ten for small screens */
714 if( ( i_chapter % 10 == 0 ) && ( i_chapter_nb > 20 ) )
718 gtk_menu_item_set_submenu(
719 GTK_MENU_ITEM( p_chapter_menu_item ),
721 gtk_menu_append( GTK_MENU( p_chapter_menu ),
722 p_chapter_menu_item );
725 snprintf( psz_name, GTK_MENU_LABEL_SIZE,
726 "%d - %d", i_chapter + 1, i_chapter + 10 );
727 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
728 p_chapter_menu_item =
729 gtk_menu_item_new_with_label( psz_name );
730 gtk_widget_show( p_chapter_menu_item );
731 p_chapter_submenu = gtk_menu_new();
734 snprintf( psz_name, GTK_MENU_LABEL_SIZE,
735 _("Chapter %d"), i_chapter + 1 );
736 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
738 p_item = gtk_radio_menu_item_new_with_label(
739 p_chapter_group, psz_name );
740 p_chapter_group = gtk_radio_menu_item_group(
741 GTK_RADIO_MENU_ITEM( p_item ) );
742 gtk_widget_show( p_item );
744 #define p_area p_intf->p_sys->p_input->stream.pp_areas[i_title]
746 p_intf->p_sys->p_input->stream.p_selected_area ) &&
747 ( p_area->i_part == i_chapter + 1 ) )
749 p_item_active = p_item;
753 /* setup signal hanling */
754 gtk_signal_connect( GTK_OBJECT( p_item ),
756 GTK_SIGNAL_FUNC( pf_toggle ),
757 (gpointer)POS2DATA( i_title, i_chapter + 1) );
759 if( i_chapter_nb > 20 )
761 gtk_menu_append( GTK_MENU( p_chapter_submenu ), p_item );
765 gtk_menu_append( GTK_MENU( p_chapter_menu ), p_item );
769 if( i_chapter_nb > 20 )
771 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_chapter_menu_item ),
773 gtk_menu_append( GTK_MENU( p_chapter_menu ),
774 p_chapter_menu_item );
777 /* link the new menu to the title menu item */
778 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_title_item ),
781 if( p_intf->p_sys->p_input->stream.pp_areas[i_title]->i_part_nb > 1 )
783 /* be sure that menu is sensitive */
784 gtk_widget_set_sensitive( p_navigation, TRUE );
787 GtkRadioMenu( p_intf, p_title_item, p_chapter_group, _("Chapter"),
788 p_intf->p_sys->p_input->stream.pp_areas[i_title]->i_part_nb,
790 p_intf->p_sys->p_input->stream.p_selected_area->i_part +
791 p_intf->p_sys->p_input->stream.p_selected_area->i_id *100,
796 gtk_widget_show( p_title_item );
798 if( i_title_nb > 20 )
800 gtk_menu_append( GTK_MENU( p_title_submenu ), p_title_item );
804 gtk_menu_append( GTK_MENU( p_title_menu ), p_title_item );
808 if( i_title_nb > 20 )
810 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_title_menu_item ),
812 gtk_menu_append( GTK_MENU( p_title_menu ), p_title_menu_item );
815 /* be sure that menu is sensitive */
816 gtk_widget_set_sensitive( p_title_menu, TRUE );
818 /* link the new menu to the menubar item */
819 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_navigation ), p_title_menu );
821 /* Default selected chapter
822 * We have to release the lock since input_ToggleES needs it */
823 if( p_item_active != NULL )
825 gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( p_item_active ),
829 if( p_intf->p_sys->p_input->stream.i_area_nb > 1 )
831 /* be sure that menu is sensitive */
832 gtk_widget_set_sensitive( p_navigation, TRUE );
839 /*****************************************************************************
840 * GtkSetupMenus: function that generates title/chapter/audio/subpic
841 * menus with help from preceding functions
842 *****************************************************************************
843 * Function called with the lock on stream
844 *****************************************************************************/
845 gint GtkSetupMenus( intf_thread_t * p_intf )
847 es_descriptor_t * p_audio_es;
848 es_descriptor_t * p_spu_es;
849 GtkWidget * p_menubar_menu;
850 GtkWidget * p_popup_menu;
853 p_intf->p_sys->b_chapter_update |= p_intf->p_sys->b_title_update;
854 p_intf->p_sys->b_audio_update |= p_intf->p_sys->b_title_update |
855 p_intf->p_sys->b_program_update;
856 p_intf->p_sys->b_spu_update |= p_intf->p_sys->b_title_update |
857 p_intf->p_sys->b_program_update;
859 if( p_intf->p_sys->b_program_update )
861 pgrm_descriptor_t * p_pgrm;
863 if( p_intf->p_sys->p_input->stream.p_new_program )
865 p_pgrm = p_intf->p_sys->p_input->stream.p_new_program;
869 p_pgrm = p_intf->p_sys->p_input->stream.p_selected_program;
872 p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
873 p_intf->p_sys->p_window ), "menubar_program" ) );
874 GtkProgramMenu( p_intf, p_menubar_menu, p_pgrm,
875 GtkMenubarProgramToggle );
877 p_intf->p_sys->b_program_update = 1;
878 p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
879 p_intf->p_sys->p_popup ), "popup_program" ) );
880 GtkProgramMenu( p_intf, p_popup_menu, p_pgrm,
881 GtkPopupProgramToggle );
883 p_intf->p_sys->b_program_update = 0;
886 if( p_intf->p_sys->b_title_update )
890 p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
891 p_intf->p_sys->p_window ), "menubar_title" ) );
892 GtkRadioMenu( p_intf, p_menubar_menu, NULL, _("Title"),
893 p_intf->p_sys->p_input->stream.i_area_nb - 1,
894 p_intf->p_sys->p_input->stream.p_selected_area->i_id,
895 GtkMenubarTitleToggle );
897 snprintf( psz_title, 4, "%d",
898 p_intf->p_sys->p_input->stream.p_selected_area->i_id );
899 psz_title[ 4 ] = '\0';
900 gtk_label_set_text( p_intf->p_sys->p_label_title, psz_title );
902 p_intf->p_sys->b_title_update = 0;
905 if( p_intf->p_sys->b_chapter_update )
909 p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
910 p_intf->p_sys->p_popup ), "popup_navigation" ) );
911 GtkTitleMenu( p_intf, p_popup_menu, GtkPopupNavigationToggle );
913 GtkRadioMenu( p_intf, p_menubar_menu, NULL, _("Title"),
914 p_intf->p_sys->p_input->stream.i_area_nb - 1,
915 p_intf->p_sys->p_input->stream.p_selected_area->i_id,
916 on_menubar_chapter_toggle );
919 p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
920 p_intf->p_sys->p_window ), "menubar_chapter" ) );
922 GtkRadioMenu( p_intf, p_menubar_menu, NULL, _("Chapter"),
923 p_intf->p_sys->p_input->stream.p_selected_area->i_part_nb,
924 p_intf->p_sys->p_input->stream.p_selected_area->i_part,
925 GtkMenubarChapterToggle );
928 snprintf( psz_chapter, 4, "%d",
929 p_intf->p_sys->p_input->stream.p_selected_area->i_part );
930 psz_chapter[ 4 ] = '\0';
931 gtk_label_set_text( p_intf->p_sys->p_label_chapter, psz_chapter );
933 p_intf->p_sys->i_part =
934 p_intf->p_sys->p_input->stream.p_selected_area->i_part;
936 p_intf->p_sys->b_chapter_update = 0;
939 /* look for selected ES */
943 for( i = 0 ; i < p_intf->p_sys->p_input->stream.i_selected_es_number ; i++ )
945 if( p_intf->p_sys->p_input->stream.pp_selected_es[i]->i_cat == AUDIO_ES )
947 p_audio_es = p_intf->p_sys->p_input->stream.pp_selected_es[i];
950 if( p_intf->p_sys->p_input->stream.pp_selected_es[i]->i_cat == SPU_ES )
952 p_spu_es = p_intf->p_sys->p_input->stream.pp_selected_es[i];
956 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
959 if( p_intf->p_sys->b_audio_update )
961 /* find audio root menu */
962 p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
963 p_intf->p_sys->p_window ), "menubar_audio" ) );
965 p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
966 p_intf->p_sys->p_popup ), "popup_audio" ) );
968 p_intf->p_sys->b_audio_update = 1;
969 GtkLanguageMenus( p_intf, p_menubar_menu, p_audio_es, AUDIO_ES,
970 GtkMenubarAudioToggle );
971 p_intf->p_sys->b_audio_update = 1;
972 GtkLanguageMenus( p_intf, p_popup_menu, p_audio_es, AUDIO_ES,
973 GtkPopupAudioToggle );
975 p_intf->p_sys->b_audio_update = 0;
978 /* sub picture menus */
979 if( p_intf->p_sys->b_spu_update )
981 /* find spu root menu */
982 p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
983 p_intf->p_sys->p_window ), "menubar_subpictures" ) );
985 p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
986 p_intf->p_sys->p_popup ), "popup_subpictures" ) );
988 p_intf->p_sys->b_spu_update = 1;
989 GtkLanguageMenus( p_intf, p_menubar_menu, p_spu_es, SPU_ES,
990 GtkMenubarSubtitleToggle );
991 p_intf->p_sys->b_spu_update = 1;
992 GtkLanguageMenus( p_intf, p_popup_menu, p_spu_es, SPU_ES,
993 GtkPopupSubtitleToggle );
995 p_intf->p_sys->b_spu_update = 0;
998 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );