1 | /****************************************************************************** |
---|
2 | * $Id: InfoTabButtonCell.m 3299 2007-10-06 22:59:07Z 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) dealloc |
---|
30 | { |
---|
31 | [fRegularImage release]; |
---|
32 | [fSelectedImage release]; |
---|
33 | [super dealloc]; |
---|
34 | } |
---|
35 | |
---|
36 | - (void) setImage: (NSImage *) image |
---|
37 | { |
---|
38 | //create regular back image |
---|
39 | if (fRegularImage) |
---|
40 | [fRegularImage release]; |
---|
41 | fRegularImage = [[NSImage imageNamed: @"InfoTabBack.tif"] copy]; |
---|
42 | [fRegularImage setFlipped: YES]; |
---|
43 | |
---|
44 | //create selected back image |
---|
45 | if (fSelectedImage) |
---|
46 | [fSelectedImage release]; |
---|
47 | fSelectedImage = [[NSImage imageNamed: @"InfoTabBackAqua.tif"] copy]; |
---|
48 | [fSelectedImage setFlipped: YES]; |
---|
49 | |
---|
50 | //composite image to back images |
---|
51 | if (image) |
---|
52 | { |
---|
53 | NSSize imageSize = [image size]; |
---|
54 | NSRect imageRect = NSMakeRect(0, 0, [fRegularImage size].width, [fRegularImage size].height); |
---|
55 | NSRect rect = NSMakeRect(imageRect.origin.x + (imageRect.size.width - imageSize.width) * 0.5, |
---|
56 | imageRect.origin.y + (imageRect.size.height - imageSize.height) * 0.5, imageSize.width, imageSize.height); |
---|
57 | |
---|
58 | [fRegularImage lockFocus]; |
---|
59 | [image drawInRect: rect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0]; |
---|
60 | [fRegularImage unlockFocus]; |
---|
61 | |
---|
62 | [fSelectedImage lockFocus]; |
---|
63 | [image drawInRect: rect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0]; |
---|
64 | [fSelectedImage unlockFocus]; |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | - (void) setPushed: (BOOL) pushed |
---|
69 | { |
---|
70 | fPushed = pushed; |
---|
71 | } |
---|
72 | |
---|
73 | - (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) controlView |
---|
74 | { |
---|
75 | #warning dim instead of set selected |
---|
76 | NSImage * image; |
---|
77 | if ([(NSMatrix *)controlView selectedCell] == self || fPushed) |
---|
78 | { |
---|
79 | if (!fSelectedImage) |
---|
80 | [self setImage: nil]; |
---|
81 | image = fSelectedImage; |
---|
82 | } |
---|
83 | else |
---|
84 | { |
---|
85 | if (!fRegularImage) |
---|
86 | [self setImage: nil]; |
---|
87 | image = fRegularImage; |
---|
88 | } |
---|
89 | |
---|
90 | [image drawInRect: cellFrame fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0]; |
---|
91 | //[super drawWithFrame: cellFrame inView: controlView]; |
---|
92 | } |
---|
93 | |
---|
94 | @end |
---|