Revision: 18407
http://bibdesk.svn.sourceforge.net/bibdesk/?rev=18407&view=rev
Author: hofman
Date: 2012-01-15 22:03:24 +0000 (Sun, 15 Jan 2012)
Log Message:
-----------
workaround for source list gradient color on 10.7
Modified Paths:
--------------
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m 2012-01-15
16:44:42 UTC (rev 18406)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m 2012-01-15
22:03:24 UTC (rev 18407)
@@ -235,8 +235,7 @@
// Magic source list color:
http://lists.apple.com/archives/cocoa-dev/2008/Jun/msg02138.html
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) {
- CGFloat red = 0.863772, green = 0.892659, blue = 0.919963;
- color = [NSColor colorWithDeviceRed:red green:green blue:blue
alpha:1.0];
+ // !!! return nil for 10.7 and later to deal with gradient colors
} else if ([NSOutlineView
instancesRespondToSelector:@selector(setSelectionHighlightStyle:)]) {
NSOutlineView *outlineView = [[NSOutlineView alloc]
initWithFrame:NSMakeRect(0,0,1,1)];
[outlineView
setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleSourceList];
@@ -2404,15 +2403,61 @@
return frame;
}
-- (void)drawRect:(NSRect)rect;
+- (void)_fillBackgroundColorOrGradientInRect:(NSRect)rect
{
- BOOL isDrawingToScreen = [[NSGraphicsContext currentContext]
isDrawingToScreen];
-
- if (isDrawingToScreen) {
+ // any solid color background should override the gradient code
+ if ([self backgroundColor]) {
[[self backgroundColor] setFill];
NSRectFillUsingOperation(rect, NSCompositeCopy);
}
+ else {
+ /*
+ The NSTableView magic source list color no longer works properly on
10.7, either
+ because they changed it from a solid color to a gradient, or just
changed the
+ drawing. I couldn't see a reasonable way to subclass NSColor and
draw a gradient
+ as Apple does, or to force the color to update properly, so we'll
just cheat and
+ do it the easy way. Using 10.5 and later API is okay, since 10.4
gets a solid
+ color anyway.
+ */
+ FVAPIAssert(floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6,
@"gradient background is only available on 10.7 and later");
+
+ // should be RGBA space, since we're drawing to the screen
+ CGColorSpaceRef cspace =
CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
+ const CGFloat locations[] = { 0, 1 };
+ CGGradientRef gradient;
+
+ // color values from DigitalColor Meter on 10.7, using Generic RGB
space
+ if ([[self window] isKeyWindow]) {
+ // ordered as lower/upper
+ const CGFloat components[8] = { 198.0 / 255.0, 207.0 / 255.0,
216.0 / 255.0, 1.0, 227.0 / 255.0, 232.0 / 255.0, 238.0 / 255.0, 1.0 };
+ gradient = CGGradientCreateWithColorComponents(cspace, components,
locations, 2);
+ }
+ else {
+ // ordered as lower/upper
+ const CGFloat components[8] = { 230.0 / 255.0, 230.0 / 255.0,
230.0 / 255.0, 1.0, 246.0 / 255.0, 246.0 / 255.0, 246.0 / 255.0, 1.0 };
+ gradient = CGGradientCreateWithColorComponents(cspace, components,
locations, 2);
+ }
+ CGContextRef ctxt = [[NSGraphicsContext currentContext] graphicsPort];
+
+ // only draw the dirty part, but we need to use the full view bounds
as the gradient extent
+ CGContextSaveGState(ctxt);
+ CGContextClipToRect(ctxt, rect);
+ const NSRect bounds = [self bounds];
+ CGContextDrawLinearGradient(ctxt, gradient, CGPointMake(0,
NSMaxY(bounds)), CGPointMake(0, NSMinY(bounds)), 0);
+ CGContextRestoreGState(ctxt);
+
+ CGGradientRelease(gradient);
+ CGColorSpaceRelease(cspace);
+ }
+}
+
+- (void)drawRect:(NSRect)rect;
+{
+ BOOL isDrawingToScreen = [[NSGraphicsContext currentContext]
isDrawingToScreen];
+ if (isDrawingToScreen)
+ [self _fillBackgroundColorOrGradientInRect:rect];
+
// Only iterate icons in the visible range, since we know the overall
geometry
NSRange rowRange, columnRange;
[self _getRangeOfRows:&rowRange columns:&columnRange inRect:rect];
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
RSA(R) Conference 2012
Mar 27 - Feb 2
Save $400 by Jan. 27
Register now!
http://p.sf.net/sfu/rsa-sfdev2dev2
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit