2007-10-06 22:23:44 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-01-02 16:55:05 +00:00
|
|
|
* Copyright (c) 2007-2008 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];
|
|
|
|
|
2007-10-18 00:04:01 +00:00
|
|
|
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
|
|
|
|
[nc addObserver: self selector: @selector(updateControlTint:)
|
|
|
|
name: NSControlTintDidChangeNotification object: nil];
|
|
|
|
|
|
|
|
fSelected = NO;
|
|
|
|
}
|
|
|
|
|
2007-10-06 22:23:44 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
2007-10-18 00:04:01 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
|
|
|
|
|
|
|
[fIcon release];
|
|
|
|
|
2007-10-06 22:23:44 +00:00
|
|
|
[fRegularImage release];
|
|
|
|
[fSelectedImage release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2007-10-07 02:25:39 +00:00
|
|
|
- (void) setIcon: (NSImage *) image
|
2007-10-06 22:23:44 +00:00
|
|
|
{
|
2007-10-18 00:04:01 +00:00
|
|
|
[fIcon release];
|
2008-01-16 04:37:27 +00:00
|
|
|
fIcon = [image retain];
|
2007-10-06 22:23:44 +00:00
|
|
|
|
2007-10-18 00:04:01 +00:00
|
|
|
if (fRegularImage)
|
|
|
|
{
|
|
|
|
[fRegularImage release];
|
|
|
|
fRegularImage = nil;
|
|
|
|
}
|
|
|
|
if (fSelectedImage)
|
2007-10-06 22:23:44 +00:00
|
|
|
{
|
2007-10-18 00:04:01 +00:00
|
|
|
[fSelectedImage release];
|
|
|
|
fSelectedImage = nil;
|
2007-10-06 22:23:44 +00:00
|
|
|
}
|
2007-10-07 02:25:39 +00:00
|
|
|
|
2007-10-18 00:04:01 +00:00
|
|
|
[self setSelectedTab: fSelected];
|
2007-10-06 22:23:44 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
NSImage * tabImage;
|
|
|
|
BOOL createImage = NO;
|
|
|
|
if (fSelected)
|
|
|
|
{
|
|
|
|
if (!fSelectedImage)
|
|
|
|
{
|
2007-10-27 20:09:29 +00:00
|
|
|
fSelectedImage = [NSColor currentControlTint] == NSGraphiteControlTint
|
2007-10-28 03:29:20 +00:00
|
|
|
? [[NSImage imageNamed: @"InfoTabBackGraphite.png"] copy] : [[NSImage imageNamed: @"InfoTabBackBlue.png"] copy];
|
2007-10-18 00:04:01 +00:00
|
|
|
createImage = YES;
|
|
|
|
}
|
|
|
|
tabImage = fSelectedImage;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!fRegularImage)
|
|
|
|
{
|
2007-10-28 03:29:20 +00:00
|
|
|
fRegularImage = [[NSImage imageNamed: @"InfoTabBack.png"] copy];
|
2007-10-18 00:04:01 +00:00
|
|
|
createImage = YES;
|
|
|
|
}
|
|
|
|
tabImage = fRegularImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (createImage)
|
|
|
|
{
|
|
|
|
if (fIcon)
|
|
|
|
{
|
2008-01-16 04:37:27 +00:00
|
|
|
NSSize iconSize = [fIcon size], tabSize = [tabImage size];
|
|
|
|
NSPoint point = NSMakePoint(floorf((tabSize.width - iconSize.width) * 0.5),
|
|
|
|
floorf((tabSize.height - iconSize.height) * 0.5));
|
|
|
|
|
2007-10-18 00:04:01 +00:00
|
|
|
[tabImage lockFocus];
|
2008-01-16 04:37:27 +00:00
|
|
|
[fIcon compositeToPoint: point operation: NSCompositeSourceOver];
|
2007-10-18 00:04:01 +00:00
|
|
|
[tabImage unlockFocus];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[self setImage: tabImage];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) updateControlTint: (NSNotification *) notification
|
|
|
|
{
|
2008-01-16 04:37:27 +00:00
|
|
|
[fSelectedImage release];
|
|
|
|
fSelectedImage = nil;
|
2007-10-18 00:04:01 +00:00
|
|
|
|
|
|
|
if (fSelected)
|
|
|
|
[self setSelectedTab: YES];
|
2007-10-06 22:59:07 +00:00
|
|
|
}
|
|
|
|
|
2007-10-06 22:23:44 +00:00
|
|
|
@end
|