2007-10-06 22:23:44 +00:00
|
|
|
/******************************************************************************
|
2012-01-14 17:12:04 +00:00
|
|
|
* Copyright (c) 2007-2012 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"
|
2018-12-21 21:39:47 +00:00
|
|
|
#import "NSApplicationAdditions.h"
|
2007-10-06 22:23:44 +00:00
|
|
|
|
|
|
|
@implementation InfoTabButtonCell
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)awakeFromNib
|
2007-10-18 00:04:01 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if (!NSApp.onMojaveOrBetter)
|
|
|
|
{
|
|
|
|
NSNotificationCenter* nc = NSNotificationCenter.defaultCenter;
|
|
|
|
[nc addObserver:self selector:@selector(updateControlTint:) name:NSControlTintDidChangeNotification object:NSApp];
|
2018-12-21 22:58:15 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-10-18 00:04:01 +00:00
|
|
|
fSelected = NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-14 15:03:14 +00:00
|
|
|
//expects the icon to currently be set as the image
|
2021-08-07 07:27:56 +00:00
|
|
|
fIcon = self.image;
|
2007-10-18 00:04:01 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)dealloc
|
2007-10-06 22:23:44 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter removeObserver:self];
|
2007-10-06 22:23:44 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setControlView:(NSView*)controlView
|
2015-12-22 00:45:09 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const hadControlView = self.controlView != nil;
|
2015-12-22 00:45:09 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
super.controlView = controlView;
|
2015-12-22 00:45:09 +00:00
|
|
|
|
|
|
|
if (!hadControlView)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[(NSMatrix*)self.controlView setToolTip:self.title forCell:self];
|
|
|
|
[self setSelectedTab:fSelected];
|
2015-12-22 00:45:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setSelectedTab:(BOOL)selected
|
2007-10-06 22:59:07 +00:00
|
|
|
{
|
2007-10-18 00:04:01 +00:00
|
|
|
fSelected = selected;
|
2019-02-16 07:50:37 +00:00
|
|
|
|
2018-12-21 22:37:17 +00:00
|
|
|
[self reloadAppearance];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)reloadAppearance
|
2018-12-21 22:37:17 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (self.controlView == nil)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2015-12-22 00:45:09 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2015-12-22 00:45:09 +00:00
|
|
|
|
2011-01-30 02:01:05 +00:00
|
|
|
NSInteger row, col;
|
2021-08-15 09:41:48 +00:00
|
|
|
[(NSMatrix*)self.controlView getRow:&row column:&col ofCell:self];
|
|
|
|
NSRect tabRect = [(NSMatrix*)self.controlView cellFrameAtRow:row column:col];
|
2011-01-30 02:36:08 +00:00
|
|
|
tabRect.origin.x = 0.0;
|
|
|
|
tabRect.origin.y = 0.0;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSImage* tabImage = [[NSImage alloc] initWithSize:tabRect.size];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-01-30 02:01:05 +00:00
|
|
|
[tabImage lockFocus];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSGradient* gradient;
|
2011-01-30 02:36:08 +00:00
|
|
|
if (fSelected)
|
2011-01-30 02:01:05 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSColor *lightColor, *darkColor;
|
|
|
|
if (@available(macOS 10.14, *))
|
|
|
|
{
|
|
|
|
lightColor = [NSColor.controlAccentColor blendedColorWithFraction:0.35 ofColor:NSColor.whiteColor];
|
|
|
|
darkColor = [NSColor.controlAccentColor blendedColorWithFraction:0.15 ofColor:NSColor.whiteColor];
|
2018-12-21 22:58:15 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
lightColor = [NSColor colorForControlTint:NSColor.currentControlTint];
|
|
|
|
darkColor = [lightColor blendedColorWithFraction:0.2 ofColor:NSColor.blackColor];
|
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if (NSApp.isDarkMode)
|
|
|
|
{
|
|
|
|
NSColor* darkColor = [NSColor colorWithCalibratedRed:60.0 / 255.0 green:60.0 / 255.0 blue:60.0 / 255.0 alpha:1.0];
|
|
|
|
NSColor* lightColor = [NSColor colorWithCalibratedRed:90.0 / 255.0 green:90.0 / 255.0 blue:90.0 / 255.0 alpha:1.0];
|
|
|
|
gradient = [[NSGradient alloc] initWithStartingColor:lightColor endingColor:darkColor];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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];
|
|
|
|
gradient = [[NSGradient alloc] initWithStartingColor:lightColor endingColor:darkColor];
|
2018-12-21 21:39:47 +00:00
|
|
|
}
|
2011-01-30 02:01:05 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
if (@available(macOS 10.14, *))
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
[NSColor.separatorColor set];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
[NSColor.grayColor set];
|
2018-12-21 21:39:47 +00:00
|
|
|
}
|
2011-01-30 02:01:05 +00:00
|
|
|
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));
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-01-30 19:32:40 +00:00
|
|
|
tabRect = NSMakeRect(0.0, 1.0, NSWidth(tabRect) - 1.0, NSHeight(tabRect) - 2.0);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[gradient drawInRect:tabRect angle:270.0];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-05-02 13:08:23 +00:00
|
|
|
if (fIcon)
|
2007-10-18 00:04:01 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSSize const iconSize = fIcon.size;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSRect const iconRect = NSMakeRect(
|
|
|
|
NSMinX(tabRect) + floor((NSWidth(tabRect) - iconSize.width) * 0.5),
|
|
|
|
NSMinY(tabRect) + floor((NSHeight(tabRect) - iconSize.height) * 0.5),
|
|
|
|
iconSize.width,
|
|
|
|
iconSize.height);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[fIcon drawInRect:iconRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
|
2007-10-18 00:04:01 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-01-30 19:34:38 +00:00
|
|
|
[tabImage unlockFocus];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
self.image = tabImage;
|
2007-10-18 00:04:01 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateControlTint:(NSNotification*)notification
|
2011-01-30 02:36:08 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSAssert(!NSApp.onMojaveOrBetter, @"should not be observing control tint color when accent color is available");
|
2019-02-16 07:50:37 +00:00
|
|
|
|
2011-01-30 02:36:08 +00:00
|
|
|
if (fSelected)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self setSelectedTab:YES];
|
|
|
|
}
|
2011-01-30 02:36:08 +00:00
|
|
|
}
|
|
|
|
|
2007-10-06 22:23:44 +00:00
|
|
|
@end
|