]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/misc.m
macosx: Use input_ItemHasErrorWhenReading to display a small icon if there was an...
[vlc] / modules / gui / macosx / misc.m
index b60ec2e564d0457f1b971050b394c2431c6d95ec..3a033f820aed22e43137cceaba0b5a8dbccd8d9e 100644 (file)
@@ -1,10 +1,11 @@
 /*****************************************************************************
  * misc.m: code not specific to vlc
  *****************************************************************************
- * Copyright (C) 2003-2007 the VideoLAN team
+ * Copyright (C) 2003-2008 the VideoLAN team
  * $Id$
  *
  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
+ *          Felix Paul Kühne <fkuehne at videolan dot org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
-#include <Cocoa/Cocoa.h>
+#import <Cocoa/Cocoa.h>
+#import <QuickTime/QuickTime.h>
 
-#include "intf.h"                                          /* VLCApplication */
-#include "misc.h"
-#include "playlist.h"
-#include "controls.h"
+#import "intf.h"                                          /* VLCApplication */
+#import "misc.h"
+#import "playlist.h"
+#import "controls.h"
 
+/*****************************************************************************
+ * NSImage (VLCAdditions)
+ *
+ *  Addition to NSImage
+ *****************************************************************************/
+@implementation NSImage (VLCAdditions)
++ (id)imageWithSystemName:(int)name
+{
+    /* ugly Carbon stuff following...
+     * regrettably, you can't get the icons through clean Cocoa */
+
+    /* retrieve our error icon */
+    NSImage * icon;
+    IconRef ourIconRef;
+    int returnValue;
+    returnValue = GetIconRef(kOnSystemDisk, 'macs', name, &ourIconRef);
+    icon = [[[NSImage alloc] initWithSize:NSMakeSize(32,32)] autorelease];
+    [icon lockFocus];
+    CGRect rect = CGRectMake(0,0,32,32);
+    PlotIconRefInContext((CGContextRef)[[NSGraphicsContext currentContext]
+        graphicsPort],
+        &rect,
+        kAlignNone,
+        kTransformNone,
+        NULL /*inLabelColor*/,
+        kPlotIconRefNormalFlags,
+        (IconRef)ourIconRef);
+    [icon unlockFocus];
+    returnValue = ReleaseIconRef(ourIconRef);
+    return icon;
+}
+
++ (id)imageWithWarningIcon
+{
+    static NSImage * imageWithWarningIcon = nil;
+    if( !imageWithWarningIcon )
+    {
+        imageWithWarningIcon = [[[self class] imageWithSystemName:'caut'] retain];
+    }
+    return imageWithWarningIcon;
+}
+
++ (id)imageWithErrorIcon
+{
+    static NSImage * imageWithErrorIcon = nil;
+    if( !imageWithErrorIcon )
+    {
+        imageWithErrorIcon = [[[self class] imageWithSystemName:'stop'] retain];
+    }
+    return imageWithErrorIcon;
+}
+
+@end
 /*****************************************************************************
  * NSAnimation (VLCAdditions)
  *
@@ -80,7 +135,7 @@ static NSMutableArray *blackoutWindows = NULL;
 + (NSScreen *)screenWithDisplayID: (CGDirectDisplayID)displayID
 {
     int i;
-    
     for( i = 0; i < [[NSScreen screens] count]; i++ )
     {
         NSScreen *screen = [[NSScreen screens] objectAtIndex: i];
@@ -90,6 +145,16 @@ static NSMutableArray *blackoutWindows = NULL;
     return nil;
 }
 
+- (BOOL)isMainScreen
+{
+    return ([self displayID] == [[[NSScreen screens] objectAtIndex:0] displayID]);
+}
+
+- (BOOL)isScreen: (NSScreen*)screen
+{
+    return ([self displayID] == [screen displayID]);
+}
+
 - (CGDirectDisplayID)displayID
 {
     return (CGDirectDisplayID)_screenNumber;
@@ -103,25 +168,35 @@ static NSMutableArray *blackoutWindows = NULL;
     [blackoutWindows makeObjectsPerformSelector:@selector(close)];
     [blackoutWindows removeAllObjects];
 
-    
     for(i = 0; i < [[NSScreen screens] count]; i++)
     {
-        VLCWindow *blackoutWindow;
         NSScreen *screen = [[NSScreen screens] objectAtIndex: i];
-        if(self == screen)
+        VLCWindow *blackoutWindow;
+        NSRect screen_rect;
+        if([self isScreen: screen])
             continue;
+
+        screen_rect = [screen frame];
+        screen_rect.origin.x = screen_rect.origin.y = 0;
+
         /* blackoutWindow alloc strategy
             - The NSMutableArray blackoutWindows has the blackoutWindow references
             - blackoutOtherDisplays is responsible for alloc/releasing its Windows
         */
-        blackoutWindow = [[VLCWindow alloc] initWithContentRect: [screen frame] styleMask: NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
+        blackoutWindow = [[VLCWindow alloc] initWithContentRect: screen_rect styleMask: NSBorderlessWindowMask
+                backing: NSBackingStoreBuffered defer: NO screen: screen];
         [blackoutWindow setBackgroundColor:[NSColor blackColor]];
         [blackoutWindow setLevel: NSFloatingWindowLevel]; /* Disappear when Expose is triggered */
-        
+        [blackoutWindow displayIfNeeded];
         [blackoutWindow orderFront: self animate: YES];
 
         [blackoutWindows addObject: blackoutWindow];
         [blackoutWindow release];
+        
+        if( [screen isMainScreen ] )
+           SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
     }
 }
 
@@ -134,6 +209,8 @@ static NSMutableArray *blackoutWindows = NULL;
         VLCWindow *blackoutWindow = [blackoutWindows objectAtIndex: i];
         [blackoutWindow closeAndAnimate: YES];
     }
+    
+   SetSystemUIMode( kUIModeNormal, 0);
 }
 
 @end
@@ -170,7 +247,7 @@ static NSMutableArray *blackoutWindows = NULL;
 - (void)closeAndAnimate: (BOOL)animate
 {
     NSInvocation *invoc;
-    
     if (!animate || MACOS_VERSION < 10.4f)
     {
         [super close];
@@ -251,7 +328,7 @@ static NSMutableArray *blackoutWindows = NULL;
     NSViewAnimation *anim;
     NSViewAnimation *current_anim;
     NSMutableDictionary *dict;
-    
     if (!animate || MACOS_VERSION < 10.4f)
     {
         [super orderFront: sender];
@@ -273,11 +350,11 @@ static NSMutableArray *blackoutWindows = NULL;
     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];
@@ -364,24 +441,15 @@ static NSMutableArray *blackoutWindows = NULL;
     [super dealloc];
 }
 
-#if GC_ENABLED
-- (void)finalize
-{
-    /* dealloc doesn't get called on 10.5 if GC is enabled, so we need to provide the basic functionality here */
-    [self unregisterDraggedTypes];
-    [super finalize];
-}
-#endif
-
 - (void)awakeFromNib
 {
-    [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType, 
+    [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
         NSFilenamesPboardType, nil]];
 }
 
 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
 {
-    if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) 
+    if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
                 == NSDragOperationGeneric)
     {
         return NSDragOperationGeneric;
@@ -451,24 +519,15 @@ static NSMutableArray *blackoutWindows = NULL;
     [super dealloc];
 }
 
-#if GC_ENABLED
-- (void)finalize
-{
-    /* dealloc doesn't get called on 10.5 if GC is enabled, so we need to provide the basic functionality here */
-    [self unregisterDraggedTypes];
-    [super finalize];
-}
-#endif
-
 - (void)awakeFromNib
 {
-    [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType, 
+    [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
         NSFilenamesPboardType, nil]];
 }
 
 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
 {
-    if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) 
+    if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
                 == NSDragOperationGeneric)
     {
         return NSDragOperationGeneric;
@@ -536,7 +595,7 @@ void _drawKnobInRect(NSRect knobRect)
     // Center knob in given rect
     knobRect.origin.x += (int)((float)(knobRect.size.width - 7)/2.0);
     knobRect.origin.y += (int)((float)(knobRect.size.height - 7)/2.0);
-    
     // Draw diamond
     NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 3, knobRect.origin.y + 6, 1, 1), NSCompositeSourceOver);
     NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 2, knobRect.origin.y + 5, 3, 1), NSCompositeSourceOver);
@@ -563,7 +622,7 @@ void _drawFrameInRect(NSRect frameRect)
     NSRectClip(NSZeroRect);
     [super drawRect:rect];
     [[NSGraphicsContext currentContext] restoreGraphicsState];
-    
     // Full size
     rect = [self bounds];
     int diff = (int)(([[self cell] knobThickness] - 7.0)/2.0) - 1;
@@ -571,13 +630,13 @@ void _drawFrameInRect(NSRect frameRect)
     rect.origin.y += diff;
     rect.size.width -= 2*diff-2;
     rect.size.height -= 2*diff;
-    
     // Draw dark
     NSRect knobRect = [[self cell] knobRectFlipped:NO];
     [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
     _drawFrameInRect(rect);
     _drawKnobInRect(knobRect);
-    
     // Draw shadow
     [[[NSColor blackColor] colorWithAlphaComponent:0.1] set];
     rect.origin.x++;
@@ -608,7 +667,7 @@ void _drawFrameInRect(NSRect frameRect)
         [newCell setAction:[oldCell action]];
         [newCell setControlSize:[oldCell controlSize]];
         [newCell setType:[oldCell type]];
-        [newCell setState:[oldCell state]]; 
+        [newCell setState:[oldCell state]];
         [newCell setAllowsTickMarkValuesOnly:[oldCell allowsTickMarkValuesOnly]];
         [newCell setAltIncrementValue:[oldCell altIncrementValue]];
         [newCell setControlTint:[oldCell controlTint]];
@@ -636,14 +695,27 @@ void _drawFrameInRect(NSRect frameRect)
 - (id)init
 {
     self = [super init];
-    _knobOff = [[NSImage imageNamed:@"volumeslider_normal"] retain];
-    _knobOn = [[NSImage imageNamed:@"volumeslider_blue"] retain];
+    _knobOff = [NSImage imageNamed:@"volumeslider_normal"];
+    [self controlTintChanged];
+    [[NSNotificationCenter defaultCenter] addObserver: self
+                                             selector: @selector( controlTintChanged )
+                                                 name: NSControlTintDidChangeNotification
+                                               object: nil];
     b_mouse_down = FALSE;
     return self;
 }
 
+- (void)controlTintChanged
+{
+    if( [NSColor currentControlTint] == NSGraphiteControlTint )
+        _knobOn = [NSImage imageNamed:@"volumeslider_graphite"];
+    else
+        _knobOn = [NSImage imageNamed:@"volumeslider_blue"];
+}
+
 - (void)dealloc
 {
+    [[NSNotificationCenter defaultCenter] removeObserver: self];
     [_knobOff release];
     [_knobOn release];
     [super dealloc];
@@ -660,12 +732,12 @@ void _drawFrameInRect(NSRect frameRect)
 
     [[self controlView] lockFocus];
     [knob compositeToPoint:NSMakePoint( knob_rect.origin.x + 1,
-        knob_rect.origin.y + knob_rect.size.height -2 )  
+        knob_rect.origin.y + knob_rect.size.height -2 )
         operation:NSCompositeSourceOver];
     [[self controlView] unlockFocus];
 }
 
-- (void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint inView: 
+- (void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint inView:
         (NSView *)controlView mouseIsUp:(BOOL)flag
 {
     b_mouse_down = NO;