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 */
43 /*****************************************************************************
44 * VLCAutoGeneratedMenuContent interface
45 *****************************************************************************
46 * This holds our data for autogenerated menus
47 *****************************************************************************/
48 @interface VLCAutoGeneratedMenuContent : NSObject
51 vlc_object_t * _vlc_object;
56 - (id)initWithVariableName: (const char *)name
57 ofObject: (vlc_object_t *)object
58 andValue: (vlc_value_t)value
62 - (vlc_object_t *)vlcObject;
68 /*****************************************************************************
69 * VLCControls implementation
70 *****************************************************************************/
71 @implementation VLCControls
76 o_fs_panel = [[VLCFSPanel alloc] init];
77 b_lockAspectRatio = YES;
83 [o_specificTime_mi setTitle: _NS("Jump To Time")];
84 [o_specificTime_cancel_btn setTitle: _NS("Cancel")];
85 [o_specificTime_ok_btn setTitle: _NS("OK")];
86 [o_specificTime_sec_lbl setStringValue: _NS("sec.")];
87 [o_specificTime_goTo_lbl setStringValue: _NS("Jump to time")];
89 o_repeat_off = [NSImage imageNamed:@"repeat_embedded"];
91 [self controlTintChanged];
93 [[NSNotificationCenter defaultCenter] addObserver: self
94 selector: @selector( controlTintChanged )
95 name: NSControlTintDidChangeNotification
99 - (void)controlTintChanged
102 if( [o_btn_repeat image] == o_repeat_single )
104 else if( [o_btn_repeat image] == o_repeat_all )
107 if( [NSColor currentControlTint] == NSGraphiteControlTint )
109 o_repeat_single = [NSImage imageNamed:@"repeat_single_embedded_graphite"];
110 o_repeat_all = [NSImage imageNamed:@"repeat_embedded_graphite"];
112 [o_btn_shuffle setAlternateImage: [NSImage imageNamed: @"shuffle_embedded_graphite"]];
113 [o_btn_addNode setAlternateImage: [NSImage imageNamed: @"add_embedded_graphite"]];
117 o_repeat_single = [NSImage imageNamed:@"repeat_single_embedded_blue"];
118 o_repeat_all = [NSImage imageNamed:@"repeat_embedded_blue"];
120 [o_btn_shuffle setAlternateImage: [NSImage imageNamed: @"shuffle_embedded_blue"]];
121 [o_btn_addNode setAlternateImage: [NSImage imageNamed: @"add_embedded_blue"]];
124 /* update the repeat button, but keep its state */
127 else if( i_repeat == 2 )
135 [[NSNotificationCenter defaultCenter] removeObserver: self];
137 [o_repeat_single release];
138 [o_repeat_all release];
139 [o_repeat_off release];
144 - (IBAction)play:(id)sender
146 intf_thread_t * p_intf = VLCIntf;
147 playlist_t * p_playlist = pl_Hold( p_intf );
151 empty = playlist_IsEmpty( p_playlist );
154 pl_Release( p_intf );
157 [o_main intfOpenFileGeneric: (id)sender];
159 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_PLAY_PAUSE );
166 id embeddedViewList = [[VLCMain sharedInstance] embeddedList];
167 NSEnumerator *enumerator = [[NSApp orderedWindows] objectEnumerator];
168 while( !voutView && ( window = [enumerator nextObject] ) )
170 /* We have an embedded vout */
171 if( [embeddedViewList windowContainsEmbedded: window] )
173 voutView = [embeddedViewList viewForWindow: window];
175 /* We have a detached vout */
176 else if( [[window className] isEqualToString: @"VLCVoutWindow"] )
178 voutView = [window voutView];
181 return [[voutView retain] autorelease];
184 - (BOOL)aspectRatioIsLocked
186 return b_lockAspectRatio;
189 - (IBAction)stop:(id)sender
191 intf_thread_t * p_intf = VLCIntf;
192 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_STOP );
193 /* Close the window directly, because we do know that there
194 * won't be anymore video. It's currently waiting a bit. */
195 [[[self voutView] window] orderOut:self];
198 - (IBAction)faster:(id)sender
200 intf_thread_t * p_intf = VLCIntf;
201 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_FASTER );
204 - (IBAction)slower:(id)sender
206 intf_thread_t * p_intf = VLCIntf;
207 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_SLOWER );
210 - (IBAction)prev:(id)sender
212 intf_thread_t * p_intf = VLCIntf;
213 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_PREV );
216 - (IBAction)next:(id)sender
218 intf_thread_t * p_intf = VLCIntf;
219 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_NEXT );
222 - (IBAction)random:(id)sender
225 intf_thread_t * p_intf = VLCIntf;
226 playlist_t * p_playlist = pl_Hold( p_intf );
228 var_Get( p_playlist, "random", &val );
229 val.b_bool = !val.b_bool;
230 var_Set( p_playlist, "random", val );
233 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Random On" ) );
234 config_PutInt( p_playlist, "random", 1 );
238 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Random Off" ) );
239 config_PutInt( p_playlist, "random", 0 );
242 p_intf->p_sys->b_playmode_update = true;
243 p_intf->p_sys->b_intf_update = true;
244 pl_Release( p_intf );
247 /* three little ugly helpers */
250 [o_btn_repeat setImage: o_repeat_single];
251 [o_btn_repeat setAlternateImage: o_repeat_all];
255 [o_btn_repeat setImage: o_repeat_all];
256 [o_btn_repeat setAlternateImage: o_repeat_off];
260 [o_btn_repeat setImage: o_repeat_off];
261 [o_btn_repeat setAlternateImage: o_repeat_single];
266 playlist_t *p_playlist = pl_Hold( VLCIntf );
267 var_Get( p_playlist, "random", &val );
268 [o_btn_shuffle setState: val.b_bool];
269 pl_Release( VLCIntf );
272 - (IBAction)repeatButtonAction:(id)sender
274 vlc_value_t looping,repeating;
275 intf_thread_t * p_intf = VLCIntf;
276 playlist_t * p_playlist = pl_Hold( p_intf );
278 var_Get( p_playlist, "repeat", &repeating );
279 var_Get( p_playlist, "loop", &looping );
281 if( !repeating.b_bool && !looping.b_bool )
283 /* was: no repeating at all, switching to Repeat One */
285 /* set our button's look */
288 /* prepare core communication */
289 repeating.b_bool = true;
290 looping.b_bool = false;
291 config_PutInt( p_playlist, "repeat", 1 );
292 config_PutInt( p_playlist, "loop", 0 );
294 /* show the change */
295 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
297 else if( repeating.b_bool && !looping.b_bool )
299 /* was: Repeat One, switching to Repeat All */
301 /* set our button's look */
304 /* prepare core communication */
305 repeating.b_bool = false;
306 looping.b_bool = true;
307 config_PutInt( p_playlist, "repeat", 0 );
308 config_PutInt( p_playlist, "loop", 1 );
310 /* show the change */
311 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
315 /* was: Repeat All or bug in VLC, switching to Repeat Off */
317 /* set our button's look */
320 /* prepare core communication */
321 repeating.b_bool = false;
322 looping.b_bool = false;
323 config_PutInt( p_playlist, "repeat", 0 );
324 config_PutInt( p_playlist, "loop", 0 );
326 /* show the change */
327 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
330 /* communicate with core and the main intf loop */
331 var_Set( p_playlist, "repeat", repeating );
332 var_Set( p_playlist, "loop", looping );
333 p_intf->p_sys->b_playmode_update = true;
334 p_intf->p_sys->b_intf_update = true;
336 pl_Release( p_intf );
340 - (IBAction)repeat:(id)sender
343 intf_thread_t * p_intf = VLCIntf;
344 playlist_t * p_playlist = pl_Hold( p_intf );
346 var_Get( p_playlist, "repeat", &val );
349 var_Set( p_playlist, "loop", val );
351 val.b_bool = !val.b_bool;
352 var_Set( p_playlist, "repeat", val );
355 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
356 config_PutInt( p_playlist, "repeat", 1 );
360 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
361 config_PutInt( p_playlist, "repeat", 0 );
364 p_intf->p_sys->b_playmode_update = true;
365 p_intf->p_sys->b_intf_update = true;
366 pl_Release( p_intf );
369 - (IBAction)loop:(id)sender
372 intf_thread_t * p_intf = VLCIntf;
373 playlist_t * p_playlist = pl_Hold( p_intf );
375 var_Get( p_playlist, "loop", &val );
378 var_Set( p_playlist, "repeat", val );
380 val.b_bool = !val.b_bool;
381 var_Set( p_playlist, "loop", val );
384 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
385 config_PutInt( p_playlist, "loop", 1 );
389 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
390 config_PutInt( p_playlist, "loop", 0 );
393 p_intf->p_sys->b_playmode_update = true;
394 p_intf->p_sys->b_intf_update = true;
395 pl_Release( p_intf );
398 - (IBAction)forward:(id)sender
400 intf_thread_t * p_intf = VLCIntf;
401 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_SHORT );
404 - (IBAction)backward:(id)sender
407 intf_thread_t * p_intf = VLCIntf;
408 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_SHORT );
412 - (IBAction)volumeUp:(id)sender
414 intf_thread_t * p_intf = VLCIntf;
415 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_UP );
416 /* Manage volume status */
417 [o_main manageVolumeSlider];
420 - (IBAction)volumeDown:(id)sender
422 intf_thread_t * p_intf = VLCIntf;
423 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_DOWN );
424 /* Manage volume status */
425 [o_main manageVolumeSlider];
428 - (IBAction)mute:(id)sender
430 intf_thread_t * p_intf = VLCIntf;
431 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_MUTE );
432 /* Manage volume status */
433 [o_main manageVolumeSlider];
436 - (IBAction)volumeSliderUpdated:(id)sender
438 intf_thread_t * p_intf = VLCIntf;
439 audio_volume_t i_volume = (audio_volume_t)[sender intValue];
440 int i_volume_step = 0;
441 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
442 aout_VolumeSet( p_intf, i_volume * i_volume_step );
443 /* Manage volume status */
444 [o_main manageVolumeSlider];
447 - (IBAction)showPosition: (id)sender
449 vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT,
453 intf_thread_t * p_intf = VLCIntf;
454 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_POSITION );
455 vlc_object_release( (vlc_object_t *)p_vout );
459 - (IBAction)toogleFullscreen:(id)sender {
460 NSMenuItem *o_mi = [[NSMenuItem alloc] initWithTitle: _NS("Fullscreen") action: nil keyEquivalent:@""];
461 [self windowAction: [o_mi autorelease]];
464 - (BOOL) isFullscreen {
465 id o_vout_view = [self voutView];
468 return [o_vout_view isFullscreen];
473 - (IBAction)windowAction:(id)sender
475 NSString *o_title = [sender title];
477 vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT,
481 id o_vout_view = [self voutView];
484 if( [o_title isEqualToString: _NS("Half Size") ] )
485 [o_vout_view scaleWindowWithFactor: 0.5 animate: YES];
486 else if( [o_title isEqualToString: _NS("Normal Size") ] )
487 [o_vout_view scaleWindowWithFactor: 1.0 animate: YES];
488 else if( [o_title isEqualToString: _NS("Double Size") ] )
489 [o_vout_view scaleWindowWithFactor: 2.0 animate: YES];
490 else if( [o_title isEqualToString: _NS("Float on Top") ] )
491 [o_vout_view toggleFloatOnTop];
492 else if( [o_title isEqualToString: _NS("Fit to Screen") ] )
494 id o_window = [o_vout_view voutWindow];
495 if( ![o_window isZoomed] )
496 [o_window performZoom:self];
498 else if( [o_title isEqualToString: _NS("Snapshot") ] )
500 [o_vout_view snapshot];
504 /* Fullscreen state for next time will be saved here too */
505 [o_vout_view toggleFullscreen];
508 vlc_object_release( (vlc_object_t *)p_vout );
512 playlist_t * p_playlist = pl_Hold( VLCIntf );
514 if( [o_title isEqualToString: _NS("Fullscreen")] ||
515 [sender isKindOfClass:[NSButton class]] )
518 var_Get( p_playlist, "fullscreen", &val );
519 var_Set( p_playlist, "fullscreen", (vlc_value_t)!val.b_bool );
522 pl_Release( VLCIntf );
527 - (IBAction)telxTransparent:(id)sender
529 intf_thread_t * p_intf = VLCIntf;
531 p_vbi = (vlc_object_t *) vlc_object_find_name( p_intf,
532 "zvbi", FIND_ANYWHERE );
535 var_SetBool( p_vbi, "vbi-opaque", [sender state] );
536 [sender setState: ![sender state]];
537 vlc_object_release( p_vbi );
541 - (IBAction)telxNavLink:(id)sender
543 intf_thread_t * p_intf = VLCIntf;
547 if( [[sender title] isEqualToString: _NS("Index")] )
549 else if( [[sender title] isEqualToString: _NS("Red")] )
551 else if( [[sender title] isEqualToString: _NS("Green")] )
553 else if( [[sender title] isEqualToString: _NS("Yellow")] )
555 else if( [[sender title] isEqualToString: _NS("Blue")] )
557 if( i_page == 0 ) return;
559 p_vbi = (vlc_object_t *) vlc_object_find_name( p_intf,
560 "zvbi", FIND_ANYWHERE );
563 var_SetInteger( p_vbi, "vbi-page", i_page );
564 vlc_object_release( p_vbi );
568 - (IBAction)lockVideosAspectRatio:(id)sender
570 if( [sender state] == NSOffState )
571 [sender setState: NSOnState];
573 [sender setState: NSOffState];
575 b_lockAspectRatio = !b_lockAspectRatio;
578 - (IBAction)addSubtitleFile:(id)sender
580 NSInteger i_returnValue = 0;
581 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
582 if( !p_input ) return;
584 input_item_t *p_item = input_GetItem( p_input );
585 if( !p_item ) return;
587 char *path = input_item_GetURI( p_item );
588 if( !path ) path = strdup( "" );
590 NSOpenPanel * openPanel = [NSOpenPanel openPanel];
591 [openPanel setCanChooseFiles: YES];
592 [openPanel setCanChooseDirectories: NO];
593 [openPanel setAllowsMultipleSelection: YES];
594 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]];
597 if( i_returnValue == NSOKButton )
600 if( !p_input ) return;
602 c = [[openPanel filenames] count];
603 NSLog( @"count: %i", c );
604 for (int i = 0; [[openPanel filenames] count] > i ; i++)
606 msg_Dbg( VLCIntf, "loading subs from %s", [[[openPanel filenames] objectAtIndex: i] UTF8String] );
607 if( input_AddSubtitle( p_input, [[[openPanel filenames] objectAtIndex: i] UTF8String], TRUE ) )
608 msg_Warn( VLCIntf, "unable to load subtitles from '%s'",
609 [[[openPanel filenames] objectAtIndex: i] UTF8String] );
614 - (void)scrollWheel:(NSEvent *)theEvent
616 intf_thread_t * p_intf = VLCIntf;
617 float f_yabsvalue = [theEvent deltaY] > 0.0f ? [theEvent deltaY] : -[theEvent deltaY];
618 float f_xabsvalue = [theEvent deltaX] > 0.0f ? [theEvent deltaX] : -[theEvent deltaX];
619 int i, i_yvlckey, i_xvlckey;
621 if ([theEvent deltaY] < 0.0f)
622 i_yvlckey = KEY_MOUSEWHEELDOWN;
624 i_yvlckey = KEY_MOUSEWHEELUP;
626 if ([theEvent deltaX] < 0.0f)
627 i_xvlckey = KEY_MOUSEWHEELRIGHT;
629 i_xvlckey = KEY_MOUSEWHEELLEFT;
631 /* Send multiple key event, depending on the intensity of the event */
632 for (i = 0; i < (int)(f_yabsvalue/4.+1.) && f_yabsvalue > 0.05 ; i++)
633 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_yvlckey );
635 /* Prioritize Y event (sound volume) over X event */
636 if (f_yabsvalue < 0.05)
638 for (i = 0; i < (int)(f_xabsvalue/6.+1.) && f_xabsvalue > 0.05; i++)
639 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_xvlckey );
643 - (BOOL)keyEvent:(NSEvent *)o_event
645 BOOL eventHandled = NO;
646 unichar key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
650 vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT,
655 if( key == (unichar) 0x1b )
657 id o_vout_view = [self voutView];
658 if( o_vout_view && [o_vout_view isFullscreen] )
660 [o_vout_view toggleFullscreen];
664 else if( key == ' ' )
669 vlc_object_release( (vlc_object_t *)p_vout );
675 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
676 target:(vlc_object_t *)p_object
677 var:(const char *)psz_variable
678 selector:(SEL)pf_callback
680 vlc_value_t val, text;
681 int i_type = var_Type( p_object, psz_variable );
683 switch( i_type & VLC_VAR_TYPE )
687 case VLC_VAR_VARIABLE:
689 case VLC_VAR_INTEGER:
692 /* Variable doesn't exist or isn't handled */
696 /* Make sure we want to display the variable */
697 if( i_type & VLC_VAR_HASCHOICE )
699 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
700 if( val.i_int == 0 ) return;
701 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
705 /* Get the descriptive name of the variable */
706 var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
707 [o_mi setTitle: [[VLCMain sharedInstance] localizedString: text.psz_string ?
708 text.psz_string : strdup( psz_variable ) ]];
710 var_Get( p_object, psz_variable, &val );
711 if( i_type & VLC_VAR_HASCHOICE )
713 NSMenu *o_menu = [o_mi submenu];
715 [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
716 var:psz_variable selector:pf_callback];
718 free( text.psz_string );
722 VLCAutoGeneratedMenuContent *o_data;
723 switch( i_type & VLC_VAR_TYPE )
726 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
727 andValue: val ofType: i_type];
728 [o_mi setRepresentedObject: [o_data autorelease]];
732 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
733 andValue: val ofType: i_type];
734 [o_mi setRepresentedObject: [o_data autorelease]];
735 if( !( i_type & VLC_VAR_ISCOMMAND ) )
736 [o_mi setState: val.b_bool ? TRUE : FALSE ];
740 free( text.psz_string );
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++ )
834 vlc_value_t another_val;
836 NSString *o_title = @"";
837 VLCAutoGeneratedMenuContent *o_data;
839 switch( i_type & VLC_VAR_TYPE )
842 another_val.psz_string =
843 strdup(val_list.p_list->p_values[i].psz_string);
845 o_title = [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string ?
846 text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
848 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
849 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: strdup(psz_variable) ofObject: p_object
850 andValue: another_val ofType: i_type];
851 [o_lmi setRepresentedObject: [o_data autorelease]];
852 [o_lmi setTarget: self];
854 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
855 [o_lmi setState: TRUE ];
859 case VLC_VAR_INTEGER:
861 o_title = text_list.p_list->p_values[i].psz_string ?
862 [[VLCMain sharedInstance] localizedString: strdup( text_list.p_list->p_values[i].psz_string )] :
863 [NSString stringWithFormat: @"%d",
864 val_list.p_list->p_values[i].i_int];
866 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
867 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: strdup(psz_variable) ofObject: p_object
868 andValue: val_list.p_list->p_values[i] ofType: i_type];
869 [o_lmi setRepresentedObject: [o_data autorelease]];
870 [o_lmi setTarget: self];
872 if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
873 [o_lmi setState: TRUE ];
881 /* special case for the subtitles sub-menu
882 * In case that we don't have any subs, we don't want a separator item at the end */
883 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
885 if( [o_menu numberOfItems] == 2 )
886 [o_menu removeItemAtIndex: 1];
889 /* clean up everything */
890 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
891 var_Change( p_object, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list );
894 - (IBAction)toggleVar:(id)sender
896 NSMenuItem *o_mi = (NSMenuItem *)sender;
897 VLCAutoGeneratedMenuContent *o_data = [o_mi representedObject];
898 [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
899 toTarget: self withObject: o_data];
904 - (int)toggleVarThread: (id)data
906 vlc_object_t *p_object;
907 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
909 assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
910 VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
912 vlc_thread_set_priority( VLCIntf , VLC_THREAD_PRIORITY_LOW );
914 p_object = [menuContent vlcObject];
916 if( p_object != NULL )
918 var_Set( p_object, [menuContent name], [menuContent value] );
919 vlc_object_release( p_object );
927 - (IBAction)goToSpecificTime:(id)sender
929 if( sender == o_specificTime_cancel_btn )
931 [NSApp endSheet: o_specificTime_win];
932 [o_specificTime_win close];
934 else if( sender == o_specificTime_ok_btn )
936 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
939 unsigned int timeInSec = 0;
940 NSString * fieldContent = [o_specificTime_enter_fld stringValue];
941 if( [[fieldContent componentsSeparatedByString: @":"] count] > 1 &&
942 [[fieldContent componentsSeparatedByString: @":"] count] <= 3 )
944 NSArray * ourTempArray = \
945 [fieldContent componentsSeparatedByString: @":"];
947 if( [[fieldContent componentsSeparatedByString: @":"] count] == 3 )
949 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 3600); //h
950 timeInSec += ([[ourTempArray objectAtIndex: 1] intValue] * 60); //m
951 timeInSec += [[ourTempArray objectAtIndex: 2] intValue]; //s
955 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 60); //m
956 timeInSec += [[ourTempArray objectAtIndex: 1] intValue]; //s
960 timeInSec = [fieldContent intValue];
962 input_Control( p_input, INPUT_SET_TIME, (int64_t)(timeInSec * 1000000));
963 vlc_object_release( p_input );
966 [NSApp endSheet: o_specificTime_win];
967 [o_specificTime_win close];
971 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
974 /* we can obviously only do that if an input is available */
975 vlc_value_t pos, length;
976 var_Get( p_input, "time", &pos );
977 [o_specificTime_enter_fld setIntValue: (pos.i_time / 1000000)];
978 var_Get( p_input, "length", &length );
979 [o_specificTime_stepper setMaxValue: (length.i_time / 1000000)];
981 [NSApp beginSheet: o_specificTime_win modalForWindow: \
982 [NSApp mainWindow] modalDelegate: self didEndSelector: nil \
984 [o_specificTime_win makeKeyWindow];
985 vlc_object_release( p_input );
996 msg_Err( VLCIntf, "FSPanel is nil" );
1003 @implementation VLCControls (NSMenuValidation)
1005 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1007 BOOL bEnabled = TRUE;
1009 intf_thread_t * p_intf = VLCIntf;
1010 playlist_t * p_playlist = pl_Hold( p_intf );
1011 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1013 if( [[o_mi title] isEqualToString: _NS("Faster")] ||
1014 [[o_mi title] isEqualToString: _NS("Slower")] )
1016 if( p_input != NULL )
1018 bEnabled = var_GetBool( p_input, "can-rate" );
1025 else if( [[o_mi title] isEqualToString: _NS("Stop")] )
1027 if( p_input == NULL )
1031 [o_main setupMenus]; /* Make sure input menu is up to date */
1033 else if( [[o_mi title] isEqualToString: _NS("Previous")] ||
1034 [[o_mi title] isEqualToString: _NS("Next")] )
1036 /** \todo fix i_size use */
1038 bEnabled = p_playlist->items.i_size > 1;
1041 else if( [[o_mi title] isEqualToString: _NS("Random")] )
1044 var_Get( p_playlist, "random", &val );
1045 i_state = val.b_bool ? NSOnState : NSOffState;
1046 [o_mi setState: i_state];
1048 else if( [[o_mi title] isEqualToString: _NS("Repeat One")] )
1051 var_Get( p_playlist, "repeat", &val );
1052 i_state = val.b_bool ? NSOnState : NSOffState;
1053 [o_mi setState: i_state];
1055 else if( [[o_mi title] isEqualToString: _NS("Repeat All")] )
1058 var_Get( p_playlist, "loop", &val );
1059 i_state = val.b_bool ? NSOnState : NSOffState;
1060 [o_mi setState: i_state];
1062 else if( [[o_mi title] isEqualToString: _NS("Step Forward")] ||
1063 [[o_mi title] isEqualToString: _NS("Step Backward")] ||
1064 [[o_mi title] isEqualToString: _NS("Jump To Time")])
1066 if( p_input != NULL )
1068 var_Get( p_input, "can-seek", &val);
1069 bEnabled = val.b_bool;
1071 else bEnabled = FALSE;
1073 else if( [[o_mi title] isEqualToString: _NS("Mute")] )
1075 [o_mi setState: p_intf->p_sys->b_mute ? NSOnState : NSOffState];
1076 [o_main setupMenus]; /* Make sure audio menu is up to date */
1078 else if( [[o_mi title] isEqualToString: _NS("Half Size")] ||
1079 [[o_mi title] isEqualToString: _NS("Normal Size")] ||
1080 [[o_mi title] isEqualToString: _NS("Double Size")] ||
1081 [[o_mi title] isEqualToString: _NS("Fit to Screen")] ||
1082 [[o_mi title] isEqualToString: _NS("Snapshot")] ||
1083 [[o_mi title] isEqualToString: _NS("Fullscreen")] ||
1084 [[o_mi title] isEqualToString: _NS("Float on Top")] )
1087 NSArray *o_windows = [NSApp orderedWindows];
1088 NSEnumerator *o_enumerator = [o_windows objectEnumerator];
1091 vout_thread_t *p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1093 if( p_vout != NULL )
1095 if( [[o_mi title] isEqualToString: _NS("Float on Top")] )
1097 var_Get( p_vout, "video-on-top", &val );
1098 [o_mi setState: val.b_bool ? NSOnState : NSOffState];
1101 while( (o_window = [o_enumerator nextObject]))
1103 if( [[o_window className] isEqualToString: @"VLCVoutWindow"] ||
1104 [[[VLCMain sharedInstance] embeddedList]
1105 windowContainsEmbedded: o_window])
1112 vlc_object_release( (vlc_object_t *)p_vout );
1114 if( [[o_mi title] isEqualToString: _NS("Fullscreen")] )
1116 var_Get( p_playlist, "fullscreen", &val );
1117 [o_mi setState: val.b_bool];
1120 [o_main setupMenus]; /* Make sure video menu is up to date */
1123 /* Special case for telx menu */
1124 if( [[o_mi title] isEqualToString: _NS("Normal Size")] )
1126 NSMenuItem *item = [[o_mi menu] itemWithTitle:_NS("Teletext")];
1127 bool b_telx = p_input && var_GetInteger( p_input, "teletext-es" ) >= 0;
1129 [[item submenu] setAutoenablesItems:NO];
1130 for( int k=0; k < [[item submenu] numberOfItems]; k++ )
1132 [[[item submenu] itemAtIndex:k] setEnabled: b_telx];
1136 if( p_input ) vlc_object_release( p_input );
1137 pl_Release( p_intf );
1144 /*****************************************************************************
1145 * VLCAutoGeneratedMenuContent implementation
1146 *****************************************************************************
1147 * Object connected to a playlistitem which remembers the data belonging to
1148 * the variable of the autogenerated menu
1149 *****************************************************************************/
1150 @implementation VLCAutoGeneratedMenuContent
1152 -(id) initWithVariableName:(const char *)name ofObject:(vlc_object_t *)object
1153 andValue:(vlc_value_t)val ofType:(int)type
1155 self = [super init];
1159 psz_name = strdup( name );
1160 _vlc_object = vlc_object_hold( object );
1170 vlc_object_release( _vlc_object );
1175 - (const char *)name
1180 - (vlc_value_t)value
1185 - (vlc_object_t *)vlcObject
1187 return vlc_object_hold( _vlc_object );
1199 /*****************************************************************************
1200 * VLCTimeField implementation
1201 *****************************************************************************
1202 * we need this to catch our click-event in the controller window
1203 *****************************************************************************/
1205 @implementation VLCTimeField
1206 - (void)mouseDown: (NSEvent *)ourEvent
1208 if( [ourEvent clickCount] > 1 )
1209 [[[VLCMain sharedInstance] controls] goToSpecificTime: nil];
1211 [[VLCMain sharedInstance] timeFieldWasClicked: self];