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_fs_panel release];
114 [o_repeat_single release];
115 [o_repeat_all release];
116 [o_repeat_off release];
121 - (IBAction)play:(id)sender
123 intf_thread_t * p_intf = VLCIntf;
124 playlist_t * p_playlist = pl_Hold( p_intf );
128 empty = playlist_IsEmpty( p_playlist );
131 pl_Release( p_intf );
134 [o_main intfOpenFileGeneric: (id)sender];
136 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_PLAY_PAUSE );
143 id o_embeddedViewList = [[VLCMain sharedInstance] embeddedList];
144 NSEnumerator *o_enumerator = [[NSApp orderedWindows] objectEnumerator];
145 while( !o_voutView && ( o_window = [o_enumerator nextObject] ) )
147 /* We have an embedded vout */
148 if( [o_embeddedViewList windowContainsEmbedded: o_window] )
150 o_voutView = [o_embeddedViewList viewForWindow: o_window];
152 /* We have a detached vout */
153 else if( [[o_window className] isEqualToString: @"VLCVoutWindow"] )
155 o_voutView = [o_window voutView];
158 return [[o_voutView retain] autorelease];
161 - (BOOL)aspectRatioIsLocked
163 return b_lockAspectRatio;
166 - (IBAction)stop:(id)sender
168 intf_thread_t * p_intf = VLCIntf;
169 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_STOP );
170 /* Close the window directly, because we do know that there
171 * won't be anymore video. It's currently waiting a bit. */
172 [[[self voutView] window] orderOut:self];
175 - (IBAction)faster:(id)sender
177 intf_thread_t * p_intf = VLCIntf;
178 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_FASTER );
181 - (IBAction)slower:(id)sender
183 intf_thread_t * p_intf = VLCIntf;
184 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_SLOWER );
187 - (IBAction)prev:(id)sender
189 intf_thread_t * p_intf = VLCIntf;
190 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_PREV );
193 - (IBAction)next:(id)sender
195 intf_thread_t * p_intf = VLCIntf;
196 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_NEXT );
199 - (IBAction)random:(id)sender
202 intf_thread_t * p_intf = VLCIntf;
203 playlist_t * p_playlist = pl_Hold( p_intf );
205 var_Get( p_playlist, "random", &val );
206 val.b_bool = !val.b_bool;
207 var_Set( p_playlist, "random", val );
210 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Random On" ) );
211 config_PutInt( p_playlist, "random", 1 );
215 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Random Off" ) );
216 config_PutInt( p_playlist, "random", 0 );
219 p_intf->p_sys->b_playmode_update = true;
220 p_intf->p_sys->b_intf_update = true;
221 pl_Release( p_intf );
224 /* three little ugly helpers */
227 [o_btn_repeat setImage: o_repeat_single];
228 [o_btn_repeat setAlternateImage: o_repeat_all];
229 [o_btn_repeat_embed setImage: [NSImage imageNamed:@"sidebarRepeatOneOn"]];
233 [o_btn_repeat setImage: o_repeat_all];
234 [o_btn_repeat setAlternateImage: o_repeat_off];
235 [o_btn_repeat_embed setImage: [NSImage imageNamed:@"sidebarRepeatOn"]];
239 [o_btn_repeat setImage: o_repeat_off];
240 [o_btn_repeat setAlternateImage: o_repeat_single];
241 [o_btn_repeat_embed setImage: [NSImage imageNamed:@"sidebarRepeat"]];
246 playlist_t *p_playlist = pl_Hold( VLCIntf );
247 var_Get( p_playlist, "random", &val );
248 [o_btn_shuffle setState: val.b_bool];
250 [o_btn_shuffle_embed setImage: [NSImage imageNamed:@"sidebarShuffleOn"]];
252 [o_btn_shuffle_embed setImage: [NSImage imageNamed:@"sidebarShuffle"]];
253 pl_Release( VLCIntf );
256 - (IBAction)repeatButtonAction:(id)sender
258 vlc_value_t looping,repeating;
259 intf_thread_t * p_intf = VLCIntf;
260 playlist_t * p_playlist = pl_Hold( p_intf );
262 var_Get( p_playlist, "repeat", &repeating );
263 var_Get( p_playlist, "loop", &looping );
265 if( !repeating.b_bool && !looping.b_bool )
267 /* was: no repeating at all, switching to Repeat One */
269 /* set our button's look */
272 /* prepare core communication */
273 repeating.b_bool = true;
274 looping.b_bool = false;
275 config_PutInt( p_playlist, "repeat", 1 );
276 config_PutInt( p_playlist, "loop", 0 );
278 /* show the change */
279 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
281 else if( repeating.b_bool && !looping.b_bool )
283 /* was: Repeat One, switching to Repeat All */
285 /* set our button's look */
288 /* prepare core communication */
289 repeating.b_bool = false;
290 looping.b_bool = true;
291 config_PutInt( p_playlist, "repeat", 0 );
292 config_PutInt( p_playlist, "loop", 1 );
294 /* show the change */
295 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
299 /* was: Repeat All or bug in VLC, switching to Repeat Off */
301 /* set our button's look */
304 /* prepare core communication */
305 repeating.b_bool = false;
306 looping.b_bool = false;
307 config_PutInt( p_playlist, "repeat", 0 );
308 config_PutInt( p_playlist, "loop", 0 );
310 /* show the change */
311 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
314 /* communicate with core and the main intf loop */
315 var_Set( p_playlist, "repeat", repeating );
316 var_Set( p_playlist, "loop", looping );
317 p_intf->p_sys->b_playmode_update = true;
318 p_intf->p_sys->b_intf_update = true;
320 pl_Release( p_intf );
324 - (IBAction)repeat:(id)sender
327 intf_thread_t * p_intf = VLCIntf;
328 playlist_t * p_playlist = pl_Hold( p_intf );
330 var_Get( p_playlist, "repeat", &val );
333 var_Set( p_playlist, "loop", val );
335 val.b_bool = !val.b_bool;
336 var_Set( p_playlist, "repeat", val );
339 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
340 config_PutInt( p_playlist, "repeat", 1 );
344 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
345 config_PutInt( p_playlist, "repeat", 0 );
348 p_intf->p_sys->b_playmode_update = true;
349 p_intf->p_sys->b_intf_update = true;
350 pl_Release( p_intf );
353 - (IBAction)loop:(id)sender
356 intf_thread_t * p_intf = VLCIntf;
357 playlist_t * p_playlist = pl_Hold( p_intf );
359 var_Get( p_playlist, "loop", &val );
362 var_Set( p_playlist, "repeat", val );
364 val.b_bool = !val.b_bool;
365 var_Set( p_playlist, "loop", val );
368 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
369 config_PutInt( p_playlist, "loop", 1 );
373 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
374 config_PutInt( p_playlist, "loop", 0 );
377 p_intf->p_sys->b_playmode_update = true;
378 p_intf->p_sys->b_intf_update = true;
379 pl_Release( p_intf );
382 - (IBAction)forward:(id)sender
384 intf_thread_t * p_intf = VLCIntf;
385 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_SHORT );
388 - (IBAction)backward:(id)sender
391 intf_thread_t * p_intf = VLCIntf;
392 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_SHORT );
396 - (IBAction)volumeUp:(id)sender
398 intf_thread_t * p_intf = VLCIntf;
399 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_UP );
400 /* Manage volume status */
401 [o_main manageVolumeSlider];
404 - (IBAction)volumeDown:(id)sender
406 intf_thread_t * p_intf = VLCIntf;
407 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_DOWN );
408 /* Manage volume status */
409 [o_main manageVolumeSlider];
412 - (IBAction)mute:(id)sender
414 intf_thread_t * p_intf = VLCIntf;
415 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_MUTE );
416 /* Manage volume status */
417 [o_main manageVolumeSlider];
420 - (IBAction)volumeSliderUpdated:(id)sender
422 intf_thread_t * p_intf = VLCIntf;
423 playlist_t * p_playlist = pl_Hold( p_intf );
424 audio_volume_t i_volume = (audio_volume_t)[sender intValue];
427 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
428 aout_VolumeSet( p_playlist, i_volume * i_volume_step );
429 pl_Release( p_playlist );
430 /* Manage volume status */
431 [o_main manageVolumeSlider];
434 - (IBAction)showPosition: (id)sender
436 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
437 if( p_input != NULL )
439 vout_thread_t *p_vout = input_GetVout( p_input );
442 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_POSITION );
443 vlc_object_release( (vlc_object_t *)p_vout );
445 vlc_object_release( p_input );
449 - (IBAction)toogleFullscreen:(id)sender {
450 NSMenuItem *o_mi = [[NSMenuItem alloc] initWithTitle: _NS("Fullscreen") action: nil keyEquivalent:@""];
451 [self windowAction: [o_mi autorelease]];
454 - (BOOL) isFullscreen {
455 id o_vout_view = [self voutView];
458 return [o_vout_view isFullscreen];
463 - (IBAction)windowAction:(id)sender
465 NSString *o_title = [sender title];
466 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
468 if( p_input != NULL )
470 vout_thread_t *p_vout = input_GetVout( p_input );
473 id o_vout_view = [self voutView];
476 if( [o_title isEqualToString: _NS("Half Size") ] )
477 [o_vout_view scaleWindowWithFactor: 0.5 animate: YES];
478 else if( [o_title isEqualToString: _NS("Normal Size") ] )
479 [o_vout_view scaleWindowWithFactor: 1.0 animate: YES];
480 else if( [o_title isEqualToString: _NS("Double Size") ] )
481 [o_vout_view scaleWindowWithFactor: 2.0 animate: YES];
482 else if( [o_title isEqualToString: _NS("Float on Top") ] )
483 [o_vout_view toggleFloatOnTop];
484 else if( [o_title isEqualToString: _NS("Fit to Screen") ] )
486 id o_window = [o_vout_view voutWindow];
487 if( ![o_window isZoomed] )
488 [o_window performZoom:self];
490 else if( [o_title isEqualToString: _NS("Snapshot") ] )
492 [o_vout_view snapshot];
496 /* Fullscreen state for next time will be saved here too */
497 [o_vout_view toggleFullscreen];
500 vlc_object_release( (vlc_object_t *)p_vout );
504 playlist_t * p_playlist = pl_Hold( VLCIntf );
506 if( [o_title isEqualToString: _NS("Fullscreen")] ||
507 [sender isKindOfClass:[NSButton class]] )
510 var_Get( p_playlist, "fullscreen", &val );
511 var_Set( p_playlist, "fullscreen", (vlc_value_t)!val.b_bool );
514 pl_Release( VLCIntf );
516 vlc_object_release( p_input );
520 - (IBAction)telxTransparent:(id)sender
522 intf_thread_t * p_intf = VLCIntf;
524 p_vbi = (vlc_object_t *) vlc_object_find_name( p_intf,
525 "zvbi", FIND_ANYWHERE );
528 var_SetBool( p_vbi, "vbi-opaque", [sender state] );
529 [sender setState: ![sender state]];
530 vlc_object_release( p_vbi );
534 - (IBAction)telxNavLink:(id)sender
536 intf_thread_t * p_intf = VLCIntf;
540 if( [[sender title] isEqualToString: _NS("Index")] )
542 else if( [[sender title] isEqualToString: _NS("Red")] )
544 else if( [[sender title] isEqualToString: _NS("Green")] )
546 else if( [[sender title] isEqualToString: _NS("Yellow")] )
548 else if( [[sender title] isEqualToString: _NS("Blue")] )
550 if( i_page == 0 ) return;
552 p_vbi = (vlc_object_t *) vlc_object_find_name( p_intf,
553 "zvbi", FIND_ANYWHERE );
556 var_SetInteger( p_vbi, "vbi-page", i_page );
557 vlc_object_release( p_vbi );
561 - (IBAction)lockVideosAspectRatio:(id)sender
563 if( [sender state] == NSOffState )
564 [sender setState: NSOnState];
566 [sender setState: NSOffState];
568 b_lockAspectRatio = !b_lockAspectRatio;
571 - (IBAction)addSubtitleFile:(id)sender
573 NSInteger i_returnValue = 0;
574 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
575 if( !p_input ) return;
577 input_item_t *p_item = input_GetItem( p_input );
578 if( !p_item ) return;
580 char *path = input_item_GetURI( p_item );
581 if( !path ) path = strdup( "" );
583 NSOpenPanel * openPanel = [NSOpenPanel openPanel];
584 [openPanel setCanChooseFiles: YES];
585 [openPanel setCanChooseDirectories: NO];
586 [openPanel setAllowsMultipleSelection: YES];
587 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]];
590 if( i_returnValue == NSOKButton )
593 if( !p_input ) return;
595 c = [[openPanel filenames] count];
597 for (int i = 0; i < [[openPanel filenames] count] ; i++)
599 msg_Dbg( VLCIntf, "loading subs from %s", [[[openPanel filenames] objectAtIndex: i] UTF8String] );
600 if( input_AddSubtitle( p_input, [[[openPanel filenames] objectAtIndex: i] UTF8String], TRUE ) )
601 msg_Warn( VLCIntf, "unable to load subtitles from '%s'",
602 [[[openPanel filenames] objectAtIndex: i] UTF8String] );
607 - (void)scrollWheel:(NSEvent *)theEvent
609 intf_thread_t * p_intf = VLCIntf;
610 float f_yabsvalue = [theEvent deltaY] > 0.0f ? [theEvent deltaY] : -[theEvent deltaY];
611 float f_xabsvalue = [theEvent deltaX] > 0.0f ? [theEvent deltaX] : -[theEvent deltaX];
612 int i, i_yvlckey, i_xvlckey;
614 if ([theEvent deltaY] < 0.0f)
615 i_yvlckey = KEY_MOUSEWHEELDOWN;
617 i_yvlckey = KEY_MOUSEWHEELUP;
619 if ([theEvent deltaX] < 0.0f)
620 i_xvlckey = KEY_MOUSEWHEELRIGHT;
622 i_xvlckey = KEY_MOUSEWHEELLEFT;
624 /* Send multiple key event, depending on the intensity of the event */
625 for (i = 0; i < (int)(f_yabsvalue/4.+1.) && f_yabsvalue > 0.05 ; i++)
626 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_yvlckey );
628 /* Prioritize Y event (sound volume) over X event */
629 if (f_yabsvalue < 0.05)
631 for (i = 0; i < (int)(f_xabsvalue/6.+1.) && f_xabsvalue > 0.05; i++)
632 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_xvlckey );
636 - (BOOL)keyEvent:(NSEvent *)o_event
638 BOOL eventHandled = NO;
639 unichar key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
643 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
644 if( p_input != NULL )
646 vout_thread_t *p_vout = input_GetVout( p_input );
651 if( key == (unichar) 0x1b )
653 id o_vout_view = [self voutView];
654 if( o_vout_view && [o_vout_view isFullscreen] )
656 [o_vout_view toggleFullscreen];
660 else if( key == ' ' )
665 vlc_object_release( (vlc_object_t *)p_vout );
667 vlc_object_release( p_input );
673 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
674 target:(vlc_object_t *)p_object
675 var:(const char *)psz_variable
676 selector:(SEL)pf_callback
678 vlc_value_t val, text;
679 int i_type = var_Type( p_object, psz_variable );
681 switch( i_type & VLC_VAR_TYPE )
685 case VLC_VAR_VARIABLE:
687 case VLC_VAR_INTEGER:
690 /* Variable doesn't exist or isn't handled */
694 /* Make sure we want to display the variable */
695 if( i_type & VLC_VAR_HASCHOICE )
697 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
698 if( val.i_int == 0 ) return;
699 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
703 /* Get the descriptive name of the variable */
704 var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
705 [o_mi setTitle: [[VLCMain sharedInstance] localizedString: text.psz_string ?
706 text.psz_string : psz_variable ]];
708 if( i_type & VLC_VAR_HASCHOICE )
710 NSMenu *o_menu = [o_mi submenu];
712 [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
713 var:psz_variable selector:pf_callback];
715 free( text.psz_string );
718 if( var_Get( p_object, psz_variable, &val ) < 0 )
723 VLCAutoGeneratedMenuContent *o_data;
724 switch( i_type & VLC_VAR_TYPE )
727 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
728 andValue: val ofType: i_type];
729 [o_mi setRepresentedObject: [o_data autorelease]];
733 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
734 andValue: val ofType: i_type];
735 [o_mi setRepresentedObject: [o_data autorelease]];
736 if( !( i_type & VLC_VAR_ISCOMMAND ) )
737 [o_mi setState: val.b_bool ? TRUE : FALSE ];
744 if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
745 free( text.psz_string );
749 - (void)setupVarMenu:(NSMenu *)o_menu
750 forMenuItem: (NSMenuItem *)o_parent
751 target:(vlc_object_t *)p_object
752 var:(const char *)psz_variable
753 selector:(SEL)pf_callback
755 vlc_value_t val, val_list, text_list;
756 int i_type, i, i_nb_items;
758 /* remove previous items */
759 i_nb_items = [o_menu numberOfItems];
760 for( i = 0; i < i_nb_items; i++ )
762 [o_menu removeItemAtIndex: 0];
765 /* Check the type of the object variable */
766 i_type = var_Type( p_object, psz_variable );
768 /* Make sure we want to display the variable */
769 if( i_type & VLC_VAR_HASCHOICE )
771 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
772 if( val.i_int == 0 ) return;
773 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
781 switch( i_type & VLC_VAR_TYPE )
785 case VLC_VAR_VARIABLE:
787 case VLC_VAR_INTEGER:
790 /* Variable doesn't exist or isn't handled */
794 if( var_Get( p_object, psz_variable, &val ) < 0 )
799 if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
800 &val_list, &text_list ) < 0 )
802 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
806 /* make (un)sensitive */
807 [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
810 if( [[o_parent title] isEqualToString: _NS("Aspect-ratio")] == YES )
812 NSMenuItem *o_lmi_tmp2;
813 o_lmi_tmp2 = [o_menu addItemWithTitle: _NS("Lock Aspect Ratio") action: @selector(lockVideosAspectRatio:) keyEquivalent: @""];
814 [o_lmi_tmp2 setTarget: self];
815 [o_lmi_tmp2 setEnabled: YES];
816 [o_lmi_tmp2 setState: b_lockAspectRatio];
817 [o_parent setEnabled: YES];
818 [o_menu addItem: [NSMenuItem separatorItem]];
821 /* special case for the subtitles items */
822 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
824 NSMenuItem * o_lmi_tmp;
825 o_lmi_tmp = [o_menu addItemWithTitle: _NS("Open File...") action: @selector(addSubtitleFile:) keyEquivalent: @""];
826 [o_lmi_tmp setTarget: self];
827 [o_lmi_tmp setEnabled: YES];
828 [o_parent setEnabled: YES];
829 [o_menu addItem: [NSMenuItem separatorItem]];
832 for( i = 0; i < val_list.p_list->i_count; i++ )
835 NSString *o_title = @"";
836 VLCAutoGeneratedMenuContent *o_data;
838 switch( i_type & VLC_VAR_TYPE )
842 o_title = [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string ?
843 text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
845 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
846 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
847 andValue: val_list.p_list->p_values[i] ofType: i_type];
848 [o_lmi setRepresentedObject: [o_data autorelease]];
849 [o_lmi setTarget: self];
851 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
852 [o_lmi setState: TRUE ];
856 case VLC_VAR_INTEGER:
858 o_title = text_list.p_list->p_values[i].psz_string ?
859 [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string] :
860 [NSString stringWithFormat: @"%d",
861 val_list.p_list->p_values[i].i_int];
863 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
864 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
865 andValue: val_list.p_list->p_values[i] ofType: i_type];
866 [o_lmi setRepresentedObject: [o_data autorelease]];
867 [o_lmi setTarget: self];
869 if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
870 [o_lmi setState: TRUE ];
878 /* special case for the subtitles sub-menu
879 * In case that we don't have any subs, we don't want a separator item at the end */
880 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
882 if( [o_menu numberOfItems] == 2 )
883 [o_menu removeItemAtIndex: 1];
886 /* clean up everything */
887 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
888 var_FreeList( &val_list, &text_list );
891 - (IBAction)toggleVar:(id)sender
893 NSMenuItem *o_mi = (NSMenuItem *)sender;
894 VLCAutoGeneratedMenuContent *o_data = [o_mi representedObject];
895 [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
896 toTarget: self withObject: o_data];
901 - (int)toggleVarThread: (id)data
903 vlc_object_t *p_object;
904 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
906 assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
907 VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
909 vlc_thread_set_priority( VLCIntf , VLC_THREAD_PRIORITY_LOW );
911 p_object = [menuContent vlcObject];
913 if( p_object != NULL )
915 var_Set( p_object, [menuContent name], [menuContent value] );
916 vlc_object_release( p_object );
924 - (IBAction)goToSpecificTime:(id)sender
926 if( sender == o_specificTime_cancel_btn )
928 [NSApp endSheet: o_specificTime_win];
929 [o_specificTime_win close];
931 else if( sender == o_specificTime_ok_btn )
933 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
936 unsigned int timeInSec = 0;
937 NSString * fieldContent = [o_specificTime_enter_fld stringValue];
938 if( [[fieldContent componentsSeparatedByString: @":"] count] > 1 &&
939 [[fieldContent componentsSeparatedByString: @":"] count] <= 3 )
941 NSArray * ourTempArray = \
942 [fieldContent componentsSeparatedByString: @":"];
944 if( [[fieldContent componentsSeparatedByString: @":"] count] == 3 )
946 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 3600); //h
947 timeInSec += ([[ourTempArray objectAtIndex: 1] intValue] * 60); //m
948 timeInSec += [[ourTempArray objectAtIndex: 2] intValue]; //s
952 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 60); //m
953 timeInSec += [[ourTempArray objectAtIndex: 1] intValue]; //s
957 timeInSec = [fieldContent intValue];
959 input_Control( p_input, INPUT_SET_TIME, (int64_t)(timeInSec * 1000000));
960 vlc_object_release( p_input );
963 [NSApp endSheet: o_specificTime_win];
964 [o_specificTime_win close];
968 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
971 /* we can obviously only do that if an input is available */
972 vlc_value_t pos, length;
973 var_Get( p_input, "time", &pos );
974 [o_specificTime_enter_fld setIntValue: (pos.i_time / 1000000)];
975 var_Get( p_input, "length", &length );
976 [o_specificTime_stepper setMaxValue: (length.i_time / 1000000)];
978 [NSApp beginSheet: o_specificTime_win modalForWindow: \
979 [NSApp mainWindow] modalDelegate: self didEndSelector: nil \
981 [o_specificTime_win makeKeyWindow];
982 vlc_object_release( p_input );
993 msg_Err( VLCIntf, "FSPanel is nil" );
1000 @implementation VLCControls (NSMenuValidation)
1002 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1004 BOOL bEnabled = TRUE;
1006 intf_thread_t * p_intf = VLCIntf;
1007 playlist_t * p_playlist = pl_Hold( p_intf );
1008 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1010 if( [[o_mi title] isEqualToString: _NS("Faster")] ||
1011 [[o_mi title] isEqualToString: _NS("Slower")] )
1013 if( p_input != NULL )
1015 bEnabled = var_GetBool( p_input, "can-rate" );
1022 else if( [[o_mi title] isEqualToString: _NS("Stop")] )
1024 if( p_input == NULL )
1028 [o_main setupMenus]; /* Make sure input menu is up to date */
1030 else if( [[o_mi title] isEqualToString: _NS("Previous")] ||
1031 [[o_mi title] isEqualToString: _NS("Next")] )
1034 bEnabled = playlist_CurrentSize( p_playlist ) > 1;
1037 else if( [[o_mi title] isEqualToString: _NS("Random")] )
1040 var_Get( p_playlist, "random", &val );
1041 i_state = val.b_bool ? NSOnState : NSOffState;
1042 [o_mi setState: i_state];
1044 else if( [[o_mi title] isEqualToString: _NS("Repeat One")] )
1047 var_Get( p_playlist, "repeat", &val );
1048 i_state = val.b_bool ? NSOnState : NSOffState;
1049 [o_mi setState: i_state];
1051 else if( [[o_mi title] isEqualToString: _NS("Repeat All")] )
1054 var_Get( p_playlist, "loop", &val );
1055 i_state = val.b_bool ? NSOnState : NSOffState;
1056 [o_mi setState: i_state];
1058 else if( [[o_mi title] isEqualToString: _NS("Step Forward")] ||
1059 [[o_mi title] isEqualToString: _NS("Step Backward")] ||
1060 [[o_mi title] isEqualToString: _NS("Jump To Time")])
1062 if( p_input != NULL )
1064 var_Get( p_input, "can-seek", &val);
1065 bEnabled = val.b_bool;
1067 else bEnabled = FALSE;
1069 else if( [[o_mi title] isEqualToString: _NS("Mute")] )
1071 [o_mi setState: p_intf->p_sys->b_mute ? NSOnState : NSOffState];
1072 [o_main setupMenus]; /* Make sure audio menu is up to date */
1074 else if( [[o_mi title] isEqualToString: _NS("Half Size")] ||
1075 [[o_mi title] isEqualToString: _NS("Normal Size")] ||
1076 [[o_mi title] isEqualToString: _NS("Double Size")] ||
1077 [[o_mi title] isEqualToString: _NS("Fit to Screen")] ||
1078 [[o_mi title] isEqualToString: _NS("Snapshot")] ||
1079 [[o_mi title] isEqualToString: _NS("Fullscreen")] ||
1080 [[o_mi title] isEqualToString: _NS("Float on Top")] )
1083 NSArray *o_windows = [NSApp orderedWindows];
1084 NSEnumerator *o_enumerator = [o_windows objectEnumerator];
1087 if( p_input != NULL )
1089 vout_thread_t *p_vout = input_GetVout( p_input );
1090 if( p_vout != NULL )
1092 if( [[o_mi title] isEqualToString: _NS("Float on Top")] )
1094 var_Get( p_vout, "video-on-top", &val );
1095 [o_mi setState: val.b_bool ? NSOnState : NSOffState];
1098 while( (o_window = [o_enumerator nextObject]))
1100 if( [[o_window className] isEqualToString: @"VLCVoutWindow"] ||
1101 [[[VLCMain sharedInstance] embeddedList]
1102 windowContainsEmbedded: o_window])
1109 vlc_object_release( (vlc_object_t *)p_vout );
1111 vlc_object_release( p_input );
1113 if( [[o_mi title] isEqualToString: _NS("Fullscreen")] )
1115 var_Get( p_playlist, "fullscreen", &val );
1116 [o_mi setState: val.b_bool];
1119 [o_main setupMenus]; /* Make sure video menu is up to date */
1122 /* Special case for telx menu */
1123 if( [[o_mi title] isEqualToString: _NS("Normal Size")] )
1125 NSMenuItem *item = [[o_mi menu] itemWithTitle:_NS("Teletext")];
1126 bool b_telx = p_input && var_GetInteger( p_input, "teletext-es" ) >= 0;
1128 [[item submenu] setAutoenablesItems:NO];
1129 for( int k=0; k < [[item submenu] numberOfItems]; k++ )
1131 [[[item submenu] itemAtIndex:k] setEnabled: b_telx];
1135 if( p_input ) vlc_object_release( p_input );
1136 pl_Release( p_intf );
1143 /*****************************************************************************
1144 * VLCAutoGeneratedMenuContent implementation
1145 *****************************************************************************
1146 * Object connected to a playlistitem which remembers the data belonging to
1147 * the variable of the autogenerated menu
1148 *****************************************************************************/
1149 @implementation VLCAutoGeneratedMenuContent
1151 -(id) initWithVariableName:(const char *)name ofObject:(vlc_object_t *)object
1152 andValue:(vlc_value_t)val ofType:(int)type
1154 self = [super init];
1158 _vlc_object = vlc_object_hold( object );
1159 psz_name = strdup( name );
1162 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1163 value.psz_string = strdup( val.psz_string );
1171 vlc_object_release( _vlc_object );
1172 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1173 free( value.psz_string );
1178 - (const char *)name
1183 - (vlc_value_t)value
1188 - (vlc_object_t *)vlcObject
1190 return vlc_object_hold( _vlc_object );
1202 /*****************************************************************************
1203 * VLCTimeField implementation
1204 *****************************************************************************
1205 * we need this to catch our click-event in the controller window
1206 *****************************************************************************/
1208 @implementation VLCTimeField
1209 - (void)mouseDown: (NSEvent *)ourEvent
1211 if( [ourEvent clickCount] > 1 )
1212 [[[VLCMain sharedInstance] controls] goToSpecificTime: nil];
1214 [[VLCMain sharedInstance] timeFieldWasClicked: self];