1 /*****************************************************************************
2 * controls.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2009 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 Paul 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 */
44 /*****************************************************************************
45 * VLCControls implementation
46 *****************************************************************************/
47 @implementation VLCControls
52 o_fs_panel = [[VLCFSPanel alloc] init];
53 b_lockAspectRatio = YES;
59 [o_specificTime_mi setTitle: _NS("Jump To Time")];
60 [o_specificTime_cancel_btn setTitle: _NS("Cancel")];
61 [o_specificTime_ok_btn setTitle: _NS("OK")];
62 [o_specificTime_sec_lbl setStringValue: _NS("sec.")];
63 [o_specificTime_goTo_lbl setStringValue: _NS("Jump to time")];
65 o_repeat_off = [NSImage imageNamed:@"repeat_embedded"];
67 [self controlTintChanged];
69 [[NSNotificationCenter defaultCenter] addObserver: self
70 selector: @selector( controlTintChanged )
71 name: NSControlTintDidChangeNotification
75 - (void)controlTintChanged
78 if( [o_btn_repeat image] == o_repeat_single )
80 else if( [o_btn_repeat image] == o_repeat_all )
83 if( [NSColor currentControlTint] == NSGraphiteControlTint )
85 o_repeat_single = [NSImage imageNamed:@"repeat_single_embedded_graphite"];
86 o_repeat_all = [NSImage imageNamed:@"repeat_embedded_graphite"];
88 [o_btn_shuffle setAlternateImage: [NSImage imageNamed: @"shuffle_embedded_graphite"]];
89 [o_btn_addNode setAlternateImage: [NSImage imageNamed: @"add_embedded_graphite"]];
93 o_repeat_single = [NSImage imageNamed:@"repeat_single_embedded_blue"];
94 o_repeat_all = [NSImage imageNamed:@"repeat_embedded_blue"];
96 [o_btn_shuffle setAlternateImage: [NSImage imageNamed: @"shuffle_embedded_blue"]];
97 [o_btn_addNode setAlternateImage: [NSImage imageNamed: @"add_embedded_blue"]];
100 /* update the repeat button, but keep its state */
103 else if( i_repeat == 2 )
111 [[NSNotificationCenter defaultCenter] removeObserver: self];
113 [o_repeat_single release];
114 [o_repeat_all release];
115 [o_repeat_off release];
120 - (IBAction)play:(id)sender
122 intf_thread_t * p_intf = VLCIntf;
123 playlist_t * p_playlist = pl_Hold( p_intf );
127 empty = playlist_IsEmpty( p_playlist );
130 pl_Release( p_intf );
133 [o_main intfOpenFileGeneric: (id)sender];
135 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_PLAY_PAUSE );
142 id o_embeddedViewList = [[VLCMain sharedInstance] embeddedList];
143 NSEnumerator *o_enumerator = [[NSApp orderedWindows] objectEnumerator];
144 while( !o_voutView && ( o_window = [o_enumerator nextObject] ) )
146 /* We have an embedded vout */
147 if( [o_embeddedViewList windowContainsEmbedded: o_window] )
149 o_voutView = [o_embeddedViewList viewForWindow: o_window];
151 /* We have a detached vout */
152 else if( [[o_window className] isEqualToString: @"VLCVoutWindow"] )
154 o_voutView = [o_window voutView];
157 return [[o_voutView retain] autorelease];
160 - (BOOL)aspectRatioIsLocked
162 return b_lockAspectRatio;
165 - (IBAction)stop:(id)sender
167 intf_thread_t * p_intf = VLCIntf;
168 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_STOP );
169 /* Close the window directly, because we do know that there
170 * won't be anymore video. It's currently waiting a bit. */
171 [[[self voutView] window] orderOut:self];
174 - (IBAction)faster:(id)sender
176 intf_thread_t * p_intf = VLCIntf;
177 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_FASTER );
180 - (IBAction)slower:(id)sender
182 intf_thread_t * p_intf = VLCIntf;
183 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_SLOWER );
186 - (IBAction)prev:(id)sender
188 intf_thread_t * p_intf = VLCIntf;
189 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_PREV );
192 - (IBAction)next:(id)sender
194 intf_thread_t * p_intf = VLCIntf;
195 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_NEXT );
198 - (IBAction)random:(id)sender
201 intf_thread_t * p_intf = VLCIntf;
202 playlist_t * p_playlist = pl_Hold( p_intf );
204 var_Get( p_playlist, "random", &val );
205 val.b_bool = !val.b_bool;
206 var_Set( p_playlist, "random", val );
209 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Random On" ) );
210 config_PutInt( p_playlist, "random", 1 );
214 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Random Off" ) );
215 config_PutInt( p_playlist, "random", 0 );
218 p_intf->p_sys->b_playmode_update = true;
219 p_intf->p_sys->b_intf_update = true;
220 pl_Release( p_intf );
223 /* three little ugly helpers */
226 [o_btn_repeat setImage: o_repeat_single];
227 [o_btn_repeat setAlternateImage: o_repeat_all];
228 [o_btn_repeat_embed setImage: [NSImage imageNamed:@"sidebarRepeatOneOn"]];
232 [o_btn_repeat setImage: o_repeat_all];
233 [o_btn_repeat setAlternateImage: o_repeat_off];
234 [o_btn_repeat_embed setImage: [NSImage imageNamed:@"sidebarRepeatOn"]];
238 [o_btn_repeat setImage: o_repeat_off];
239 [o_btn_repeat setAlternateImage: o_repeat_single];
240 [o_btn_repeat_embed setImage: [NSImage imageNamed:@"sidebarRepeat"]];
245 playlist_t *p_playlist = pl_Hold( VLCIntf );
246 var_Get( p_playlist, "random", &val );
247 [o_btn_shuffle setState: val.b_bool];
249 [o_btn_shuffle_embed setImage: [NSImage imageNamed:@"sidebarShuffleOn"]];
251 [o_btn_shuffle_embed setImage: [NSImage imageNamed:@"sidebarShuffle"]];
252 pl_Release( VLCIntf );
255 - (IBAction)repeatButtonAction:(id)sender
257 vlc_value_t looping,repeating;
258 intf_thread_t * p_intf = VLCIntf;
259 playlist_t * p_playlist = pl_Hold( p_intf );
261 var_Get( p_playlist, "repeat", &repeating );
262 var_Get( p_playlist, "loop", &looping );
264 if( !repeating.b_bool && !looping.b_bool )
266 /* was: no repeating at all, switching to Repeat One */
268 /* set our button's look */
271 /* prepare core communication */
272 repeating.b_bool = true;
273 looping.b_bool = false;
274 config_PutInt( p_playlist, "repeat", 1 );
275 config_PutInt( p_playlist, "loop", 0 );
277 /* show the change */
278 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
280 else if( repeating.b_bool && !looping.b_bool )
282 /* was: Repeat One, switching to Repeat All */
284 /* set our button's look */
287 /* prepare core communication */
288 repeating.b_bool = false;
289 looping.b_bool = true;
290 config_PutInt( p_playlist, "repeat", 0 );
291 config_PutInt( p_playlist, "loop", 1 );
293 /* show the change */
294 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
298 /* was: Repeat All or bug in VLC, switching to Repeat Off */
300 /* set our button's look */
303 /* prepare core communication */
304 repeating.b_bool = false;
305 looping.b_bool = false;
306 config_PutInt( p_playlist, "repeat", 0 );
307 config_PutInt( p_playlist, "loop", 0 );
309 /* show the change */
310 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
313 /* communicate with core and the main intf loop */
314 var_Set( p_playlist, "repeat", repeating );
315 var_Set( p_playlist, "loop", looping );
316 p_intf->p_sys->b_playmode_update = true;
317 p_intf->p_sys->b_intf_update = true;
319 pl_Release( p_intf );
323 - (IBAction)repeat:(id)sender
326 intf_thread_t * p_intf = VLCIntf;
327 playlist_t * p_playlist = pl_Hold( p_intf );
329 var_Get( p_playlist, "repeat", &val );
332 var_Set( p_playlist, "loop", val );
334 val.b_bool = !val.b_bool;
335 var_Set( p_playlist, "repeat", val );
338 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
339 config_PutInt( p_playlist, "repeat", 1 );
343 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
344 config_PutInt( p_playlist, "repeat", 0 );
347 p_intf->p_sys->b_playmode_update = true;
348 p_intf->p_sys->b_intf_update = true;
349 pl_Release( p_intf );
352 - (IBAction)loop:(id)sender
355 intf_thread_t * p_intf = VLCIntf;
356 playlist_t * p_playlist = pl_Hold( p_intf );
358 var_Get( p_playlist, "loop", &val );
361 var_Set( p_playlist, "repeat", val );
363 val.b_bool = !val.b_bool;
364 var_Set( p_playlist, "loop", val );
367 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
368 config_PutInt( p_playlist, "loop", 1 );
372 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
373 config_PutInt( p_playlist, "loop", 0 );
376 p_intf->p_sys->b_playmode_update = true;
377 p_intf->p_sys->b_intf_update = true;
378 pl_Release( p_intf );
381 - (IBAction)forward:(id)sender
383 intf_thread_t * p_intf = VLCIntf;
384 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_SHORT );
387 - (IBAction)backward:(id)sender
390 intf_thread_t * p_intf = VLCIntf;
391 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_SHORT );
395 - (IBAction)volumeUp:(id)sender
397 intf_thread_t * p_intf = VLCIntf;
398 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_UP );
399 /* Manage volume status */
400 [o_main manageVolumeSlider];
403 - (IBAction)volumeDown:(id)sender
405 intf_thread_t * p_intf = VLCIntf;
406 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_DOWN );
407 /* Manage volume status */
408 [o_main manageVolumeSlider];
411 - (IBAction)mute:(id)sender
413 intf_thread_t * p_intf = VLCIntf;
414 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_MUTE );
415 /* Manage volume status */
416 [o_main manageVolumeSlider];
419 - (IBAction)volumeSliderUpdated:(id)sender
421 intf_thread_t * p_intf = VLCIntf;
422 audio_volume_t i_volume = (audio_volume_t)[sender intValue];
423 int i_volume_step = 0;
424 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
425 aout_VolumeSet( p_intf, i_volume * i_volume_step );
426 /* Manage volume status */
427 [o_main manageVolumeSlider];
430 - (IBAction)showPosition: (id)sender
432 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
433 if( p_input != NULL )
435 vout_thread_t *p_vout = input_GetVout( p_input );
438 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_POSITION );
439 vlc_object_release( (vlc_object_t *)p_vout );
441 vlc_object_release( p_input );
445 - (IBAction)toogleFullscreen:(id)sender {
446 NSMenuItem *o_mi = [[NSMenuItem alloc] initWithTitle: _NS("Fullscreen") action: nil keyEquivalent:@""];
447 [self windowAction: [o_mi autorelease]];
450 - (BOOL) isFullscreen {
451 id o_vout_view = [self voutView];
454 return [o_vout_view isFullscreen];
459 - (IBAction)windowAction:(id)sender
461 NSString *o_title = [sender title];
462 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
464 if( p_input != NULL )
466 vout_thread_t *p_vout = input_GetVout( p_input );
469 id o_vout_view = [self voutView];
472 if( [o_title isEqualToString: _NS("Half Size") ] )
473 [o_vout_view scaleWindowWithFactor: 0.5 animate: YES];
474 else if( [o_title isEqualToString: _NS("Normal Size") ] )
475 [o_vout_view scaleWindowWithFactor: 1.0 animate: YES];
476 else if( [o_title isEqualToString: _NS("Double Size") ] )
477 [o_vout_view scaleWindowWithFactor: 2.0 animate: YES];
478 else if( [o_title isEqualToString: _NS("Float on Top") ] )
479 [o_vout_view toggleFloatOnTop];
480 else if( [o_title isEqualToString: _NS("Fit to Screen") ] )
482 id o_window = [o_vout_view voutWindow];
483 if( ![o_window isZoomed] )
484 [o_window performZoom:self];
486 else if( [o_title isEqualToString: _NS("Snapshot") ] )
488 [o_vout_view snapshot];
492 /* Fullscreen state for next time will be saved here too */
493 [o_vout_view toggleFullscreen];
496 vlc_object_release( (vlc_object_t *)p_vout );
500 playlist_t * p_playlist = pl_Hold( VLCIntf );
502 if( [o_title isEqualToString: _NS("Fullscreen")] ||
503 [sender isKindOfClass:[NSButton class]] )
506 var_Get( p_playlist, "fullscreen", &val );
507 var_Set( p_playlist, "fullscreen", (vlc_value_t)!val.b_bool );
510 pl_Release( VLCIntf );
512 vlc_object_release( p_input );
516 - (IBAction)telxTransparent:(id)sender
518 intf_thread_t * p_intf = VLCIntf;
520 p_vbi = (vlc_object_t *) vlc_object_find_name( p_intf,
521 "zvbi", FIND_ANYWHERE );
524 var_SetBool( p_vbi, "vbi-opaque", [sender state] );
525 [sender setState: ![sender state]];
526 vlc_object_release( p_vbi );
530 - (IBAction)telxNavLink:(id)sender
532 intf_thread_t * p_intf = VLCIntf;
536 if( [[sender title] isEqualToString: _NS("Index")] )
538 else if( [[sender title] isEqualToString: _NS("Red")] )
540 else if( [[sender title] isEqualToString: _NS("Green")] )
542 else if( [[sender title] isEqualToString: _NS("Yellow")] )
544 else if( [[sender title] isEqualToString: _NS("Blue")] )
546 if( i_page == 0 ) return;
548 p_vbi = (vlc_object_t *) vlc_object_find_name( p_intf,
549 "zvbi", FIND_ANYWHERE );
552 var_SetInteger( p_vbi, "vbi-page", i_page );
553 vlc_object_release( p_vbi );
557 - (IBAction)lockVideosAspectRatio:(id)sender
559 if( [sender state] == NSOffState )
560 [sender setState: NSOnState];
562 [sender setState: NSOffState];
564 b_lockAspectRatio = !b_lockAspectRatio;
567 - (IBAction)addSubtitleFile:(id)sender
569 NSInteger i_returnValue = 0;
570 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
571 if( !p_input ) return;
573 input_item_t *p_item = input_GetItem( p_input );
574 if( !p_item ) return;
576 char *path = input_item_GetURI( p_item );
577 if( !path ) path = strdup( "" );
579 NSOpenPanel * openPanel = [NSOpenPanel openPanel];
580 [openPanel setCanChooseFiles: YES];
581 [openPanel setCanChooseDirectories: NO];
582 [openPanel setAllowsMultipleSelection: YES];
583 i_returnValue = [openPanel runModalForDirectory: [NSString stringWithUTF8String: path] file: nil types: [NSArray arrayWithObjects: @"cdg",@"@idx",@"srt",@"sub",@"utf",@"ass",@"ssa",@"aqt",@"jss",@"psb",@"rt",@"smi", nil]];
586 if( i_returnValue == NSOKButton )
589 if( !p_input ) return;
591 c = [[openPanel filenames] count];
592 NSLog( @"count: %i", c );
593 for (int i = 0; [[openPanel filenames] count] > i ; i++)
595 msg_Dbg( VLCIntf, "loading subs from %s", [[[openPanel filenames] objectAtIndex: i] UTF8String] );
596 if( input_AddSubtitle( p_input, [[[openPanel filenames] objectAtIndex: i] UTF8String], TRUE ) )
597 msg_Warn( VLCIntf, "unable to load subtitles from '%s'",
598 [[[openPanel filenames] objectAtIndex: i] UTF8String] );
603 - (void)scrollWheel:(NSEvent *)theEvent
605 intf_thread_t * p_intf = VLCIntf;
606 float f_yabsvalue = [theEvent deltaY] > 0.0f ? [theEvent deltaY] : -[theEvent deltaY];
607 float f_xabsvalue = [theEvent deltaX] > 0.0f ? [theEvent deltaX] : -[theEvent deltaX];
608 int i, i_yvlckey, i_xvlckey;
610 if ([theEvent deltaY] < 0.0f)
611 i_yvlckey = KEY_MOUSEWHEELDOWN;
613 i_yvlckey = KEY_MOUSEWHEELUP;
615 if ([theEvent deltaX] < 0.0f)
616 i_xvlckey = KEY_MOUSEWHEELRIGHT;
618 i_xvlckey = KEY_MOUSEWHEELLEFT;
620 /* Send multiple key event, depending on the intensity of the event */
621 for (i = 0; i < (int)(f_yabsvalue/4.+1.) && f_yabsvalue > 0.05 ; i++)
622 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_yvlckey );
624 /* Prioritize Y event (sound volume) over X event */
625 if (f_yabsvalue < 0.05)
627 for (i = 0; i < (int)(f_xabsvalue/6.+1.) && f_xabsvalue > 0.05; i++)
628 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_xvlckey );
632 - (BOOL)keyEvent:(NSEvent *)o_event
634 BOOL eventHandled = NO;
635 unichar key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
639 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
640 if( p_input != NULL )
642 vout_thread_t *p_vout = input_GetVout( p_input );
647 if( key == (unichar) 0x1b )
649 id o_vout_view = [self voutView];
650 if( o_vout_view && [o_vout_view isFullscreen] )
652 [o_vout_view toggleFullscreen];
656 else if( key == ' ' )
661 vlc_object_release( (vlc_object_t *)p_vout );
663 vlc_object_release( p_input );
669 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
670 target:(vlc_object_t *)p_object
671 var:(const char *)psz_variable
672 selector:(SEL)pf_callback
674 vlc_value_t val, text;
675 int i_type = var_Type( p_object, psz_variable );
677 switch( i_type & VLC_VAR_TYPE )
681 case VLC_VAR_VARIABLE:
683 case VLC_VAR_INTEGER:
686 /* Variable doesn't exist or isn't handled */
690 /* Make sure we want to display the variable */
691 if( i_type & VLC_VAR_HASCHOICE )
693 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
694 if( val.i_int == 0 ) return;
695 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
699 /* Get the descriptive name of the variable */
700 var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
701 [o_mi setTitle: [[VLCMain sharedInstance] localizedString: text.psz_string ?
702 text.psz_string : psz_variable ]];
704 var_Get( p_object, psz_variable, &val );
705 if( i_type & VLC_VAR_HASCHOICE )
707 NSMenu *o_menu = [o_mi submenu];
709 [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
710 var:psz_variable selector:pf_callback];
712 free( text.psz_string );
716 VLCAutoGeneratedMenuContent *o_data;
717 switch( i_type & VLC_VAR_TYPE )
720 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
721 andValue: val ofType: i_type];
722 [o_mi setRepresentedObject: [o_data autorelease]];
726 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
727 andValue: val ofType: i_type];
728 [o_mi setRepresentedObject: [o_data autorelease]];
729 if( !( i_type & VLC_VAR_ISCOMMAND ) )
730 [o_mi setState: val.b_bool ? TRUE : FALSE ];
734 free( text.psz_string );
738 if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
739 free( text.psz_string );
743 - (void)setupVarMenu:(NSMenu *)o_menu
744 forMenuItem: (NSMenuItem *)o_parent
745 target:(vlc_object_t *)p_object
746 var:(const char *)psz_variable
747 selector:(SEL)pf_callback
749 vlc_value_t val, val_list, text_list;
750 int i_type, i, i_nb_items;
752 /* remove previous items */
753 i_nb_items = [o_menu numberOfItems];
754 for( i = 0; i < i_nb_items; i++ )
756 [o_menu removeItemAtIndex: 0];
759 /* Check the type of the object variable */
760 i_type = var_Type( p_object, psz_variable );
762 /* Make sure we want to display the variable */
763 if( i_type & VLC_VAR_HASCHOICE )
765 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
766 if( val.i_int == 0 ) return;
767 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
775 switch( i_type & VLC_VAR_TYPE )
779 case VLC_VAR_VARIABLE:
781 case VLC_VAR_INTEGER:
784 /* Variable doesn't exist or isn't handled */
788 if( var_Get( p_object, psz_variable, &val ) < 0 )
793 if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
794 &val_list, &text_list ) < 0 )
796 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
800 /* make (un)sensitive */
801 [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
804 if( [[o_parent title] isEqualToString: _NS("Aspect-ratio")] == YES )
806 NSMenuItem *o_lmi_tmp2;
807 o_lmi_tmp2 = [o_menu addItemWithTitle: _NS("Lock Aspect Ratio") action: @selector(lockVideosAspectRatio:) keyEquivalent: @""];
808 [o_lmi_tmp2 setTarget: self];
809 [o_lmi_tmp2 setEnabled: YES];
810 [o_lmi_tmp2 setState: b_lockAspectRatio];
811 [o_parent setEnabled: YES];
812 [o_menu addItem: [NSMenuItem separatorItem]];
815 /* special case for the subtitles items */
816 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
818 NSMenuItem * o_lmi_tmp;
819 o_lmi_tmp = [o_menu addItemWithTitle: _NS("Open File...") action: @selector(addSubtitleFile:) keyEquivalent: @""];
820 [o_lmi_tmp setTarget: self];
821 [o_lmi_tmp setEnabled: YES];
822 [o_parent setEnabled: YES];
823 [o_menu addItem: [NSMenuItem separatorItem]];
826 for( i = 0; i < val_list.p_list->i_count; i++ )
828 vlc_value_t another_val;
830 NSString *o_title = @"";
831 VLCAutoGeneratedMenuContent *o_data;
833 switch( i_type & VLC_VAR_TYPE )
836 another_val.psz_string =
837 strdup(val_list.p_list->p_values[i].psz_string);
839 o_title = [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string ?
840 text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
842 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
843 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
844 andValue: another_val ofType: i_type];
845 [o_lmi setRepresentedObject: [o_data autorelease]];
846 [o_lmi setTarget: self];
848 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
849 [o_lmi setState: TRUE ];
853 case VLC_VAR_INTEGER:
855 o_title = text_list.p_list->p_values[i].psz_string ?
856 [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string] :
857 [NSString stringWithFormat: @"%d",
858 val_list.p_list->p_values[i].i_int];
860 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
861 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
862 andValue: val_list.p_list->p_values[i] ofType: i_type];
863 [o_lmi setRepresentedObject: [o_data autorelease]];
864 [o_lmi setTarget: self];
866 if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
867 [o_lmi setState: TRUE ];
875 /* special case for the subtitles sub-menu
876 * In case that we don't have any subs, we don't want a separator item at the end */
877 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
879 if( [o_menu numberOfItems] == 2 )
880 [o_menu removeItemAtIndex: 1];
883 /* clean up everything */
884 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
885 var_FreeList( &val_list, &text_list );
888 - (IBAction)toggleVar:(id)sender
890 NSMenuItem *o_mi = (NSMenuItem *)sender;
891 VLCAutoGeneratedMenuContent *o_data = [o_mi representedObject];
892 [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
893 toTarget: self withObject: o_data];
898 - (int)toggleVarThread: (id)data
900 vlc_object_t *p_object;
901 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
903 assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
904 VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
906 vlc_thread_set_priority( VLCIntf , VLC_THREAD_PRIORITY_LOW );
908 p_object = [menuContent vlcObject];
910 if( p_object != NULL )
912 var_Set( p_object, [menuContent name], [menuContent value] );
913 vlc_object_release( p_object );
921 - (IBAction)goToSpecificTime:(id)sender
923 if( sender == o_specificTime_cancel_btn )
925 [NSApp endSheet: o_specificTime_win];
926 [o_specificTime_win close];
928 else if( sender == o_specificTime_ok_btn )
930 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
933 unsigned int timeInSec = 0;
934 NSString * fieldContent = [o_specificTime_enter_fld stringValue];
935 if( [[fieldContent componentsSeparatedByString: @":"] count] > 1 &&
936 [[fieldContent componentsSeparatedByString: @":"] count] <= 3 )
938 NSArray * ourTempArray = \
939 [fieldContent componentsSeparatedByString: @":"];
941 if( [[fieldContent componentsSeparatedByString: @":"] count] == 3 )
943 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 3600); //h
944 timeInSec += ([[ourTempArray objectAtIndex: 1] intValue] * 60); //m
945 timeInSec += [[ourTempArray objectAtIndex: 2] intValue]; //s
949 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 60); //m
950 timeInSec += [[ourTempArray objectAtIndex: 1] intValue]; //s
954 timeInSec = [fieldContent intValue];
956 input_Control( p_input, INPUT_SET_TIME, (int64_t)(timeInSec * 1000000));
957 vlc_object_release( p_input );
960 [NSApp endSheet: o_specificTime_win];
961 [o_specificTime_win close];
965 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
968 /* we can obviously only do that if an input is available */
969 vlc_value_t pos, length;
970 var_Get( p_input, "time", &pos );
971 [o_specificTime_enter_fld setIntValue: (pos.i_time / 1000000)];
972 var_Get( p_input, "length", &length );
973 [o_specificTime_stepper setMaxValue: (length.i_time / 1000000)];
975 [NSApp beginSheet: o_specificTime_win modalForWindow: \
976 [NSApp mainWindow] modalDelegate: self didEndSelector: nil \
978 [o_specificTime_win makeKeyWindow];
979 vlc_object_release( p_input );
990 msg_Err( VLCIntf, "FSPanel is nil" );
997 @implementation VLCControls (NSMenuValidation)
999 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1001 BOOL bEnabled = TRUE;
1003 intf_thread_t * p_intf = VLCIntf;
1004 playlist_t * p_playlist = pl_Hold( p_intf );
1005 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1007 if( [[o_mi title] isEqualToString: _NS("Faster")] ||
1008 [[o_mi title] isEqualToString: _NS("Slower")] )
1010 if( p_input != NULL )
1012 bEnabled = var_GetBool( p_input, "can-rate" );
1019 else if( [[o_mi title] isEqualToString: _NS("Stop")] )
1021 if( p_input == NULL )
1025 [o_main setupMenus]; /* Make sure input menu is up to date */
1027 else if( [[o_mi title] isEqualToString: _NS("Previous")] ||
1028 [[o_mi title] isEqualToString: _NS("Next")] )
1031 bEnabled = playlist_CurrentSize( p_playlist ) > 1;
1034 else if( [[o_mi title] isEqualToString: _NS("Random")] )
1037 var_Get( p_playlist, "random", &val );
1038 i_state = val.b_bool ? NSOnState : NSOffState;
1039 [o_mi setState: i_state];
1041 else if( [[o_mi title] isEqualToString: _NS("Repeat One")] )
1044 var_Get( p_playlist, "repeat", &val );
1045 i_state = val.b_bool ? NSOnState : NSOffState;
1046 [o_mi setState: i_state];
1048 else if( [[o_mi title] isEqualToString: _NS("Repeat All")] )
1051 var_Get( p_playlist, "loop", &val );
1052 i_state = val.b_bool ? NSOnState : NSOffState;
1053 [o_mi setState: i_state];
1055 else if( [[o_mi title] isEqualToString: _NS("Step Forward")] ||
1056 [[o_mi title] isEqualToString: _NS("Step Backward")] ||
1057 [[o_mi title] isEqualToString: _NS("Jump To Time")])
1059 if( p_input != NULL )
1061 var_Get( p_input, "can-seek", &val);
1062 bEnabled = val.b_bool;
1064 else bEnabled = FALSE;
1066 else if( [[o_mi title] isEqualToString: _NS("Mute")] )
1068 [o_mi setState: p_intf->p_sys->b_mute ? NSOnState : NSOffState];
1069 [o_main setupMenus]; /* Make sure audio menu is up to date */
1071 else if( [[o_mi title] isEqualToString: _NS("Half Size")] ||
1072 [[o_mi title] isEqualToString: _NS("Normal Size")] ||
1073 [[o_mi title] isEqualToString: _NS("Double Size")] ||
1074 [[o_mi title] isEqualToString: _NS("Fit to Screen")] ||
1075 [[o_mi title] isEqualToString: _NS("Snapshot")] ||
1076 [[o_mi title] isEqualToString: _NS("Fullscreen")] ||
1077 [[o_mi title] isEqualToString: _NS("Float on Top")] )
1080 NSArray *o_windows = [NSApp orderedWindows];
1081 NSEnumerator *o_enumerator = [o_windows objectEnumerator];
1084 if( p_input != NULL )
1086 vout_thread_t *p_vout = input_GetVout( p_input );
1087 if( p_vout != NULL )
1089 if( [[o_mi title] isEqualToString: _NS("Float on Top")] )
1091 var_Get( p_vout, "video-on-top", &val );
1092 [o_mi setState: val.b_bool ? NSOnState : NSOffState];
1095 while( (o_window = [o_enumerator nextObject]))
1097 if( [[o_window className] isEqualToString: @"VLCVoutWindow"] ||
1098 [[[VLCMain sharedInstance] embeddedList]
1099 windowContainsEmbedded: o_window])
1106 vlc_object_release( (vlc_object_t *)p_vout );
1108 vlc_object_release( p_input );
1110 if( [[o_mi title] isEqualToString: _NS("Fullscreen")] )
1112 var_Get( p_playlist, "fullscreen", &val );
1113 [o_mi setState: val.b_bool];
1116 [o_main setupMenus]; /* Make sure video menu is up to date */
1119 /* Special case for telx menu */
1120 if( [[o_mi title] isEqualToString: _NS("Normal Size")] )
1122 NSMenuItem *item = [[o_mi menu] itemWithTitle:_NS("Teletext")];
1123 bool b_telx = p_input && var_GetInteger( p_input, "teletext-es" ) >= 0;
1125 [[item submenu] setAutoenablesItems:NO];
1126 for( int k=0; k < [[item submenu] numberOfItems]; k++ )
1128 [[[item submenu] itemAtIndex:k] setEnabled: b_telx];
1132 if( p_input ) vlc_object_release( p_input );
1133 pl_Release( p_intf );
1140 /*****************************************************************************
1141 * VLCAutoGeneratedMenuContent implementation
1142 *****************************************************************************
1143 * Object connected to a playlistitem which remembers the data belonging to
1144 * the variable of the autogenerated menu
1145 *****************************************************************************/
1146 @implementation VLCAutoGeneratedMenuContent
1148 -(id) initWithVariableName:(const char *)name ofObject:(vlc_object_t *)object
1149 andValue:(vlc_value_t)val ofType:(int)type
1151 self = [super init];
1155 psz_name = strdup( name );
1156 _vlc_object = vlc_object_hold( object );
1166 vlc_object_release( _vlc_object );
1171 - (const char *)name
1176 - (vlc_value_t)value
1181 - (vlc_object_t *)vlcObject
1183 return vlc_object_hold( _vlc_object );
1195 /*****************************************************************************
1196 * VLCTimeField implementation
1197 *****************************************************************************
1198 * we need this to catch our click-event in the controller window
1199 *****************************************************************************/
1201 @implementation VLCTimeField
1202 - (void)mouseDown: (NSEvent *)ourEvent
1204 if( [ourEvent clickCount] > 1 )
1205 [[[VLCMain sharedInstance] controls] goToSpecificTime: nil];
1207 [[VLCMain sharedInstance] timeFieldWasClicked: self];