X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fmacosx%2Fmisc.m;h=b20ab77fff7d42f949b825ae1c0d0185e5438308;hb=f35c3d113308cf288376db1a6a342ed2b324f257;hp=678c91746ad5c880bfa60d58bd686fa0b388ee99;hpb=8fd45605df2306b336be809947e5eb5c458ed3d3;p=vlc diff --git a/modules/gui/macosx/misc.m b/modules/gui/macosx/misc.m index 678c91746a..b20ab77fff 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-2013 VLC authors and VideoLAN + * Copyright (C) 2003-2014 VLC authors and VideoLAN * $Id$ * * Authors: Jon Lech Johansen @@ -22,6 +22,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ +#import "CompatibilityFixes.h" #import "misc.h" #import "intf.h" /* VLCApplication */ #import "MainWindow.h" @@ -165,10 +166,22 @@ static NSMapTable *VLCAdditions_userInfo = NULL; static NSMutableArray *blackoutWindows = NULL; +static bool b_old_spaces_style = YES; + + (void)load { /* init our fake object attribute */ blackoutWindows = [[NSMutableArray alloc] initWithCapacity:1]; + + if (OSX_MAVERICKS || OSX_YOSEMITE) { + NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init]; + [userDefaults addSuiteNamed:@"com.apple.spaces"]; + /* this is system settings -> mission control -> monitors using different spaces */ + NSNumber *o_span_displays = [userDefaults objectForKey:@"spans-displays"]; + + b_old_spaces_style = [o_span_displays boolValue]; + [userDefaults release]; + } } + (NSScreen *)screenWithDisplayID: (CGDirectDisplayID)displayID @@ -185,7 +198,10 @@ static NSMutableArray *blackoutWindows = NULL; - (BOOL)hasMenuBar { - return ([self displayID] == [[[NSScreen screens] objectAtIndex:0] displayID]); + if (b_old_spaces_style) + return ([self displayID] == [[[NSScreen screens] objectAtIndex:0] displayID]); + else + return YES; } - (BOOL)hasDock @@ -239,6 +255,7 @@ static NSMutableArray *blackoutWindows = NULL; backing: NSBackingStoreBuffered defer: NO screen: screen]; [blackoutWindow setBackgroundColor:[NSColor blackColor]]; [blackoutWindow setLevel: NSFloatingWindowLevel]; /* Disappear when Expose is triggered */ + [blackoutWindow setReleasedWhenClosed:NO]; // window is released when deleted from array above [blackoutWindow displayIfNeeded]; [blackoutWindow orderFront: self animate: YES]; @@ -284,10 +301,42 @@ static NSMutableArray *blackoutWindows = NULL; @end /***************************************************************************** - * VLBrushedMetalImageView + * VLCDragDropView + *****************************************************************************/ + +@implementation VLCDropDisabledImageView + +- (void)awakeFromNib +{ + [self unregisterDraggedTypes]; +} + +@end + +/***************************************************************************** + * VLCDragDropView *****************************************************************************/ -@implementation VLBrushedMetalImageView +@implementation VLCDragDropView + +@synthesize dropHandler=_dropHandler; +@synthesize drawBorder; + +- (id)initWithFrame:(NSRect)frame +{ + self = [super initWithFrame:frame]; + if (self) { + // default value + [self setDrawBorder:YES]; + } + + return self; +} + +- (void)enablePlaylistItems +{ + [self registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, @"VLCPlaylistItemPboardType", nil]]; +} - (BOOL)mouseDownCanMoveWindow { @@ -302,20 +351,33 @@ static NSMutableArray *blackoutWindows = NULL; - (void)awakeFromNib { - [self registerForDraggedTypes:@[NSFilenamesPboardType]]; - [self setImageScaling: NSScaleToFit]; - [self setImageFrameStyle: NSImageFrameNone]; - [self setImageAlignment: NSImageAlignCenter]; + [self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]]; } - (NSDragOperation)draggingEntered:(id )sender { - if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) == NSDragOperationGeneric) - return NSDragOperationGeneric; + if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) == NSDragOperationGeneric) { + b_activeDragAndDrop = YES; + [self setNeedsDisplay:YES]; + + return NSDragOperationCopy; + } return NSDragOperationNone; } +- (void)draggingEnded:(id < NSDraggingInfo >)sender +{ + b_activeDragAndDrop = NO; + [self setNeedsDisplay:YES]; +} + +- (void)draggingExited:(id < NSDraggingInfo >)sender +{ + b_activeDragAndDrop = NO; + [self setNeedsDisplay:YES]; +} + - (BOOL)prepareForDragOperation:(id )sender { return YES; @@ -324,7 +386,11 @@ static NSMutableArray *blackoutWindows = NULL; - (BOOL)performDragOperation:(id )sender { BOOL b_returned; - b_returned = [[VLCCoreInteraction sharedInstance] performDragOperation: sender]; + + if (_dropHandler && [_dropHandler respondsToSelector:@selector(performDragOperation:)]) + b_returned = [_dropHandler performDragOperation: sender]; + else // default + b_returned = [[VLCCoreInteraction sharedInstance] performDragOperation: sender]; [self setNeedsDisplay:YES]; return b_returned; @@ -335,6 +401,18 @@ static NSMutableArray *blackoutWindows = NULL; [self setNeedsDisplay:YES]; } +- (void)drawRect:(NSRect)dirtyRect +{ + if ([self drawBorder] && b_activeDragAndDrop) { + NSRect frameRect = [self bounds]; + + [[NSColor selectedControlColor] set]; + NSFrameRectWithWidthUsingOperation(frameRect, 2., NSCompositeHighlight); + } + + [super drawRect:dirtyRect]; +} + @end @@ -410,7 +488,6 @@ void _drawFrameInRect(NSRect frameRect) - (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]; @@ -456,10 +533,10 @@ void _drawFrameInRect(NSRect frameRect) - (void)awakeFromNib { if (config_GetInt( VLCIntf, "macosx-interfacestyle" )) { - o_knob_img = [NSImage imageNamed:@"progression-knob_dark"]; + o_knob_img = imageFromRes(@"progression-knob_dark"); b_dark = YES; } else { - o_knob_img = [NSImage imageNamed:@"progression-knob"]; + o_knob_img = imageFromRes(@"progression-knob"); b_dark = NO; } img_rect.size = [o_knob_img size]; @@ -515,7 +592,6 @@ void _drawFrameInRect(NSRect frameRect) - (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]; @@ -528,7 +604,6 @@ void _drawFrameInRect(NSRect frameRect) // 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; @@ -611,9 +686,9 @@ void _drawFrameInRect(NSRect frameRect) { BOOL b_dark = config_GetInt( VLCIntf, "macosx-interfacestyle" ); if (b_dark) - img = [NSImage imageNamed:@"volume-slider-knob_dark"]; + img = imageFromRes(@"volume-slider-knob_dark"); else - img = [NSImage imageNamed:@"volume-slider-knob"]; + img = imageFromRes(@"volume-slider-knob"); image_rect.size = [img size]; image_rect.origin.x = 0; @@ -656,7 +731,8 @@ void _drawFrameInRect(NSRect frameRect) *****************************************************************************/ @implementation VLCTimeField -+ (void)initialize{ ++ (void)initialize +{ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys: @"NO", @"DisplayTimeAsTimeRemaining", @@ -666,16 +742,6 @@ void _drawFrameInRect(NSRect frameRect) [defaults registerDefaults:appDefaults]; } -- (id)initWithFrame:(NSRect)frameRect -{ - if (self = [super initWithFrame:frameRect]) { - textAlignment = NSCenterTextAlignment; - o_remaining_identifier = @""; - } - - return self; -} - - (void)setRemainingIdentifier:(NSString *)o_string { o_remaining_identifier = o_string; @@ -718,24 +784,19 @@ void _drawFrameInRect(NSRect frameRect) [[[VLCMain sharedInstance] controls] goToSpecificTime: nil]; else { - 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 { + if (o_remaining_identifier) { + b_time_remaining = [[NSUserDefaults standardUserDefaults] boolForKey:o_remaining_identifier]; b_time_remaining = !b_time_remaining; [[NSUserDefaults standardUserDefaults] setObject:(b_time_remaining ? @"YES" : @"NO") forKey:o_remaining_identifier]; + } else { + b_time_remaining = !b_time_remaining; } } } - (BOOL)timeRemaining { - if (![o_remaining_identifier isEqualToString: @""]) + if (o_remaining_identifier) return [[NSUserDefaults standardUserDefaults] boolForKey:o_remaining_identifier]; else return b_time_remaining; @@ -799,52 +860,6 @@ void _drawFrameInRect(NSRect frameRect) @end -@implementation VLCThreePartDropView - -- (BOOL)mouseDownCanMoveWindow -{ - return YES; -} - -- (void)dealloc -{ - [self unregisterDraggedTypes]; - [super dealloc]; -} - -- (void)awakeFromNib -{ - [self registerForDraggedTypes:@[NSFilenamesPboardType]]; -} - -- (NSDragOperation)draggingEntered:(id )sender -{ - if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) == NSDragOperationGeneric) - return NSDragOperationGeneric; - - return NSDragOperationNone; -} - -- (BOOL)prepareForDragOperation:(id )sender -{ - return YES; -} - -- (BOOL)performDragOperation:(id )sender -{ - BOOL b_returned; - b_returned = [[VLCCoreInteraction sharedInstance] performDragOperation: sender]; - - [self setNeedsDisplay:YES]; - return YES; -} - -- (void)concludeDragOperation:(id )sender -{ - [self setNeedsDisplay:YES]; -} - -@end @implementation PositionFormatter @@ -852,7 +867,7 @@ void _drawFrameInRect(NSRect frameRect) { self = [super init]; NSMutableCharacterSet *nonNumbers = [[[NSCharacterSet decimalDigitCharacterSet] invertedSet] mutableCopy]; - [nonNumbers removeCharactersInString:@":"]; + [nonNumbers removeCharactersInString:@"-:"]; o_forbidden_characters = [nonNumbers copy]; [nonNumbers release]; @@ -867,7 +882,12 @@ void _drawFrameInRect(NSRect frameRect) - (NSString*)stringForObjectValue:(id)obj { - return obj; + if([obj isKindOfClass:[NSString class]]) + return obj; + if([obj isKindOfClass:[NSNumber class]]) + return [obj stringValue]; + + return nil; } - (BOOL)getObjectValue:(id*)obj forString:(NSString*)string errorDescription:(NSString**)error @@ -876,7 +896,7 @@ void _drawFrameInRect(NSRect frameRect) return YES; } -- (bool)isPartialStringValid:(NSString*)partialString newEditingString:(NSString**)newString errorDescription:(NSString**)error +- (BOOL)isPartialStringValid:(NSString*)partialString newEditingString:(NSString**)newString errorDescription:(NSString**)error { if ([partialString rangeOfCharacterFromSet:o_forbidden_characters options:NSLiteralSearch].location != NSNotFound) { return NO; @@ -885,7 +905,6 @@ void _drawFrameInRect(NSRect frameRect) } } - @end @implementation NSView (EnableSubviews) @@ -912,3 +931,72 @@ void _drawFrameInRect(NSRect frameRect) } @end + +/***************************************************************************** + * VLCByteCountFormatter addition + *****************************************************************************/ + +@implementation VLCByteCountFormatter + ++ (NSString *)stringFromByteCount:(long long)byteCount countStyle:(NSByteCountFormatterCountStyle)countStyle +{ + // Use native implementation on >= mountain lion + Class byteFormatterClass = NSClassFromString(@"NSByteCountFormatter"); + if (byteFormatterClass && [byteFormatterClass respondsToSelector:@selector(stringFromByteCount:countStyle:)]) { + return [byteFormatterClass stringFromByteCount:byteCount countStyle:NSByteCountFormatterCountStyleFile]; + } + + float devider = 0.; + float returnValue = 0.; + NSString *suffix; + + NSNumberFormatter *theFormatter = [[NSNumberFormatter alloc] init]; + [theFormatter setLocale:[NSLocale currentLocale]]; + [theFormatter setAllowsFloats:YES]; + + NSString *returnString = @""; + + if (countStyle != NSByteCountFormatterCountStyleDecimal) + devider = 1024.; + else + devider = 1000.; + + if (byteCount < 1000) { + returnValue = byteCount; + suffix = _NS("B"); + [theFormatter setMaximumFractionDigits:0]; + goto end; + } + + if (byteCount < 1000000) { + returnValue = byteCount / devider; + suffix = _NS("KB"); + [theFormatter setMaximumFractionDigits:0]; + goto end; + } + + if (byteCount < 1000000000) { + returnValue = byteCount / devider / devider; + suffix = _NS("MB"); + [theFormatter setMaximumFractionDigits:1]; + goto end; + } + + [theFormatter setMaximumFractionDigits:2]; + if (byteCount < 1000000000000) { + returnValue = byteCount / devider / devider / devider; + suffix = _NS("GB"); + goto end; + } + + returnValue = byteCount / devider / devider / devider / devider; + suffix = _NS("TB"); + +end: + returnString = [NSString stringWithFormat:@"%@ %@", [theFormatter stringFromNumber:[NSNumber numberWithFloat:returnValue]], suffix]; + [theFormatter release]; + + return returnString; +} + +@end