Skip to content

Commit

Permalink
Adjust highlighting
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.textmate.org/trunk/Tools/CommitWindowProject@5536 dfb7d73b-c2ec-0310-8fea-fb051d288c6d
  • Loading branch information
Chris Thomas committed Oct 21, 2006
1 parent 9b54e3f commit 0c783c2
Showing 1 changed file with 64 additions and 15 deletions.
79 changes: 64 additions & 15 deletions CXTextWithButtonStripCell.m
Expand Up @@ -14,6 +14,8 @@
#define kIconButtonWidth 16.0
#define kButtonInteriorVerticalEdgeMargin 8.0



@interface NSBezierPath (CXBezierPathAdditions)
+ (NSBezierPath*)bezierPathWithCapsuleRect:(NSRect)rect;
@end
Expand All @@ -35,6 +37,10 @@ + (NSBezierPath*)bezierPathWithCapsuleRect:(NSRect)rect

@end

@interface CXTextWithButtonStripCell (Private)
- (NSDictionary *) titleTextAttributes;
@end

@implementation CXTextWithButtonStripCell

// NSTableView frequently wants to make copies of the cell. Retain anything that later will be released.
Expand All @@ -57,16 +63,6 @@ - (void) dealloc
#pragma mark Geometry
#endif

- (NSDictionary *) titleTextAttributes
{
NSMutableDictionary * attributes = [NSMutableDictionary dictionary];

[attributes setObject:[NSFont systemFontOfSize:9.0] forKey:NSFontAttributeName];
[attributes setObject:[NSColor whiteColor] forKey:NSForegroundColorAttributeName];

return attributes;
}

// Maintaining a cache of the button boundrects simplifies the rest of the code
- (void)calcButtonRects
{
Expand Down Expand Up @@ -240,23 +236,76 @@ - (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame ofView:(NSView *
#pragma mark Drawing
#endif

- (BOOL)drawAsHighlighted
{
NSView * selfView = [self controlView];
NSWindow * selfWindow = [selfView window];

return (([selfWindow firstResponder] == selfView)
&& [selfWindow isKeyWindow]);
}

- (NSDictionary *) titleTextAttributes
{
NSMutableDictionary * attributes = [NSMutableDictionary dictionary];
NSColor * foreColor;

if( [self isHighlighted] && [self drawAsHighlighted] )
{
foreColor = [NSColor alternateSelectedControlColor];
}
else
{
foreColor = [NSColor whiteColor];
}

[attributes setObject:[NSFont systemFontOfSize:9.0] forKey:NSFontAttributeName];
[attributes setObject:foreColor forKey:NSForegroundColorAttributeName];

return attributes;
}

- (void)drawButtonContent:(id)content inRect:(NSRect)rect selected:(BOOL)selected menu:(NSMenu *)menu
{
//
// Draw background
NSBezierPath * path = [NSBezierPath bezierPathWithCapsuleRect:NSInsetRect(rect, 0.5f, 0.5f)];
//
NSBezierPath * path = [NSBezierPath bezierPathWithCapsuleRect:NSInsetRect(rect, 0.5f, 0.5f)];
NSColor * backgroundColor = nil;
// NSColor * foregroundColor = nil;

if( selected )
// Table row is selected?
if( [self isHighlighted] && [self drawAsHighlighted] )
{
[[NSColor darkGrayColor] set];
if( selected )
{
backgroundColor = [NSColor whiteColor];
}
else
{
backgroundColor = [NSColor colorForControlTint:[NSColor currentControlTint]];
backgroundColor = [[backgroundColor shadowWithLevel:0.1] blendedColorWithFraction:0.85 ofColor:[NSColor whiteColor]];
}
}
else
{
[[NSColor lightGrayColor] set];
if( selected )
{
backgroundColor = [NSColor colorWithDeviceWhite:0.2 alpha:1.0];
}
else
{
backgroundColor = [NSColor lightGrayColor];
}
}

[backgroundColor set];
[path fill];

// Draw content (send the polymorphism lecture to the AppKit team, thanks)
//
// Draw content
// (send the polymorphism lecture to the AppKit team, thanks)
//
if( [content isKindOfClass:[NSString class]] )
{
NSRect textRect = NSInsetRect(rect, kButtonInteriorVerticalEdgeMargin, 0.5f);
Expand Down

0 comments on commit 0c783c2

Please sign in to comment.