]> git.sesse.net Git - vlc/blob - plugins/gtk/gtk_menu.c
* More precise way to retrieve a PTS from the bit stream.
[vlc] / plugins / gtk / gtk_menu.c
1 /*****************************************************************************
2  * gtk_menu.c : functions to handle menu items.
3  *****************************************************************************
4  * Copyright (C) 2000, 2001 VideoLAN
5  * $Id: gtk_menu.c,v 1.18 2002/01/07 02:12:29 sam Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *          Stéphane Borel <stef@via.ecp.fr>
9  *      
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <sys/types.h>                                              /* off_t */
29 #include <stdlib.h>
30
31 #include <videolan/vlc.h>
32
33 #ifdef MODULE_NAME_IS_gnome
34 #   include <gnome.h>
35 #else
36 #   include <gtk/gtk.h>
37 #endif
38
39 #include <string.h>
40
41 #include "stream_control.h"
42 #include "input_ext-intf.h"
43
44 #include "interface.h"
45 #include "intf_playlist.h"
46
47 #include "video.h"
48 #include "video_output.h"
49 #include "audio_output.h"
50
51 #include "gtk_callbacks.h"
52 #include "gtk_interface.h"
53 #include "gtk_support.h"
54 #include "gtk_playlist.h"
55 #include "gtk_common.h"
56
57 /*
58  * Local Prototypes
59  */
60 static gint GtkLanguageMenus( gpointer , GtkWidget *, es_descriptor_t *, gint,
61                         void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) );
62
63 void GtkMenubarAudioToggle   ( GtkCheckMenuItem *, gpointer );
64 void GtkPopupAudioToggle     ( GtkCheckMenuItem *, gpointer );
65 void GtkMenubarSubtitleToggle( GtkCheckMenuItem *, gpointer );
66 void GtkPopupSubtitleToggle  ( GtkCheckMenuItem *, gpointer );
67 static gint GtkTitleMenu( gpointer, GtkWidget *, 
68                     void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) );
69 static gint GtkRadioMenu( intf_thread_t *, GtkWidget *, GSList *,
70                           char *, int, int,
71                    void( *pf_toggle )( GtkCheckMenuItem *, gpointer ) );
72 void GtkMenubarAngleToggle( GtkCheckMenuItem *, gpointer );
73 void GtkPopupAngleToggle( GtkCheckMenuItem *, gpointer );
74
75 gint GtkSetupMenus( intf_thread_t * p_intf );
76
77 /****************************************************************************
78  * Gtk*Toggle: callbacks to toggle the value of a checkmenuitem
79  ****************************************************************************
80  * We need separate functions for menubar and popup here since we can't use
81  * user_data to transmit intf_* and we need to refresh the other menu.
82  ****************************************************************************/
83
84 #define GTKLANGTOGGLE( intf, window, menu, type, callback, b_update )   \
85     intf_thread_t *         p_intf;                                     \
86     GtkWidget *             p_menu;                                     \
87     es_descriptor_t *       p_es;                                       \
88                                                                         \
89     p_intf = GetIntf( GTK_WIDGET(menuitem), (intf) );                   \
90                                                                         \
91     if( !p_intf->p_sys->b_update )                                      \
92     {                                                                   \
93         p_menu = GTK_WIDGET( gtk_object_get_data(                       \
94                    GTK_OBJECT( p_intf->p_sys->window ), (menu) ) );     \
95         p_es = (es_descriptor_t*)user_data;                             \
96                                                                         \
97         input_ToggleES( p_input_bank->pp_input[0], p_es, menuitem->active );      \
98                                                                         \
99         p_intf->p_sys->b_update = menuitem->active;                     \
100                                                                         \
101         if( p_intf->p_sys->b_update )                                   \
102         {                                                               \
103             GtkLanguageMenus( p_intf, p_menu, p_es, type, callback );   \
104         }                                                               \
105                                                                         \
106         p_intf->p_sys->b_update = 0;                                    \
107     }
108
109 /*
110  * Audio
111  */ 
112
113 void GtkMenubarAudioToggle( GtkCheckMenuItem * menuitem, gpointer user_data )
114 {
115     GTKLANGTOGGLE( "intf_window", p_popup, "popup_audio", AUDIO_ES,
116                    GtkPopupAudioToggle, b_audio_update );
117 }
118
119 void GtkPopupAudioToggle( GtkCheckMenuItem * menuitem, gpointer user_data )
120 {
121     GTKLANGTOGGLE( "intf_popup", p_window, "menubar_audio", AUDIO_ES,
122                    GtkMenubarAudioToggle, b_audio_update );
123 }
124
125 /* 
126  * Subtitles
127  */ 
128
129 void GtkMenubarSubtitleToggle( GtkCheckMenuItem * menuitem, gpointer user_data )
130 {
131     GTKLANGTOGGLE( "intf_window", p_popup, "popup_subpictures", SPU_ES,
132                    GtkPopupSubtitleToggle, b_spu_update );
133 }
134
135 void GtkPopupSubtitleToggle( GtkCheckMenuItem * menuitem, gpointer user_data )
136 {
137     GTKLANGTOGGLE( "intf_popup", p_window, "menubar_subpictures", SPU_ES,
138                    GtkMenubarSubtitleToggle, b_spu_update );
139 }
140
141 #undef GTKLANGTOGGLE
142
143 /*
144  * Navigation
145  */
146
147 void GtkPopupNavigationToggle( GtkCheckMenuItem * menuitem,
148                                gpointer user_data )
149 {
150     intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_popup" );
151
152     if( menuitem->active &&
153         !p_intf->p_sys->b_title_update &&
154         !p_intf->p_sys->b_chapter_update )
155     {
156         input_area_t   *p_area;
157
158         gint i_title   = DATA2TITLE( user_data );
159         gint i_chapter = DATA2CHAPTER( user_data );
160
161         p_area = p_input_bank->pp_input[0]->stream.p_selected_area;
162
163         if( p_area != p_input_bank->pp_input[0]->stream.pp_areas[i_title] )
164         {
165             p_area = p_input_bank->pp_input[0]->stream.pp_areas[i_title];
166             p_intf->p_sys->b_title_update = 1;
167         }
168
169         p_area->i_part = i_chapter;
170
171         input_ChangeArea( p_input_bank->pp_input[0], (input_area_t*)p_area );
172
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 );
177
178         input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
179     }
180 }
181
182 /*
183  * Title
184  */
185
186 void GtkMenubarTitleToggle( GtkCheckMenuItem * menuitem, gpointer user_data )
187 {
188     intf_thread_t * p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
189
190     if( menuitem->active && !p_intf->p_sys->b_title_update )
191     {
192         gint i_title = (gint)((long)user_data);
193         input_ChangeArea( p_input_bank->pp_input[0],
194                           p_input_bank->pp_input[0]->stream.pp_areas[i_title] );
195
196         p_intf->p_sys->b_title_update = 1;
197         vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );
198         GtkSetupMenus( p_intf );
199         vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );
200         p_intf->p_sys->b_title_update = 0;
201
202         input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
203
204     }
205 }
206
207 /*
208  * Chapter
209  */
210
211 void GtkMenubarChapterToggle( GtkCheckMenuItem * menuitem, gpointer user_data )
212 {
213     intf_thread_t * p_intf;
214     input_area_t *  p_area;
215     gint            i_chapter;
216     char            psz_chapter[5];
217     GtkWidget *     p_popup_menu;
218
219     p_intf    = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
220     p_area    = p_input_bank->pp_input[0]->stream.p_selected_area;
221     i_chapter = (gint)((long)user_data);
222
223     if( menuitem->active && !p_intf->p_sys->b_chapter_update )
224     {
225         p_area->i_part = i_chapter;
226         input_ChangeArea( p_input_bank->pp_input[0], (input_area_t*)p_area );
227
228         snprintf( psz_chapter, 4, "%02d", p_area->i_part );
229         psz_chapter[ 4 ] = '\0';
230         gtk_label_set_text( p_intf->p_sys->p_label_chapter, psz_chapter );
231
232         p_intf->p_sys->b_chapter_update = 1;
233         p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
234                              p_intf->p_sys->p_popup ), "popup_navigation" ) );
235
236         vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );
237         GtkTitleMenu( p_intf, p_popup_menu, GtkPopupNavigationToggle );
238         vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );
239
240         p_intf->p_sys->b_chapter_update = 0;
241
242         input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
243     }
244 }
245
246
247 /*
248  * Angle
249  */
250
251 #define GTKANGLETOGGLE( intf, window, menu, callback )                      \
252     intf_thread_t * p_intf;                                                 \
253     GtkWidget *     p_menu;                                                 \
254     input_area_t *  p_area;                                                 \
255                                                                             \
256     p_intf    = GetIntf( GTK_WIDGET(menuitem), (intf) );                    \
257                                                                             \
258     if( menuitem->active && !p_intf->p_sys->b_angle_update )                \
259     {                                                                       \
260         p_menu    = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(            \
261                                 p_intf->p_sys->window ), (menu) ) );        \
262         p_area    = p_input_bank->pp_input[0]->stream.p_selected_area;                \
263         p_area->i_angle = (gint)((long)user_data);                          \
264                                                                             \
265         input_ChangeArea( p_input_bank->pp_input[0], (input_area_t*)p_area );         \
266                                                                             \
267         p_intf->p_sys->b_angle_update = 1;                                  \
268         vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );             \
269         GtkRadioMenu( p_intf, p_menu, NULL, "Angle",                        \
270                       p_area->i_angle_nb, p_area->i_angle, (callback) );    \
271         vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );           \
272         p_intf->p_sys->b_angle_update = 0;                                  \
273     }
274
275 void GtkMenubarAngleToggle( GtkCheckMenuItem * menuitem, gpointer user_data )
276 {
277     GTKANGLETOGGLE( "intf_window", p_popup, "popup_angle",
278                     GtkPopupAngleToggle );
279 }
280
281 void GtkPopupAngleToggle( GtkCheckMenuItem * menuitem, gpointer user_data )
282 {
283     GTKANGLETOGGLE( "intf_popup", p_window, "menubar_angle",
284                     GtkMenubarAngleToggle );
285 }
286
287 #undef GTKANGLETOGGLE
288
289 /****************************************************************************
290  * Functions to generate menus
291  ****************************************************************************/
292
293 /*****************************************************************************
294  * GtkRadioMenu: update interactive menus of the interface
295  *****************************************************************************
296  * Sets up menus with information from input
297  * Warning: since this function is designed to be called by management
298  * function, the interface lock has to be taken
299  *****************************************************************************/
300 static gint GtkRadioMenu( intf_thread_t * p_intf,
301                             GtkWidget * p_root, GSList * p_menu_group,
302                             char * psz_item_name,
303                             int i_nb, int i_selected,
304                      void( *pf_toggle )( GtkCheckMenuItem *, gpointer ) )
305 {
306     char                psz_name[ GTK_MENU_LABEL_SIZE ];
307     GtkWidget *         p_menu;
308     GtkWidget *         p_submenu;
309     GtkWidget *         p_item_group;
310     GtkWidget *         p_item;
311     GtkWidget *         p_item_selected;
312     GSList *            p_group;
313     gint                i_item;
314
315     /* temporary hack to avoid blank menu when an open menu is removed */
316     if( GTK_MENU_ITEM(p_root)->submenu != NULL )
317     {
318         gtk_menu_popdown( GTK_MENU( GTK_MENU_ITEM(p_root)->submenu ) );
319     }
320     /* removes previous menu */
321     gtk_menu_item_remove_submenu( GTK_MENU_ITEM( p_root ) );
322     gtk_widget_set_sensitive( p_root, FALSE );
323
324     p_item_group = NULL;
325     p_submenu = NULL;
326     p_item_selected = NULL;
327     p_group = p_menu_group;
328
329     p_menu = gtk_menu_new();
330
331     for( i_item = 0 ; i_item < i_nb ; i_item++ )
332     {
333         /* we group chapters in packets of ten for small screens */
334         if( ( i_item % 10 == 0 ) && ( i_nb > 20 ) )
335         {
336             if( i_item != 0 )
337             {
338                 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_item_group ),
339                                            p_submenu );
340                 gtk_menu_append( GTK_MENU( p_menu ), p_item_group );
341             }
342
343             snprintf( psz_name, GTK_MENU_LABEL_SIZE,
344                       "%ss %d to %d", psz_item_name, i_item + 1, i_item + 10);
345             psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
346             p_item_group = gtk_menu_item_new_with_label( psz_name );
347             gtk_widget_show( p_item_group );
348             p_submenu = gtk_menu_new();
349         }
350
351         snprintf( psz_name, GTK_MENU_LABEL_SIZE, "%s %d",
352                   psz_item_name, i_item + 1 );
353         psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
354
355         p_item = gtk_radio_menu_item_new_with_label( p_group, psz_name );
356         p_group = gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_item ) );
357
358         if( i_selected == i_item + 1 )
359         {
360             p_item_selected = p_item;
361         }
362         
363         gtk_widget_show( p_item );
364
365         /* setup signal hanling */
366         gtk_signal_connect( GTK_OBJECT( p_item ),
367                             "toggled",
368                             GTK_SIGNAL_FUNC( pf_toggle ),
369                             (gpointer)((long)(i_item + 1)) );
370
371         if( i_nb > 20 )
372         {
373             gtk_menu_append( GTK_MENU( p_submenu ), p_item );
374         }
375         else
376         {
377             gtk_menu_append( GTK_MENU( p_menu ), p_item );
378         }
379     }
380
381     if( i_nb > 20 )
382     {
383         gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_item_group ), p_submenu );
384         gtk_menu_append( GTK_MENU( p_menu ), p_item_group );
385     }
386
387     /* link the new menu to the title menu item */
388     gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_root ), p_menu );
389
390     /* toggle currently selected chapter
391      * We have to release the lock since input_ToggleES needs it */
392     if( p_item_selected != NULL )
393     {
394         vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );
395         gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( p_item_selected ),
396                                         TRUE );
397         vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );
398     }
399
400     /* be sure that menu is sensitive, if there are several items */
401     if( i_nb > 1 )
402     {
403         gtk_widget_set_sensitive( p_root, TRUE );
404     }
405
406     return TRUE;
407 }
408
409 /*****************************************************************************
410  * GtkLanguageMenus: update interactive menus of the interface
411  *****************************************************************************
412  * Sets up menus with information from input:
413  *  -languages
414  *  -sub-pictures
415  * Warning: since this function is designed to be called by management
416  * function, the interface lock has to be taken
417  *****************************************************************************/
418 static gint GtkLanguageMenus( gpointer          p_data,
419                                 GtkWidget *       p_root,
420                                 es_descriptor_t * p_es,
421                                 gint              i_cat,
422                           void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) )
423 {
424     intf_thread_t *     p_intf;
425     GtkWidget *         p_menu;
426     GtkWidget *         p_separator;
427     GtkWidget *         p_item;
428     GtkWidget *         p_item_active;
429     GSList *            p_group;
430     char                psz_name[ GTK_MENU_LABEL_SIZE ];
431     gint                i_item;
432     gint                i;
433
434     
435
436     /* cast */
437     p_intf = (intf_thread_t *)p_data;
438
439     /* temporary hack to avoid blank menu when an open menu is removed */
440     if( GTK_MENU_ITEM(p_root)->submenu != NULL )
441     {
442         gtk_menu_popdown( GTK_MENU( GTK_MENU_ITEM(p_root)->submenu ) );
443     }
444     /* removes previous menu */
445     gtk_menu_item_remove_submenu( GTK_MENU_ITEM( p_root ) );
446     gtk_widget_set_sensitive( p_root, FALSE );
447
448     p_group = NULL;
449
450     /* menu container */
451     p_menu = gtk_menu_new();
452
453     /* special case for "off" item */
454     snprintf( psz_name, GTK_MENU_LABEL_SIZE, "None" );
455     psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
456
457     p_item = gtk_radio_menu_item_new_with_label( p_group, psz_name );
458     p_group = gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_item ) );
459
460     gtk_widget_show( p_item );
461
462     /* signal hanling for off */
463     gtk_signal_connect( GTK_OBJECT( p_item ), "toggled",
464                         GTK_SIGNAL_FUNC ( pf_toggle ), NULL );
465
466     gtk_menu_append( GTK_MENU( p_menu ), p_item );
467
468     p_separator = gtk_menu_item_new();
469     gtk_widget_set_sensitive( p_separator, FALSE );
470     gtk_widget_show( p_separator );
471     gtk_menu_append( GTK_MENU( p_menu ), p_separator );
472
473     p_item_active = NULL;
474     i_item = 0;
475
476     vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );
477
478     /* create a set of language buttons and append them to the container */
479     for( i = 0 ; i < p_input_bank->pp_input[0]->stream.i_es_number ; i++ )
480     {
481         if( p_input_bank->pp_input[0]->stream.pp_es[i]->i_cat == i_cat )
482         {
483             i_item++;
484             strcpy( psz_name, p_input_bank->pp_input[0]->stream.pp_es[i]->psz_desc );
485             if( psz_name[0] == '\0' )
486             {
487                 snprintf( psz_name, GTK_MENU_LABEL_SIZE,
488                           "Language %d", i_item );
489                 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
490             }
491
492             p_item = gtk_radio_menu_item_new_with_label( p_group, psz_name );
493             p_group =
494                 gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_item ) );
495
496             if( p_es == p_input_bank->pp_input[0]->stream.pp_es[i] )
497             {
498                 /* don't lose p_item when we append into menu */
499                 p_item_active = p_item;
500             }
501
502             gtk_widget_show( p_item );
503
504             /* setup signal hanling */
505             gtk_signal_connect( GTK_OBJECT( p_item ), "toggled",
506                             GTK_SIGNAL_FUNC( pf_toggle ),
507                             (gpointer)( p_input_bank->pp_input[0]->stream.pp_es[i] ) );
508
509             gtk_menu_append( GTK_MENU( p_menu ), p_item );
510         }
511     }
512
513     vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );
514
515     /* link the new menu to the menubar item */
516     gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_root ), p_menu );
517
518     /* acitvation will call signals so we can only do it
519      * when submenu is attached to menu - to get intf_window 
520      * We have to release the lock since input_ToggleES needs it */
521     if( p_item_active != NULL )
522     {
523         gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( p_item_active ),
524                                         TRUE );
525     }
526
527     /* be sure that menu is sensitive if non empty */
528     if( i_item > 0 )
529     {
530         gtk_widget_set_sensitive( p_root, TRUE );
531     }
532
533     return TRUE;
534 }
535
536 /*****************************************************************************
537  * GtkTitleMenu: sets menus for titles and chapters selection
538  *****************************************************************************
539  * Generates two types of menus:
540  *  -simple list of titles
541  *  -cascaded lists of chapters for each title
542  *****************************************************************************/
543 static gint GtkTitleMenu( gpointer       p_data,
544                             GtkWidget *    p_navigation, 
545                             void(*pf_toggle )( GtkCheckMenuItem *, gpointer ) )
546 {
547     intf_thread_t *     p_intf;
548     char                psz_name[ GTK_MENU_LABEL_SIZE ];
549     GtkWidget *         p_title_menu;
550     GtkWidget *         p_title_submenu;
551     GtkWidget *         p_title_item;
552     GtkWidget *         p_item_active;
553     GtkWidget *         p_chapter_menu;
554     GtkWidget *         p_chapter_submenu;
555     GtkWidget *         p_title_menu_item;
556     GtkWidget *         p_chapter_menu_item;
557     GtkWidget *         p_item;
558     GSList *            p_title_group;
559     GSList *            p_chapter_group;
560     gint                i_title;
561     gint                i_chapter;
562     gint                i_title_nb;
563     gint                i_chapter_nb;
564
565     /* cast */
566     p_intf = (intf_thread_t*)p_data;
567
568     /* temporary hack to avoid blank menu when an open menu is removed */
569     if( GTK_MENU_ITEM(p_navigation)->submenu != NULL )
570     {
571         gtk_menu_popdown( GTK_MENU( GTK_MENU_ITEM(p_navigation)->submenu ) );
572     }
573     /* removes previous menu */
574     gtk_menu_item_remove_submenu( GTK_MENU_ITEM( p_navigation ) );
575     gtk_widget_set_sensitive( p_navigation, FALSE );
576
577     p_title_menu = gtk_menu_new();
578     p_title_group = NULL;
579     p_title_submenu = NULL;
580     p_title_menu_item = NULL;
581     p_chapter_group = NULL;
582     p_chapter_submenu = NULL;
583     p_chapter_menu_item = NULL;
584     p_item_active = NULL;
585     i_title_nb = p_input_bank->pp_input[0]->stream.i_area_nb;
586
587     /* loop on titles */
588     for( i_title = 1 ; i_title < i_title_nb ; i_title++ )
589     {
590         /* we group titles in packets of ten for small screens */
591         if( ( i_title % 10 == 1 ) && ( i_title_nb > 20 ) )
592         {
593             if( i_title != 1 )
594             {
595                 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_title_menu_item ),
596                                            p_title_submenu );
597                 gtk_menu_append( GTK_MENU( p_title_menu ), p_title_menu_item );
598             }
599
600             snprintf( psz_name, GTK_MENU_LABEL_SIZE,
601                       "%d - %d", i_title, i_title + 9 );
602             psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
603             p_title_menu_item = gtk_menu_item_new_with_label( psz_name );
604             gtk_widget_show( p_title_menu_item );
605             p_title_submenu = gtk_menu_new();
606         }
607
608         snprintf( psz_name, GTK_MENU_LABEL_SIZE, "Title %d (%d)", i_title,
609                   p_input_bank->pp_input[0]->stream.pp_areas[i_title]->i_part_nb );
610         psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
611 #if 0
612         if( pf_toggle == on_menubar_title_toggle )
613         {
614             p_title_item = gtk_radio_menu_item_new_with_label( p_title_group,
615                                                            psz_name );
616             p_title_group =
617               gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM( p_title_item ) );
618
619             if( p_input_bank->pp_input[0]->stream.pp_areas[i_title] ==
620                          p_input_bank->pp_input[0]->stream.p_selected_area )
621             {
622                 p_item_active = p_title_item;
623             }
624
625             /* setup signal hanling */
626             gtk_signal_connect( GTK_OBJECT( p_title_item ),
627                      "toggled",
628                      GTK_SIGNAL_FUNC( pf_toggle ),
629                      (gpointer)(p_input_bank->pp_input[0]->stream.pp_areas[i_title]) );
630
631             if( p_input_bank->pp_input[0]->stream.i_area_nb > 1 )
632             {
633                 /* be sure that menu is sensitive */
634                 gtk_widget_set_sensitive( p_navigation, TRUE );
635             }
636         }
637         else
638 #endif
639         {
640             p_title_item = gtk_menu_item_new_with_label( psz_name );
641
642 #if 1    
643             p_chapter_menu = gtk_menu_new();
644             i_chapter_nb =
645                     p_input_bank->pp_input[0]->stream.pp_areas[i_title]->i_part_nb;
646     
647             for( i_chapter = 0 ; i_chapter < i_chapter_nb ; i_chapter++ )
648             {
649                 /* we group chapters in packets of ten for small screens */
650                 if( ( i_chapter % 10 == 0 ) && ( i_chapter_nb > 20 ) )
651                 {
652                     if( i_chapter != 0 )
653                     {
654                         gtk_menu_item_set_submenu(
655                                     GTK_MENU_ITEM( p_chapter_menu_item ),
656                                     p_chapter_submenu );
657                         gtk_menu_append( GTK_MENU( p_chapter_menu ),
658                                          p_chapter_menu_item );
659                     }
660
661                     snprintf( psz_name, GTK_MENU_LABEL_SIZE,
662                               "%d - %d", i_chapter + 1, i_chapter + 10 );
663                     psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
664                     p_chapter_menu_item =
665                             gtk_menu_item_new_with_label( psz_name );
666                     gtk_widget_show( p_chapter_menu_item );
667                     p_chapter_submenu = gtk_menu_new();
668                 }
669
670                 snprintf( psz_name, GTK_MENU_LABEL_SIZE,
671                           "Chapter %d", i_chapter + 1 );
672                 psz_name[ GTK_MENU_LABEL_SIZE - 1 ] = '\0';
673     
674                 p_item = gtk_radio_menu_item_new_with_label(
675                                                 p_chapter_group, psz_name );
676                 p_chapter_group = gtk_radio_menu_item_group(
677                                                 GTK_RADIO_MENU_ITEM( p_item ) );
678                 gtk_widget_show( p_item );
679
680 #define p_area p_input_bank->pp_input[0]->stream.pp_areas[i_title]
681                 if( ( p_area == p_input_bank->pp_input[0]->stream.p_selected_area ) &&
682                     ( p_area->i_part == i_chapter + 1 ) )
683                 {
684                     p_item_active = p_item;
685                 }
686 #undef p_area
687
688                 /* setup signal hanling */
689                 gtk_signal_connect( GTK_OBJECT( p_item ),
690                            "toggled",
691                            GTK_SIGNAL_FUNC( pf_toggle ),
692                            (gpointer)POS2DATA( i_title, i_chapter + 1) );
693
694                 if( i_chapter_nb > 20 )
695                 {
696                     gtk_menu_append( GTK_MENU( p_chapter_submenu ), p_item );
697                 }
698                 else
699                 {
700                     gtk_menu_append( GTK_MENU( p_chapter_menu ), p_item );
701                 }
702             }
703
704             if( i_chapter_nb > 20 )
705             {
706                 gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_chapter_menu_item ),
707                                            p_chapter_submenu );
708                 gtk_menu_append( GTK_MENU( p_chapter_menu ),
709                                  p_chapter_menu_item );
710             }
711
712             /* link the new menu to the title menu item */
713             gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_title_item ),
714                                        p_chapter_menu );
715
716             if( p_input_bank->pp_input[0]->stream.pp_areas[i_title]->i_part_nb > 1 )
717             {
718                 /* be sure that menu is sensitive */
719                 gtk_widget_set_sensitive( p_navigation, TRUE );
720             }
721 #else
722         GtkRadioMenu( p_intf, p_title_item, p_chapter_group, "Chapter",
723                         p_input_bank->pp_input[0]->stream.pp_areas[i_title]->i_part_nb,
724                         i_title * 100,
725                         p_input_bank->pp_input[0]->stream.p_selected_area->i_part +
726                             p_input_bank->pp_input[0]->stream.p_selected_area->i_id *100,
727                         pf_toggle );
728
729 #endif
730         }
731         gtk_widget_show( p_title_item );
732
733         if( i_title_nb > 20 )
734         {
735             gtk_menu_append( GTK_MENU( p_title_submenu ), p_title_item );
736         }
737         else
738         {
739             gtk_menu_append( GTK_MENU( p_title_menu ), p_title_item );
740         }
741     }
742
743     if( i_title_nb > 20 )
744     {
745         gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_title_menu_item ),
746                                    p_title_submenu );
747         gtk_menu_append( GTK_MENU( p_title_menu ), p_title_menu_item );
748     }
749
750     /* be sure that menu is sensitive */
751     gtk_widget_set_sensitive( p_title_menu, TRUE );
752
753     /* link the new menu to the menubar item */
754     gtk_menu_item_set_submenu( GTK_MENU_ITEM( p_navigation ), p_title_menu );
755
756     /* Default selected chapter
757      * We have to release the lock since input_ToggleES needs it */
758     if( p_item_active != NULL )
759     {
760         vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );
761         gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( p_item_active ),
762                                         TRUE );
763         vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );
764     }
765 #if 0
766     if( p_input_bank->pp_input[0]->stream.i_area_nb > 1 )
767     {
768         /* be sure that menu is sensitive */
769         gtk_widget_set_sensitive( p_navigation, TRUE );
770     }
771 #endif
772
773     return TRUE;
774 }
775
776 /*****************************************************************************
777  * GtkSetupMenus: function that generates title/chapter/audio/subpic
778  * menus with help from preceding functions
779  *****************************************************************************/
780 gint GtkSetupMenus( intf_thread_t * p_intf )
781 {
782     es_descriptor_t *   p_audio_es;
783     es_descriptor_t *   p_spu_es;
784     GtkWidget *         p_menubar_menu;
785     GtkWidget *         p_popup_menu;
786     gint                i;
787
788     p_intf->p_sys->b_chapter_update |= p_intf->p_sys->b_title_update;
789     p_intf->p_sys->b_angle_update |= p_intf->p_sys->b_title_update;
790     p_intf->p_sys->b_audio_update |= p_intf->p_sys->b_title_update;
791     p_intf->p_sys->b_spu_update |= p_intf->p_sys->b_title_update;
792
793 //    vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );
794
795     if( p_intf->p_sys->b_title_update )
796     { 
797         char            psz_title[5];
798
799         p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
800                             p_intf->p_sys->p_window ), "menubar_title" ) );
801         GtkRadioMenu( p_intf, p_menubar_menu, NULL, "Title",
802                       p_input_bank->pp_input[0]->stream.i_area_nb - 1,
803                       p_input_bank->pp_input[0]->stream.p_selected_area->i_id,
804                       GtkMenubarTitleToggle );
805
806         snprintf( psz_title, 4, "%d",
807                   p_input_bank->pp_input[0]->stream.p_selected_area->i_id );
808         psz_title[ 4 ] = '\0';
809         gtk_label_set_text( p_intf->p_sys->p_label_title, psz_title );
810
811         p_intf->p_sys->b_title_update = 0;
812     }
813
814     if( p_intf->p_sys->b_chapter_update )
815     {
816         char            psz_chapter[5];
817
818         p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
819                              p_intf->p_sys->p_popup ), "popup_navigation" ) );
820         GtkTitleMenu( p_intf, p_popup_menu, GtkPopupNavigationToggle );
821 #if 0
822         GtkRadioMenu( p_intf, p_menubar_menu, NULL, "Title",
823                         p_input_bank->pp_input[0]->stream.i_area_nb - 1,
824                         p_input_bank->pp_input[0]->stream.p_selected_area->i_id,
825                         on_menubar_chapter_toggle );
826 #endif
827
828         p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
829                              p_intf->p_sys->p_window ), "menubar_chapter" ) );
830
831         GtkRadioMenu( p_intf, p_menubar_menu, NULL, "Chapter",
832                         p_input_bank->pp_input[0]->stream.p_selected_area->i_part_nb,
833                         p_input_bank->pp_input[0]->stream.p_selected_area->i_part,
834                         GtkMenubarChapterToggle );
835
836
837         snprintf( psz_chapter, 4, "%d", 
838                   p_input_bank->pp_input[0]->stream.p_selected_area->i_part );
839         psz_chapter[ 4 ] = '\0';
840         gtk_label_set_text( p_intf->p_sys->p_label_chapter, psz_chapter );
841
842         p_intf->p_sys->i_part =
843                 p_input_bank->pp_input[0]->stream.p_selected_area->i_part;
844
845         p_intf->p_sys->b_chapter_update = 0;
846     }
847
848     if( p_intf->p_sys->b_angle_update )
849     {
850         p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
851                              p_intf->p_sys->p_window ), "menubar_angle" ) );
852         GtkRadioMenu( p_intf, p_menubar_menu, NULL, "Angle",
853                         p_input_bank->pp_input[0]->stream.p_selected_area->i_angle_nb,
854                         p_input_bank->pp_input[0]->stream.p_selected_area->i_angle,
855                         GtkMenubarAngleToggle );
856
857         p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
858                              p_intf->p_sys->p_popup ), "popup_angle" ) );
859         GtkRadioMenu( p_intf, p_popup_menu, NULL, "Angle",
860                         p_input_bank->pp_input[0]->stream.p_selected_area->i_angle_nb,
861                         p_input_bank->pp_input[0]->stream.p_selected_area->i_angle,
862                         GtkPopupAngleToggle );
863
864         p_intf->p_sys->b_angle_update = 0;
865     }
866     
867     /* look for selected ES */
868     p_audio_es = NULL;
869     p_spu_es = NULL;
870
871     for( i = 0 ; i < p_input_bank->pp_input[0]->stream.i_selected_es_number ; i++ )
872     {
873         if( p_input_bank->pp_input[0]->stream.pp_selected_es[i]->i_cat == AUDIO_ES )
874         {
875             p_audio_es = p_input_bank->pp_input[0]->stream.pp_selected_es[i];
876         }
877
878         if( p_input_bank->pp_input[0]->stream.pp_selected_es[i]->i_cat == SPU_ES )
879         {
880             p_spu_es = p_input_bank->pp_input[0]->stream.pp_selected_es[i];
881         }
882     }
883
884     vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );
885
886     /* audio menus */
887     if( p_intf->p_sys->b_audio_update )
888     {
889         /* find audio root menu */
890         p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
891                              p_intf->p_sys->p_window ), "menubar_audio" ) );
892     
893         p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
894                      p_intf->p_sys->p_popup ), "popup_audio" ) );
895     
896         p_intf->p_sys->b_audio_update = 1;
897         GtkLanguageMenus( p_intf, p_menubar_menu, p_audio_es, AUDIO_ES,
898                             GtkMenubarAudioToggle );
899         p_intf->p_sys->b_audio_update = 1;
900         GtkLanguageMenus( p_intf, p_popup_menu, p_audio_es, AUDIO_ES,
901                             GtkPopupAudioToggle );
902     
903         p_intf->p_sys->b_audio_update = 0;
904     }
905     
906     /* sub picture menus */
907     if( p_intf->p_sys->b_spu_update )
908     {
909         /* find spu root menu */
910         p_menubar_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
911                           p_intf->p_sys->p_window ), "menubar_subpictures" ) );
912     
913         p_popup_menu = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
914                      p_intf->p_sys->p_popup ), "popup_subpictures" ) );
915     
916         p_intf->p_sys->b_spu_update = 1;
917         GtkLanguageMenus( p_intf, p_menubar_menu, p_spu_es, SPU_ES,
918                             GtkMenubarSubtitleToggle  );
919         p_intf->p_sys->b_spu_update = 1;
920         GtkLanguageMenus( p_intf, p_popup_menu, p_spu_es, SPU_ES,
921                             GtkPopupSubtitleToggle );
922     
923         p_intf->p_sys->b_spu_update = 0;
924     }
925
926     vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );
927
928     return TRUE;
929 }
930