]> git.sesse.net Git - vlc/blob - modules/gui/macosx/controls.m
Support for multiple OSD channels :
[vlc] / modules / gui / macosx / controls.m
1 /*****************************************************************************
2  * controls.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2002-2003 VideoLAN
5  * $Id$
6  *
7  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8  *          Christophe Massiot <massiot@via.ecp.fr>
9  *          Derk-Jan Hartman <hartman at videolan dot org>
10  *
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.
15  * 
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.
20  *
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  *****************************************************************************/
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #include <stdlib.h>                                      /* malloc(), free() */
30 #include <sys/param.h>                                    /* for MAXPATHLEN */
31 #include <string.h>
32
33 #include "intf.h"
34 #include "vout.h"
35 #include "open.h"
36 #include "controls.h"
37 #include <osd.h>
38
39 /*****************************************************************************
40  * VLCControls implementation 
41  *****************************************************************************/
42 @implementation VLCControls
43
44 - (IBAction)play:(id)sender
45 {
46     vlc_value_t val;
47     playlist_t * p_playlist;
48     intf_thread_t * p_intf = [NSApp getIntf];
49     input_thread_t * p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
50                                                        FIND_ANYWHERE );
51
52     val.i_int = PLAYING_S;
53     if( p_input )
54     {
55         var_Get( p_input, "state", &val );
56     }
57     if( p_input && val.i_int != PAUSE_S )
58     {
59         vout_OSDMessage( p_intf, SOLO_CHAN, _( "Pause" ) );
60         val.i_int = PAUSE_S;
61         var_Set( p_input, "state", val );
62     }
63     else
64     {
65         p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
66                                         FIND_ANYWHERE );
67         if( p_playlist )
68         {
69             vlc_mutex_lock( &p_playlist->object_lock );
70             if( p_playlist->i_size )
71             {
72                 vlc_mutex_unlock( &p_playlist->object_lock );
73                 vout_OSDMessage( p_intf, SOLO_CHAN, _( "Play" ) );
74                 playlist_Play( p_playlist );
75                 vlc_object_release( p_playlist );
76             }
77             else
78             {
79                 vlc_mutex_unlock( &p_playlist->object_lock );
80                 vlc_object_release( p_playlist );
81                 [o_open openFileGeneric: nil];
82             }
83         }
84     }
85     if( p_input ) vlc_object_release( p_input );
86 }
87
88 - (IBAction)stop:(id)sender
89 {
90     intf_thread_t * p_intf = [NSApp getIntf];
91     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
92                                                        FIND_ANYWHERE );
93     if( p_playlist != NULL )
94     {
95         vout_OSDMessage( p_intf, SOLO_CHAN, _( "Stop" ) );
96         playlist_Stop( p_playlist );
97         vlc_object_release( p_playlist );
98     }
99 }
100
101 - (IBAction)faster:(id)sender
102 {
103     intf_thread_t * p_intf = [NSApp getIntf];
104     input_thread_t * p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
105                                                        FIND_ANYWHERE );
106     if( p_input != NULL )
107     {
108         vlc_value_t val; val.b_bool = VLC_TRUE;
109
110         var_Set( p_input, "rate-faster", val );
111         vout_OSDMessage( p_intf, SOLO_CHAN, _( "Faster" ) );
112         vlc_object_release( p_input );
113     }
114 }
115
116 - (IBAction)slower:(id)sender
117 {
118     intf_thread_t * p_intf = [NSApp getIntf];
119     input_thread_t * p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
120                                                        FIND_ANYWHERE );
121     if( p_input != NULL )
122     {
123         vlc_value_t val; val.b_bool = VLC_TRUE;
124
125         var_Set( p_input, "rate-slower", val );
126         vout_OSDMessage( p_intf, SOLO_CHAN, _( "Slower" ) );
127         vlc_object_release( p_input );
128     }
129 }
130
131 - (IBAction)prev:(id)sender
132 {
133     intf_thread_t * p_intf = [NSApp getIntf];
134     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
135                                                        FIND_ANYWHERE );
136     if( p_playlist )
137     {
138         playlist_Prev( p_playlist );
139         vlc_object_release( p_playlist );
140         vout_OSDMessage( p_intf, SOLO_CHAN, _( "Previous" ) );
141     }
142 }
143
144 - (IBAction)next:(id)sender
145 {
146     intf_thread_t * p_intf = [NSApp getIntf];
147     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
148                                                        FIND_ANYWHERE );
149     if( p_playlist )
150     {
151         playlist_Next( p_playlist );
152         vlc_object_release( p_playlist );
153         vout_OSDMessage( p_intf, SOLO_CHAN, _( "Next" ) );
154     }
155 }
156
157 - (IBAction)random:(id)sender
158 {
159     intf_thread_t * p_intf = [NSApp getIntf];
160     vlc_value_t val;
161     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
162                                                        FIND_ANYWHERE );
163     if( p_playlist == NULL )
164     {
165         return;
166     }
167
168     var_Get( p_playlist, "random", &val );
169     val.b_bool = !val.b_bool;
170     var_Set( p_playlist, "random", val );
171     if( val.b_bool )
172     {
173         vout_OSDMessage( p_intf, SOLO_CHAN, _( "Random On" ) );
174     }
175     else
176     {
177         vout_OSDMessage( p_intf, SOLO_CHAN, _( "Random Off" ) );
178     }    
179
180     p_intf->p_sys->b_playlist_update = VLC_TRUE;
181     p_intf->p_sys->b_intf_update = VLC_TRUE;
182     vlc_object_release( p_playlist );
183 }
184
185 - (IBAction)repeat:(id)sender
186 {
187     intf_thread_t * p_intf = [NSApp getIntf];
188     vlc_value_t val;
189     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
190                                                        FIND_ANYWHERE );
191     if( p_playlist == NULL )
192     {
193         return;
194     }
195
196     var_Get( p_playlist, "repeat", &val );
197     if (!val.b_bool)
198     {   
199         var_Set( p_playlist, "loop", val );
200     } 
201     val.b_bool = !val.b_bool;
202     var_Set( p_playlist, "repeat", val );
203     if( val.b_bool )
204     {
205         vout_OSDMessage( p_intf, SOLO_CHAN, _( "Repeat All" ) );
206     }
207     else
208     {
209         vout_OSDMessage( p_intf, SOLO_CHAN, _( "Repeat Off" ) );
210     }
211
212     p_intf->p_sys->b_playlist_update = VLC_TRUE;    
213     p_intf->p_sys->b_intf_update = VLC_TRUE;
214     vlc_object_release( p_playlist );
215 }
216
217 - (IBAction)loop:(id)sender
218 {
219     intf_thread_t * p_intf = [NSApp getIntf];
220     vlc_value_t val;
221     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
222                                                        FIND_ANYWHERE );
223     if( p_playlist == NULL )
224     {
225         return;
226     }
227
228     var_Get( p_playlist, "loop", &val );
229     if (!val.b_bool)
230     {
231         var_Set( p_playlist, "repeat", val );
232     }
233     val.b_bool = !val.b_bool;
234     var_Set( p_playlist, "loop", val );
235     if( val.b_bool )
236     {
237         vout_OSDMessage( p_intf, SOLO_CHAN, _( "Repeat One" ) );
238     }
239     else
240     {
241         vout_OSDMessage( p_intf, SOLO_CHAN, _( "Repeat Off" ) );
242     }    
243
244     p_intf->p_sys->b_playlist_update = VLC_TRUE;
245     p_intf->p_sys->b_intf_update = VLC_TRUE;
246     vlc_object_release( p_playlist );
247 }
248
249 - (IBAction)forward:(id)sender
250 {
251     intf_thread_t * p_intf = [NSApp getIntf];
252     input_thread_t * p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
253                                                        FIND_ANYWHERE );
254     if( p_input != NULL )
255     {
256         vlc_value_t time;
257         time.i_time = 10 * 1000000;
258         var_Set( p_input, "time-offset", time );
259         vout_OSDMessage( p_intf, SOLO_CHAN, _( "Jump +10 Seconds" ) );
260         vlc_object_release( p_input );
261     }
262 }
263
264 - (IBAction)backward:(id)sender
265 {
266     intf_thread_t * p_intf = [NSApp getIntf];
267     input_thread_t * p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
268                                                        FIND_ANYWHERE );
269     if( p_input != NULL )
270     {
271         vlc_value_t time;
272         time.i_time = -10 * 1000000;
273         var_Set( p_input, "time-offset", time );
274         vout_OSDMessage( p_intf, SOLO_CHAN, _( "Jump -10 Seconds" ) );
275         vlc_object_release( p_input );
276     }
277 }
278
279
280 - (IBAction)volumeUp:(id)sender
281 {
282     intf_thread_t * p_intf = [NSApp getIntf];
283
284     if( p_intf->p_sys->b_mute )
285     {
286         [self mute: nil];
287     }
288
289     aout_VolumeUp( p_intf, 1, NULL );
290
291     [self updateVolumeSlider];
292 }
293
294 - (IBAction)volumeDown:(id)sender
295 {
296     intf_thread_t * p_intf = [NSApp getIntf];
297
298     if( p_intf->p_sys->b_mute )
299     {
300         [self mute: nil];
301     }
302     
303     aout_VolumeDown( p_intf, 1, NULL );
304
305     [self updateVolumeSlider];
306 }
307
308 - (IBAction)mute:(id)sender
309 {
310     intf_thread_t * p_intf = [NSApp getIntf];
311     audio_volume_t i_volume;
312
313     aout_VolumeMute( p_intf, &i_volume );
314     p_intf->p_sys->b_mute = ( i_volume == 0 );
315
316     [self updateVolumeSlider];
317 }
318
319 - (IBAction)volumeSliderUpdated:(id)sender
320 {
321     intf_thread_t * p_intf = [NSApp getIntf];
322     audio_volume_t i_volume = (audio_volume_t)[sender intValue];
323
324     aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_STEP );
325 }
326
327 - (void)updateVolumeSlider
328 {
329     intf_thread_t * p_intf = [NSApp getIntf];
330     audio_volume_t i_volume;
331
332     aout_VolumeGet( p_intf, &i_volume );
333
334     [o_volumeslider setFloatValue: (float)(i_volume / AOUT_VOLUME_STEP)];
335
336     vout_OSDMessage( p_intf, SOLO_CHAN, "Vol %d%%", 
337                      i_volume*100/AOUT_VOLUME_MAX );
338 }
339
340 - (IBAction)windowAction:(id)sender
341 {
342     id o_window = [NSApp keyWindow];
343     NSString *o_title = [sender title];
344     NSArray *o_windows = [NSApp orderedWindows];
345     NSEnumerator *o_enumerator = [o_windows objectEnumerator];
346     vout_thread_t   *p_vout = vlc_object_find( [NSApp getIntf], VLC_OBJECT_VOUT,
347                                               FIND_ANYWHERE );
348
349     if( p_vout != NULL )
350     {
351         while ((o_window = [o_enumerator nextObject]))
352         {
353             if( [[o_window className] isEqualToString: @"VLCWindow"] )
354             {
355                 if( [o_title isEqualToString: _NS("Half Size") ] )
356                     [o_window scaleWindowWithFactor: 0.5];
357                 else if( [o_title isEqualToString: _NS("Normal Size") ] )
358                     [o_window scaleWindowWithFactor: 1.0];
359                 else if( [o_title isEqualToString: _NS("Double Size") ] )
360                     [o_window scaleWindowWithFactor: 2.0];
361                 else if( [o_title isEqualToString: _NS("Float on Top") ] )
362                     [o_window toggleFloatOnTop];
363                 else if( [o_title isEqualToString: _NS("Fit to Screen") ] )
364                 {
365                     if( ![o_window isZoomed] )
366                         [o_window performZoom:self];
367                 }
368                 else
369                 {
370                     [o_window toggleFullscreen];
371                 }
372                 break;
373             }
374         }
375         vlc_object_release( (vlc_object_t *)p_vout );
376     }
377 }
378
379 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
380                     target:(vlc_object_t *)p_object
381                     var:(const char *)psz_variable
382                     selector:(SEL)pf_callback
383 {
384     vlc_value_t val, text;
385     int i_type = var_Type( p_object, psz_variable );
386
387     switch( i_type & VLC_VAR_TYPE )
388     {
389     case VLC_VAR_VOID:
390     case VLC_VAR_BOOL:
391     case VLC_VAR_VARIABLE:
392     case VLC_VAR_STRING:
393     case VLC_VAR_INTEGER:
394         break;
395     default:
396         /* Variable doesn't exist or isn't handled */
397         return;
398     }
399     
400     /* Make sure we want to display the variable */
401     if( i_type & VLC_VAR_HASCHOICE )
402     {
403         var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
404         if( val.i_int == 0 ) return;
405         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
406             return;
407     }
408     
409     /* Get the descriptive name of the variable */
410     var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
411     [o_mi setTitle: [NSApp localizedString: text.psz_string ?
412                                         text.psz_string : strdup( psz_variable ) ]];
413
414     var_Get( p_object, psz_variable, &val );
415     if( i_type & VLC_VAR_HASCHOICE )
416     {
417         NSMenu *o_menu = [o_mi submenu];
418
419         [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
420                         var:psz_variable selector:pf_callback];
421         
422         if( text.psz_string ) free( text.psz_string );
423         return;
424     }
425
426     VLCMenuExt *o_data;
427     switch( i_type & VLC_VAR_TYPE )
428     {
429     case VLC_VAR_VOID:
430         o_data = [[VLCMenuExt alloc] initWithVar: psz_variable Object: p_object->i_object_id
431                 Value: val ofType: i_type];
432         [o_mi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
433         break;
434
435     case VLC_VAR_BOOL:
436         o_data = [[VLCMenuExt alloc] initWithVar: psz_variable Object: p_object->i_object_id
437                 Value: val ofType: i_type];
438         [o_mi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
439         if( !( i_type & VLC_VAR_ISCOMMAND ) )
440             [o_mi setState: val.b_bool ? TRUE : FALSE ];
441         break;
442
443     default:
444         if( text.psz_string ) free( text.psz_string );
445         return;
446     }
447
448     if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
449     if( text.psz_string ) free( text.psz_string );
450 }
451
452
453 - (void)setupVarMenu:(NSMenu *)o_menu
454                     forMenuItem: (NSMenuItem *)o_parent
455                     target:(vlc_object_t *)p_object
456                     var:(const char *)psz_variable
457                     selector:(SEL)pf_callback
458 {
459     vlc_value_t val, val_list, text_list;
460     int i_type, i, i_nb_items;
461
462     /* remove previous items */
463     i_nb_items = [o_menu numberOfItems];
464     for( i = 0; i < i_nb_items; i++ )
465     {
466         [o_menu removeItemAtIndex: 0];
467     }
468
469     /* Check the type of the object variable */
470     i_type = var_Type( p_object, psz_variable );
471
472     /* Make sure we want to display the variable */
473     if( i_type & VLC_VAR_HASCHOICE )
474     {
475         var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
476         if( val.i_int == 0 ) return;
477         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
478             return;
479     }
480     else
481     {
482         return;
483     }
484
485     switch( i_type & VLC_VAR_TYPE )
486     {
487     case VLC_VAR_VOID:
488     case VLC_VAR_BOOL:
489     case VLC_VAR_VARIABLE:
490     case VLC_VAR_STRING:
491     case VLC_VAR_INTEGER:
492         break;
493     default:
494         /* Variable doesn't exist or isn't handled */
495         return;
496     }
497
498     if( var_Get( p_object, psz_variable, &val ) < 0 )
499     {
500         return;
501     }
502
503     if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
504                     &val_list, &text_list ) < 0 )
505     {
506         if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
507         return;
508     }
509
510     /* make (un)sensitive */
511     [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
512
513     for( i = 0; i < val_list.p_list->i_count; i++ )
514     {
515         vlc_value_t another_val;
516         NSMenuItem * o_lmi;
517         NSString *o_title = @"";
518         VLCMenuExt *o_data;
519
520         switch( i_type & VLC_VAR_TYPE )
521         {
522         case VLC_VAR_STRING:
523             another_val.psz_string =
524                 strdup(val_list.p_list->p_values[i].psz_string);
525
526             o_title = [NSApp localizedString: text_list.p_list->p_values[i].psz_string ?
527                 text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
528
529             o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
530             o_data = [[VLCMenuExt alloc] initWithVar: strdup(psz_variable) Object: p_object->i_object_id
531                     Value: another_val ofType: i_type];
532             [o_lmi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
533             [o_lmi setTarget: self];
534             
535             if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
536                 [o_lmi setState: TRUE ];
537
538             break;
539
540         case VLC_VAR_INTEGER:
541
542              o_title = text_list.p_list->p_values[i].psz_string ?
543                                  [NSApp localizedString: strdup( text_list.p_list->p_values[i].psz_string )] :
544                                  [NSString stringWithFormat: @"%d",
545                                  val_list.p_list->p_values[i].i_int];
546
547             o_lmi = [[o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""] retain ];
548             o_data = [[VLCMenuExt alloc] initWithVar: strdup(psz_variable) Object: p_object->i_object_id
549                     Value: val_list.p_list->p_values[i] ofType: i_type];
550             [o_lmi setRepresentedObject: [NSValue valueWithPointer:[ o_data retain]]];
551             [o_lmi setTarget: self];
552
553             if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
554                 [o_lmi setState: TRUE ];
555             break;
556
557         default:
558           break;
559         }
560     }
561     
562     /* clean up everything */
563     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
564     var_Change( p_object, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list );
565 }
566
567 - (IBAction)toggleVar:(id)sender
568 {
569     NSMenuItem *o_mi = (NSMenuItem *)sender;
570     VLCMenuExt *o_data = [[o_mi representedObject] pointerValue];
571     [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
572         toTarget: self withObject: o_data];
573
574     return;
575 }
576
577 - (int)toggleVarThread: (id)_o_data
578 {
579     vlc_object_t *p_object;
580     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
581     VLCMenuExt *o_data = (VLCMenuExt *)_o_data;
582
583     vlc_thread_set_priority( [NSApp getIntf] , VLC_THREAD_PRIORITY_LOW );
584
585     p_object = (vlc_object_t *)vlc_object_get( [NSApp getIntf],
586                                     [o_data objectID] );
587
588     if( p_object != NULL )
589     {
590         var_Set( p_object, strdup([o_data name]), [o_data value] );
591         vlc_object_release( p_object );
592         [o_pool release];
593         return VLC_TRUE;
594     }
595     [o_pool release];
596     return VLC_EGENERIC;
597 }
598
599 @end
600
601 @implementation VLCControls (NSMenuValidation)
602  
603 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
604 {
605     BOOL bEnabled = TRUE;
606     vlc_value_t val;
607     intf_thread_t * p_intf = [NSApp getIntf];
608     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
609                                                        FIND_ANYWHERE );
610
611     if( p_playlist != NULL )
612     {
613         vlc_mutex_lock( &p_playlist->object_lock );
614     }
615
616 #define p_input p_playlist->p_input
617
618     if( [[o_mi title] isEqualToString: _NS("Faster")] ||
619         [[o_mi title] isEqualToString: _NS("Slower")] )
620     {
621         if( p_playlist != NULL && p_input != NULL )
622         {
623             vlc_mutex_lock( &p_input->stream.stream_lock );
624             bEnabled = p_input->stream.b_pace_control;
625             vlc_mutex_unlock( &p_input->stream.stream_lock );
626         }
627         else
628         {
629             bEnabled = FALSE;
630         }
631     }
632     else if( [[o_mi title] isEqualToString: _NS("Stop")] )
633     {
634         if( p_playlist == NULL || p_input == NULL )
635         {
636             bEnabled = FALSE;
637         }
638     }
639     else if( [[o_mi title] isEqualToString: _NS("Previous")] ||
640              [[o_mi title] isEqualToString: _NS("Next")] )
641     {
642         if( p_playlist == NULL )
643         {
644             bEnabled = FALSE;
645         }
646         else
647         {
648             bEnabled = p_playlist->i_size > 1;
649
650             if( p_input != NULL )
651             {
652                 vlc_mutex_lock( &p_input->stream.stream_lock );
653                 bEnabled |= p_input->stream.i_area_nb > 1;
654                 vlc_mutex_unlock( &p_input->stream.stream_lock );
655             }
656         }
657     }
658     else if( [[o_mi title] isEqualToString: _NS("Random")] )
659     {
660         int i_state;
661         var_Get( p_playlist, "random", &val );
662         i_state = val.b_bool ? NSOnState : NSOffState;
663         [o_mi setState: i_state];
664     }
665     else if( [[o_mi title] isEqualToString: _NS("Repeat One")] )
666     {
667         int i_state;
668         var_Get( p_playlist, "repeat", &val );
669         i_state = val.b_bool ? NSOnState : NSOffState;
670         [o_mi setState: i_state];
671     }
672     else if( [[o_mi title] isEqualToString: _NS("Repeat All")] )
673     {
674         int i_state;
675         var_Get( p_playlist, "loop", &val );
676         i_state = val.b_bool ? NSOnState : NSOffState;
677         [o_mi setState: i_state];
678     }
679     else if( [[o_mi title] isEqualToString: _NS("Step Forward")] ||
680              [[o_mi title] isEqualToString: _NS("Step Backward")] )
681     {
682         if( p_playlist != NULL && p_input != NULL )
683         {
684             vlc_mutex_lock( &p_input->stream.stream_lock );
685             bEnabled = p_input->stream.b_seekable;
686             vlc_mutex_unlock( &p_input->stream.stream_lock );
687         }
688         else
689         {
690             bEnabled = FALSE;
691         }
692     }
693     else if( [[o_mi title] isEqualToString: _NS("Mute")] ) 
694     {
695         [o_mi setState: p_intf->p_sys->b_mute ? NSOnState : NSOffState];
696     }
697     else if( [[o_mi title] isEqualToString: _NS("Fullscreen")] ||
698                 [[o_mi title] isEqualToString: _NS("Half Size")] ||
699                 [[o_mi title] isEqualToString: _NS("Normal Size")] ||
700                 [[o_mi title] isEqualToString: _NS("Double Size")] ||
701                 [[o_mi title] isEqualToString: _NS("Fit to Screen")] ||
702                 [[o_mi title] isEqualToString: _NS("Float on Top")] )
703     {
704         id o_window;
705         NSArray *o_windows = [NSApp orderedWindows];
706         NSEnumerator *o_enumerator = [o_windows objectEnumerator];
707         bEnabled = FALSE;
708         
709         vout_thread_t   *p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
710                                               FIND_ANYWHERE );
711         if( p_vout != NULL )
712         {
713             if ( [[o_mi title] isEqualToString: _NS("Float on Top")] )
714             {
715                 var_Get( p_vout, "video-on-top", &val );
716                 [o_mi setState: val.b_bool ?  NSOnState : NSOffState];
717             }
718
719             while ((o_window = [o_enumerator nextObject]))
720             {
721                 if( [[o_window className] isEqualToString: @"VLCWindow"] )
722                 {
723                     bEnabled = TRUE;
724                     break;
725                 }
726             }
727             vlc_object_release( (vlc_object_t *)p_vout );
728         }
729     }
730
731     if( p_playlist != NULL )
732     {
733         vlc_mutex_unlock( &p_playlist->object_lock );
734         vlc_object_release( p_playlist );
735     }
736
737     return( bEnabled );
738 }
739
740 @end
741
742 /*****************************************************************************
743  * VLCMenuExt implementation 
744  *****************************************************************************
745  * Object connected to a playlistitem which remembers the data belonging to
746  * the variable of the autogenerated menu
747  *****************************************************************************/
748 @implementation VLCMenuExt
749
750 - (id)initWithVar: (const char *)_psz_name Object: (int)i_id
751         Value: (vlc_value_t)val ofType: (int)_i_type
752 {
753     self = [super init];
754
755     if( self != nil )
756     {
757         psz_name = strdup( _psz_name );
758         i_object_id = i_id;
759         value = val;
760         i_type = _i_type;
761     }
762
763     return( self );
764 }
765
766 - (void)dealloc
767 {
768     free( psz_name );
769 }
770
771 - (char *)name
772 {
773     return psz_name;
774 }
775
776 - (int)objectID
777 {
778     return i_object_id;
779 }
780
781 - (vlc_value_t)value
782 {
783     return value;
784 }
785
786 - (int)type
787 {
788     return i_type;
789 }
790
791 @end