source: trunk/macosx/TrackerTableView.m @ 6889

Last change on this file since 6889 was 6889, checked in by livings124, 14 years ago

more changes in counter scope

  • Property svn:keywords set to Date Rev Author Id
File size: 3.6 KB
Line 
1/******************************************************************************
2 * $Id: TrackerTableView.m 6889 2008-10-12 22:17:27Z livings124 $
3 *
4 * Copyright (c) 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 "TrackerTableView.h"
26#import "NSApplicationAdditions.h"
27
28@implementation TrackerTableView
29
30- (void) mouseDown: (NSEvent *) event
31{
32    [[self window] makeKeyWindow];
33    [super mouseDown: event];
34}
35
36- (void) setTrackers: (NSArray *) trackers
37{
38    fTrackers = trackers;
39}
40
41//alternating rows - first row after group row is white
42- (void) highlightSelectionInClipRect: (NSRect) clipRect
43{
44    NSColor * altColor = [[NSColor controlAlternatingRowBackgroundColors] objectAtIndex: 1];
45    [altColor set];
46   
47    NSRect visibleRect = clipRect;
48    NSRange rows = [self rowsInRect: visibleRect];
49    BOOL start = YES;
50   
51    if (rows.length > 0)
52    {
53        BOOL onLeopard = [NSApp isOnLeopardOrBetter];
54       
55        //determine what the first row color should be
56        if (onLeopard)
57        {
58            if (![[fTrackers objectAtIndex: rows.location] isKindOfClass: [NSNumber class]])
59            {
60                for (NSInteger i = rows.location-1; i>=0; i--)
61                {
62                    if ([[fTrackers objectAtIndex: i] isKindOfClass: [NSNumber class]])
63                        break;
64                    start = !start;
65                }
66            }
67            else
68            {
69                rows.location++;
70                rows.length--;
71            }
72        }
73       
74        NSInteger i;
75        for (i = rows.location; i < NSMaxRange(rows); i++)
76        {
77            if ([[fTrackers objectAtIndex: i] isKindOfClass: [NSNumber class]] && onLeopard)
78            {
79                start = YES;
80                continue;
81            }
82           
83            if (!start && ![self isRowSelected: i])
84                NSRectFill([self rectOfRow: i]);
85           
86            start = !start;
87        }
88       
89        float newY = NSMaxY([self rectOfRow: i-1]);
90        visibleRect.size.height -= newY - visibleRect.origin.y;
91        visibleRect.origin.y = newY;
92    }
93   
94    //remaining visible rows continue alternating
95    float height = [self rowHeight] + [self intercellSpacing].height;
96    int numberOfRects = ceil(visibleRect.size.height / height);
97    visibleRect.size.height = height;
98   
99    for (NSInteger i=0; i<numberOfRects; i++)
100    {
101        if (!start)
102            NSRectFill(visibleRect);
103       
104        start = !start;
105        visibleRect.origin.y += height;
106    }
107   
108    [super highlightSelectionInClipRect: clipRect];
109}
110
111@end
Note: See TracBrowser for help on using the repository browser.