1 /*****************************************************************************
2 * controls.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2007 the VideoLAN team
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 * Felix Kühne <fkuehne at videolan dot org>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
28 /*****************************************************************************
30 *****************************************************************************/
31 #include <stdlib.h> /* malloc(), free() */
32 #include <sys/param.h> /* for MAXPATHLEN */
43 /*****************************************************************************
44 * VLCControls implementation
45 *****************************************************************************/
46 @implementation VLCControls
51 o_fs_panel = [[VLCFSPanel alloc] init];
57 [o_specificTime_mi setTitle: _NS("Jump To Time")];
58 [o_specificTime_cancel_btn setTitle: _NS("Cancel")];
59 [o_specificTime_ok_btn setTitle: _NS("OK")];
60 [o_specificTime_sec_lbl setStringValue: _NS("sec.")];
61 [o_specificTime_goTo_lbl setStringValue: _NS("Jump to time")];
63 o_repeat_off = [NSImage imageNamed:@"repeat_embedded"];
65 [self controlTintChanged];
67 [[NSNotificationCenter defaultCenter] addObserver: self
68 selector: @selector( controlTintChanged )
69 name: NSControlTintDidChangeNotification
73 - (void)controlTintChanged
76 if( [o_btn_repeat image] == o_repeat_single )
78 else if( [o_btn_repeat image] == o_repeat_all )
81 if( [NSColor currentControlTint] == NSGraphiteControlTint )
83 o_repeat_single = [NSImage imageNamed:@"repeat_single_embedded_graphite"];
84 o_repeat_all = [NSImage imageNamed:@"repeat_embedded_graphite"];
86 [o_btn_shuffle setAlternateImage: [NSImage imageNamed: @"shuffle_embedded_graphite"]];
87 [o_btn_addNode setAlternateImage: [NSImage imageNamed: @"add_embedded_graphite"]];
91 o_repeat_single = [NSImage imageNamed:@"repeat_single_embedded_blue"];
92 o_repeat_all = [NSImage imageNamed:@"repeat_embedded_blue"];
94 [o_btn_shuffle setAlternateImage: [NSImage imageNamed: @"shuffle_embedded_blue"]];
95 [o_btn_addNode setAlternateImage: [NSImage imageNamed: @"add_embedded_blue"]];
98 /* update the repeat button, but keep its state */
101 else if( i_repeat == 2 )
109 [[NSNotificationCenter defaultCenter] removeObserver: self];
111 [o_repeat_single release];
112 [o_repeat_all release];
113 [o_repeat_off release];
118 - (IBAction)play:(id)sender
121 intf_thread_t * p_intf = VLCIntf;
122 playlist_t * p_playlist = pl_Yield( p_intf );
124 vlc_object_lock( p_playlist );
125 if( playlist_IsEmpty( p_playlist ) )
127 vlc_object_unlock( p_playlist );
128 vlc_object_release( p_playlist );
129 [o_main intfOpenFileGeneric: (id)sender];
133 vlc_object_unlock( p_playlist );
134 vlc_object_release( p_playlist );
137 val.i_int = config_GetInt( p_intf, "key-play-pause" );
138 var_Set( p_intf->p_libvlc, "key-pressed", val );
141 /* Small helper method */
146 id o_vout_view = nil;
147 id o_embedded_vout_list = [[VLCMain sharedInstance] getEmbeddedList];
148 NSEnumerator *o_enumerator = [[NSApp orderedWindows] objectEnumerator];
149 while( !o_vout_view && ( o_window = [o_enumerator nextObject] ) )
151 /* We have an embedded vout */
152 if( [o_embedded_vout_list windowContainsEmbedded: o_window] )
154 o_vout_view = [o_embedded_vout_list getViewForWindow: o_window];
156 /* We have a detached vout */
157 else if( [[o_window className] isEqualToString: @"VLCVoutWindow"] )
159 msg_Dbg( VLCIntf, "detached vout controls.m call getVoutView" );
160 o_vout_view = [o_window getVoutView];
166 - (IBAction)stop:(id)sender
169 intf_thread_t * p_intf = VLCIntf;
170 val.i_int = config_GetInt( p_intf, "key-stop" );
171 var_Set( p_intf->p_libvlc, "key-pressed", val );
172 /* Close the window directly, because we do know that there
173 * won't be anymore video. It's currently waiting a bit. */
174 [[[self getVoutView] window] orderOut:self];
177 - (IBAction)faster:(id)sender
180 intf_thread_t * p_intf = VLCIntf;
181 val.i_int = config_GetInt( p_intf, "key-faster" );
182 var_Set( p_intf->p_libvlc, "key-pressed", val );
185 - (IBAction)slower:(id)sender
188 intf_thread_t * p_intf = VLCIntf;
189 val.i_int = config_GetInt( p_intf, "key-slower" );
190 var_Set( p_intf->p_libvlc, "key-pressed", val );
193 - (IBAction)prev:(id)sender
196 intf_thread_t * p_intf = VLCIntf;
197 val.i_int = config_GetInt( p_intf, "key-prev" );
198 var_Set( p_intf->p_libvlc, "key-pressed", val );
201 - (IBAction)next:(id)sender
204 intf_thread_t * p_intf = VLCIntf;
205 val.i_int = config_GetInt( p_intf, "key-next" );
206 var_Set( p_intf->p_libvlc, "key-pressed", val );
209 - (IBAction)random:(id)sender
212 intf_thread_t * p_intf = VLCIntf;
213 playlist_t * p_playlist = pl_Yield( p_intf );
215 var_Get( p_playlist, "random", &val );
216 val.b_bool = !val.b_bool;
217 var_Set( p_playlist, "random", val );
220 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Random On" ) );
221 config_PutInt( p_playlist, "random", 1 );
225 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Random Off" ) );
226 config_PutInt( p_playlist, "random", 0 );
229 p_intf->p_sys->b_playmode_update = true;
230 p_intf->p_sys->b_intf_update = true;
231 vlc_object_release( p_playlist );
234 /* three little ugly helpers */
237 [o_btn_repeat setImage: o_repeat_single];
238 [o_btn_repeat setAlternateImage: o_repeat_all];
242 [o_btn_repeat setImage: o_repeat_all];
243 [o_btn_repeat setAlternateImage: o_repeat_off];
247 [o_btn_repeat setImage: o_repeat_off];
248 [o_btn_repeat setAlternateImage: o_repeat_single];
253 playlist_t *p_playlist = pl_Yield( VLCIntf );
254 var_Get( p_playlist, "random", &val );
255 [o_btn_shuffle setState: val.b_bool];
256 vlc_object_release( p_playlist );
259 - (IBAction)repeatButtonAction:(id)sender
261 vlc_value_t looping,repeating;
262 intf_thread_t * p_intf = VLCIntf;
263 playlist_t * p_playlist = pl_Yield( p_intf );
265 var_Get( p_playlist, "repeat", &repeating );
266 var_Get( p_playlist, "loop", &looping );
268 if( !repeating.b_bool && !looping.b_bool )
270 /* was: no repeating at all, switching to Repeat One */
272 /* set our button's look */
275 /* prepare core communication */
276 repeating.b_bool = true;
277 looping.b_bool = false;
278 config_PutInt( p_playlist, "repeat", 1 );
279 config_PutInt( p_playlist, "loop", 0 );
281 /* show the change */
282 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
284 else if( repeating.b_bool && !looping.b_bool )
286 /* was: Repeat One, switching to Repeat All */
288 /* set our button's look */
291 /* prepare core communication */
292 repeating.b_bool = false;
293 looping.b_bool = true;
294 config_PutInt( p_playlist, "repeat", 0 );
295 config_PutInt( p_playlist, "loop", 1 );
297 /* show the change */
298 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
302 /* was: Repeat All or bug in VLC, switching to Repeat Off */
304 /* set our button's look */
307 /* prepare core communication */
308 repeating.b_bool = false;
309 looping.b_bool = false;
310 config_PutInt( p_playlist, "repeat", 0 );
311 config_PutInt( p_playlist, "loop", 0 );
313 /* show the change */
314 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
317 /* communicate with core and the main intf loop */
318 var_Set( p_playlist, "repeat", repeating );
319 var_Set( p_playlist, "loop", looping );
320 p_intf->p_sys->b_playmode_update = true;
321 p_intf->p_sys->b_intf_update = true;
323 vlc_object_release( p_playlist );
327 - (IBAction)repeat:(id)sender
330 intf_thread_t * p_intf = VLCIntf;
331 playlist_t * p_playlist = pl_Yield( p_intf );
333 var_Get( p_playlist, "repeat", &val );
336 var_Set( p_playlist, "loop", val );
338 val.b_bool = !val.b_bool;
339 var_Set( p_playlist, "repeat", val );
342 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
343 config_PutInt( p_playlist, "repeat", 1 );
347 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
348 config_PutInt( p_playlist, "repeat", 0 );
351 p_intf->p_sys->b_playmode_update = true;
352 p_intf->p_sys->b_intf_update = true;
353 vlc_object_release( p_playlist );
356 - (IBAction)loop:(id)sender
359 intf_thread_t * p_intf = VLCIntf;
360 playlist_t * p_playlist = pl_Yield( p_intf );
362 var_Get( p_playlist, "loop", &val );
365 var_Set( p_playlist, "repeat", val );
367 val.b_bool = !val.b_bool;
368 var_Set( p_playlist, "loop", val );
371 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
372 config_PutInt( p_playlist, "loop", 1 );
376 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
377 config_PutInt( p_playlist, "loop", 0 );
380 p_intf->p_sys->b_playmode_update = true;
381 p_intf->p_sys->b_intf_update = true;
382 vlc_object_release( p_playlist );
385 - (IBAction)forward:(id)sender
388 intf_thread_t * p_intf = VLCIntf;
389 val.i_int = config_GetInt( p_intf, "key-jump+short" );
390 var_Set( p_intf->p_libvlc, "key-pressed", val );
393 - (IBAction)backward:(id)sender
396 intf_thread_t * p_intf = VLCIntf;
397 val.i_int = config_GetInt( p_intf, "key-jump-short" );
398 var_Set( p_intf->p_libvlc, "key-pressed", val );
402 - (IBAction)volumeUp:(id)sender
405 intf_thread_t * p_intf = VLCIntf;
406 val.i_int = config_GetInt( p_intf, "key-vol-up" );
407 var_Set( p_intf->p_libvlc, "key-pressed", val );
408 /* Manage volume status */
409 [o_main manageVolumeSlider];
412 - (IBAction)volumeDown:(id)sender
415 intf_thread_t * p_intf = VLCIntf;
416 val.i_int = config_GetInt( p_intf, "key-vol-down" );
417 var_Set( p_intf->p_libvlc, "key-pressed", val );
418 /* Manage volume status */
419 [o_main manageVolumeSlider];
422 - (IBAction)mute:(id)sender
425 intf_thread_t * p_intf = VLCIntf;
426 val.i_int = config_GetInt( p_intf, "key-vol-mute" );
427 var_Set( p_intf->p_libvlc, "key-pressed", val );
428 /* Manage volume status */
429 [o_main manageVolumeSlider];
432 - (IBAction)volumeSliderUpdated:(id)sender
434 intf_thread_t * p_intf = VLCIntf;
435 audio_volume_t i_volume = (audio_volume_t)[sender intValue];
436 int i_volume_step = 0;
437 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
438 aout_VolumeSet( p_intf, i_volume * i_volume_step );
439 /* Manage volume status */
440 [o_main manageVolumeSlider];
443 - (IBAction)showPosition: (id)sender
445 vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT,
450 intf_thread_t * p_intf = VLCIntf;
451 val.i_int = config_GetInt( p_intf, "key-position" );
452 var_Set( p_intf, "key-pressed", val );
453 vlc_object_release( (vlc_object_t *)p_vout );
457 - (IBAction)toogleFullscreen:(id)sender {
458 NSMenuItem *o_mi = [[NSMenuItem alloc] initWithTitle: _NS("Fullscreen") action: nil keyEquivalent:@""];
459 [self windowAction: [o_mi autorelease]];
462 - (BOOL) isFullscreen {
463 id o_vout_view = [self getVoutView];
466 return [o_vout_view isFullscreen];
471 - (IBAction)windowAction:(id)sender
473 NSString *o_title = [sender title];
475 vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT,
479 id o_vout_view = [self getVoutView];
482 if( [o_title isEqualToString: _NS("Half Size") ] )
483 [o_vout_view scaleWindowWithFactor: 0.5 animate: YES];
484 else if( [o_title isEqualToString: _NS("Normal Size") ] )
485 [o_vout_view scaleWindowWithFactor: 1.0 animate: YES];
486 else if( [o_title isEqualToString: _NS("Double Size") ] )
487 [o_vout_view scaleWindowWithFactor: 2.0 animate: YES];
488 else if( [o_title isEqualToString: _NS("Float on Top") ] )
489 [o_vout_view toggleFloatOnTop];
490 else if( [o_title isEqualToString: _NS("Fit to Screen") ] )
492 id o_window = [o_vout_view getWindow];
493 if( ![o_window isZoomed] )
494 [o_window performZoom:self];
496 else if( [o_title isEqualToString: _NS("Snapshot") ] )
498 [o_vout_view snapshot];
502 /* Fullscreen state for next time will be saved here too */
503 [o_vout_view toggleFullscreen];
506 vlc_object_release( (vlc_object_t *)p_vout );
510 playlist_t * p_playlist = pl_Yield( VLCIntf );
512 if( [o_title isEqualToString: _NS("Fullscreen")] ||
513 [sender isKindOfClass:[NSButton class]] )
516 var_Get( p_playlist, "fullscreen", &val );
517 var_Set( p_playlist, "fullscreen", (vlc_value_t)!val.b_bool );
520 pl_Release( VLCIntf );
525 - (void)scrollWheel:(NSEvent *)theEvent
527 intf_thread_t * p_intf = VLCIntf;
528 float f_yabsvalue = [theEvent deltaY] > 0.0f ? [theEvent deltaY] : -[theEvent deltaY];
529 float f_xabsvalue = [theEvent deltaX] > 0.0f ? [theEvent deltaX] : -[theEvent deltaX];
530 int i, i_yvlckey, i_xvlckey;
532 if ([theEvent deltaY] < 0.0f)
533 i_yvlckey = KEY_MOUSEWHEELDOWN;
535 i_yvlckey = KEY_MOUSEWHEELUP;
537 if ([theEvent deltaX] < 0.0f)
538 i_xvlckey = KEY_MOUSEWHEELRIGHT;
540 i_xvlckey = KEY_MOUSEWHEELLEFT;
542 /* Send multiple key event, depending on the intensity of the event */
543 for (i = 0; i < (int)(f_yabsvalue/4.+1.) && f_yabsvalue > 0.05 ; i++)
544 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_yvlckey );
546 /* Prioritize Y event (sound volume) over X event */
547 if (f_yabsvalue < 0.05)
549 for (i = 0; i < (int)(f_xabsvalue/6.+1.) && f_xabsvalue > 0.05; i++)
550 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_xvlckey );
554 - (BOOL)keyEvent:(NSEvent *)o_event
556 BOOL eventHandled = NO;
557 unichar key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
561 vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT,
566 if( key == (unichar) 0x1b )
568 id o_vout_view = [self getVoutView];
569 if( o_vout_view && [o_vout_view isFullscreen] )
571 [o_vout_view toggleFullscreen];
575 else if( key == ' ' )
580 vlc_object_release( (vlc_object_t *)p_vout );
586 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
587 target:(vlc_object_t *)p_object
588 var:(const char *)psz_variable
589 selector:(SEL)pf_callback
591 vlc_value_t val, text;
592 int i_type = var_Type( p_object, psz_variable );
594 switch( i_type & VLC_VAR_TYPE )
598 case VLC_VAR_VARIABLE:
600 case VLC_VAR_INTEGER:
603 /* Variable doesn't exist or isn't handled */
607 /* Make sure we want to display the variable */
608 if( i_type & VLC_VAR_HASCHOICE )
610 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
611 if( val.i_int == 0 ) return;
612 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
616 /* Get the descriptive name of the variable */
617 var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
618 [o_mi setTitle: [[VLCMain sharedInstance] localizedString: text.psz_string ?
619 text.psz_string : strdup( psz_variable ) ]];
621 var_Get( p_object, psz_variable, &val );
622 if( i_type & VLC_VAR_HASCHOICE )
624 NSMenu *o_menu = [o_mi submenu];
626 [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
627 var:psz_variable selector:pf_callback];
629 free( text.psz_string );
634 switch( i_type & VLC_VAR_TYPE )
637 o_data = [[VLCMenuExt alloc] initWithVar: psz_variable Object: p_object->i_object_id
638 Value: val ofType: i_type];
639 [o_mi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
643 o_data = [[VLCMenuExt alloc] initWithVar: psz_variable Object: p_object->i_object_id
644 Value: val ofType: i_type];
645 [o_mi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
646 if( !( i_type & VLC_VAR_ISCOMMAND ) )
647 [o_mi setState: val.b_bool ? TRUE : FALSE ];
651 free( text.psz_string );
655 if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
656 free( text.psz_string );
660 - (void)setupVarMenu:(NSMenu *)o_menu
661 forMenuItem: (NSMenuItem *)o_parent
662 target:(vlc_object_t *)p_object
663 var:(const char *)psz_variable
664 selector:(SEL)pf_callback
666 vlc_value_t val, val_list, text_list;
667 int i_type, i, i_nb_items;
669 /* remove previous items */
670 i_nb_items = [o_menu numberOfItems];
671 for( i = 0; i < i_nb_items; i++ )
673 [o_menu removeItemAtIndex: 0];
676 /* Check the type of the object variable */
677 i_type = var_Type( p_object, psz_variable );
679 /* Make sure we want to display the variable */
680 if( i_type & VLC_VAR_HASCHOICE )
682 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
683 if( val.i_int == 0 ) return;
684 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
692 switch( i_type & VLC_VAR_TYPE )
696 case VLC_VAR_VARIABLE:
698 case VLC_VAR_INTEGER:
701 /* Variable doesn't exist or isn't handled */
705 if( var_Get( p_object, psz_variable, &val ) < 0 )
710 if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
711 &val_list, &text_list ) < 0 )
713 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
717 /* make (un)sensitive */
718 [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
720 for( i = 0; i < val_list.p_list->i_count; i++ )
722 vlc_value_t another_val;
724 NSString *o_title = @"";
727 switch( i_type & VLC_VAR_TYPE )
730 another_val.psz_string =
731 strdup(val_list.p_list->p_values[i].psz_string);
733 o_title = [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string ?
734 text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
736 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
737 o_data = [[VLCMenuExt alloc] initWithVar: strdup(psz_variable) Object: p_object->i_object_id
738 Value: another_val ofType: i_type];
739 [o_lmi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
740 [o_lmi setTarget: self];
742 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
743 [o_lmi setState: TRUE ];
747 case VLC_VAR_INTEGER:
749 o_title = text_list.p_list->p_values[i].psz_string ?
750 [[VLCMain sharedInstance] localizedString: strdup( text_list.p_list->p_values[i].psz_string )] :
751 [NSString stringWithFormat: @"%d",
752 val_list.p_list->p_values[i].i_int];
754 o_lmi = [[o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""] retain ];
755 o_data = [[VLCMenuExt alloc] initWithVar: strdup(psz_variable) Object: p_object->i_object_id
756 Value: val_list.p_list->p_values[i] ofType: i_type];
757 [o_lmi setRepresentedObject: [NSValue valueWithPointer:[ o_data retain]]];
758 [o_lmi setTarget: self];
760 if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
761 [o_lmi setState: TRUE ];
769 /* clean up everything */
770 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
771 var_Change( p_object, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list );
774 - (IBAction)toggleVar:(id)sender
776 NSMenuItem *o_mi = (NSMenuItem *)sender;
777 VLCMenuExt *o_data = [[o_mi representedObject] pointerValue];
778 [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
779 toTarget: self withObject: o_data];
784 - (int)toggleVarThread: (id)_o_data
786 vlc_object_t *p_object;
787 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
788 VLCMenuExt *o_data = (VLCMenuExt *)_o_data;
790 vlc_thread_set_priority( VLCIntf , VLC_THREAD_PRIORITY_LOW );
792 p_object = (vlc_object_t *)vlc_object_get( [o_data objectID] );
794 if( p_object != NULL )
796 var_Set( p_object, strdup([o_data name]), [o_data value] );
797 vlc_object_release( p_object );
805 - (IBAction)goToSpecificTime:(id)sender
807 if( sender == o_specificTime_cancel_btn )
809 [NSApp endSheet: o_specificTime_win];
810 [o_specificTime_win close];
812 else if( sender == o_specificTime_ok_btn )
814 input_thread_t * p_input = (input_thread_t *)vlc_object_find( VLCIntf, \
815 VLC_OBJECT_INPUT, FIND_ANYWHERE );
818 unsigned int timeInSec = 0;
819 NSString * fieldContent = [o_specificTime_enter_fld stringValue];
820 if( [[fieldContent componentsSeparatedByString: @":"] count] > 1 &&
821 [[fieldContent componentsSeparatedByString: @":"] count] <= 3 )
823 NSArray * ourTempArray = \
824 [fieldContent componentsSeparatedByString: @":"];
826 if( [[fieldContent componentsSeparatedByString: @":"] count] == 3 )
828 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 3600); //h
829 timeInSec += ([[ourTempArray objectAtIndex: 1] intValue] * 60); //m
830 timeInSec += [[ourTempArray objectAtIndex: 2] intValue]; //s
834 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 60); //m
835 timeInSec += [[ourTempArray objectAtIndex: 1] intValue]; //s
839 timeInSec = [fieldContent intValue];
841 input_Control( p_input, INPUT_SET_TIME, (int64_t)(timeInSec * 1000000));
842 vlc_object_release( p_input );
845 [NSApp endSheet: o_specificTime_win];
846 [o_specificTime_win close];
850 input_thread_t * p_input = (input_thread_t *)vlc_object_find( VLCIntf, \
851 VLC_OBJECT_INPUT, FIND_ANYWHERE );
854 /* we can obviously only do that if an input is available */
855 vlc_value_t pos, length;
856 var_Get( p_input, "time", &pos );
857 [o_specificTime_enter_fld setIntValue: (pos.i_time / 1000000)];
858 var_Get( p_input, "length", &length );
859 [o_specificTime_stepper setMaxValue: (length.i_time / 1000000)];
861 [NSApp beginSheet: o_specificTime_win modalForWindow: \
862 [NSApp mainWindow] modalDelegate: self didEndSelector: nil \
864 [o_specificTime_win makeKeyWindow];
865 vlc_object_release( p_input );
876 msg_Err( VLCIntf, "FSPanel is nil" );
883 @implementation VLCControls (NSMenuValidation)
885 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
887 BOOL bEnabled = TRUE;
889 intf_thread_t * p_intf = VLCIntf;
890 playlist_t * p_playlist = pl_Yield( p_intf );
891 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
893 if( [[o_mi title] isEqualToString: _NS("Faster")] ||
894 [[o_mi title] isEqualToString: _NS("Slower")] )
896 if( p_input != NULL )
898 bEnabled = p_input->b_can_pace_control;
905 else if( [[o_mi title] isEqualToString: _NS("Stop")] )
907 if( p_input == NULL )
911 [o_main setupMenus]; /* Make sure input menu is up to date */
913 else if( [[o_mi title] isEqualToString: _NS("Previous")] ||
914 [[o_mi title] isEqualToString: _NS("Next")] )
916 /** \todo fix i_size use */
918 bEnabled = p_playlist->items.i_size > 1;
921 else if( [[o_mi title] isEqualToString: _NS("Random")] )
924 var_Get( p_playlist, "random", &val );
925 i_state = val.b_bool ? NSOnState : NSOffState;
926 [o_mi setState: i_state];
928 else if( [[o_mi title] isEqualToString: _NS("Repeat One")] )
931 var_Get( p_playlist, "repeat", &val );
932 i_state = val.b_bool ? NSOnState : NSOffState;
933 [o_mi setState: i_state];
935 else if( [[o_mi title] isEqualToString: _NS("Repeat All")] )
938 var_Get( p_playlist, "loop", &val );
939 i_state = val.b_bool ? NSOnState : NSOffState;
940 [o_mi setState: i_state];
942 else if( [[o_mi title] isEqualToString: _NS("Step Forward")] ||
943 [[o_mi title] isEqualToString: _NS("Step Backward")] ||
944 [[o_mi title] isEqualToString: _NS("Jump To Time")])
946 if( p_input != NULL )
948 var_Get( p_input, "seekable", &val);
949 bEnabled = val.b_bool;
951 else bEnabled = FALSE;
953 else if( [[o_mi title] isEqualToString: _NS("Mute")] )
955 [o_mi setState: p_intf->p_sys->b_mute ? NSOnState : NSOffState];
956 [o_main setupMenus]; /* Make sure audio menu is up to date */
958 else if( [[o_mi title] isEqualToString: _NS("Half Size")] ||
959 [[o_mi title] isEqualToString: _NS("Normal Size")] ||
960 [[o_mi title] isEqualToString: _NS("Double Size")] ||
961 [[o_mi title] isEqualToString: _NS("Fit to Screen")] ||
962 [[o_mi title] isEqualToString: _NS("Snapshot")] ||
963 [[o_mi title] isEqualToString: _NS("Fullscreen")] ||
964 [[o_mi title] isEqualToString: _NS("Float on Top")] )
967 NSArray *o_windows = [NSApp orderedWindows];
968 NSEnumerator *o_enumerator = [o_windows objectEnumerator];
971 vout_thread_t *p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
975 if( [[o_mi title] isEqualToString: _NS("Float on Top")] )
977 var_Get( p_vout, "video-on-top", &val );
978 [o_mi setState: val.b_bool ? NSOnState : NSOffState];
981 while( (o_window = [o_enumerator nextObject]))
983 if( [[o_window className] isEqualToString: @"VLCVoutWindow"] ||
984 [[[VLCMain sharedInstance] getEmbeddedList]
985 windowContainsEmbedded: o_window])
992 vlc_object_release( (vlc_object_t *)p_vout );
994 if( [[o_mi title] isEqualToString: _NS("Fullscreen")] )
996 var_Get( p_playlist, "fullscreen", &val );
997 [o_mi setState: val.b_bool];
1000 [o_main setupMenus]; /* Make sure video menu is up to date */
1003 if( p_input ) vlc_object_release( p_input );
1004 vlc_object_release( p_playlist );
1011 /*****************************************************************************
1012 * VLCMenuExt implementation
1013 *****************************************************************************
1014 * Object connected to a playlistitem which remembers the data belonging to
1015 * the variable of the autogenerated menu
1016 *****************************************************************************/
1017 @implementation VLCMenuExt
1019 - (id)initWithVar: (const char *)_psz_name Object: (int)i_id
1020 Value: (vlc_value_t)val ofType: (int)_i_type
1022 self = [super init];
1026 psz_name = strdup( _psz_name );
1051 - (vlc_value_t)value
1064 /*****************************************************************************
1065 * VLCTimeField implementation
1066 *****************************************************************************
1067 * we need this to catch our click-event in the controller window
1068 *****************************************************************************/
1070 @implementation VLCTimeField
1071 - (void)mouseDown: (NSEvent *)ourEvent
1073 if( [ourEvent clickCount] > 1 )
1074 [[[VLCMain sharedInstance] getControls] goToSpecificTime: nil];