// // JSRunSideBarView.m // JSRun // // Created by Jonathan Saggau on 2/26/07. // Copyright 2007 Jonathan Saggau. All rights reserved. // // some code from omniappkit. // Copyright 2003-2005 Omni Development, Inc. All rights reserved. // // This software may only be used and reproduced according to the // terms in the file OmniSourceLicense.html, which should be // distributed with this project and can also be found at // . // // It's a modified version of the gradient table view from omniappkit using // CTGradient to draw the gradient #import "JSRunSideBarView.h" #import "JSCommonMacros.h" #import "CTGradient.h" @implementation JSRunSideBarView - (void)selectAllCells { [self selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:NO]; } - (void)drawRow:(int)rowIndex clipRect:(NSRect)clipRect { [super drawRow:rowIndex clipRect:clipRect]; } - (void)drawBackgroundInClipRect:(NSRect)clipRect { [[self backgroundColor] set]; NSRectFill(clipRect); } // NSTableView subclass - (id)_highlightColorForCell:(NSCell *)cell; { //keeps the cell from drawing the highlight return nil; } //from omniappkit (with CTGradient modification by JS) - (void)highlightSelectionInClipRect:(NSRect)rect; { // Take the color apart NSColor *alternateSelectedControlColor = [NSColor alternateSelectedControlColor]; float hue, saturation, brightness, alpha; [[alternateSelectedControlColor colorUsingColorSpaceName:NSDeviceRGBColorSpace] getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha]; // Create synthetic darker and lighter versions // NSColor *lighterColor = [NSColor colorWithDeviceHue:hue - (1.0/120.0) saturation:MAX(0.0, saturation-0.12) brightness:MIN(1.0, brightness+0.045) alpha:alpha]; NSColor *lighterColor = [NSColor colorWithDeviceHue:hue saturation:MAX(0.0, saturation-.12) brightness:MIN(1.0, brightness+0.30) alpha:alpha]; NSColor *darkerColor = [NSColor colorWithDeviceHue:hue saturation:MIN(1.0, (saturation > .04) ? saturation+0.12 : 0.0) brightness:MAX(0.0, brightness-0.045) alpha:alpha]; // If this view isn't key, use the gray version of the dark color. Note that this varies from the standard gray version that NSCell returns as its highlightColorWithFrame: when the cell is not in a key view, in that this is a lot darker. Mike and I think this is justified for this kind of view -- if you're using the dark selection color to show the selected status, it makes sense to leave it dark. if ([[self window] firstResponder] != self || ![[self window] isKeyWindow]) { alternateSelectedControlColor = [[alternateSelectedControlColor colorUsingColorSpaceName:NSDeviceWhiteColorSpace] colorUsingColorSpaceName:NSDeviceRGBColorSpace]; lighterColor = [[lighterColor colorUsingColorSpaceName:NSDeviceWhiteColorSpace] colorUsingColorSpaceName:NSDeviceRGBColorSpace]; darkerColor = [[darkerColor colorUsingColorSpaceName:NSDeviceWhiteColorSpace] colorUsingColorSpaceName:NSDeviceRGBColorSpace]; } NSEnumerator *selectedRowEnumerator = [self selectedRowEnumerator]; NSNumber *rowIndexNumber = [selectedRowEnumerator nextObject]; unsigned int rowIndex = rowIndexNumber ? [rowIndexNumber unsignedIntValue] : NSNotFound; while (rowIndex != NSNotFound) { unsigned int endOfCurrentRunRowIndex, newRowIndex = rowIndex; do { endOfCurrentRunRowIndex = newRowIndex; rowIndexNumber = [selectedRowEnumerator nextObject]; newRowIndex = rowIndexNumber ? [rowIndexNumber unsignedIntValue] : NSNotFound; } while (newRowIndex == endOfCurrentRunRowIndex + 1); NSRect rowRect = NSUnionRect([self rectOfRow:rowIndex], [self rectOfRow:endOfCurrentRunRowIndex]); NSRect topBar, washRect; NSDivideRect(rowRect, &topBar, &washRect, 1.0, NSMinYEdge); // Draw the top line of pixels of the selected row in the alternateSelectedControlColor [alternateSelectedControlColor set]; NSRectFill(topBar); NSGraphicsContext *nsContext = [NSGraphicsContext currentContext]; [nsContext saveGraphicsState]; CTGradient *gradient = [CTGradient gradientWithBeginningColor:darkerColor endingColor:lighterColor]; [gradient fillRect:washRect angle:270.0]; [nsContext restoreGraphicsState]; rowIndex = newRowIndex; } } - (void)selectRow:(int)row byExtendingSelection:(BOOL)extend; { [super selectRow:row byExtendingSelection:extend]; [self setNeedsDisplay:YES]; // we display extra because we draw multiple contiguous selected rows differently, so changing one row's selection can change how others draw. } - (void)deselectRow:(int)row; { [super deselectRow:row]; [self setNeedsDisplay:YES]; // we display extra because we draw multiple contiguous selected rows differently, so changing one row's selection can change how others draw. } @end