]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/misc.m
macosx: compilation fix
[vlc] / modules / gui / macosx / misc.m
index c6ae9b56c9f7061fca68d5c231cce04db096570c..b3689faeb614a26192a0f558dbf535d23bb0c5c6 100644 (file)
@@ -165,10 +165,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_REDACTED) {
+        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
@@ -176,7 +188,7 @@ static NSMutableArray *blackoutWindows = NULL;
     NSUInteger count = [[NSScreen screens] count];
 
     for ( NSUInteger i = 0; i < count; i++ ) {
-        NSScreen *screen = [NSScreen screens][i];
+        NSScreen *screen = [[NSScreen screens] objectAtIndex:i];
         if ([screen displayID] == displayID)
             return screen;
     }
@@ -185,7 +197,10 @@ static NSMutableArray *blackoutWindows = NULL;
 
 - (BOOL)hasMenuBar
 {
-    return ([self displayID] == [[NSScreen screens][0] displayID]);
+    if (b_old_spaces_style)
+        return ([self displayID] == [[[NSScreen screens] objectAtIndex:0] displayID]);
+    else
+        return YES;
 }
 
 - (BOOL)hasDock
@@ -221,7 +236,7 @@ static NSMutableArray *blackoutWindows = NULL;
 
     NSUInteger screenCount = [[NSScreen screens] count];
     for (NSUInteger i = 0; i < screenCount; i++) {
-        NSScreen *screen = [NSScreen screens][i];
+        NSScreen *screen = [[NSScreen screens] objectAtIndex:i];
         VLCWindow *blackoutWindow;
         NSRect screen_rect;
 
@@ -239,6 +254,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];
@@ -255,7 +271,7 @@ static NSMutableArray *blackoutWindows = NULL;
     NSUInteger blackoutWindowCount = [blackoutWindows count];
 
     for (NSUInteger i = 0; i < blackoutWindowCount; i++) {
-        VLCWindow *blackoutWindow = blackoutWindows[i];
+        VLCWindow *blackoutWindow = [blackoutWindows objectAtIndex:i];
         [[blackoutWindow screen] setNonFullscreenPresentationOptions];
         [blackoutWindow closeAndAnimate: YES];
     }
@@ -302,7 +318,7 @@ static NSMutableArray *blackoutWindows = NULL;
 
 - (void)awakeFromNib
 {
-    [self registerForDraggedTypes:@[NSFilenamesPboardType]];
+    [self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
     [self setImageScaling: NSScaleToFit];
     [self setImageFrameStyle: NSImageFrameNone];
     [self setImageAlignment: NSImageAlignCenter];
@@ -511,6 +527,8 @@ void _drawFrameInRect(NSRect frameRect)
 
 @implementation VLCVolumeSliderCommon : NSSlider
 
+@synthesize usesBrightArtwork = _usesBrightArtwork;
+
 - (void)scrollWheel:(NSEvent *)o_event
 {
     intf_thread_t * p_intf = VLCIntf;
@@ -543,6 +561,60 @@ void _drawFrameInRect(NSRect frameRect)
     }
 }
 
+- (void)drawFullVolumeMarker
+{
+    CGFloat maxAudioVol = self.maxValue / AOUT_VOLUME_DEFAULT;
+    if (maxAudioVol < 1.)
+        return;
+
+    NSColor *drawingColor;
+    // for bright artwork, a black color is used and vice versa
+    if (_usesBrightArtwork)
+        drawingColor = [[NSColor blackColor] colorWithAlphaComponent:.4];
+    else
+        drawingColor = [[NSColor whiteColor] colorWithAlphaComponent:.4];
+
+    NSBezierPath* bezierPath = [NSBezierPath bezierPath];
+    [self drawFullVolBezierPath:bezierPath];
+    [bezierPath closePath];
+
+    bezierPath.lineWidth = 1.;
+    [drawingColor setStroke];
+    [bezierPath stroke];
+}
+
+- (CGFloat)fullVolumePos
+{
+    CGFloat maxAudioVol = self.maxValue / AOUT_VOLUME_DEFAULT;
+    CGFloat sliderRange = [self frame].size.width - [self knobThickness];
+    CGFloat sliderOrigin = [self knobThickness] / 2.;
+
+    return 1. / maxAudioVol * sliderRange + sliderOrigin;
+}
+
+- (void)drawFullVolBezierPath:(NSBezierPath*)bezierPath
+{
+    CGFloat fullVolPos = [self fullVolumePos];
+    [bezierPath moveToPoint:NSMakePoint(fullVolPos, [self frame].size.height - 3.)];
+    [bezierPath lineToPoint:NSMakePoint(fullVolPos, 2.)];
+}
+
+@end
+
+@implementation VolumeSliderCell
+
+- (BOOL)continueTracking:(NSPoint)lastPoint at:(NSPoint)currentPoint inView:(NSView *)controlView
+{
+    VLCVolumeSliderCommon *o_slider = (VLCVolumeSliderCommon *)controlView;
+    CGFloat fullVolumePos = [o_slider fullVolumePos] + 2.;
+
+    CGPoint snapToPoint = currentPoint;
+    if (ABS(fullVolumePos - currentPoint.x) <= 4.)
+        snapToPoint.x = fullVolumePos;
+
+    return [super continueTracking:lastPoint at:snapToPoint inView:controlView];
+}
+
 @end
 
 /*****************************************************************************
@@ -584,6 +656,8 @@ void _drawFrameInRect(NSRect frameRect)
     [super drawRect:rect];
     [[NSGraphicsContext currentContext] restoreGraphicsState];
 
+    [self drawFullVolumeMarker];
+
     NSRect knobRect = [[self cell] knobRectFlipped:NO];
     knobRect.origin.y+=2;
     [self drawKnobInRect: knobRect];
@@ -604,7 +678,7 @@ void _drawFrameInRect(NSRect frameRect)
                                  @"NO", @"DisplayTimeAsTimeRemaining",
                                  @"YES", @"DisplayFullscreenTimeAsTimeRemaining",
                                  nil];
-    
+
     [defaults registerDefaults:appDefaults];
 }
 
@@ -614,7 +688,7 @@ void _drawFrameInRect(NSRect frameRect)
         textAlignment = NSCenterTextAlignment;
         o_remaining_identifier = @"";
     }
-    
+
     return self;
 }
 
@@ -756,7 +830,7 @@ void _drawFrameInRect(NSRect frameRect)
 
 - (void)awakeFromNib
 {
-    [self registerForDraggedTypes:@[NSFilenamesPboardType]];
+    [self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
 }
 
 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
@@ -809,7 +883,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
@@ -828,4 +907,29 @@ void _drawFrameInRect(NSRect frameRect)
 }
 
 
+@end
+
+@implementation NSView (EnableSubviews)
+
+- (void)enableSubviews:(BOOL)b_enable
+{
+    for (NSView *o_view in [self subviews]) {
+        [o_view enableSubviews:b_enable];
+
+        // enable NSControl
+        if ([o_view respondsToSelector:@selector(setEnabled:)]) {
+            [(NSControl *)o_view setEnabled:b_enable];
+        }
+        // also "enable / disable" text views
+        if ([o_view respondsToSelector:@selector(setTextColor:)]) {
+            if (b_enable == NO) {
+                [(NSTextField *)o_view setTextColor:[NSColor disabledControlTextColor]];
+            } else {
+                [(NSTextField *)o_view setTextColor:[NSColor controlTextColor]];
+            }
+        }
+
+    }
+}
+
 @end