source: trunk/macosx/InfoTabButtonCell.m @ 4779

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

support adding torrent from data with ipc

  • Property svn:keywords set to Date Rev Author Id
File size: 3.6 KB
Line 
1/******************************************************************************
2 * $Id: InfoTabButtonCell.m 4779 2008-01-21 06:23:10Z livings124 $
3 *
4 * Copyright (c) 2007-2008 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    [(NSMatrix *)[self controlView] setToolTip: [self title] forCell: self];
32   
33    NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
34    [nc addObserver: self selector: @selector(updateControlTint:)
35            name: NSControlTintDidChangeNotification object: nil];
36   
37    fSelected = NO;
38}
39
40- (void) dealloc
41{
42    [[NSNotificationCenter defaultCenter] removeObserver: self];
43   
44    [fIcon release];
45   
46    [fRegularImage release];
47    [fSelectedImage release];
48    [super dealloc];
49}
50
51- (void) setIcon: (NSImage *) image
52{
53    [fIcon release];
54    fIcon = [image retain];
55   
56    if (fRegularImage)
57    {
58        [fRegularImage release];
59        fRegularImage = nil;
60    }
61    if (fSelectedImage)
62    {
63        [fSelectedImage release];
64        fSelectedImage = nil;
65    }
66   
67    [self setSelectedTab: fSelected];
68}
69
70- (void) setSelectedTab: (BOOL) selected
71{
72    fSelected = selected;
73   
74    NSImage * tabImage;
75    BOOL createImage = NO;
76    if (fSelected)
77    {
78        if (!fSelectedImage)
79        {
80            fSelectedImage = [NSColor currentControlTint] == NSGraphiteControlTint
81                ? [[NSImage imageNamed: @"InfoTabBackGraphite.png"] copy] : [[NSImage imageNamed: @"InfoTabBackBlue.png"] copy];
82            createImage = YES;
83        }
84        tabImage = fSelectedImage;
85    }
86    else
87    {
88        if (!fRegularImage)
89        {
90            fRegularImage = [[NSImage imageNamed: @"InfoTabBack.png"] copy];
91            createImage = YES;
92        }
93        tabImage = fRegularImage;
94    }
95   
96    if (createImage)
97    {
98        if (fIcon)
99        {
100            NSSize iconSize = [fIcon size], tabSize = [tabImage size];
101            NSPoint point = NSMakePoint(floorf((tabSize.width - iconSize.width) * 0.5),
102                                        floorf((tabSize.height - iconSize.height) * 0.5));
103           
104            [tabImage lockFocus];
105            [fIcon compositeToPoint: point operation: NSCompositeSourceOver];
106            [tabImage unlockFocus];
107        }
108    }
109   
110    [self setImage: tabImage];
111}
112
113- (void) updateControlTint: (NSNotification *) notification
114{
115    [fSelectedImage release];
116    fSelectedImage = nil;
117   
118    if (fSelected)
119        [self setSelectedTab: YES];
120}
121
122@end
Note: See TracBrowser for help on using the repository browser.