]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/misc.m
macosx: get rid of the infamous 'get' prefixes everywhere and finally respect Cocoa...
[vlc] / modules / gui / macosx / misc.m
index dc011bcf816faffcd61ad85a9afdfaf3a5712bb7..ee673f65d0468bb5d84c084703abda5ef493d493 100644 (file)
@@ -1,10 +1,11 @@
 /*****************************************************************************
  * misc.m: code not specific to vlc
  *****************************************************************************
- * Copyright (C) 2003-2007 the VideoLAN team
+ * Copyright (C) 2003-2009 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 <Carbon/Carbon.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)
  *
@@ -102,7 +157,7 @@ static NSMutableArray *blackoutWindows = NULL;
 
 - (CGDirectDisplayID)displayID
 {
-    return (CGDirectDisplayID)_screenNumber;
+       return (CGDirectDisplayID)[[[self deviceDescription] objectForKey: @"NSScreenNumber"] intValue];
 }
 
 - (void)blackoutOtherScreens
@@ -113,7 +168,6 @@ static NSMutableArray *blackoutWindows = NULL;
     [blackoutWindows makeObjectsPerformSelector:@selector(close)];
     [blackoutWindows removeAllObjects];
 
     for(i = 0; i < [[NSScreen screens] count]; i++)
     {
         NSScreen *screen = [[NSScreen screens] objectAtIndex: i];
@@ -124,7 +178,7 @@ static NSMutableArray *blackoutWindows = NULL;
             continue;
 
         screen_rect = [screen frame];
-        screen_rect.origin.x = screen_rect.origin.y = 0.0f;
+        screen_rect.origin.x = screen_rect.origin.y = 0;
 
         /* blackoutWindow alloc strategy
             - The NSMutableArray blackoutWindows has the blackoutWindow references
@@ -135,10 +189,14 @@ static NSMutableArray *blackoutWindows = NULL;
         [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);
     }
 }
 
@@ -151,6 +209,8 @@ static NSMutableArray *blackoutWindows = NULL;
         VLCWindow *blackoutWindow = [blackoutWindows objectAtIndex: i];
         [blackoutWindow closeAndAnimate: YES];
     }
+    
+   SetSystemUIMode( kUIModeNormal, 0);
 }
 
 @end
@@ -162,7 +222,7 @@ static NSMutableArray *blackoutWindows = NULL;
  *****************************************************************************/
 
 @implementation VLCWindow
-- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask
+- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask
     backing:(NSBackingStoreType)backingType defer:(BOOL)flag
 {
     self = [super initWithContentRect:contentRect styleMask:styleMask backing:backingType defer:flag];
@@ -188,7 +248,7 @@ static NSMutableArray *blackoutWindows = NULL;
 {
     NSInvocation *invoc;
  
-    if (!animate || MACOS_VERSION < 10.4f)
+    if (!animate)
     {
         [super close];
         return;
@@ -220,7 +280,7 @@ static NSMutableArray *blackoutWindows = NULL;
     NSViewAnimation *current_anim;
     NSMutableDictionary *dict;
 
-    if (!animate || MACOS_VERSION < 10.4f)
+    if (!animate)
     {
         [self orderOut: sender];
         return;
@@ -269,7 +329,7 @@ static NSMutableArray *blackoutWindows = NULL;
     NSViewAnimation *current_anim;
     NSMutableDictionary *dict;
  
-    if (!animate || MACOS_VERSION < 10.4f)
+    if (!animate)
     {
         [super orderFront: sender];
         [self setAlphaValue: 1.0];
@@ -343,15 +403,26 @@ static NSMutableArray *blackoutWindows = NULL;
 
 @implementation VLCControllerWindow
 
-- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask
+- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask
     backing:(NSBackingStoreType)backingType defer:(BOOL)flag
 {
+    BOOL b_useTextured = YES;
+    if( [[NSWindow class] instancesRespondToSelector:@selector(setContentBorderThickness:forEdge:)] )
+    {
+        b_useTextured = NO;
+        styleMask ^= NSTexturedBackgroundWindowMask;
+    }
+
     self = [super initWithContentRect:contentRect styleMask:styleMask //& ~NSTitledWindowMask
     backing:backingType defer:flag];
 
     [[VLCMain sharedInstance] updateTogglePlaylistState];
 
-    return( self );
+    if(! b_useTextured )
+    {
+        [self setContentBorderThickness:28.0 forEdge:NSMinYEdge];
+    }
+    return self;
 }
 
 - (BOOL)performKeyEquivalent:(NSEvent *)o_event
@@ -362,7 +433,7 @@ static NSMutableArray *blackoutWindows = NULL;
         return TRUE;
 
     return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event] ||
-           [(VLCControls *)[[VLCMain sharedInstance] getControls] keyEvent:o_event];
+           [(VLCControls *)[[VLCMain sharedInstance] controls] keyEvent:o_event];
 }
 
 @end
@@ -427,7 +498,7 @@ static NSMutableArray *blackoutWindows = NULL;
                 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
                 o_array = [o_array arrayByAddingObject: o_dic];
             }
-            [(VLCPlaylist *)[[VLCMain sharedInstance] getPlaylist] appendArray: o_array atPos: -1 enqueue:NO];
+            [(VLCPlaylist *)[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:NO];
             return YES;
         }
     }
@@ -507,9 +578,9 @@ static NSMutableArray *blackoutWindows = NULL;
                 o_array = [o_array arrayByAddingObject: o_dic];
             }
             if( b_autoplay )
-                [[[VLCMain sharedInstance] getPlaylist] appendArray: o_array atPos: -1 enqueue:NO];
+                [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:NO];
             else
-                [[[VLCMain sharedInstance] getPlaylist] appendArray: o_array atPos: -1 enqueue:YES];
+                [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:YES];
             return YES;
         }
     }
@@ -618,7 +689,7 @@ void _drawFrameInRect(NSRect frameRect)
         [newCell setNumberOfTickMarks:[oldCell numberOfTickMarks]];
         [newCell setEditable:[oldCell isEditable]];
         [newCell setEnabled:[oldCell isEnabled]];
-        [newCell setEntryType:[oldCell entryType]];
+        [newCell setFormatter:[oldCell formatter]];
         [newCell setHighlighted:[oldCell isHighlighted]];
         [newCell setTickMarkPosition:[oldCell tickMarkPosition]];
         [self setCell:newCell];
@@ -635,14 +706,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];