Revision: 15263
http://bibdesk.svn.sourceforge.net/bibdesk/?rev=15263&view=rev
Author: hofman
Date: 2009-05-04 12:03:53 +0000 (Mon, 04 May 2009)
Log Message:
-----------
no need to redisplay whole group table after selection change
Modified Paths:
--------------
trunk/bibdesk/BDSKGradientTableView.m
Modified: trunk/bibdesk/BDSKGradientTableView.m
===================================================================
--- trunk/bibdesk/BDSKGradientTableView.m 2009-05-04 11:51:33 UTC (rev
15262)
+++ trunk/bibdesk/BDSKGradientTableView.m 2009-05-04 12:03:53 UTC (rev
15263)
@@ -66,7 +66,8 @@
#import "BDSKGradientTableView.h"
#import "NSLayoutManager_BDSKExtensions.h"
-// This class is basically a copy of OAGradientTableView
+// The main gradient code for these classes is basically copied from
OAGradientTableView
+// These classes are only effectively used on Tiger, on Leopard they simply
use the built-in source list highlight style
typedef struct {
CGFloat red1, green1, blue1, alpha1;
@@ -104,7 +105,6 @@
[[highlightColor colorUsingColorSpaceName:NSDeviceRGBColorSpace]
getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha];
// Create synthetic darker and lighter versions
- // NSColor *highlightLightColor = [NSColor colorWithDeviceHue:hue -
(1.0/120.0) saturation:MAX(0.0, saturation-0.12) brightness:MIN(1.0,
brightness+0.045) alpha:alpha];
highlightLightColor = [[NSColor colorWithDeviceHue:hue
saturation:MAX(0.0, saturation-.12) brightness:MIN(1.0, brightness+0.30)
alpha:alpha] retain];
highlightDarkColor = [[NSColor colorWithDeviceHue:hue
saturation:MIN(1.0, (saturation > .04) ? saturation+0.12 : 0.0)
brightness:MAX(0.0, brightness-0.045) alpha:alpha] retain];
secondaryHighlightLightColor = [[[highlightLightColor
colorUsingColorSpaceName:NSDeviceWhiteColorSpace]
colorUsingColorSpaceName:NSDeviceRGBColorSpace] retain];
@@ -112,45 +112,13 @@
}
}
-...@implementation BDSKGradientTableView
-
-+ (void)initialize {
- BDSKINITIALIZE;
- initializeHighlightColors();
-}
-
-- (id)initWithFrame:(NSRect)frameRect {
- if (self = [super initWithFrame:frameRect]) {
- if ([self respondsToSelector:@selector(setSelectionHighlightStyle:)])
- [self
setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleSourceList];
- else // from Mail.app on 10.4
- [self setBackgroundColor:[[NSColor
colorWithCalibratedRed:231.0f/255.0f green:237.0f/255.0f blue:246.0f/255.0f
alpha:1.0] colorUsingColorSpaceName:NSDeviceRGBColorSpace]];
- }
- return self;
-}
-
-- (id)initWithCoder:(NSCoder *)coder {
- if (self = [super initWithCoder:coder]) {
- if ([self respondsToSelector:@selector(setSelectionHighlightStyle:)])
- [self
setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleSourceList];
- else // from Mail.app on 10.4
- [self setBackgroundColor:[[NSColor
colorWithCalibratedRed:231.0f/255.0f green:237.0f/255.0f blue:246.0f/255.0f
alpha:1.0] colorUsingColorSpaceName:NSDeviceRGBColorSpace]];
- }
- return self;
-}
-
-- (void)highlightSelectionInClipRect:(NSRect)rect {
- if ([self respondsToSelector:@selector(setSelectionHighlightStyle:)]) {
- [super highlightSelectionInClipRect:rect];
- return;
- }
-
+static void highlightSelectionUsingGradient(NSTableView *tableView) {
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
NSColor *color, *lightColor, *darkColor;
CGFunctionRef linearBlendFunctionRef;
- if ([[self window] firstResponder] == self && [[self window] isKeyWindow])
{
+ if ([[[tableView window] firstResponder] isEqual:tableView] && [[tableView
window] isKeyWindow]) {
color = highlightColor;
lightColor = highlightLightColor;
darkColor = highlightDarkColor;
@@ -167,11 +135,11 @@
[darkColor getRed:&twoColors->red2 green:&twoColors->green2
blue:&twoColors->blue2 alpha:&twoColors->alpha2];
linearBlendFunctionRef = CGFunctionCreate(twoColors, 1, domainAndRange, 4,
domainAndRange, &linearFunctionCallbacks);
- NSIndexSet *selectedRowIndexes = [self selectedRowIndexes];
+ NSIndexSet *selectedRowIndexes = [tableView selectedRowIndexes];
NSUInteger rowIndex = [selectedRowIndexes firstIndex], prevRowIndex =
NSNotFound;
while (rowIndex != NSNotFound) {
- NSRect rowRect = [self rectOfRow:rowIndex];
+ NSRect rowRect = [tableView rectOfRow:rowIndex];
NSRect topBar, washRect;
NSDivideRect(rowRect, &topBar, &washRect, 1.0, NSMinYEdge);
@@ -198,6 +166,42 @@
CGColorSpaceRelease(colorSpace);
}
+#pragma mark -
+
+...@implementation BDSKGradientTableView
+
++ (void)initialize {
+ BDSKINITIALIZE;
+ initializeHighlightColors();
+}
+
+- (id)initWithFrame:(NSRect)frameRect {
+ if (self = [super initWithFrame:frameRect]) {
+ if ([self respondsToSelector:@selector(setSelectionHighlightStyle:)])
+ [self
setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleSourceList];
+ else // from Mail.app on 10.4
+ [self setBackgroundColor:[[NSColor
colorWithCalibratedRed:231.0f/255.0f green:237.0f/255.0f blue:246.0f/255.0f
alpha:1.0] colorUsingColorSpaceName:NSDeviceRGBColorSpace]];
+ }
+ return self;
+}
+
+- (id)initWithCoder:(NSCoder *)coder {
+ if (self = [super initWithCoder:coder]) {
+ if ([self respondsToSelector:@selector(setSelectionHighlightStyle:)])
+ [self
setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleSourceList];
+ else // from Mail.app on 10.4
+ [self setBackgroundColor:[[NSColor
colorWithCalibratedRed:231.0f/255.0f green:237.0f/255.0f blue:246.0f/255.0f
alpha:1.0] colorUsingColorSpaceName:NSDeviceRGBColorSpace]];
+ }
+ return self;
+}
+
+- (void)highlightSelectionInClipRect:(NSRect)rect {
+ if ([self respondsToSelector:@selector(setSelectionHighlightStyle:)])
+ [super highlightSelectionInClipRect:rect];
+ else
+ highlightSelectionUsingGradient(self);
+}
+
- (CGFloat)rowHeightForFont:(NSFont *)font {
return [NSLayoutManager defaultViewLineHeightForFont:font] + 2.0;
}
@@ -238,62 +242,10 @@
}
- (void)highlightSelectionInClipRect:(NSRect)rect {
- if ([self respondsToSelector:@selector(setSelectionHighlightStyle:)]) {
+ if ([self respondsToSelector:@selector(setSelectionHighlightStyle:)])
[super highlightSelectionInClipRect:rect];
- return;
- }
-
- CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
-
- NSColor *color, *lightColor, *darkColor;
- CGFunctionRef linearBlendFunctionRef;
-
- if ([[self window] firstResponder] == self && [[self window] isKeyWindow])
{
- color = highlightColor;
- lightColor = highlightLightColor;
- darkColor = highlightDarkColor;
- } else {
- color = secondaryHighlightColor;
- lightColor = secondaryHighlightLightColor;
- darkColor = secondaryHighlightDarkColor;
- }
-
- static const CGFloat domainAndRange[8] = {0.0, 1.0, 0.0, 1.0, 0.0, 1.0,
0.0, 1.0};
-
- _twoColorsType *twoColors = malloc(sizeof(_twoColorsType)); // We malloc()
the helper data because we may draw this wash during printing, in which case it
won't necessarily be evaluated immediately. We need for all the data the
shading function needs to draw to potentially outlive us.
- [lightColor getRed:&twoColors->red1 green:&twoColors->green1
blue:&twoColors->blue1 alpha:&twoColors->alpha1];
- [darkColor getRed:&twoColors->red2 green:&twoColors->green2
blue:&twoColors->blue2 alpha:&twoColors->alpha2];
- linearBlendFunctionRef = CGFunctionCreate(twoColors, 1, domainAndRange, 4,
domainAndRange, &linearFunctionCallbacks);
-
- NSIndexSet *selectedRowIndexes = [self selectedRowIndexes];
- NSUInteger rowIndex = [selectedRowIndexes firstIndex], prevRowIndex =
NSNotFound;
-
- while (rowIndex != NSNotFound) {
- NSRect rowRect = [self rectOfRow:rowIndex];
-
- NSRect topBar, washRect;
- NSDivideRect(rowRect, &topBar, &washRect, 1.0, NSMinYEdge);
-
- // Draw the top line of pixels of the selected row in the
alternateSelectedControlColor
- if (rowIndex == 0 || rowIndex - 1 != prevRowIndex) {
- [color setFill];
- NSRectFill(topBar);
- }
-
- // Draw a soft wash underneath it
- CGContextRef context = [[NSGraphicsContext currentContext]
graphicsPort];
- CGContextSaveGState(context);
- CGContextClipToRect(context, NSRectToCGRect(washRect));
- CGShadingRef cgShading = CGShadingCreateAxial(colorSpace,
CGPointMake(0, NSMinY(washRect)), CGPointMake(0, NSMaxY(washRect)),
linearBlendFunctionRef, NO, NO);
- CGContextDrawShading(context, cgShading);
- CGShadingRelease(cgShading);
- CGContextRestoreGState(context);
-
- prevRowIndex = rowIndex;
- rowIndex = [selectedRowIndexes indexGreaterThanIndex:rowIndex];
- }
- CGFunctionRelease(linearBlendFunctionRef);
- CGColorSpaceRelease(colorSpace);
+ else
+ highlightSelectionUsingGradient(self);
}
- (CGFloat)rowHeightForFont:(NSFont *)font {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations
Conference from O'Reilly Media. Velocity features a full day of
expert-led, hands-on workshops and two days of sessions from industry
leaders in dedicated Performance & Operations tracks. Use code vel09scf
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit