2007-10-06 22:23:44 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2011-01-01 20:42:14 +00:00
|
|
|
* Copyright (c) 2007-2011 Transmission authors and contributors
|
2007-10-06 22:23:44 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#import "InfoTabButtonCell.h"
|
|
|
|
|
|
|
|
@implementation InfoTabButtonCell
|
|
|
|
|
2007-10-18 00:04:01 +00:00
|
|
|
- (void) awakeFromNib
|
|
|
|
{
|
2007-11-18 02:20:28 +00:00
|
|
|
[(NSMatrix *)[self controlView] setToolTip: [self title] forCell: self];
|
2011-01-30 02:36:08 +00:00
|
|
|
|
|
|
|
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
|
|
|
|
[nc addObserver: self selector: @selector(updateControlTint:)
|
|
|
|
name: NSControlTintDidChangeNotification object: NSApp];
|
2011-01-30 02:01:05 +00:00
|
|
|
|
2007-10-18 00:04:01 +00:00
|
|
|
fSelected = NO;
|
2010-03-14 15:03:14 +00:00
|
|
|
|
|
|
|
//expects the icon to currently be set as the image
|
|
|
|
fIcon = [[self image] retain];
|
|
|
|
[self setSelectedTab: fSelected];
|
2007-10-18 00:04:01 +00:00
|
|
|
}
|
|
|
|
|
2007-10-06 22:23:44 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
2011-01-30 02:36:08 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
|
|
|
|
2007-10-18 00:04:01 +00:00
|
|
|
[fIcon release];
|
2007-10-06 22:23:44 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2007-10-07 02:25:39 +00:00
|
|
|
- (void) setSelectedTab: (BOOL) selected
|
2007-10-06 22:59:07 +00:00
|
|
|
{
|
2007-10-18 00:04:01 +00:00
|
|
|
fSelected = selected;
|
|
|
|
|
2011-01-30 02:01:05 +00:00
|
|
|
NSInteger row, col;
|
|
|
|
[(NSMatrix *)[self controlView] getRow: &row column: &col ofCell: self];
|
2011-01-30 02:36:08 +00:00
|
|
|
NSRect tabRect = [(NSMatrix *)[self controlView] cellFrameAtRow: row column: col];
|
|
|
|
tabRect.origin.x = 0.0;
|
|
|
|
tabRect.origin.y = 0.0;
|
2011-01-30 02:01:05 +00:00
|
|
|
|
2011-01-30 02:36:08 +00:00
|
|
|
NSImage * tabImage = [[NSImage alloc] initWithSize: tabRect.size];
|
2011-01-30 02:01:05 +00:00
|
|
|
|
|
|
|
[tabImage lockFocus];
|
|
|
|
|
2011-01-30 19:32:40 +00:00
|
|
|
NSGradient * gradient;
|
2011-01-30 02:36:08 +00:00
|
|
|
if (fSelected)
|
2011-01-30 02:01:05 +00:00
|
|
|
{
|
2011-01-30 02:36:08 +00:00
|
|
|
NSColor * lightColor = [NSColor colorForControlTint: [NSColor currentControlTint]];
|
|
|
|
NSColor * darkColor = [lightColor blendedColorWithFraction: 0.2 ofColor: [NSColor blackColor]];
|
2011-01-30 19:32:40 +00:00
|
|
|
gradient = [[NSGradient alloc] initWithStartingColor: lightColor endingColor: darkColor];
|
2011-01-30 02:01:05 +00:00
|
|
|
}
|
2007-10-18 00:04:01 +00:00
|
|
|
else
|
2011-01-30 02:01:05 +00:00
|
|
|
{
|
2011-01-30 02:52:03 +00:00
|
|
|
NSColor * lightColor = [NSColor colorWithCalibratedRed: 245.0/255.0 green: 245.0/255.0 blue: 245.0/255.0 alpha: 1.0];
|
|
|
|
NSColor * darkColor = [NSColor colorWithCalibratedRed: 215.0/255.0 green: 215.0/255.0 blue: 215.0/255.0 alpha: 1.0];
|
2011-01-30 19:32:40 +00:00
|
|
|
gradient = [[NSGradient alloc] initWithStartingColor: lightColor endingColor: darkColor];
|
2011-01-30 02:01:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[[NSColor grayColor] set];
|
|
|
|
NSRectFill(NSMakeRect(0.0, 0.0, NSWidth(tabRect), 1.0));
|
|
|
|
NSRectFill(NSMakeRect(0.0, NSHeight(tabRect) - 1.0, NSWidth(tabRect), 1.0));
|
|
|
|
NSRectFill(NSMakeRect(NSWidth(tabRect) - 1.0, 1.0, NSWidth(tabRect) - 1.0, NSHeight(tabRect) - 2.0));
|
2007-10-18 00:04:01 +00:00
|
|
|
|
2011-01-30 19:32:40 +00:00
|
|
|
tabRect = NSMakeRect(0.0, 1.0, NSWidth(tabRect) - 1.0, NSHeight(tabRect) - 2.0);
|
|
|
|
|
|
|
|
[gradient drawInRect: tabRect angle: 270.0];
|
|
|
|
[gradient release];
|
|
|
|
|
2008-05-02 13:08:23 +00:00
|
|
|
if (fIcon)
|
2007-10-18 00:04:01 +00:00
|
|
|
{
|
2011-01-30 02:01:05 +00:00
|
|
|
const NSSize iconSize = [fIcon size];
|
2009-12-21 23:47:16 +00:00
|
|
|
|
2011-01-30 21:34:46 +00:00
|
|
|
const NSRect iconRect = NSMakeRect(NSMinX(tabRect) + floor((NSWidth(tabRect) - iconSize.width) * 0.5),
|
|
|
|
NSMinY(tabRect) + floor((NSHeight(tabRect) - iconSize.height) * 0.5),
|
2009-12-21 23:47:16 +00:00
|
|
|
iconSize.width, iconSize.height);
|
2008-05-02 13:08:23 +00:00
|
|
|
|
2009-12-21 23:47:16 +00:00
|
|
|
[fIcon drawInRect: iconRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
|
2007-10-18 00:04:01 +00:00
|
|
|
}
|
|
|
|
|
2011-01-30 19:34:38 +00:00
|
|
|
[tabImage unlockFocus];
|
|
|
|
|
2007-10-18 00:04:01 +00:00
|
|
|
[self setImage: tabImage];
|
2008-05-02 13:08:23 +00:00
|
|
|
[tabImage release];
|
2007-10-18 00:04:01 +00:00
|
|
|
}
|
|
|
|
|
2011-01-30 02:36:08 +00:00
|
|
|
- (void) updateControlTint: (NSNotification *) notification
|
|
|
|
{
|
|
|
|
if (fSelected)
|
|
|
|
[self setSelectedTab: YES];
|
|
|
|
}
|
|
|
|
|
2007-10-06 22:23:44 +00:00
|
|
|
@end
|