2007-10-06 22:23:44 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2010-01-01 21:12:04 +00:00
|
|
|
* Copyright (c) 2007-2010 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:)
|
2010-01-05 04:34:31 +00:00
|
|
|
name: NSControlTintDidChangeNotification object: NSApp];
|
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
|
|
|
|
{
|
2007-10-18 00:04:01 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
|
|
|
|
|
|
|
[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;
|
|
|
|
|
|
|
|
NSImage * tabImage;
|
|
|
|
if (fSelected)
|
2008-05-02 13:08:23 +00:00
|
|
|
tabImage = [NSColor currentControlTint] == NSGraphiteControlTint
|
|
|
|
? [[NSImage imageNamed: @"InfoTabBackGraphite.png"] copy] : [[NSImage imageNamed: @"InfoTabBackBlue.png"] copy];
|
2007-10-18 00:04:01 +00:00
|
|
|
else
|
2008-05-02 13:08:23 +00:00
|
|
|
tabImage = [[NSImage imageNamed: @"InfoTabBack.png"] copy];
|
2007-10-18 00:04:01 +00:00
|
|
|
|
2008-05-02 13:08:23 +00:00
|
|
|
if (fIcon)
|
2007-10-18 00:04:01 +00:00
|
|
|
{
|
2009-12-21 23:47:16 +00:00
|
|
|
const NSSize iconSize = [fIcon size], tabSize = [tabImage size];
|
|
|
|
|
|
|
|
const NSRect iconRect = NSMakeRect(floor((tabSize.width - iconSize.width) * 0.5),
|
|
|
|
floor((tabSize.height - iconSize.height) * 0.5),
|
|
|
|
iconSize.width, iconSize.height);
|
2008-05-02 13:08:23 +00:00
|
|
|
|
|
|
|
[tabImage lockFocus];
|
2009-12-21 23:47:16 +00:00
|
|
|
[fIcon drawInRect: iconRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
|
2008-05-02 13:08:23 +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
|
|
|
}
|
|
|
|
|
|
|
|
- (void) updateControlTint: (NSNotification *) notification
|
|
|
|
{
|
|
|
|
if (fSelected)
|
|
|
|
[self setSelectedTab: YES];
|
2007-10-06 22:59:07 +00:00
|
|
|
}
|
|
|
|
|
2007-10-06 22:23:44 +00:00
|
|
|
@end
|