source: trunk/macosx/FileOutlineView.m @ 7514

Last change on this file since 7514 was 7514, checked in by livings124, 12 years ago

eliminate some more enumerator objects

  • Property Id set to /Users/mitchell/Desktop/Transmission/macosx/ActionMenuRatioToDisplayRatioTransformer.h
  • Property svn:keywords set to Date Rev Author Id
File size: 7.4 KB
Line 
1/******************************************************************************
2 * $Id: FileOutlineView.m 7514 2008-12-26 07:25:17Z 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 "FileOutlineView.h"
26#import "FileNameCell.h"
27#import "FilePriorityCell.h"
28#import "Torrent.h"
29#import "FileListNode.h"
30#import "QuickLookController.h"
31
32@implementation FileOutlineView
33
34- (void) awakeFromNib
35{
36    FileNameCell * nameCell = [[FileNameCell alloc] init];
37    [[self tableColumnWithIdentifier: @"Name"] setDataCell: nameCell];
38    [nameCell release];
39   
40    FilePriorityCell * priorityCell = [[FilePriorityCell alloc] init];
41    [[self tableColumnWithIdentifier: @"Priority"] setDataCell: priorityCell];
42    [priorityCell release];
43   
44    [self setAutoresizesOutlineColumn: NO];
45    [self setIndentationPerLevel: 14.0];
46   
47    NSColor * endingColor = [NSColor colorWithCalibratedRed: 217.0/255.0 green: 250.0/255.0 blue: 211.0/255.0 alpha: 1.0];
48    NSColor * beginningColor = [endingColor blendedColorWithFraction: 0.3 ofColor: [NSColor whiteColor]];
49    fHighPriorityGradient = [[NSGradient alloc] initWithStartingColor: beginningColor endingColor: endingColor];
50   
51    endingColor = [NSColor colorWithCalibratedRed: 255.0/255.0 green: 243.0/255.0 blue: 206.0/255.0 alpha: 1.0];
52    beginningColor = [endingColor blendedColorWithFraction: 0.3 ofColor: [NSColor whiteColor]];
53    fLowPriorityGradient = [[NSGradient alloc] initWithStartingColor: beginningColor endingColor: endingColor];
54   
55    endingColor = [NSColor colorWithCalibratedRed: 225.0/255.0 green: 218.0/255.0 blue: 255.0/255.0 alpha: 1.0];
56    beginningColor = [endingColor blendedColorWithFraction: 0.3 ofColor: [NSColor whiteColor]];
57    fMixedPriorityGradient = [[NSGradient alloc] initWithStartingColor: beginningColor endingColor: endingColor];
58   
59    fMouseRow = -1;
60}
61
62- (void) dealloc
63{
64    [fHighPriorityGradient release];
65    [fLowPriorityGradient release];
66    [fMixedPriorityGradient release];
67   
68    [super dealloc];
69}
70
71- (void) setTorrent: (Torrent *) torrent
72{
73    fTorrent = torrent;
74}
75
76- (Torrent *) torrent
77{
78    return fTorrent;
79}
80
81- (void) mouseDown: (NSEvent *) event
82{
83    [[self window] makeKeyWindow];
84    [super mouseDown: event];
85}
86
87- (void) keyDown: (NSEvent *) event
88{
89    unichar firstChar = [[event charactersIgnoringModifiers] characterAtIndex: 0];
90    if (firstChar == ' ')
91        [[QuickLookController quickLook] toggleQuickLook];
92    else if (firstChar == NSRightArrowFunctionKey)
93        [[QuickLookController quickLook] pressRight];
94    else if (firstChar == NSLeftArrowFunctionKey)
95        [[QuickLookController quickLook] pressLeft];
96    else;
97   
98    [super keyDown: event]; 
99}
100
101- (NSMenu *) menuForEvent: (NSEvent *) event
102{
103    int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
104   
105    if (row >= 0)
106    {
107        if (![self isRowSelected: row])
108            [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO];
109    }
110    else
111        [self deselectAll: self];
112   
113    return [self menu];
114}
115
116- (NSRect) iconRectForRow: (int) row
117{
118    FileNameCell * cell = (FileNameCell *)[self preparedCellAtColumn: [self columnWithIdentifier: @"Name"] row: row];
119    NSRect iconRect = [cell imageRectForBounds: [self rectOfRow: row]];
120   
121    iconRect.origin.x += [self indentationPerLevel] * (float)([self levelForRow: row] + 1);
122    return iconRect;
123}
124
125- (void) updateTrackingAreas
126{
127    [super updateTrackingAreas];
128   
129    for (NSTrackingArea * area in [self trackingAreas])
130    {
131        if ([area owner] == self && [[area userInfo] objectForKey: @"Row"])
132            [self removeTrackingArea: area];
133    }
134   
135    NSRange visibleRows = [self rowsInRect: [self visibleRect]];
136    if (visibleRows.length == 0)
137        return;
138   
139    NSPoint mouseLocation = [self convertPoint: [[self window] convertScreenToBase: [NSEvent mouseLocation]] fromView: nil];
140   
141    for (NSInteger row = visibleRows.location, col = [self columnWithIdentifier: @"Priority"]; row < NSMaxRange(visibleRows); row++)
142    {
143        FilePriorityCell * cell = (FilePriorityCell *)[self preparedCellAtColumn: col row: row];
144       
145        NSDictionary * userInfo = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: row] forKey: @"Row"];
146        [cell addTrackingAreasForView: self inRect: [self frameOfCellAtColumn: col row: row] withUserInfo: userInfo
147                mouseLocation: mouseLocation];
148    }
149}
150
151- (int) hoveredRow
152{
153    return fMouseRow;
154}
155
156- (void) mouseEntered: (NSEvent *) event
157{
158    NSNumber * row;
159    if ((row = [(NSDictionary *)[event userData] objectForKey: @"Row"]))
160    {
161        fMouseRow = [row intValue];
162        [self setNeedsDisplayInRect: [self frameOfCellAtColumn: [self columnWithIdentifier: @"Priority"] row: fMouseRow]];
163    }
164}
165
166- (void) mouseExited: (NSEvent *) event
167{
168    NSNumber * row;
169    if ((row = [(NSDictionary *)[event userData] objectForKey: @"Row"]))
170    {
171        [self setNeedsDisplayInRect: [self frameOfCellAtColumn: [self columnWithIdentifier: @"Priority"] row: [row intValue]]];
172        fMouseRow = -1;
173    }
174}
175
176- (void) drawRow: (NSInteger) row clipRect: (NSRect) clipRect
177{
178    if (![self isRowSelected: row])
179    {
180        NSDictionary * item = [self itemAtRow: row];
181        NSIndexSet * indexes = [(FileListNode *)item indexes];
182       
183        if ([fTorrent checkForFiles: indexes] != NSOffState)
184        {
185            NSGradient * gradient = nil;
186           
187            NSSet * priorities = [fTorrent filePrioritiesForIndexes: indexes];
188            int count = [priorities count];
189            if (count == 1)
190            {
191                switch ([[priorities anyObject] intValue])
192                {
193                    case TR_PRI_LOW:
194                        gradient = fLowPriorityGradient;
195                        break;
196                    case TR_PRI_HIGH:
197                        gradient = fHighPriorityGradient;
198                        break;
199                }
200            }
201            else if (count > 1)
202                gradient = fMixedPriorityGradient;
203            else;
204           
205            if (gradient)
206            {
207                NSRect rect = [self rectOfRow: row];
208                rect.size.height -= 1.0;
209                [gradient drawInRect: rect angle: 90];
210            }
211        }
212    }
213   
214    [super drawRow: row clipRect: clipRect];
215}
216
217@end
Note: See TracBrowser for help on using the repository browser.