X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fmacosx%2Fmisc.m;h=62779b18246b5f52a331b7dbb12366a68fe0dbe9;hb=2828486c4579fe1950af50d953aa1103137f3ace;hp=34fa00efc3bd2f2020447f0a1c354accf43dab14;hpb=acc847396cd8d3ef8c246c18da39bc7ac69425a8;p=vlc diff --git a/modules/gui/macosx/misc.m b/modules/gui/macosx/misc.m index 34fa00efc3..62779b1824 100644 --- a/modules/gui/macosx/misc.m +++ b/modules/gui/macosx/misc.m @@ -1,7 +1,7 @@ /***************************************************************************** * misc.m: code not specific to vlc ***************************************************************************** - * Copyright (C) 2003-2011 VLC authors and VideoLAN + * Copyright (C) 2003-2013 VLC authors and VideoLAN * $Id$ * * Authors: Jon Lech Johansen @@ -22,16 +22,105 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#import -#import - -#import "CompatibilityFixes.h" +#import "misc.h" #import "intf.h" /* VLCApplication */ #import "MainWindow.h" -#import "misc.h" -#import "playlist.h" +#import "ControlsBar.h" #import "controls.h" -#import +#import "CoreInteraction.h" +#import +#import + + +/***************************************************************************** + * NSSound (VLCAdditions) + * + * added code to change the system volume, needed for the apple remote code + * this is simplified code, which won't let you set the exact volume + * (that's what the audio output is for after all), but just the system volume + * in steps of 1/16 (matching the default AR or volume key implementation). + *****************************************************************************/ + +@implementation NSSound (VLCAdditions) + ++ (float)systemVolumeForChannel:(int)channel +{ + AudioDeviceID i_device; + float f_volume; + OSStatus err; + UInt32 i_size; + + i_size = sizeof( i_device ); + AudioObjectPropertyAddress deviceAddress = { kAudioHardwarePropertyDefaultOutputDevice, kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementMaster }; + err = AudioObjectGetPropertyData( kAudioObjectSystemObject, &deviceAddress, 0, NULL, &i_size, &i_device ); + if (err != noErr) { + msg_Warn( VLCIntf, "couldn't get main audio output device" ); + return .0; + } + + AudioObjectPropertyAddress propertyAddress = { kAudioDevicePropertyVolumeScalar, kAudioDevicePropertyScopeOutput, channel }; + i_size = sizeof( f_volume ); + err = AudioObjectGetPropertyData(i_device, &propertyAddress, 0, NULL, &i_size, &f_volume); + if (err != noErr) { + msg_Warn( VLCIntf, "couldn't get volume value" ); + return .0; + } + + return f_volume; +} + ++ (bool)setSystemVolume:(float)f_volume forChannel:(int)i_channel +{ + /* the following code will fail on S/PDIF devices. there is an easy work-around, but we'd like to match the OS behavior */ + + AudioDeviceID i_device; + OSStatus err; + UInt32 i_size; + Boolean b_writeable; + + i_size = sizeof( i_device ); + AudioObjectPropertyAddress deviceAddress = { kAudioHardwarePropertyDefaultOutputDevice, kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementMaster }; + err = AudioObjectGetPropertyData( kAudioObjectSystemObject, &deviceAddress, 0, NULL, &i_size, &i_device ); + if (err != noErr) { + msg_Warn( VLCIntf, "couldn't get main audio output device" ); + return NO; + } + + AudioObjectPropertyAddress propertyAddress = { kAudioDevicePropertyVolumeScalar, kAudioDevicePropertyScopeOutput, i_channel }; + i_size = sizeof( f_volume ); + err = AudioObjectIsPropertySettable( i_device, &propertyAddress, &b_writeable ); + if (err != noErr || !b_writeable ) { + msg_Warn( VLCIntf, "we can't set the main audio devices' volume" ); + return NO; + } + err = AudioObjectSetPropertyData(i_device, &propertyAddress, 0, NULL, i_size, &f_volume); + + return YES; +} + ++ (void)increaseSystemVolume +{ + float f_volume = [NSSound systemVolumeForChannel:1]; // we trust that mono is always available and that all channels got the same volume + f_volume += .0625; // 1/16 to match the OS + bool b_returned = YES; + + /* since core audio doesn't provide a reasonable way to see how many channels we got, let's see how long we can do this */ + for (NSUInteger x = 1; b_returned ; x++) + b_returned = [NSSound setSystemVolume: f_volume forChannel:x]; +} + ++ (void)decreaseSystemVolume +{ + float f_volume = [NSSound systemVolumeForChannel:1]; // we trust that mono is always available and that all channels got the same volume + f_volume -= .0625; // 1/16 to match the OS + bool b_returned = YES; + + /* since core audio doesn't provide a reasonable way to see how many channels we got, let's see how long we can do this */ + for (NSUInteger x = 1; b_returned ; x++) + b_returned = [NSSound setSystemVolume: f_volume forChannel:x]; +} + +@end /***************************************************************************** * NSAnimation (VLCAdditions) @@ -86,20 +175,34 @@ static NSMutableArray *blackoutWindows = NULL; { NSUInteger count = [[NSScreen screens] count]; - for( NSUInteger i = 0; i < count; i++ ) - { + for ( NSUInteger i = 0; i < count; i++ ) { NSScreen *screen = [[NSScreen screens] objectAtIndex: i]; - if([screen displayID] == displayID) + if ([screen displayID] == displayID) return screen; } return nil; } -- (BOOL)isMainScreen +- (BOOL)hasMenuBar { return ([self displayID] == [[[NSScreen screens] objectAtIndex:0] displayID]); } +- (BOOL)hasDock +{ + NSRect screen_frame = [self frame]; + NSRect screen_visible_frame = [self visibleFrame]; + CGFloat f_menu_bar_thickness = [self hasMenuBar] ? [[NSStatusBar systemStatusBar] thickness] : 0.0; + + BOOL b_found_dock = NO; + if (screen_visible_frame.size.width < screen_frame.size.width) + b_found_dock = YES; + else if (screen_visible_frame.size.height + f_menu_bar_thickness < screen_frame.size.height) + b_found_dock = YES; + + return b_found_dock; +} + - (BOOL)isScreen: (NSScreen*)screen { return ([self displayID] == [screen displayID]); @@ -107,7 +210,7 @@ static NSMutableArray *blackoutWindows = NULL; - (CGDirectDisplayID)displayID { - return (CGDirectDisplayID)[[[self deviceDescription] objectForKey: @"NSScreenNumber"] intValue]; + return (CGDirectDisplayID)[[[self deviceDescription] objectForKey: @"NSScreenNumber"] intValue]; } - (void)blackoutOtherScreens @@ -117,13 +220,12 @@ static NSMutableArray *blackoutWindows = NULL; [blackoutWindows removeAllObjects]; NSUInteger screenCount = [[NSScreen screens] count]; - for(NSUInteger i = 0; i < screenCount; i++) - { + for (NSUInteger i = 0; i < screenCount; i++) { NSScreen *screen = [[NSScreen screens] objectAtIndex: i]; VLCWindow *blackoutWindow; NSRect screen_rect; - if([self isScreen: screen]) + if ([self isScreen: screen]) continue; screen_rect = [screen frame]; @@ -144,16 +246,7 @@ static NSMutableArray *blackoutWindows = NULL; [blackoutWindows addObject: blackoutWindow]; [blackoutWindow release]; - if( [screen isMainScreen ] ) - { - if ([screen isMainScreen]) - { - if (OSX_LEOPARD) - SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar); - else - [NSApp setPresentationOptions:(NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)]; - } - } + [screen setFullscreenPresentationOptions]; } } @@ -161,306 +254,31 @@ static NSMutableArray *blackoutWindows = NULL; { NSUInteger blackoutWindowCount = [blackoutWindows count]; - for(NSUInteger i = 0; i < blackoutWindowCount; i++) - { + for (NSUInteger i = 0; i < blackoutWindowCount; i++) { VLCWindow *blackoutWindow = [blackoutWindows objectAtIndex: i]; + [[blackoutWindow screen] setNonFullscreenPresentationOptions]; [blackoutWindow closeAndAnimate: YES]; } - - if (OSX_LEOPARD) - SetSystemUIMode( kUIModeNormal, kUIOptionAutoShowMenuBar); - else - [NSApp setPresentationOptions:(NSApplicationPresentationDefault)]; -} - -@end - -/***************************************************************************** - * VLCWindow - * - * Missing extension to NSWindow - *****************************************************************************/ - -@implementation VLCWindow -- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask - backing:(NSBackingStoreType)backingType defer:(BOOL)flag -{ - self = [super initWithContentRect:contentRect styleMask:styleMask backing:backingType defer:flag]; - if( self ) - { - b_isFullscreen = NO; - b_isset_canBecomeKeyWindow = NO; - /* we don't want this window to be restored on relaunch */ - if (OSX_LION) - [self setRestorable:NO]; - } - return self; -} -- (void)setCanBecomeKeyWindow: (BOOL)canBecomeKey -{ - b_isset_canBecomeKeyWindow = YES; - b_canBecomeKeyWindow = canBecomeKey; -} - -- (BOOL)canBecomeKeyWindow -{ - if(b_isset_canBecomeKeyWindow) - return b_canBecomeKeyWindow; - - return [super canBecomeKeyWindow]; -} - -- (void)closeAndAnimate: (BOOL)animate -{ - NSInvocation *invoc; - - if (!animate) - { - [super close]; - return; - } - - invoc = [NSInvocation invocationWithMethodSignature:[super methodSignatureForSelector:@selector(close)]]; - [invoc setTarget: self]; - - if (![self isVisible] || [self alphaValue] == 0.0) - { - [super close]; - return; - } - - [self orderOut: self animate: YES callback: invoc]; -} - -- (void)orderOut: (id)sender animate: (BOOL)animate -{ - NSInvocation *invoc = [NSInvocation invocationWithMethodSignature:[super methodSignatureForSelector:@selector(orderOut:)]]; - [invoc setTarget: self]; - [invoc setArgument: sender atIndex: 0]; - [self orderOut: sender animate: animate callback: invoc]; -} - -- (void)orderOut: (id)sender animate: (BOOL)animate callback:(NSInvocation *)callback -{ - NSViewAnimation *anim; - NSViewAnimation *current_anim; - NSMutableDictionary *dict; - - if (!animate) - { - [self orderOut: sender]; - return; - } - - dict = [[NSMutableDictionary alloc] initWithCapacity:2]; - - [dict setObject:self forKey:NSViewAnimationTargetKey]; - - [dict setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey]; - anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict, nil]]; - [dict release]; - - [anim setAnimationBlockingMode:NSAnimationNonblocking]; - [anim setDuration:0.9]; - [anim setFrameRate:30]; - [anim setUserInfo: callback]; - - @synchronized(self) { - current_anim = self->animation; - - if ([[[current_anim viewAnimations] objectAtIndex:0] objectForKey: NSViewAnimationEffectKey] == NSViewAnimationFadeOutEffect && [current_anim isAnimating]) - { - [anim release]; - } - else - { - if (current_anim) - { - [current_anim stopAnimation]; - [anim setCurrentProgress:1.0-[current_anim currentProgress]]; - [current_anim release]; - } - else - [anim setCurrentProgress:1.0 - [self alphaValue]]; - self->animation = anim; - [self setDelegate: self]; - [anim startAnimation]; - } - } -} - -- (void)orderFront: (id)sender animate: (BOOL)animate -{ - NSViewAnimation *anim; - NSViewAnimation *current_anim; - NSMutableDictionary *dict; - - if (!animate) - { - [super orderFront: sender]; - [self setAlphaValue: 1.0]; - return; - } - - if (![self isVisible]) - { - [self setAlphaValue: 0.0]; - [super orderFront: sender]; - } - else if ([self alphaValue] == 1.0) - { - [super orderFront: self]; - return; - } - - dict = [[NSMutableDictionary alloc] initWithCapacity:2]; - - [dict setObject:self forKey:NSViewAnimationTargetKey]; - - [dict setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey]; - anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict, nil]]; - [dict release]; - - [anim setAnimationBlockingMode:NSAnimationNonblocking]; - [anim setDuration:0.5]; - [anim setFrameRate:30]; - - @synchronized(self) { - current_anim = self->animation; - - if ([[[current_anim viewAnimations] objectAtIndex:0] objectForKey: NSViewAnimationEffectKey] == NSViewAnimationFadeInEffect && [current_anim isAnimating]) - { - [anim release]; - } - else - { - if (current_anim) - { - [current_anim stopAnimation]; - [anim setCurrentProgress:1.0 - [current_anim currentProgress]]; - [current_anim release]; - } - else - [anim setCurrentProgress:[self alphaValue]]; - self->animation = anim; - [self setDelegate: self]; - [self orderFront: sender]; - [anim startAnimation]; - } - } -} - -- (void)animationDidEnd:(NSAnimation*)anim -{ - if ([self alphaValue] <= 0.0) - { - NSInvocation * invoc; - [super orderOut: nil]; - [self setAlphaValue: 1.0]; - if ((invoc = [anim userInfo])) - [invoc invoke]; - } -} - -- (void)setFullscreen:(BOOL)b_var -{ - b_isFullscreen = b_var; -} - -- (BOOL)isFullscreen -{ - return b_isFullscreen; -} - -@end - -/***************************************************************************** - * VLCControllerView - *****************************************************************************/ - -@implementation VLCControllerView - -- (void)dealloc -{ - [self unregisterDraggedTypes]; - [super dealloc]; -} - -- (void)awakeFromNib -{ - [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType, - NSFilenamesPboardType, nil]]; -} - -- (NSDragOperation)draggingEntered:(id )sender -{ - if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) - == NSDragOperationGeneric) - { - return NSDragOperationGeneric; - } - else - { - return NSDragOperationNone; - } -} - -- (BOOL)prepareForDragOperation:(id )sender -{ - return YES; } -- (BOOL)performDragOperation:(id )sender +- (void)setFullscreenPresentationOptions { - NSPasteboard *o_paste = [sender draggingPasteboard]; - NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil]; - NSString *o_desired_type = [o_paste availableTypeFromArray:o_types]; - NSData *o_carried_data = [o_paste dataForType:o_desired_type]; - - if( o_carried_data ) - { - if ([o_desired_type isEqualToString:NSFilenamesPboardType]) - { - NSArray *o_array = [NSArray array]; - NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; - NSUInteger count = [o_values count]; - - input_thread_t * p_input = pl_CurrentInput( VLCIntf ); - BOOL b_returned = NO; - - if (count == 1 && p_input) - { - b_returned = input_AddSubtitle( p_input, make_URI([[o_values objectAtIndex:0] UTF8String], NULL), true ); - vlc_object_release( p_input ); - if(!b_returned) - return YES; - } - else if( p_input ) - vlc_object_release( p_input ); - - for( NSUInteger i = 0; i < count; i++) - { - NSDictionary *o_dic; - char *psz_uri = make_URI([[o_values objectAtIndex:i] UTF8String], NULL); - if( !psz_uri ) - continue; - - o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"]; - - free( psz_uri ); - o_array = [o_array arrayByAddingObject: o_dic]; - } - [(VLCPlaylist *)[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:NO]; - return YES; - } - } - [self setNeedsDisplay:YES]; - return YES; + NSApplicationPresentationOptions presentationOpts = [NSApp presentationOptions]; + if ([self hasMenuBar]) + presentationOpts |= NSApplicationPresentationAutoHideMenuBar; + if ([self hasMenuBar] || [self hasDock]) + presentationOpts |= NSApplicationPresentationAutoHideDock; + [NSApp setPresentationOptions:presentationOpts]; } -- (void)concludeDragOperation:(id )sender +- (void)setNonFullscreenPresentationOptions { - [self setNeedsDisplay:YES]; + NSApplicationPresentationOptions presentationOpts = [NSApp presentationOptions]; + if ([self hasMenuBar]) + presentationOpts &= (~NSApplicationPresentationAutoHideMenuBar); + if ([self hasMenuBar] || [self hasDock]) + presentationOpts &= (~NSApplicationPresentationAutoHideDock); + [NSApp setPresentationOptions:presentationOpts]; } @end @@ -484,8 +302,7 @@ static NSMutableArray *blackoutWindows = NULL; - (void)awakeFromNib { - [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType, - NSFilenamesPboardType, nil]]; + [self registerForDraggedTypes:[NSArray arrayWithObject: NSFilenamesPboardType]]; [self setImageScaling: NSScaleToFit]; [self setImageFrameStyle: NSImageFrameNone]; [self setImageAlignment: NSImageAlignCenter]; @@ -493,15 +310,10 @@ static NSMutableArray *blackoutWindows = NULL; - (NSDragOperation)draggingEntered:(id )sender { - if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) - == NSDragOperationGeneric) - { + if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) == NSDragOperationGeneric) return NSDragOperationGeneric; - } - else - { - return NSDragOperationNone; - } + + return NSDragOperationNone; } - (BOOL)prepareForDragOperation:(id )sender @@ -511,54 +323,11 @@ static NSMutableArray *blackoutWindows = NULL; - (BOOL)performDragOperation:(id )sender { - NSPasteboard *o_paste = [sender draggingPasteboard]; - NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil]; - NSString *o_desired_type = [o_paste availableTypeFromArray:o_types]; - NSData *o_carried_data = [o_paste dataForType:o_desired_type]; - BOOL b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" ); - - if( o_carried_data ) - { - if ([o_desired_type isEqualToString:NSFilenamesPboardType]) - { - NSArray *o_array = [NSArray array]; - NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; - NSUInteger count = [o_values count]; - - input_thread_t * p_input = pl_CurrentInput( VLCIntf ); - BOOL b_returned = NO; - - if (count == 1 && p_input) - { - b_returned = input_AddSubtitle( p_input, make_URI([[o_values objectAtIndex:0] UTF8String], NULL), true ); - vlc_object_release( p_input ); - if(!b_returned) - return YES; - } - else if( p_input ) - vlc_object_release( p_input ); + BOOL b_returned; + b_returned = [[VLCCoreInteraction sharedInstance] performDragOperation: sender]; - for( NSUInteger i = 0; i < count; i++) - { - NSDictionary *o_dic; - char *psz_uri = make_URI([[o_values objectAtIndex:i] UTF8String], NULL); - if( !psz_uri ) - continue; - - o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"]; - free( psz_uri ); - - o_array = [o_array arrayByAddingObject: o_dic]; - } - if( b_autoplay ) - [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:NO]; - else - [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:YES]; - return YES; - } - } [self setNeedsDisplay:YES]; - return YES; + return b_returned; } - (void)concludeDragOperation:(id )sender @@ -633,6 +402,51 @@ void _drawFrameInRect(NSRect frameRect) @end +/***************************************************************************** + * ProgressView + *****************************************************************************/ + +@implementation VLCProgressView : NSView + +- (void)scrollWheel:(NSEvent *)o_event +{ + intf_thread_t * p_intf = VLCIntf; + BOOL b_forward = NO; + CGFloat f_deltaY = [o_event deltaY]; + CGFloat f_deltaX = [o_event deltaX]; + + if (!OSX_SNOW_LEOPARD && [o_event isDirectionInvertedFromDevice]) + f_deltaX = -f_deltaX; // optimisation, actually double invertion of f_deltaY here + else + f_deltaY = -f_deltaY; + + // positive for left / down, negative otherwise + CGFloat f_delta = f_deltaX + f_deltaY; + CGFloat f_abs; + int i_vlckey; + + if (f_delta > 0.0f) + f_abs = f_delta; + else { + b_forward = YES; + f_abs = -f_delta; + } + + for (NSUInteger i = 0; i < (int)(f_abs/4.+1.) && f_abs > 0.05 ; i++) { + if (b_forward) + [[VLCCoreInteraction sharedInstance] forwardExtraShort]; + else + [[VLCCoreInteraction sharedInstance] backwardExtraShort]; + } +} + +- (BOOL)acceptsFirstResponder +{ + return YES; +} + +@end + /***************************************************************************** * TimeLineSlider *****************************************************************************/ @@ -641,10 +455,13 @@ void _drawFrameInRect(NSRect frameRect) - (void)awakeFromNib { - if (config_GetInt( VLCIntf, "macosx-interfacestyle" )) + if (config_GetInt( VLCIntf, "macosx-interfacestyle" )) { o_knob_img = [NSImage imageNamed:@"progression-knob_dark"]; - else + b_dark = YES; + } else { o_knob_img = [NSImage imageNamed:@"progression-knob"]; + b_dark = NO; + } img_rect.size = [o_knob_img size]; img_rect.origin.x = img_rect.origin.y = 0; } @@ -672,6 +489,9 @@ void _drawFrameInRect(NSRect frameRect) - (void)drawRect:(NSRect)rect { + [[[[VLCMain sharedInstance] mainWindow] controlsBar] drawFancyGradientEffectForTimeSlider]; + msleep( 10000 ); //wait for the gradient to draw completely + /* Draw default to make sure the slider behaves correctly */ [[NSGraphicsContext currentContext] saveGraphicsState]; NSRectClip(NSZeroRect); @@ -685,6 +505,46 @@ void _drawFrameInRect(NSRect frameRect) @end +/***************************************************************************** + * VLCVolumeSliderCommon + *****************************************************************************/ + +@implementation VLCVolumeSliderCommon : NSSlider + +- (void)scrollWheel:(NSEvent *)o_event +{ + intf_thread_t * p_intf = VLCIntf; + BOOL b_up = NO; + CGFloat f_deltaY = [o_event deltaY]; + CGFloat f_deltaX = [o_event deltaX]; + + if (!OSX_SNOW_LEOPARD && [o_event isDirectionInvertedFromDevice]) + f_deltaX = -f_deltaX; // optimisation, actually double invertion of f_deltaY here + else + f_deltaY = -f_deltaY; + + // positive for left / down, negative otherwise + CGFloat f_delta = f_deltaX + f_deltaY; + CGFloat f_abs; + int i_vlckey; + + if (f_delta > 0.0f) + f_abs = f_delta; + else { + b_up = YES; + f_abs = -f_delta; + } + + for (NSUInteger i = 0; i < (int)(f_abs/4.+1.) && f_abs > 0.05 ; i++) { + if (b_up) + [[VLCCoreInteraction sharedInstance] volumeUp]; + else + [[VLCCoreInteraction sharedInstance] volumeDown]; + } +} + +@end + /***************************************************************************** * ITSlider *****************************************************************************/ @@ -740,21 +600,28 @@ void _drawFrameInRect(NSRect frameRect) @implementation VLCTimeField + (void)initialize{ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:@"NO" forKey:@"DisplayTimeAsTimeRemaining"]; - + NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys: + @"NO", @"DisplayTimeAsTimeRemaining", + @"YES", @"DisplayFullscreenTimeAsTimeRemaining", + nil]; + [defaults registerDefaults:appDefaults]; } -- (void)awakeFromNib +- (id)initWithFrame:(NSRect)frameRect { - NSColor *o_string_color; - if (!config_GetInt( VLCIntf, "macosx-interfacestyle")) - o_string_color = [NSColor colorWithCalibratedRed:0.229 green:0.229 blue:0.229 alpha:100.0]; - else - o_string_color = [NSColor colorWithCalibratedRed:0.64 green:0.64 blue:0.64 alpha:100.0]; + if (self = [super initWithFrame:frameRect]) { + textAlignment = NSCenterTextAlignment; + o_remaining_identifier = @""; + } + + return self; +} - textAlignment = NSCenterTextAlignment; - o_string_attributes_dict = [[NSDictionary dictionaryWithObjectsAndKeys: o_string_color, NSForegroundColorAttributeName, [NSFont titleBarFontOfSize:10.0], NSFontAttributeName, nil] retain]; +- (void)setRemainingIdentifier:(NSString *)o_string +{ + o_remaining_identifier = o_string; + b_time_remaining = [[NSUserDefaults standardUserDefaults] boolForKey:o_remaining_identifier]; } - (void)setAlignment:(NSTextAlignment)alignment @@ -766,20 +633,19 @@ void _drawFrameInRect(NSRect frameRect) - (void)dealloc { [o_string_shadow release]; - [o_string_attributes_dict release]; + [super dealloc]; } - (void)setStringValue:(NSString *)string { - if (!o_string_shadow) - { + if (!o_string_shadow) { o_string_shadow = [[NSShadow alloc] init]; [o_string_shadow setShadowColor: [NSColor colorWithCalibratedWhite:1.0 alpha:0.5]]; - [o_string_shadow setShadowOffset:NSMakeSize(0.0, -1.5)]; + [o_string_shadow setShadowOffset:NSMakeSize(0.0, -1.0)]; [o_string_shadow setShadowBlurRadius:0.0]; } - NSMutableAttributedString *o_attributed_string = [[NSMutableAttributedString alloc] initWithString:string attributes: o_string_attributes_dict]; + NSMutableAttributedString *o_attributed_string = [[NSMutableAttributedString alloc] initWithString:string attributes: nil]; NSUInteger i_stringLength = [string length]; [o_attributed_string addAttribute: NSShadowAttributeName value: o_string_shadow range: NSMakeRange(0, i_stringLength)]; @@ -790,21 +656,33 @@ void _drawFrameInRect(NSRect frameRect) - (void)mouseDown: (NSEvent *)ourEvent { - if( [ourEvent clickCount] > 1 ) + if ( [ourEvent clickCount] > 1 ) [[[VLCMain sharedInstance] controls] goToSpecificTime: nil]; else { - if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DisplayTimeAsTimeRemaining"]) - [[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:@"DisplayTimeAsTimeRemaining"]; - else - [[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"DisplayTimeAsTimeRemaining"]; + if (![o_remaining_identifier isEqualToString: @""]) { + if ([[NSUserDefaults standardUserDefaults] boolForKey:o_remaining_identifier]) { + [[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:o_remaining_identifier]; + b_time_remaining = NO; + } else { + [[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:o_remaining_identifier]; + b_time_remaining = YES; + } + } else { + b_time_remaining = !b_time_remaining; + [[NSUserDefaults standardUserDefaults] setObject:(b_time_remaining ? @"YES" : @"NO") forKey:o_remaining_identifier]; + } } } - (BOOL)timeRemaining { - return [[NSUserDefaults standardUserDefaults] boolForKey:@"DisplayTimeAsTimeRemaining"]; + if (![o_remaining_identifier isEqualToString: @""]) + return [[NSUserDefaults standardUserDefaults] boolForKey:o_remaining_identifier]; + else + return b_time_remaining; } + @end /***************************************************************************** @@ -825,29 +703,13 @@ void _drawFrameInRect(NSRect frameRect) { return 1.0; } - -- (void)adjustSubviews -{ - NSArray *o_subviews = [self subviews]; - NSRect viewDimensions = [self frame]; - NSRect leftViewDimensions = [[o_subviews objectAtIndex:0] frame]; - NSRect rightViewDimensions = [[o_subviews objectAtIndex:1] frame]; - CGFloat f_dividerThickness = [self dividerThickness]; - - leftViewDimensions.size.height = viewDimensions.size.height; - [[o_subviews objectAtIndex:0] setFrame: leftViewDimensions]; - - rightViewDimensions.origin.x = leftViewDimensions.size.width + f_dividerThickness; - rightViewDimensions.size.width = viewDimensions.size.width - leftViewDimensions.size.width - f_dividerThickness; - rightViewDimensions.size.height = viewDimensions.size.height; - [[o_subviews objectAtIndex:1] setFrame: rightViewDimensions]; -} @end /***************************************************************************** * VLCThreePartImageView interface *****************************************************************************/ @implementation VLCThreePartImageView + - (void)dealloc { [o_left_img release]; @@ -894,21 +756,15 @@ void _drawFrameInRect(NSRect frameRect) - (void)awakeFromNib { - [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType, - NSFilenamesPboardType, nil]]; + [self registerForDraggedTypes:[NSArray arrayWithObject: NSFilenamesPboardType]]; } - (NSDragOperation)draggingEntered:(id )sender { - if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) - == NSDragOperationGeneric) - { + if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) == NSDragOperationGeneric) return NSDragOperationGeneric; - } - else - { - return NSDragOperationNone; - } + + return NSDragOperationNone; } - (BOOL)prepareForDragOperation:(id )sender @@ -918,52 +774,9 @@ void _drawFrameInRect(NSRect frameRect) - (BOOL)performDragOperation:(id )sender { - NSPasteboard *o_paste = [sender draggingPasteboard]; - NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil]; - NSString *o_desired_type = [o_paste availableTypeFromArray:o_types]; - NSData *o_carried_data = [o_paste dataForType:o_desired_type]; - BOOL b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" ); + BOOL b_returned; + b_returned = [[VLCCoreInteraction sharedInstance] performDragOperation: sender]; - if( o_carried_data ) - { - if ([o_desired_type isEqualToString:NSFilenamesPboardType]) - { - NSArray *o_array = [NSArray array]; - NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; - NSUInteger count = [o_values count]; - - input_thread_t * p_input = pl_CurrentInput( VLCIntf ); - BOOL b_returned = NO; - - if (count == 1 && p_input) - { - b_returned = input_AddSubtitle( p_input, make_URI([[o_values objectAtIndex:0] UTF8String], NULL), true ); - vlc_object_release( p_input ); - if(!b_returned) - return YES; - } - else if( p_input ) - vlc_object_release( p_input ); - - for( NSUInteger i = 0; i < count; i++) - { - NSDictionary *o_dic; - char *psz_uri = make_URI([[o_values objectAtIndex:i] UTF8String], NULL); - if( !psz_uri ) - continue; - - o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"]; - free( psz_uri ); - - o_array = [o_array arrayByAddingObject: o_dic]; - } - if( b_autoplay ) - [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:NO]; - else - [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:YES]; - return YES; - } - } [self setNeedsDisplay:YES]; return YES; }