source: trunk/macosx/InfoTabButtonCell.m @ 3453

Last change on this file since 3453 was 3453, checked in by livings124, 15 years ago

generate the info tab button images when needed, add backend support for different colored tabs depending on aqua/graphite

  • Property svn:keywords set to Date Rev Author Id
File size: 3.7 KB
Line 
1/******************************************************************************
2 * $Id: InfoTabButtonCell.m 3453 2007-10-18 00:04:01Z livings124 $
3 *
4 * Copyright (c) 2007 Transmission authors and contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#import "InfoTabButtonCell.h"
26
27@implementation InfoTabButtonCell
28
29- (void) awakeFromNib
30{
31    NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
32    [nc addObserver: self selector: @selector(updateControlTint:)
33            name: NSControlTintDidChangeNotification object: nil];
34   
35    fSelected = NO;
36}
37
38- (void) dealloc
39{
40    [[NSNotificationCenter defaultCenter] removeObserver: self];
41   
42    [fIcon release];
43   
44    [fRegularImage release];
45    [fSelectedImage release];
46    [super dealloc];
47}
48
49- (void) setIcon: (NSImage *) image
50{
51    [fIcon release];
52    fIcon = image ? [image retain] : nil;
53   
54    if (fRegularImage)
55    {
56        [fRegularImage release];
57        fRegularImage = nil;
58    }
59    if (fSelectedImage)
60    {
61        [fSelectedImage release];
62        fSelectedImage = nil;
63    }
64   
65    [self setSelectedTab: fSelected];
66}
67
68- (void) setSelectedTab: (BOOL) selected
69{
70    fSelected = selected;
71   
72    NSImage * tabImage;
73    BOOL createImage = NO;
74    if (fSelected)
75    {
76        if (!fSelectedImage)
77        {
78            fSelectedImage = [NSColor currentControlTint] == NSGraphiteControlTint ? [[NSImage imageNamed: @"InfoTabBackBlue.tif"] copy]
79                                : [[NSImage imageNamed: @"InfoTabBackBlue.tif"] copy];
80            createImage = YES;
81        }
82        tabImage = fSelectedImage;
83    }
84    else
85    {
86        if (!fRegularImage)
87        {
88            fRegularImage = [[NSImage imageNamed: @"InfoTabBack.tif"] copy];
89            createImage = YES;
90        }
91        tabImage = fRegularImage;
92    }
93   
94    if (createImage)
95    {
96        if (fIcon)
97        {
98            NSSize iconSize = [fIcon size];
99            NSRect imageRect = NSMakeRect(0, 0, [tabImage size].width, [tabImage size].height);
100            NSRect rect = NSMakeRect(imageRect.origin.x + (imageRect.size.width - iconSize.width) * 0.5,
101                            imageRect.origin.y + (imageRect.size.height - iconSize.height) * 0.5, iconSize.width, iconSize.height);
102
103            [tabImage lockFocus];
104            [fIcon drawInRect: rect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
105            [tabImage unlockFocus];
106        }
107    }
108   
109    [self setImage: tabImage];
110}
111
112- (void) updateControlTint: (NSNotification *) notification
113{
114    if (fSelectedImage)
115    {
116        [fSelectedImage release];
117        fSelectedImage = nil;
118    }
119   
120    if (fSelected)
121        [self setSelectedTab: YES];
122}
123
124@end
Note: See TracBrowser for help on using the repository browser.