Bug Summary

File:Frameworks/AIUtilities Framework/Source/AIAlternatingRowOutlineView.m
Location:line 152, column 3
Description:dead store

Annotated Source Code

1/*-------------------------------------------------------------------------------------------------------*\
2| Adium, Copyright (C) 2001-2005, Adam Iser (adamiser@mac.com | http://www.adiumx.com) |
3\---------------------------------------------------------------------------------------------------------/
4 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU
5 | General Public License as published by the Free Software Foundation; either version 2 of the License,
6 | or (at your option) any later version.
7 |
8 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
9 | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
10 | Public License for more details.
11 |
12 | You should have received a copy of the GNU General Public License along with this program; if not,
13 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14 \------------------------------------------------------------------------------------------------------ */
15
16/*
17 A subclass of outline view that adds:
18
19 - Alternating rows
20 - A vertical column grid
21 - Gradient selection highlighting
22 */
23
24#import "AIAlternatingRowOutlineView.h"
25#import "AIOutlineView.h"
26#import "AIGradient.h"
27#import "AIColorAdditions.h"
28
29@interface AIAlternatingRowOutlineView (PRIVATE)
30- (void)_initAlternatingRowOutlineView;
31- (void)outlineViewDeleteSelectedRows:(NSTableView *)tableView;
32- (void)_drawGridInClipRect:(NSRect)rect;
33- (BOOL)_restoreSelectionFromSavedSelection;
34- (void)_saveCurrentSelection;
35@end
36
37@interface NSOutlineView (Undocumented)
38- (id)_highlightColorForCell:(NSCell *)cell;
39@end
40
41@implementation AIAlternatingRowOutlineView
42
43- (id)initWithCoder:(NSCoder *)aDecoder
44{
45 if ((self = [super initWithCoder:aDecoder])) {
46 [self _initAlternatingRowOutlineView];
47 }
48 return self;
49}
50
51- (id)initWithFrame:(NSRect)frameRect
52{
53 if ((self = [super initWithFrame:frameRect])) {
54 [self _initAlternatingRowOutlineView];
55 }
56 return self;
57}
58
59- (void)_initAlternatingRowOutlineView
60{
61 drawsAlternatingRows = NO( BOOL ) 0;
62 drawsBackground = YES( BOOL ) 1;
63 drawsGradientSelection = NO( BOOL ) 0;
64 alternatingRowColor = [[NSColor colorWithCalibratedRed:(237.0/255.0) green:(243.0/255.0) blue:(254.0/255.0) alpha:1.0] retain];
65
66 [[NSNotificationCenter defaultCenter] addObserver:self
67 selector:@selector(alternatingRowOutlineViewSelectionDidChange:)
68 name:NSOutlineViewSelectionDidChangeNotification
69 object:self];
70}
71
72- (void)dealloc
73{
74 [alternatingRowColor release];
75 [[NSNotificationCenter defaultCenter] removeObserver:self];
76
77 [super dealloc];
78}
79
80
81//Configuring ----------------------------------------------------------------------
82//Toggle the drawing of alternating rows
83- (void)setDrawsAlternatingRows:(BOOL)flag
84{
85 drawsAlternatingRows = flag;
86 [self setNeedsDisplay:YES( BOOL ) 1];
87}
88- (BOOL)drawsAlternatingRows{
89 return drawsAlternatingRows;
90}
91
92- (void)setDrawsGradientSelection:(BOOL)inDrawsGradientSelection
93{
94 drawsGradientSelection = inDrawsGradientSelection;
95 [self setNeedsDisplay:YES( BOOL ) 1];
96}
97
98- (BOOL)drawsGradientSelection
99{
100 return drawsGradientSelection;
101}
102
103//Set the alternating row color
104- (void)setAlternatingRowColor:(NSColor *)color
105{
106 if (color != alternatingRowColor) {
107 [alternatingRowColor release];
108 alternatingRowColor = [color retain];
109 [self setNeedsDisplay:YES( BOOL ) 1];
110 }
111}
112- (NSColor *)alternatingRowColor{
113 return alternatingRowColor;
114}
115
116//Toggle drawing of our background (Including the alternating grid)
117//Set this to NO if cells are going to take responsibility for drawing the background or grid
118- (void)setDrawsBackground:(BOOL)inDraw
119{
120 drawsBackground = inDraw;
121 [self setNeedsDisplay:YES( BOOL ) 1];
122}
123- (BOOL)drawsBackground{
124 return drawsBackground;
125}
126
127//Returns the color which will be drawn behind the specified row
128- (NSColor *)backgroundColorForRow:(int)row
129{
130 return ((row % 2) ? [self backgroundColor] : [self alternatingRowColor]);
131}
132
133#pragma mark Drawing
134
135//Draw the alternating colors and grid below the "bottom" of the outlineview
136- (void)drawAlternatingRowsInRect:(NSRect)rect
137{
138 if (!drawsBackground || !drawsAlternatingRows) return;
139
140 NSRect rowRect;
141 int rowHeight;
142 int numberOfRows;
143 int row;
144 int rectNumber = 0;
145
146 //Setup
147 numberOfRows = [self numberOfRows];
148 rowHeight = [self rowHeight];
149 if (numberOfRows == 0) {
150 rowRect = NSMakeRect(0,0,rect.size.width,rowHeight);
151 } else {
Value stored to 'rowRect' is never read
152 rowRect = [self rectOfRow:0];
153 }
154
155 NSRect *gridRects = (NSRect *)malloc(sizeof(NSRect) * (numberOfRows + ((int)round(((rect.size.height / rowHeight) / 2) + 0.5))));
156 for (row = 0; row < numberOfRows; row += 2) {
157 if (row < numberOfRows) {
158 NSRect thisRect = [self rectOfRow:row];
159 if (NSIntersectsRect(thisRect, rect)) {
160 gridRects[rectNumber++] = thisRect;
161 } else {
162 NSLog(@"Not drawing because %@ is not in %@",NSStringFromRect(thisRect),NSStringFromRect(rect));
163 }
164 }
165 }
166
167 if (rectNumber > 0) {
168 [[self alternatingRowColor] set];
169 NSRectFillList(gridRects, rectNumber);
170 }
171 free(gridRects);
172}
173
174- (void)drawRect:(NSRect)rect
175{
176 [super drawRect:rect];
177
178 if (drawsBackground && drawsAlternatingRows && [self drawsGrid]) {
179 [self _drawGridInClipRect:rect];
180 }
181}
182
183#pragma mark Gradient selection and alternating rows
184/*
185 * @brief If we are drawing a gradient selection, returns the gradient to draw
186 */
187- (AIGradient *)selectedControlGradient
188{
189 return [AIGradient selectedControlGradientWithDirection:AIVertical];
190}
191
192- (void)highlightSelectionInClipRect:(NSRect)clipRect
193{
194 [self drawAlternatingRowsInRect:clipRect];
195
196 if (drawsGradientSelection && [[self window] isKeyWindow] && ([[self window] firstResponder] == self)) {
197 NSIndexSet *indices = [self selectedRowIndexes];
198 unsigned int bufSize = [indices count];
199 unsigned int *buf = malloc(bufSize * sizeof(unsigned int));
200 unsigned int i = 0, j = 0;
201
202 AIGradient *gradient = [self selectedControlGradient];
203
204 NSRange range = NSMakeRange([indices firstIndex], ([indices lastIndex]-[indices firstIndex]) + 1);
205 [indices getIndexes:buf maxCount:bufSize inIndexRange:&range];
206
207 NSRect *selectionLineRects = (NSRect *)malloc(sizeof(NSRect) * bufSize);
208
209 while (i < bufSize) {
210 int startIndex = buf[i];
211 int lastIndex = buf[i];
212
213 while ((i + 1 < bufSize) &&
214 (buf[i + 1] == lastIndex + 1)){
215 i++;
216 lastIndex++;
217 }
218
219 NSRect startRow = [self rectOfRow:startIndex];
220 NSRect endRow = [self rectOfRow:lastIndex];
221 if (!NSIsEmptyRect(startRow)) {
222 NSRect thisRect;
223 if (!NSIsEmptyRect(endRow)) {
224 thisRect = NSUnionRect(startRow, endRow);
225 } else {
226 thisRect = startRow;
227 }
228
229 [gradient drawInRect:thisRect];
230
231 //Draw a line at the light side, to make it look a lot cleaner
232 thisRect.size.height = 1;
233 selectionLineRects[j++] = thisRect;
234 }
235
236 i++;
237 }
238
239 [[[gradient firstColor] darkenAndAdjustSaturationBy:0.1] set];
240 NSRectFillListUsingOperation(selectionLineRects, j, NSCompositeSourceOver);
241
242 free(buf);
243 free(selectionLineRects);
244
245 } else {
246 [super highlightSelectionInClipRect:clipRect];
247 }
248}
249
250//Override to prevent drawing glitches; otherwise, the cell will try to draw a highlight, too
251- (id)_highlightColorForCell:(NSCell *)cell
252{
253 if (drawsGradientSelection && [[self window] isKeyWindow] && ([[self window] firstResponder] == self)) {
254 return nil0;
255 } else {
256 return [super _highlightColorForCell:cell];
257 }
258}
259
260- (void)alternatingRowOutlineViewSelectionDidChange:(NSNotification *)notification
261{
262 if (drawsGradientSelection) {
263 //We do fancy drawing, so we need a full redisplay when selection changes
264 [self setNeedsDisplay:YES( BOOL ) 1];
265 }
266}
267
268#pragma mark Grid
269
270- (void)drawGridInClipRect:(NSRect)rect
271{
272 if (drawsBackground && drawsAlternatingRows) {
273 //We do our grid drawing later
274 } else {
275 [super drawGridInClipRect:rect];
276 }
277}
278
279- (void)_drawGridInClipRect:(NSRect)rect
280{
281 NSEnumerator *enumerator;
282 NSTableColumn *column;
283 float xPos = 0.5;
284 int intercellWidth = [self intercellSpacing].width;
285
286 [[self gridColor] set];
287 [NSBezierPath setDefaultLineWidth:1.0];
288
289 enumerator = [[self tableColumns] objectEnumerator];
290 while ((column = [enumerator nextObject])) {
291 xPos += [column width] + intercellWidth;
292
293 [NSBezierPath strokeLineFromPoint:NSMakePoint(xPos, rect.origin.y)
294 toPoint:NSMakePoint(xPos, rect.origin.y + rect.size.height)];
295 }
296}
297
298@end