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 if( i_type & VLC_VAR_HASCHOICE )
706 NSMenu *o_menu = [o_mi submenu];
708 [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
709 var:psz_variable selector:pf_callback];
711 free( text.psz_string );
714 if( var_Get( p_object, psz_variable, &val ) < 0 )
719 VLCAutoGeneratedMenuContent *o_data;
720 switch( i_type & VLC_VAR_TYPE )
723 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
724 andValue: val ofType: i_type];
725 [o_mi setRepresentedObject: [o_data autorelease]];
729 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
730 andValue: val ofType: i_type];
731 [o_mi setRepresentedObject: [o_data autorelease]];
732 if( !( i_type & VLC_VAR_ISCOMMAND ) )
733 [o_mi setState: val.b_bool ? TRUE : FALSE ];
740 if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
741 free( text.psz_string );
745 - (void)setupVarMenu:(NSMenu *)o_menu
746 forMenuItem: (NSMenuItem *)o_parent
747 target:(vlc_object_t *)p_object
748 var:(const char *)psz_variable
749 selector:(SEL)pf_callback
751 vlc_value_t val, val_list, text_list;
752 int i_type, i, i_nb_items;
754 /* remove previous items */
755 i_nb_items = [o_menu numberOfItems];
756 for( i = 0; i < i_nb_items; i++ )
758 [o_menu removeItemAtIndex: 0];
761 /* Check the type of the object variable */
762 i_type = var_Type( p_object, psz_variable );
764 /* Make sure we want to display the variable */
765 if( i_type & VLC_VAR_HASCHOICE )
767 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
768 if( val.i_int == 0 ) return;
769 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
777 switch( i_type & VLC_VAR_TYPE )
781 case VLC_VAR_VARIABLE:
783 case VLC_VAR_INTEGER:
786 /* Variable doesn't exist or isn't handled */
790 if( var_Get( p_object, psz_variable, &val ) < 0 )
795 if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
796 &val_list, &text_list ) < 0 )
798 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
802 /* make (un)sensitive */
803 [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
806 if( [[o_parent title] isEqualToString: _NS("Aspect-ratio")] == YES )
808 NSMenuItem *o_lmi_tmp2;
809 o_lmi_tmp2 = [o_menu addItemWithTitle: _NS("Lock Aspect Ratio") action: @selector(lockVideosAspectRatio:) keyEquivalent: @""];
810 [o_lmi_tmp2 setTarget: self];
811 [o_lmi_tmp2 setEnabled: YES];
812 [o_lmi_tmp2 setState: b_lockAspectRatio];
813 [o_parent setEnabled: YES];
814 [o_menu addItem: [NSMenuItem separatorItem]];
817 /* special case for the subtitles items */
818 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
820 NSMenuItem * o_lmi_tmp;
821 o_lmi_tmp = [o_menu addItemWithTitle: _NS("Open File...") action: @selector(addSubtitleFile:) keyEquivalent: @""];
822 [o_lmi_tmp setTarget: self];
823 [o_lmi_tmp setEnabled: YES];
824 [o_parent setEnabled: YES];
825 [o_menu addItem: [NSMenuItem separatorItem]];
828 for( i = 0; i < val_list.p_list->i_count; i++ )
831 NSString *o_title = @"";
832 VLCAutoGeneratedMenuContent *o_data;
834 switch( i_type & VLC_VAR_TYPE )
838 o_title = [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string ?
839 text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
841 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
842 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
843 andValue: val_list.p_list->p_values[i] ofType: i_type];
844 [o_lmi setRepresentedObject: [o_data autorelease]];
845 [o_lmi setTarget: self];
847 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
848 [o_lmi setState: TRUE ];
852 case VLC_VAR_INTEGER:
854 o_title = text_list.p_list->p_values[i].psz_string ?
855 [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string] :
856 [NSString stringWithFormat: @"%d",
857 val_list.p_list->p_values[i].i_int];
859 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
860 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
861 andValue: val_list.p_list->p_values[i] ofType: i_type];
862 [o_lmi setRepresentedObject: [o_data autorelease]];
863 [o_lmi setTarget: self];
865 if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
866 [o_lmi setState: TRUE ];
874 /* special case for the subtitles sub-menu
875 * In case that we don't have any subs, we don't want a separator item at the end */
876 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
878 if( [o_menu numberOfItems] == 2 )
879 [o_menu removeItemAtIndex: 1];
882 /* clean up everything */
883 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
884 var_FreeList( &val_list, &text_list );
887 - (IBAction)toggleVar:(id)sender
889 NSMenuItem *o_mi = (NSMenuItem *)sender;
890 VLCAutoGeneratedMenuContent *o_data = [o_mi representedObject];
891 [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
892 toTarget: self withObject: o_data];
897 - (int)toggleVarThread: (id)data
899 vlc_object_t *p_object;
900 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
902 assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
903 VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
905 vlc_thread_set_priority( VLCIntf , VLC_THREAD_PRIORITY_LOW );
907 p_object = [menuContent vlcObject];
909 if( p_object != NULL )
911 var_Set( p_object, [menuContent name], [menuContent value] );
912 vlc_object_release( p_object );
920 - (IBAction)goToSpecificTime:(id)sender
922 if( sender == o_specificTime_cancel_btn )
924 [NSApp endSheet: o_specificTime_win];
925 [o_specificTime_win close];
927 else if( sender == o_specificTime_ok_btn )
929 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
932 unsigned int timeInSec = 0;
933 NSString * fieldContent = [o_specificTime_enter_fld stringValue];
934 if( [[fieldContent componentsSeparatedByString: @":"] count] > 1 &&
935 [[fieldContent componentsSeparatedByString: @":"] count] <= 3 )
937 NSArray * ourTempArray = \
938 [fieldContent componentsSeparatedByString: @":"];
940 if( [[fieldContent componentsSeparatedByString: @":"] count] == 3 )
942 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 3600); //h
943 timeInSec += ([[ourTempArray objectAtIndex: 1] intValue] * 60); //m
944 timeInSec += [[ourTempArray objectAtIndex: 2] intValue]; //s
948 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 60); //m
949 timeInSec += [[ourTempArray objectAtIndex: 1] intValue]; //s
953 timeInSec = [fieldContent intValue];
955 input_Control( p_input, INPUT_SET_TIME, (int64_t)(timeInSec * 1000000));
956 vlc_object_release( p_input );
959 [NSApp endSheet: o_specificTime_win];
960 [o_specificTime_win close];
964 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
967 /* we can obviously only do that if an input is available */
968 vlc_value_t pos, length;
969 var_Get( p_input, "time", &pos );
970 [o_specificTime_enter_fld setIntValue: (pos.i_time / 1000000)];
971 var_Get( p_input, "length", &length );
972 [o_specificTime_stepper setMaxValue: (length.i_time / 1000000)];
974 [NSApp beginSheet: o_specificTime_win modalForWindow: \
975 [NSApp mainWindow] modalDelegate: self didEndSelector: nil \
977 [o_specificTime_win makeKeyWindow];
978 vlc_object_release( p_input );
989 msg_Err( VLCIntf, "FSPanel is nil" );
996 @implementation VLCControls (NSMenuValidation)
998 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1000 BOOL bEnabled = TRUE;
1002 intf_thread_t * p_intf = VLCIntf;
1003 playlist_t * p_playlist = pl_Hold( p_intf );
1004 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1006 if( [[o_mi title] isEqualToString: _NS("Faster")] ||
1007 [[o_mi title] isEqualToString: _NS("Slower")] )
1009 if( p_input != NULL )
1011 bEnabled = var_GetBool( p_input, "can-rate" );
1018 else if( [[o_mi title] isEqualToString: _NS("Stop")] )
1020 if( p_input == NULL )
1024 [o_main setupMenus]; /* Make sure input menu is up to date */
1026 else if( [[o_mi title] isEqualToString: _NS("Previous")] ||
1027 [[o_mi title] isEqualToString: _NS("Next")] )
1030 bEnabled = playlist_CurrentSize( p_playlist ) > 1;
1033 else if( [[o_mi title] isEqualToString: _NS("Random")] )
1036 var_Get( p_playlist, "random", &val );
1037 i_state = val.b_bool ? NSOnState : NSOffState;
1038 [o_mi setState: i_state];
1040 else if( [[o_mi title] isEqualToString: _NS("Repeat One")] )
1043 var_Get( p_playlist, "repeat", &val );
1044 i_state = val.b_bool ? NSOnState : NSOffState;
1045 [o_mi setState: i_state];
1047 else if( [[o_mi title] isEqualToString: _NS("Repeat All")] )
1050 var_Get( p_playlist, "loop", &val );
1051 i_state = val.b_bool ? NSOnState : NSOffState;
1052 [o_mi setState: i_state];
1054 else if( [[o_mi title] isEqualToString: _NS("Step Forward")] ||
1055 [[o_mi title] isEqualToString: _NS("Step Backward")] ||
1056 [[o_mi title] isEqualToString: _NS("Jump To Time")])
1058 if( p_input != NULL )
1060 var_Get( p_input, "can-seek", &val);
1061 bEnabled = val.b_bool;
1063 else bEnabled = FALSE;
1065 else if( [[o_mi title] isEqualToString: _NS("Mute")] )
1067 [o_mi setState: p_intf->p_sys->b_mute ? NSOnState : NSOffState];
1068 [o_main setupMenus]; /* Make sure audio menu is up to date */
1070 else if( [[o_mi title] isEqualToString: _NS("Half Size")] ||
1071 [[o_mi title] isEqualToString: _NS("Normal Size")] ||
1072 [[o_mi title] isEqualToString: _NS("Double Size")] ||
1073 [[o_mi title] isEqualToString: _NS("Fit to Screen")] ||
1074 [[o_mi title] isEqualToString: _NS("Snapshot")] ||
1075 [[o_mi title] isEqualToString: _NS("Fullscreen")] ||
1076 [[o_mi title] isEqualToString: _NS("Float on Top")] )
1079 NSArray *o_windows = [NSApp orderedWindows];
1080 NSEnumerator *o_enumerator = [o_windows objectEnumerator];
1083 if( p_input != NULL )
1085 vout_thread_t *p_vout = input_GetVout( p_input );
1086 if( p_vout != NULL )
1088 if( [[o_mi title] isEqualToString: _NS("Float on Top")] )
1090 var_Get( p_vout, "video-on-top", &val );
1091 [o_mi setState: val.b_bool ? NSOnState : NSOffState];
1094 while( (o_window = [o_enumerator nextObject]))
1096 if( [[o_window className] isEqualToString: @"VLCVoutWindow"] ||
1097 [[[VLCMain sharedInstance] embeddedList]
1098 windowContainsEmbedded: o_window])
1105 vlc_object_release( (vlc_object_t *)p_vout );
1107 vlc_object_release( p_input );
1109 if( [[o_mi title] isEqualToString: _NS("Fullscreen")] )
1111 var_Get( p_playlist, "fullscreen", &val );
1112 [o_mi setState: val.b_bool];
1115 [o_main setupMenus]; /* Make sure video menu is up to date */
1118 /* Special case for telx menu */
1119 if( [[o_mi title] isEqualToString: _NS("Normal Size")] )
1121 NSMenuItem *item = [[o_mi menu] itemWithTitle:_NS("Teletext")];
1122 bool b_telx = p_input && var_GetInteger( p_input, "teletext-es" ) >= 0;
1124 [[item submenu] setAutoenablesItems:NO];
1125 for( int k=0; k < [[item submenu] numberOfItems]; k++ )
1127 [[[item submenu] itemAtIndex:k] setEnabled: b_telx];
1131 if( p_input ) vlc_object_release( p_input );
1132 pl_Release( p_intf );
1139 /*****************************************************************************
1140 * VLCAutoGeneratedMenuContent implementation
1141 *****************************************************************************
1142 * Object connected to a playlistitem which remembers the data belonging to
1143 * the variable of the autogenerated menu
1144 *****************************************************************************/
1145 @implementation VLCAutoGeneratedMenuContent
1147 -(id) initWithVariableName:(const char *)name ofObject:(vlc_object_t *)object
1148 andValue:(vlc_value_t)val ofType:(int)type
1150 self = [super init];
1154 _vlc_object = vlc_object_hold( object );
1155 psz_name = strdup( name );
1158 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1159 value.psz_string = strdup( val.psz_string );
1167 vlc_object_release( _vlc_object );
1168 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1169 free( value.psz_string );
1174 - (const char *)name
1179 - (vlc_value_t)value
1184 - (vlc_object_t *)vlcObject
1186 return vlc_object_hold( _vlc_object );
1198 /*****************************************************************************
1199 * VLCTimeField implementation
1200 *****************************************************************************
1201 * we need this to catch our click-event in the controller window
1202 *****************************************************************************/
1204 @implementation VLCTimeField
1205 - (void)mouseDown: (NSEvent *)ourEvent
1207 if( [ourEvent clickCount] > 1 )
1208 [[[VLCMain sharedInstance] controls] goToSpecificTime: nil];
1210 [[VLCMain sharedInstance] timeFieldWasClicked: self];