]> git.sesse.net Git - vlc/blob - modules/gui/macosx/controls.m
* New Fullscreen controller panel
[vlc] / modules / gui / macosx / controls.m
1 /*****************************************************************************
2  * controls.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2002-2005 the VideoLAN team
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  *          Benjamin Pracht <bigben at videolan doit org>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  * 
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25  *****************************************************************************/
26
27 /*****************************************************************************
28  * Preamble
29  *****************************************************************************/
30 #include <stdlib.h>                                      /* malloc(), free() */
31 #include <sys/param.h>                                    /* for MAXPATHLEN */
32 #include <string.h>
33
34 #include "intf.h"
35 #include "fspanel.h"
36 #include "vout.h"
37 #include "open.h"
38 #include "controls.h"
39 #include <vlc_osd.h>
40
41
42 /*****************************************************************************
43  * VLCControls implementation 
44  *****************************************************************************/
45 @implementation VLCControls
46
47 - (id)init
48 {
49     [super init];
50     o_fs_panel = [[VLCFSPanel alloc] init];
51     return self;
52 }
53
54 - (void)awakeFromNib
55 {
56     [o_specificTime_mi setTitle: _NS("Jump To Time")];
57     [o_specificTime_cancel_btn setTitle: _NS("Cancel")];
58     [o_specificTime_ok_btn setTitle: _NS("OK")];
59     [o_specificTime_sec_lbl setStringValue: _NS("sec.")];
60     [o_specificTime_goTo_lbl setStringValue: _NS("Jump to time")];
61 }
62
63 - (IBAction)play:(id)sender
64 {
65     vlc_value_t val;
66     intf_thread_t * p_intf = VLCIntf;
67     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
68                                         FIND_ANYWHERE );
69     if( p_playlist )
70     {
71         vlc_mutex_lock( &p_playlist->object_lock );
72         if( p_playlist->i_size <= 0 )
73         {
74             vlc_mutex_unlock( &p_playlist->object_lock );
75             vlc_object_release( p_playlist );
76             [o_main intfOpenFileGeneric: (id)sender];
77         }
78         else
79         {
80             vlc_mutex_unlock( &p_playlist->object_lock );
81             vlc_object_release( p_playlist );
82         }
83
84     }
85     val.i_int = config_GetInt( p_intf, "key-play-pause" );
86     var_Set( p_intf->p_vlc, "key-pressed", val );
87 }
88
89 /* Small helper method */
90
91 -(id) getVoutView
92 {
93     id o_window;
94     id o_vout_view = nil;
95     id o_embedded_vout_list = [[VLCMain sharedInstance] getEmbeddedList];
96     NSEnumerator *o_enumerator = [[NSApp orderedWindows] objectEnumerator];
97     while( !o_vout_view && ( o_window = [o_enumerator nextObject] ) )
98     {
99         /* We have an embedded vout */
100         if( [o_embedded_vout_list windowContainsEmbedded: o_window] )
101         {
102             o_vout_view = [o_embedded_vout_list getViewForWindow: o_window];
103         }
104         /* We have a detached vout */
105         else if( [[o_window className] isEqualToString: @"VLCWindow"] )
106         {
107             msg_Dbg( VLCIntf, "detached vout controls.m call getVoutView" );
108             o_vout_view = [o_window getVoutView];
109         }
110     }
111     return o_vout_view;
112 }
113
114
115 - (IBAction)stop:(id)sender
116 {
117     vlc_value_t val;
118     intf_thread_t * p_intf = VLCIntf;
119     val.i_int = config_GetInt( p_intf, "key-stop" );
120     var_Set( p_intf->p_vlc, "key-pressed", val );
121 }
122
123 - (IBAction)faster:(id)sender
124 {
125     vlc_value_t val;
126     intf_thread_t * p_intf = VLCIntf;
127     val.i_int = config_GetInt( p_intf, "key-faster" );
128     var_Set( p_intf->p_vlc, "key-pressed", val );
129 }
130
131 - (IBAction)slower:(id)sender
132 {
133     vlc_value_t val;
134     intf_thread_t * p_intf = VLCIntf;
135     val.i_int = config_GetInt( p_intf, "key-slower" );
136     var_Set( p_intf->p_vlc, "key-pressed", val );
137 }
138
139 - (IBAction)prev:(id)sender
140 {
141     vlc_value_t val;
142     intf_thread_t * p_intf = VLCIntf;
143     val.i_int = config_GetInt( p_intf, "key-prev" );
144     var_Set( p_intf->p_vlc, "key-pressed", val );
145 }
146
147 - (IBAction)next:(id)sender
148 {
149     vlc_value_t val;
150     intf_thread_t * p_intf = VLCIntf;
151     val.i_int = config_GetInt( p_intf, "key-next" );
152     var_Set( p_intf->p_vlc, "key-pressed", val );
153 }
154
155 - (IBAction)random:(id)sender
156 {
157     vlc_value_t val;
158     intf_thread_t * p_intf = VLCIntf;
159     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
160                                                        FIND_ANYWHERE );
161     if( p_playlist == NULL )
162     {
163         return;
164     }
165
166     var_Get( p_playlist, "random", &val );
167     val.b_bool = !val.b_bool;
168     var_Set( p_playlist, "random", val );
169     if( val.b_bool )
170     {
171         vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Random On" ) );
172         config_PutInt( p_playlist, "random", 1 );
173     }
174     else
175     {
176         vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Random Off" ) );
177         config_PutInt( p_playlist, "random", 0 );
178     }
179
180     p_intf->p_sys->b_playmode_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     vlc_value_t val;
188     intf_thread_t * p_intf = VLCIntf;
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, DEFAULT_CHAN, _( "Repeat One" ) );
206         config_PutInt( p_playlist, "repeat", 1 );
207     }
208     else
209     {
210         vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
211         config_PutInt( p_playlist, "repeat", 0 );
212     }
213     
214     p_intf->p_sys->b_playmode_update = VLC_TRUE;
215     p_intf->p_sys->b_intf_update = VLC_TRUE;
216     vlc_object_release( p_playlist );
217 }
218
219 - (IBAction)loop:(id)sender
220 {
221     vlc_value_t val;
222     intf_thread_t * p_intf = VLCIntf;
223     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
224                                                        FIND_ANYWHERE );
225     if( p_playlist == NULL )
226     {
227         return;
228     }
229
230     var_Get( p_playlist, "loop", &val );
231     if (!val.b_bool)
232     {
233         var_Set( p_playlist, "repeat", val );
234     }
235     val.b_bool = !val.b_bool;
236     var_Set( p_playlist, "loop", val );
237     if( val.b_bool )
238     {
239         vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
240         config_PutInt( p_playlist, "loop", 1 );
241     }
242     else
243     {
244         vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
245         config_PutInt( p_playlist, "loop", 0 );
246     }
247
248     p_intf->p_sys->b_playmode_update = VLC_TRUE;
249     p_intf->p_sys->b_intf_update = VLC_TRUE;
250     vlc_object_release( p_playlist );
251 }
252
253 - (IBAction)forward:(id)sender
254 {
255     vlc_value_t val;
256     intf_thread_t * p_intf = VLCIntf;
257     val.i_int = config_GetInt( p_intf, "key-jump+short" );
258     var_Set( p_intf->p_vlc, "key-pressed", val );
259 }
260
261 - (IBAction)backward:(id)sender
262 {
263     vlc_value_t val;
264     intf_thread_t * p_intf = VLCIntf;
265     val.i_int = config_GetInt( p_intf, "key-jump-short" );
266     var_Set( p_intf->p_vlc, "key-pressed", val );
267 }
268
269
270 - (IBAction)volumeUp:(id)sender
271 {
272     vlc_value_t val;
273     intf_thread_t * p_intf = VLCIntf;
274     val.i_int = config_GetInt( p_intf, "key-vol-up" );
275     var_Set( p_intf->p_vlc, "key-pressed", val );
276     /* Manage volume status */
277     [o_main manageVolumeSlider];
278 }
279
280 - (IBAction)volumeDown:(id)sender
281 {
282     vlc_value_t val;
283     intf_thread_t * p_intf = VLCIntf;
284     val.i_int = config_GetInt( p_intf, "key-vol-down" );
285     var_Set( p_intf->p_vlc, "key-pressed", val );
286     /* Manage volume status */
287     [o_main manageVolumeSlider];
288 }
289
290 - (IBAction)mute:(id)sender
291 {
292     vlc_value_t val;
293     intf_thread_t * p_intf = VLCIntf;
294     val.i_int = config_GetInt( p_intf, "key-vol-mute" );
295     var_Set( p_intf->p_vlc, "key-pressed", val );
296     /* Manage volume status */
297     [o_main manageVolumeSlider];
298 }
299
300 - (IBAction)volumeSliderUpdated:(id)sender
301 {
302     intf_thread_t * p_intf = VLCIntf;
303     audio_volume_t i_volume = (audio_volume_t)[sender intValue];
304     int i_volume_step = 0;
305     i_volume_step = config_GetInt( p_intf->p_vlc, "volume-step" );
306     aout_VolumeSet( p_intf, i_volume * i_volume_step );
307     /* Manage volume status */
308     [o_main manageVolumeSlider];
309 }
310
311 - (IBAction)windowAction:(id)sender
312 {
313     NSString *o_title = [sender title];
314
315     vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT,
316                                               FIND_ANYWHERE );
317     if( p_vout != NULL )
318     {
319         id o_vout_view = [self getVoutView];
320         if( o_vout_view )
321         {
322             if( [o_title isEqualToString: _NS("Half Size") ] )
323                 [o_vout_view scaleWindowWithFactor: 0.5];
324             else if( [o_title isEqualToString: _NS("Normal Size") ] )
325                 [o_vout_view scaleWindowWithFactor: 1.0];
326             else if( [o_title isEqualToString: _NS("Double Size") ] )
327                 [o_vout_view scaleWindowWithFactor: 2.0];
328             else if( [o_title isEqualToString: _NS("Float on Top") ] )
329                 [o_vout_view toggleFloatOnTop];
330             else if( [o_title isEqualToString: _NS("Fit to Screen") ] )
331             {
332                 id o_window = [o_vout_view getWindow];
333                 if( ![o_window isZoomed] )
334                     [o_window performZoom:self];
335             }
336             else if( [o_title isEqualToString: _NS("Snapshot") ] )
337             {
338                 [o_vout_view snapshot];
339             }
340             else
341             {
342                 [o_vout_view toggleFullscreen];
343             }
344         }
345         vlc_object_release( (vlc_object_t *)p_vout );
346     }
347     else
348     {
349         playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
350                                               FIND_ANYWHERE );
351
352         if( p_playlist && ( [o_title isEqualToString: _NS("Fullscreen")] ||
353             [sender isKindOfClass:[NSButton class]] ) )
354         {
355             vlc_value_t val;
356             var_Get( p_playlist, "fullscreen", &val );
357             var_Set( p_playlist, "fullscreen", (vlc_value_t)!val.b_bool );
358         }
359         if( p_playlist ) vlc_object_release( (vlc_object_t *)p_playlist );
360     }
361
362 }
363
364 - (BOOL)keyEvent:(NSEvent *)o_event
365 {
366     BOOL eventHandled = NO;
367     unichar key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
368
369     if( key )
370     {
371         vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT,
372                                               FIND_ANYWHERE );
373         if( p_vout != NULL )
374         {
375             /* Escape */
376             if( key == (unichar) 0x1b )
377             {
378                 id o_vout_view = [self getVoutView];
379                 if( o_vout_view && [o_vout_view isFullscreen] )
380                 {
381                     [o_vout_view toggleFullscreen];
382                     eventHandled = YES;
383                 }
384             }
385             else if( key == ' ' )
386             {
387                 [self play:self];
388                 eventHandled = YES;
389             }
390             vlc_object_release( (vlc_object_t *)p_vout );
391         }
392     }
393     return eventHandled;
394 }
395
396 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
397                     target:(vlc_object_t *)p_object
398                     var:(const char *)psz_variable
399                     selector:(SEL)pf_callback
400 {
401     vlc_value_t val, text;
402     int i_type = var_Type( p_object, psz_variable );
403
404     switch( i_type & VLC_VAR_TYPE )
405     {
406     case VLC_VAR_VOID:
407     case VLC_VAR_BOOL:
408     case VLC_VAR_VARIABLE:
409     case VLC_VAR_STRING:
410     case VLC_VAR_INTEGER:
411         break;
412     default:
413         /* Variable doesn't exist or isn't handled */
414         return;
415     }
416     
417     /* Make sure we want to display the variable */
418     if( i_type & VLC_VAR_HASCHOICE )
419     {
420         var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
421         if( val.i_int == 0 ) return;
422         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
423             return;
424     }
425     
426     /* Get the descriptive name of the variable */
427     var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
428     [o_mi setTitle: [[VLCMain sharedInstance] localizedString: text.psz_string ?
429                                         text.psz_string : strdup( psz_variable ) ]];
430
431     var_Get( p_object, psz_variable, &val );
432     if( i_type & VLC_VAR_HASCHOICE )
433     {
434         NSMenu *o_menu = [o_mi submenu];
435
436         [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
437                         var:psz_variable selector:pf_callback];
438         
439         if( text.psz_string ) free( text.psz_string );
440         return;
441     }
442
443     VLCMenuExt *o_data;
444     switch( i_type & VLC_VAR_TYPE )
445     {
446     case VLC_VAR_VOID:
447         o_data = [[VLCMenuExt alloc] initWithVar: psz_variable Object: p_object->i_object_id
448                 Value: val ofType: i_type];
449         [o_mi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
450         break;
451
452     case VLC_VAR_BOOL:
453         o_data = [[VLCMenuExt alloc] initWithVar: psz_variable Object: p_object->i_object_id
454                 Value: val ofType: i_type];
455         [o_mi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
456         if( !( i_type & VLC_VAR_ISCOMMAND ) )
457             [o_mi setState: val.b_bool ? TRUE : FALSE ];
458         break;
459
460     default:
461         if( text.psz_string ) free( text.psz_string );
462         return;
463     }
464
465     if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
466     if( text.psz_string ) free( text.psz_string );
467 }
468
469
470 - (void)setupVarMenu:(NSMenu *)o_menu
471                     forMenuItem: (NSMenuItem *)o_parent
472                     target:(vlc_object_t *)p_object
473                     var:(const char *)psz_variable
474                     selector:(SEL)pf_callback
475 {
476     vlc_value_t val, val_list, text_list;
477     int i_type, i, i_nb_items;
478
479     /* remove previous items */
480     i_nb_items = [o_menu numberOfItems];
481     for( i = 0; i < i_nb_items; i++ )
482     {
483         [o_menu removeItemAtIndex: 0];
484     }
485
486     /* Check the type of the object variable */
487     i_type = var_Type( p_object, psz_variable );
488
489     /* Make sure we want to display the variable */
490     if( i_type & VLC_VAR_HASCHOICE )
491     {
492         var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
493         if( val.i_int == 0 ) return;
494         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
495             return;
496     }
497     else
498     {
499         return;
500     }
501
502     switch( i_type & VLC_VAR_TYPE )
503     {
504     case VLC_VAR_VOID:
505     case VLC_VAR_BOOL:
506     case VLC_VAR_VARIABLE:
507     case VLC_VAR_STRING:
508     case VLC_VAR_INTEGER:
509         break;
510     default:
511         /* Variable doesn't exist or isn't handled */
512         return;
513     }
514
515     if( var_Get( p_object, psz_variable, &val ) < 0 )
516     {
517         return;
518     }
519
520     if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
521                     &val_list, &text_list ) < 0 )
522     {
523         if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
524         return;
525     }
526
527     /* make (un)sensitive */
528     [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
529
530     for( i = 0; i < val_list.p_list->i_count; i++ )
531     {
532         vlc_value_t another_val;
533         NSMenuItem * o_lmi;
534         NSString *o_title = @"";
535         VLCMenuExt *o_data;
536
537         switch( i_type & VLC_VAR_TYPE )
538         {
539         case VLC_VAR_STRING:
540             another_val.psz_string =
541                 strdup(val_list.p_list->p_values[i].psz_string);
542
543             o_title = [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string ?
544                 text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
545
546             o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
547             o_data = [[VLCMenuExt alloc] initWithVar: strdup(psz_variable) Object: p_object->i_object_id
548                     Value: another_val ofType: i_type];
549             [o_lmi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
550             [o_lmi setTarget: self];
551
552             if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
553                 [o_lmi setState: TRUE ];
554
555             break;
556
557         case VLC_VAR_INTEGER:
558
559              o_title = text_list.p_list->p_values[i].psz_string ?
560                                  [[VLCMain sharedInstance] localizedString: strdup( text_list.p_list->p_values[i].psz_string )] :
561                                  [NSString stringWithFormat: @"%d",
562                                  val_list.p_list->p_values[i].i_int];
563
564             o_lmi = [[o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""] retain ];
565             o_data = [[VLCMenuExt alloc] initWithVar: strdup(psz_variable) Object: p_object->i_object_id
566                     Value: val_list.p_list->p_values[i] ofType: i_type];
567             [o_lmi setRepresentedObject: [NSValue valueWithPointer:[ o_data retain]]];
568             [o_lmi setTarget: self];
569
570             if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
571                 [o_lmi setState: TRUE ];
572             break;
573
574         default:
575           break;
576         }
577     }
578
579     /* clean up everything */
580     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
581     var_Change( p_object, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list );
582 }
583
584 - (IBAction)toggleVar:(id)sender
585 {
586     NSMenuItem *o_mi = (NSMenuItem *)sender;
587     VLCMenuExt *o_data = [[o_mi representedObject] pointerValue];
588     [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
589         toTarget: self withObject: o_data];
590
591     return;
592 }
593
594 - (int)toggleVarThread: (id)_o_data
595 {
596     vlc_object_t *p_object;
597     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
598     VLCMenuExt *o_data = (VLCMenuExt *)_o_data;
599
600     vlc_thread_set_priority( VLCIntf , VLC_THREAD_PRIORITY_LOW );
601
602     p_object = (vlc_object_t *)vlc_object_get( VLCIntf,
603                                     [o_data objectID] );
604
605     if( p_object != NULL )
606     {
607         var_Set( p_object, strdup([o_data name]), [o_data value] );
608         vlc_object_release( p_object );
609         [o_pool release];
610         return VLC_TRUE;
611     }
612     [o_pool release];
613     return VLC_EGENERIC;
614 }
615
616 - (IBAction)goToSpecificTime:(id)sender
617 {
618     if( sender == o_specificTime_cancel_btn )
619     {
620         [NSApp endSheet: o_specificTime_win];
621         [o_specificTime_win close];
622     }
623     else if( sender == o_specificTime_ok_btn )
624     {
625         input_thread_t * p_input = (input_thread_t *)vlc_object_find( VLCIntf, \
626             VLC_OBJECT_INPUT, FIND_ANYWHERE );
627         if( p_input )
628         {
629             unsigned int timeInSec = 0;
630             NSString * fieldContent = [o_specificTime_enter_fld stringValue];
631             if( [[fieldContent componentsSeparatedByString: @":"] count] > 1 && 
632                 [[fieldContent componentsSeparatedByString: @":"] count] <= 3 )
633             {
634                 NSArray * ourTempArray = \
635                     [fieldContent componentsSeparatedByString: @":"];
636
637                 if( [[fieldContent componentsSeparatedByString: @":"] count] == 3 )
638                 {
639                     timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 3600); //h
640                     timeInSec += ([[ourTempArray objectAtIndex: 1] intValue] * 60); //m
641                     timeInSec += [[ourTempArray objectAtIndex: 2] intValue];        //s
642                 }
643                 else
644                 {
645                     timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 60); //m
646                     timeInSec += [[ourTempArray objectAtIndex: 1] intValue]; //s
647                 }
648             }
649             else
650                 timeInSec = [fieldContent intValue];
651
652             input_Control( p_input, INPUT_SET_TIME, (int64_t)(timeInSec * 1000000));
653             vlc_object_release( p_input );
654         }
655     
656         [NSApp endSheet: o_specificTime_win];
657         [o_specificTime_win close];
658     }
659     else
660     {
661         input_thread_t * p_input = (input_thread_t *)vlc_object_find( VLCIntf, \
662             VLC_OBJECT_INPUT, FIND_ANYWHERE );
663         if( p_input )
664         {
665             /* we can obviously only do that if an input is available */
666             vlc_value_t pos, length;
667             var_Get( p_input, "time", &pos );
668             [o_specificTime_enter_fld setIntValue: (pos.i_time / 1000000)];
669             var_Get( p_input, "length", &length );
670             [o_specificTime_stepper setMaxValue: (length.i_time / 1000000)];
671
672             [NSApp beginSheet: o_specificTime_win modalForWindow: \
673                 [NSApp mainWindow] modalDelegate: self didEndSelector: nil \
674                 contextInfo: nil];
675             [o_specificTime_win makeKeyWindow];
676             vlc_object_release( p_input );
677         }
678     }
679 }
680
681 - (id)getFSPanel
682 {
683     if( o_fs_panel )
684         return o_fs_panel;
685     else
686     {
687         msg_Err( VLCIntf, "FSPanel is nil" );
688         return NULL;
689     }
690 }
691
692 @end
693
694 @implementation VLCControls (NSMenuValidation)
695
696 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
697 {
698     BOOL bEnabled = TRUE;
699     vlc_value_t val;
700     intf_thread_t * p_intf = VLCIntf;
701     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
702                                                        FIND_ANYWHERE );
703
704     if( p_playlist != NULL )
705     {
706         vlc_mutex_lock( &p_playlist->object_lock );
707     }
708     else return FALSE;
709
710 #define p_input p_playlist->p_input
711
712     if( [[o_mi title] isEqualToString: _NS("Faster")] ||
713         [[o_mi title] isEqualToString: _NS("Slower")] )
714     {
715         if( p_input != NULL )
716         {
717             bEnabled = p_input->input.b_can_pace_control;
718         }
719         else
720         {
721             bEnabled = FALSE;
722         }
723     }
724     else if( [[o_mi title] isEqualToString: _NS("Stop")] )
725     {
726         if( p_input == NULL )
727         {
728             bEnabled = FALSE;
729         }
730         [o_main setupMenus]; /* Make sure input menu is up to date */
731     }
732     else if( [[o_mi title] isEqualToString: _NS("Previous")] ||
733              [[o_mi title] isEqualToString: _NS("Next")] )
734     {
735             bEnabled = p_playlist->i_size > 1;
736     }
737     else if( [[o_mi title] isEqualToString: _NS("Random")] )
738     {
739         int i_state;
740         var_Get( p_playlist, "random", &val );
741         i_state = val.b_bool ? NSOnState : NSOffState;
742         [o_mi setState: i_state];
743     }
744     else if( [[o_mi title] isEqualToString: _NS("Repeat One")] )
745     {
746         int i_state;
747         var_Get( p_playlist, "repeat", &val );
748         i_state = val.b_bool ? NSOnState : NSOffState;
749         [o_mi setState: i_state];
750     }
751     else if( [[o_mi title] isEqualToString: _NS("Repeat All")] )
752     {
753         int i_state;
754         var_Get( p_playlist, "loop", &val );
755         i_state = val.b_bool ? NSOnState : NSOffState;
756         [o_mi setState: i_state];
757     }
758     else if( [[o_mi title] isEqualToString: _NS("Step Forward")] ||
759              [[o_mi title] isEqualToString: _NS("Step Backward")] ||
760              [[o_mi title] isEqualToString: _NS("Jump To Time")])
761     {
762         if( p_input != NULL )
763         {
764             var_Get( p_input, "seekable", &val);
765             bEnabled = val.b_bool;
766         }
767         else bEnabled = FALSE;
768     }
769     else if( [[o_mi title] isEqualToString: _NS("Mute")] )
770     {
771         [o_mi setState: p_intf->p_sys->b_mute ? NSOnState : NSOffState];
772         [o_main setupMenus]; /* Make sure audio menu is up to date */
773     }
774     else if( [[o_mi title] isEqualToString: _NS("Half Size")] ||
775                 [[o_mi title] isEqualToString: _NS("Normal Size")] ||
776                 [[o_mi title] isEqualToString: _NS("Double Size")] ||
777                 [[o_mi title] isEqualToString: _NS("Fit to Screen")] ||
778                 [[o_mi title] isEqualToString: _NS("Snapshot")] ||
779                 [[o_mi title] isEqualToString: _NS("Fullscreen")] ||
780                 [[o_mi title] isEqualToString: _NS("Float on Top")] )
781     {
782         id o_window;
783         NSArray *o_windows = [NSApp orderedWindows];
784         NSEnumerator *o_enumerator = [o_windows objectEnumerator];
785         bEnabled = FALSE;
786         
787         vout_thread_t   *p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
788                                               FIND_ANYWHERE );
789         if( p_vout != NULL )
790         {
791             if( [[o_mi title] isEqualToString: _NS("Float on Top")] )
792             {
793                 var_Get( p_vout, "video-on-top", &val );
794                 [o_mi setState: val.b_bool ?  NSOnState : NSOffState];
795             }
796
797             while( (o_window = [o_enumerator nextObject]))
798             {
799                 if( [[o_window className] isEqualToString: @"VLCWindow"] ||
800                             [[[VLCMain sharedInstance] getEmbeddedList]
801                             windowContainsEmbedded: o_window])
802                 {
803                     bEnabled = TRUE;
804                     break;
805                 }
806             }
807             vlc_object_release( (vlc_object_t *)p_vout );
808         }
809         else if( [[o_mi title] isEqualToString: _NS("Fullscreen")] )
810         {
811             var_Get( p_playlist, "fullscreen", &val );
812             [o_mi setState: val.b_bool];
813             bEnabled = TRUE;
814         }
815         [o_main setupMenus]; /* Make sure video menu is up to date */
816     }
817
818     vlc_mutex_unlock( &p_playlist->object_lock );
819     vlc_object_release( p_playlist );
820
821     return( bEnabled );
822 }
823
824 @end
825
826 /*****************************************************************************
827  * VLCMenuExt implementation 
828  *****************************************************************************
829  * Object connected to a playlistitem which remembers the data belonging to
830  * the variable of the autogenerated menu
831  *****************************************************************************/
832 @implementation VLCMenuExt
833
834 - (id)initWithVar: (const char *)_psz_name Object: (int)i_id
835         Value: (vlc_value_t)val ofType: (int)_i_type
836 {
837     self = [super init];
838
839     if( self != nil )
840     {
841         psz_name = strdup( _psz_name );
842         i_object_id = i_id;
843         value = val;
844         i_type = _i_type;
845     }
846
847     return( self );
848 }
849
850 - (void)dealloc
851 {
852     free( psz_name );
853     [super dealloc];
854 }
855
856 - (char *)name
857 {
858     return psz_name;
859 }
860
861 - (int)objectID
862 {
863     return i_object_id;
864 }
865
866 - (vlc_value_t)value
867 {
868     return value;
869 }
870
871 - (int)type
872 {
873     return i_type;
874 }
875
876 @end
877
878
879 /*****************************************************************************
880  * VLCTimeField implementation 
881  *****************************************************************************
882  * we need this to catch our click-event in the controller window
883  *****************************************************************************/
884
885 @implementation VLCTimeField
886 - (void)mouseDown: (NSEvent *)ourEvent
887 {
888     if( [ourEvent clickCount] > 1 )
889         [[[VLCMain sharedInstance] getControls] goToSpecificTime: nil];
890 }
891 @end