1 /*****************************************************************************
2 * controls.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2007 the VideoLAN team
7 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8 * Christophe Massiot <massiot@via.ecp.fr>
9 * Derk-Jan Hartman <hartman at videolan dot org>
10 * Benjamin Pracht <bigben at videolan doit org>
11 * Felix Kühne <fkuehne at videolan dot org>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
28 /*****************************************************************************
30 *****************************************************************************/
31 #include <stdlib.h> /* malloc(), free() */
32 #include <sys/param.h> /* for MAXPATHLEN */
43 /*****************************************************************************
44 * 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];
82 [o_specificTime_mi setTitle: _NS("Jump To Time")];
83 [o_specificTime_cancel_btn setTitle: _NS("Cancel")];
84 [o_specificTime_ok_btn setTitle: _NS("OK")];
85 [o_specificTime_sec_lbl setStringValue: _NS("sec.")];
86 [o_specificTime_goTo_lbl setStringValue: _NS("Jump to time")];
88 o_repeat_off = [NSImage imageNamed:@"repeat_embedded"];
90 [self controlTintChanged];
92 [[NSNotificationCenter defaultCenter] addObserver: self
93 selector: @selector( controlTintChanged )
94 name: NSControlTintDidChangeNotification
98 - (void)controlTintChanged
101 if( [o_btn_repeat image] == o_repeat_single )
103 else if( [o_btn_repeat image] == o_repeat_all )
106 if( [NSColor currentControlTint] == NSGraphiteControlTint )
108 o_repeat_single = [NSImage imageNamed:@"repeat_single_embedded_graphite"];
109 o_repeat_all = [NSImage imageNamed:@"repeat_embedded_graphite"];
111 [o_btn_shuffle setAlternateImage: [NSImage imageNamed: @"shuffle_embedded_graphite"]];
112 [o_btn_addNode setAlternateImage: [NSImage imageNamed: @"add_embedded_graphite"]];
116 o_repeat_single = [NSImage imageNamed:@"repeat_single_embedded_blue"];
117 o_repeat_all = [NSImage imageNamed:@"repeat_embedded_blue"];
119 [o_btn_shuffle setAlternateImage: [NSImage imageNamed: @"shuffle_embedded_blue"]];
120 [o_btn_addNode setAlternateImage: [NSImage imageNamed: @"add_embedded_blue"]];
123 /* update the repeat button, but keep its state */
126 else if( i_repeat == 2 )
134 [[NSNotificationCenter defaultCenter] removeObserver: self];
136 [o_repeat_single release];
137 [o_repeat_all release];
138 [o_repeat_off release];
143 - (IBAction)play:(id)sender
145 intf_thread_t * p_intf = VLCIntf;
146 playlist_t * p_playlist = pl_Hold( p_intf );
150 empty = playlist_IsEmpty( p_playlist );
153 pl_Release( p_intf );
156 [o_main intfOpenFileGeneric: (id)sender];
158 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_PLAY_PAUSE );
165 id embeddedViewList = [[VLCMain sharedInstance] getEmbeddedList];
166 NSEnumerator *enumerator = [[NSApp orderedWindows] objectEnumerator];
167 while( !voutView && ( window = [enumerator nextObject] ) )
169 /* We have an embedded vout */
170 if( [embeddedViewList windowContainsEmbedded: window] )
172 voutView = [embeddedViewList getViewForWindow: window];
174 /* We have a detached vout */
175 else if( [[window className] isEqualToString: @"VLCVoutWindow"] )
177 msg_Dbg( VLCIntf, "detached vout controls.m call voutView" );
178 voutView = [window voutView];
181 return [[voutView retain] autorelease];
184 - (IBAction)stop:(id)sender
186 intf_thread_t * p_intf = VLCIntf;
187 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_STOP );
188 /* Close the window directly, because we do know that there
189 * won't be anymore video. It's currently waiting a bit. */
190 [[[self voutView] window] orderOut:self];
193 - (IBAction)faster:(id)sender
195 intf_thread_t * p_intf = VLCIntf;
196 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_FASTER );
199 - (IBAction)slower:(id)sender
201 intf_thread_t * p_intf = VLCIntf;
202 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_SLOWER );
205 - (IBAction)prev:(id)sender
207 intf_thread_t * p_intf = VLCIntf;
208 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_PREV );
211 - (IBAction)next:(id)sender
213 intf_thread_t * p_intf = VLCIntf;
214 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_NEXT );
217 - (IBAction)random:(id)sender
220 intf_thread_t * p_intf = VLCIntf;
221 playlist_t * p_playlist = pl_Hold( p_intf );
223 var_Get( p_playlist, "random", &val );
224 val.b_bool = !val.b_bool;
225 var_Set( p_playlist, "random", val );
228 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Random On" ) );
229 config_PutInt( p_playlist, "random", 1 );
233 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Random Off" ) );
234 config_PutInt( p_playlist, "random", 0 );
237 p_intf->p_sys->b_playmode_update = true;
238 p_intf->p_sys->b_intf_update = true;
239 vlc_object_release( p_playlist );
242 /* three little ugly helpers */
245 [o_btn_repeat setImage: o_repeat_single];
246 [o_btn_repeat setAlternateImage: o_repeat_all];
250 [o_btn_repeat setImage: o_repeat_all];
251 [o_btn_repeat setAlternateImage: o_repeat_off];
255 [o_btn_repeat setImage: o_repeat_off];
256 [o_btn_repeat setAlternateImage: o_repeat_single];
261 playlist_t *p_playlist = pl_Hold( VLCIntf );
262 var_Get( p_playlist, "random", &val );
263 [o_btn_shuffle setState: val.b_bool];
264 vlc_object_release( p_playlist );
267 - (IBAction)repeatButtonAction:(id)sender
269 vlc_value_t looping,repeating;
270 intf_thread_t * p_intf = VLCIntf;
271 playlist_t * p_playlist = pl_Hold( p_intf );
273 var_Get( p_playlist, "repeat", &repeating );
274 var_Get( p_playlist, "loop", &looping );
276 if( !repeating.b_bool && !looping.b_bool )
278 /* was: no repeating at all, switching to Repeat One */
280 /* set our button's look */
283 /* prepare core communication */
284 repeating.b_bool = true;
285 looping.b_bool = false;
286 config_PutInt( p_playlist, "repeat", 1 );
287 config_PutInt( p_playlist, "loop", 0 );
289 /* show the change */
290 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
292 else if( repeating.b_bool && !looping.b_bool )
294 /* was: Repeat One, switching to Repeat All */
296 /* set our button's look */
299 /* prepare core communication */
300 repeating.b_bool = false;
301 looping.b_bool = true;
302 config_PutInt( p_playlist, "repeat", 0 );
303 config_PutInt( p_playlist, "loop", 1 );
305 /* show the change */
306 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
310 /* was: Repeat All or bug in VLC, switching to Repeat Off */
312 /* set our button's look */
315 /* prepare core communication */
316 repeating.b_bool = false;
317 looping.b_bool = false;
318 config_PutInt( p_playlist, "repeat", 0 );
319 config_PutInt( p_playlist, "loop", 0 );
321 /* show the change */
322 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
325 /* communicate with core and the main intf loop */
326 var_Set( p_playlist, "repeat", repeating );
327 var_Set( p_playlist, "loop", looping );
328 p_intf->p_sys->b_playmode_update = true;
329 p_intf->p_sys->b_intf_update = true;
331 vlc_object_release( p_playlist );
335 - (IBAction)repeat:(id)sender
338 intf_thread_t * p_intf = VLCIntf;
339 playlist_t * p_playlist = pl_Hold( p_intf );
341 var_Get( p_playlist, "repeat", &val );
344 var_Set( p_playlist, "loop", val );
346 val.b_bool = !val.b_bool;
347 var_Set( p_playlist, "repeat", val );
350 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
351 config_PutInt( p_playlist, "repeat", 1 );
355 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
356 config_PutInt( p_playlist, "repeat", 0 );
359 p_intf->p_sys->b_playmode_update = true;
360 p_intf->p_sys->b_intf_update = true;
361 vlc_object_release( p_playlist );
364 - (IBAction)loop:(id)sender
367 intf_thread_t * p_intf = VLCIntf;
368 playlist_t * p_playlist = pl_Hold( p_intf );
370 var_Get( p_playlist, "loop", &val );
373 var_Set( p_playlist, "repeat", val );
375 val.b_bool = !val.b_bool;
376 var_Set( p_playlist, "loop", val );
379 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
380 config_PutInt( p_playlist, "loop", 1 );
384 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
385 config_PutInt( p_playlist, "loop", 0 );
388 p_intf->p_sys->b_playmode_update = true;
389 p_intf->p_sys->b_intf_update = true;
390 vlc_object_release( p_playlist );
393 - (IBAction)forward:(id)sender
395 intf_thread_t * p_intf = VLCIntf;
396 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_SHORT );
399 - (IBAction)backward:(id)sender
402 intf_thread_t * p_intf = VLCIntf;
403 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_SHORT );
407 - (IBAction)volumeUp:(id)sender
409 intf_thread_t * p_intf = VLCIntf;
410 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_UP );
411 /* Manage volume status */
412 [o_main manageVolumeSlider];
415 - (IBAction)volumeDown:(id)sender
417 intf_thread_t * p_intf = VLCIntf;
418 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_DOWN );
419 /* Manage volume status */
420 [o_main manageVolumeSlider];
423 - (IBAction)mute:(id)sender
425 intf_thread_t * p_intf = VLCIntf;
426 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_MUTE );
427 /* Manage volume status */
428 [o_main manageVolumeSlider];
431 - (IBAction)volumeSliderUpdated:(id)sender
433 intf_thread_t * p_intf = VLCIntf;
434 audio_volume_t i_volume = (audio_volume_t)[sender intValue];
435 int i_volume_step = 0;
436 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
437 aout_VolumeSet( p_intf, i_volume * i_volume_step );
438 /* Manage volume status */
439 [o_main manageVolumeSlider];
442 - (IBAction)showPosition: (id)sender
444 vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT,
448 intf_thread_t * p_intf = VLCIntf;
449 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_POSITION );
450 vlc_object_release( (vlc_object_t *)p_vout );
454 - (IBAction)toogleFullscreen:(id)sender {
455 NSMenuItem *o_mi = [[NSMenuItem alloc] initWithTitle: _NS("Fullscreen") action: nil keyEquivalent:@""];
456 [self windowAction: [o_mi autorelease]];
459 - (BOOL) isFullscreen {
460 id o_vout_view = [self voutView];
463 return [o_vout_view isFullscreen];
468 - (IBAction)windowAction:(id)sender
470 NSString *o_title = [sender title];
472 vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT,
476 id o_vout_view = [self voutView];
479 if( [o_title isEqualToString: _NS("Half Size") ] )
480 [o_vout_view scaleWindowWithFactor: 0.5 animate: YES];
481 else if( [o_title isEqualToString: _NS("Normal Size") ] )
482 [o_vout_view scaleWindowWithFactor: 1.0 animate: YES];
483 else if( [o_title isEqualToString: _NS("Double Size") ] )
484 [o_vout_view scaleWindowWithFactor: 2.0 animate: YES];
485 else if( [o_title isEqualToString: _NS("Float on Top") ] )
486 [o_vout_view toggleFloatOnTop];
487 else if( [o_title isEqualToString: _NS("Fit to Screen") ] )
489 id o_window = [o_vout_view getWindow];
490 if( ![o_window isZoomed] )
491 [o_window performZoom:self];
493 else if( [o_title isEqualToString: _NS("Snapshot") ] )
495 [o_vout_view snapshot];
499 /* Fullscreen state for next time will be saved here too */
500 [o_vout_view toggleFullscreen];
503 vlc_object_release( (vlc_object_t *)p_vout );
507 playlist_t * p_playlist = pl_Hold( VLCIntf );
509 if( [o_title isEqualToString: _NS("Fullscreen")] ||
510 [sender isKindOfClass:[NSButton class]] )
513 var_Get( p_playlist, "fullscreen", &val );
514 var_Set( p_playlist, "fullscreen", (vlc_value_t)!val.b_bool );
517 pl_Release( VLCIntf );
522 - (IBAction)telxTransparent:(id)sender
524 intf_thread_t * p_intf = VLCIntf;
526 p_vbi = (vlc_object_t *) vlc_object_find_name( p_intf,
527 "zvbi", FIND_ANYWHERE );
530 var_SetBool( p_vbi, "vbi-opaque", [sender state] );
531 [sender setState: ![sender state]];
532 vlc_object_release( p_vbi );
536 - (IBAction)telxNavLink:(id)sender;
538 intf_thread_t * p_intf = VLCIntf;
542 if( [[sender title] isEqualToString: _NS("Index")] )
544 else if( [[sender title] isEqualToString: _NS("Red")] )
546 else if( [[sender title] isEqualToString: _NS("Green")] )
548 else if( [[sender title] isEqualToString: _NS("Yellow")] )
550 else if( [[sender title] isEqualToString: _NS("Blue")] )
552 if( i_page == 0 ) return;
554 p_vbi = (vlc_object_t *) vlc_object_find_name( p_intf,
555 "zvbi", FIND_ANYWHERE );
558 var_SetInteger( p_vbi, "vbi-page", i_page );
559 vlc_object_release( p_vbi );
563 - (void)scrollWheel:(NSEvent *)theEvent
565 intf_thread_t * p_intf = VLCIntf;
566 float f_yabsvalue = [theEvent deltaY] > 0.0f ? [theEvent deltaY] : -[theEvent deltaY];
567 float f_xabsvalue = [theEvent deltaX] > 0.0f ? [theEvent deltaX] : -[theEvent deltaX];
568 int i, i_yvlckey, i_xvlckey;
570 if ([theEvent deltaY] < 0.0f)
571 i_yvlckey = KEY_MOUSEWHEELDOWN;
573 i_yvlckey = KEY_MOUSEWHEELUP;
575 if ([theEvent deltaX] < 0.0f)
576 i_xvlckey = KEY_MOUSEWHEELRIGHT;
578 i_xvlckey = KEY_MOUSEWHEELLEFT;
580 /* Send multiple key event, depending on the intensity of the event */
581 for (i = 0; i < (int)(f_yabsvalue/4.+1.) && f_yabsvalue > 0.05 ; i++)
582 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_yvlckey );
584 /* Prioritize Y event (sound volume) over X event */
585 if (f_yabsvalue < 0.05)
587 for (i = 0; i < (int)(f_xabsvalue/6.+1.) && f_xabsvalue > 0.05; i++)
588 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_xvlckey );
592 - (BOOL)keyEvent:(NSEvent *)o_event
594 BOOL eventHandled = NO;
595 unichar key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
599 vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT,
604 if( key == (unichar) 0x1b )
606 id o_vout_view = [self voutView];
607 if( o_vout_view && [o_vout_view isFullscreen] )
609 [o_vout_view toggleFullscreen];
613 else if( key == ' ' )
618 vlc_object_release( (vlc_object_t *)p_vout );
624 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
625 target:(vlc_object_t *)p_object
626 var:(const char *)psz_variable
627 selector:(SEL)pf_callback
629 vlc_value_t val, text;
630 int i_type = var_Type( p_object, psz_variable );
632 switch( i_type & VLC_VAR_TYPE )
636 case VLC_VAR_VARIABLE:
638 case VLC_VAR_INTEGER:
641 /* Variable doesn't exist or isn't handled */
645 /* Make sure we want to display the variable */
646 if( i_type & VLC_VAR_HASCHOICE )
648 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
649 if( val.i_int == 0 ) return;
650 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
654 /* Get the descriptive name of the variable */
655 var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
656 [o_mi setTitle: [[VLCMain sharedInstance] localizedString: text.psz_string ?
657 text.psz_string : strdup( psz_variable ) ]];
659 var_Get( p_object, psz_variable, &val );
660 if( i_type & VLC_VAR_HASCHOICE )
662 NSMenu *o_menu = [o_mi submenu];
664 [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
665 var:psz_variable selector:pf_callback];
667 free( text.psz_string );
671 VLCAutoGeneratedMenuContent *o_data;
672 switch( i_type & VLC_VAR_TYPE )
675 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
676 andValue: val ofType: i_type];
677 [o_mi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
681 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
682 andValue: val ofType: i_type];
683 [o_mi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
684 if( !( i_type & VLC_VAR_ISCOMMAND ) )
685 [o_mi setState: val.b_bool ? TRUE : FALSE ];
689 free( text.psz_string );
693 if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
694 free( text.psz_string );
698 - (void)setupVarMenu:(NSMenu *)o_menu
699 forMenuItem: (NSMenuItem *)o_parent
700 target:(vlc_object_t *)p_object
701 var:(const char *)psz_variable
702 selector:(SEL)pf_callback
704 vlc_value_t val, val_list, text_list;
705 int i_type, i, i_nb_items;
707 /* remove previous items */
708 i_nb_items = [o_menu numberOfItems];
709 for( i = 0; i < i_nb_items; i++ )
711 [o_menu removeItemAtIndex: 0];
714 /* Check the type of the object variable */
715 i_type = var_Type( p_object, psz_variable );
717 /* Make sure we want to display the variable */
718 if( i_type & VLC_VAR_HASCHOICE )
720 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
721 if( val.i_int == 0 ) return;
722 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
730 switch( i_type & VLC_VAR_TYPE )
734 case VLC_VAR_VARIABLE:
736 case VLC_VAR_INTEGER:
739 /* Variable doesn't exist or isn't handled */
743 if( var_Get( p_object, psz_variable, &val ) < 0 )
748 if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
749 &val_list, &text_list ) < 0 )
751 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
755 /* make (un)sensitive */
756 [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
758 for( i = 0; i < val_list.p_list->i_count; i++ )
760 vlc_value_t another_val;
762 NSString *o_title = @"";
763 VLCAutoGeneratedMenuContent *o_data;
765 switch( i_type & VLC_VAR_TYPE )
768 another_val.psz_string =
769 strdup(val_list.p_list->p_values[i].psz_string);
771 o_title = [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string ?
772 text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
774 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
775 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: strdup(psz_variable) ofObject: p_object
776 andValue: another_val ofType: i_type];
777 [o_lmi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
778 [o_lmi setTarget: self];
780 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
781 [o_lmi setState: TRUE ];
785 case VLC_VAR_INTEGER:
787 o_title = text_list.p_list->p_values[i].psz_string ?
788 [[VLCMain sharedInstance] localizedString: strdup( text_list.p_list->p_values[i].psz_string )] :
789 [NSString stringWithFormat: @"%d",
790 val_list.p_list->p_values[i].i_int];
792 o_lmi = [[o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""] retain ];
793 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: strdup(psz_variable) ofObject: p_object
794 andValue: val_list.p_list->p_values[i] ofType: i_type];
795 [o_lmi setRepresentedObject: [NSValue valueWithPointer:[ o_data retain]]];
796 [o_lmi setTarget: self];
798 if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
799 [o_lmi setState: TRUE ];
807 /* clean up everything */
808 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
809 var_Change( p_object, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list );
812 - (IBAction)toggleVar:(id)sender
814 NSMenuItem *o_mi = (NSMenuItem *)sender;
815 VLCAutoGeneratedMenuContent *o_data = [[o_mi representedObject] pointerValue];
816 [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
817 toTarget: self withObject: o_data];
822 - (int)toggleVarThread: (id)data
824 vlc_object_t *p_object;
825 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
827 assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
828 VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
830 vlc_thread_set_priority( VLCIntf , VLC_THREAD_PRIORITY_LOW );
832 p_object = [menuContent vlcObject];
834 if( p_object != NULL )
836 var_Set( p_object, [menuContent name], [menuContent value] );
837 vlc_object_release( p_object );
845 - (IBAction)goToSpecificTime:(id)sender
847 if( sender == o_specificTime_cancel_btn )
849 [NSApp endSheet: o_specificTime_win];
850 [o_specificTime_win close];
852 else if( sender == o_specificTime_ok_btn )
854 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
857 unsigned int timeInSec = 0;
858 NSString * fieldContent = [o_specificTime_enter_fld stringValue];
859 if( [[fieldContent componentsSeparatedByString: @":"] count] > 1 &&
860 [[fieldContent componentsSeparatedByString: @":"] count] <= 3 )
862 NSArray * ourTempArray = \
863 [fieldContent componentsSeparatedByString: @":"];
865 if( [[fieldContent componentsSeparatedByString: @":"] count] == 3 )
867 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 3600); //h
868 timeInSec += ([[ourTempArray objectAtIndex: 1] intValue] * 60); //m
869 timeInSec += [[ourTempArray objectAtIndex: 2] intValue]; //s
873 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 60); //m
874 timeInSec += [[ourTempArray objectAtIndex: 1] intValue]; //s
878 timeInSec = [fieldContent intValue];
880 input_Control( p_input, INPUT_SET_TIME, (int64_t)(timeInSec * 1000000));
881 vlc_object_release( p_input );
884 [NSApp endSheet: o_specificTime_win];
885 [o_specificTime_win close];
889 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
892 /* we can obviously only do that if an input is available */
893 vlc_value_t pos, length;
894 var_Get( p_input, "time", &pos );
895 [o_specificTime_enter_fld setIntValue: (pos.i_time / 1000000)];
896 var_Get( p_input, "length", &length );
897 [o_specificTime_stepper setMaxValue: (length.i_time / 1000000)];
899 [NSApp beginSheet: o_specificTime_win modalForWindow: \
900 [NSApp mainWindow] modalDelegate: self didEndSelector: nil \
902 [o_specificTime_win makeKeyWindow];
903 vlc_object_release( p_input );
914 msg_Err( VLCIntf, "FSPanel is nil" );
921 @implementation VLCControls (NSMenuValidation)
923 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
925 BOOL bEnabled = TRUE;
927 intf_thread_t * p_intf = VLCIntf;
928 playlist_t * p_playlist = pl_Hold( p_intf );
929 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
931 if( [[o_mi title] isEqualToString: _NS("Faster")] ||
932 [[o_mi title] isEqualToString: _NS("Slower")] )
934 if( p_input != NULL )
936 bEnabled = p_input->b_can_pace_control;
943 else if( [[o_mi title] isEqualToString: _NS("Stop")] )
945 if( p_input == NULL )
949 [o_main setupMenus]; /* Make sure input menu is up to date */
951 else if( [[o_mi title] isEqualToString: _NS("Previous")] ||
952 [[o_mi title] isEqualToString: _NS("Next")] )
954 /** \todo fix i_size use */
956 bEnabled = p_playlist->items.i_size > 1;
959 else if( [[o_mi title] isEqualToString: _NS("Random")] )
962 var_Get( p_playlist, "random", &val );
963 i_state = val.b_bool ? NSOnState : NSOffState;
964 [o_mi setState: i_state];
966 else if( [[o_mi title] isEqualToString: _NS("Repeat One")] )
969 var_Get( p_playlist, "repeat", &val );
970 i_state = val.b_bool ? NSOnState : NSOffState;
971 [o_mi setState: i_state];
973 else if( [[o_mi title] isEqualToString: _NS("Repeat All")] )
976 var_Get( p_playlist, "loop", &val );
977 i_state = val.b_bool ? NSOnState : NSOffState;
978 [o_mi setState: i_state];
980 else if( [[o_mi title] isEqualToString: _NS("Step Forward")] ||
981 [[o_mi title] isEqualToString: _NS("Step Backward")] ||
982 [[o_mi title] isEqualToString: _NS("Jump To Time")])
984 if( p_input != NULL )
986 var_Get( p_input, "seekable", &val);
987 bEnabled = val.b_bool;
989 else bEnabled = FALSE;
991 else if( [[o_mi title] isEqualToString: _NS("Mute")] )
993 [o_mi setState: p_intf->p_sys->b_mute ? NSOnState : NSOffState];
994 [o_main setupMenus]; /* Make sure audio menu is up to date */
996 else if( [[o_mi title] isEqualToString: _NS("Half Size")] ||
997 [[o_mi title] isEqualToString: _NS("Normal Size")] ||
998 [[o_mi title] isEqualToString: _NS("Double Size")] ||
999 [[o_mi title] isEqualToString: _NS("Fit to Screen")] ||
1000 [[o_mi title] isEqualToString: _NS("Snapshot")] ||
1001 [[o_mi title] isEqualToString: _NS("Fullscreen")] ||
1002 [[o_mi title] isEqualToString: _NS("Float on Top")] )
1005 NSArray *o_windows = [NSApp orderedWindows];
1006 NSEnumerator *o_enumerator = [o_windows objectEnumerator];
1009 vout_thread_t *p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1011 if( p_vout != NULL )
1013 if( [[o_mi title] isEqualToString: _NS("Float on Top")] )
1015 var_Get( p_vout, "video-on-top", &val );
1016 [o_mi setState: val.b_bool ? NSOnState : NSOffState];
1019 while( (o_window = [o_enumerator nextObject]))
1021 if( [[o_window className] isEqualToString: @"VLCVoutWindow"] ||
1022 [[[VLCMain sharedInstance] getEmbeddedList]
1023 windowContainsEmbedded: o_window])
1030 vlc_object_release( (vlc_object_t *)p_vout );
1032 if( [[o_mi title] isEqualToString: _NS("Fullscreen")] )
1034 var_Get( p_playlist, "fullscreen", &val );
1035 [o_mi setState: val.b_bool];
1038 [o_main setupMenus]; /* Make sure video menu is up to date */
1041 /* Special case for telx menu */
1042 if( [[o_mi title] isEqualToString: _NS("Normal Size")] );
1044 NSMenuItem *item = [[o_mi menu] itemWithTitle:_NS("Teletext")];
1045 bool b_telx = false;
1048 const int i_teletext_es = var_GetInteger( p_input, "teletext-es" );
1049 const int i_spu_es = var_GetInteger( p_input, "spu-es" );
1051 if( i_teletext_es >= 0 && i_teletext_es == i_spu_es )
1054 [[item submenu] setAutoenablesItems:NO];
1055 for( int k=0; k < [[item submenu] numberOfItems]; k++ )
1057 [[[item submenu] itemAtIndex:k] setEnabled: b_telx];
1061 if( p_input ) vlc_object_release( p_input );
1062 vlc_object_release( p_playlist );
1069 /*****************************************************************************
1070 * VLCAutoGeneratedMenuContent implementation
1071 *****************************************************************************
1072 * Object connected to a playlistitem which remembers the data belonging to
1073 * the variable of the autogenerated menu
1074 *****************************************************************************/
1075 @implementation VLCAutoGeneratedMenuContent
1077 -(id) initWithVariableName:(const char *)name ofObject:(vlc_object_t *)object
1078 andValue:(vlc_value_t)val ofType:(int)type
1080 self = [super init];
1084 psz_name = strdup( name );
1085 _vlc_object = vlc_object_hold( object );
1095 vlc_object_release( _vlc_object );
1100 - (const char *)name
1105 - (vlc_value_t)value
1110 - (vlc_object_t *)vlcObject
1112 return vlc_object_hold( _vlc_object );
1124 /*****************************************************************************
1125 * VLCTimeField implementation
1126 *****************************************************************************
1127 * we need this to catch our click-event in the controller window
1128 *****************************************************************************/
1130 @implementation VLCTimeField
1131 - (void)mouseDown: (NSEvent *)ourEvent
1133 if( [ourEvent clickCount] > 1 )
1134 [[[VLCMain sharedInstance] getControls] goToSpecificTime: nil];