source: trunk/macosx/TorrentTableView.m @ 261

Last change on this file since 261 was 261, checked in by titer, 16 years ago

Updated svn:keywords

  • Property svn:keywords set to Date Rev Author Id
File size: 5.8 KB
Line 
1/******************************************************************************
2 * $Id: TorrentTableView.m 261 2006-05-29 21:27:31Z titer $
3 *
4 * Copyright (c) 2005-2006 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 "TorrentTableView.h"
26#import "Controller.h"
27#import "Torrent.h"
28#import "Utils.h"
29
30@implementation TorrentTableView
31
32- (void) setTorrents: (NSArray *) torrents
33{
34    fTorrents = torrents;
35}
36
37- (NSRect) pauseRectForRow: (int) row
38{
39    int col;
40    NSRect cellRect, rect;
41
42    col      = [self columnWithIdentifier: @"Torrent"];
43    cellRect = [self frameOfCellAtColumn: col row: row];
44    rect     = NSMakeRect( cellRect.origin.x + cellRect.size.width - 39,
45                           cellRect.origin.y + 3, 14, 14 );
46
47    return rect;
48}
49
50- (NSRect) revealRectForRow: (int) row
51{
52    int col;
53    NSRect cellRect, rect;
54
55    col      = [self columnWithIdentifier: @"Torrent"];
56    cellRect = [self frameOfCellAtColumn: col row: row];
57    rect     = NSMakeRect( cellRect.origin.x + cellRect.size.width - 20,
58                           cellRect.origin.y + 3, 14, 14 );
59
60    return rect;
61}
62
63- (BOOL) pointInPauseRect: (NSPoint) point
64{
65    return NSPointInRect( point, [self pauseRectForRow:
66                                    [self rowAtPoint: point]] );
67}
68
69- (BOOL) pointInRevealRect: (NSPoint) point
70{
71    return NSPointInRect( point, [self revealRectForRow:
72                                    [self rowAtPoint: point]] );
73}
74
75- (void) mouseDown: (NSEvent *) e
76{
77    fClickPoint = [self convertPoint: [e locationInWindow] fromView: nil];
78    int row = [self rowAtPoint: fClickPoint];
79
80    if( [e modifierFlags] & NSAlternateKeyMask )
81    {
82        [fController advancedChanged: self];
83        fClickPoint = NSMakePoint( 0, 0 );
84    }
85    else if( ![self pointInPauseRect: fClickPoint] &&
86             ![self pointInRevealRect: fClickPoint] )
87    {
88        [super mouseDown: e];
89    }
90    else;
91
92    [self display];
93}
94
95- (void) mouseUp: (NSEvent *) e
96{
97    NSPoint point;
98    int row;
99    bool sameRow;
100    Torrent * torrent;
101
102    point = [self convertPoint: [e locationInWindow] fromView: nil];
103    row   = [self rowAtPoint: point];
104    sameRow = row == [self rowAtPoint: fClickPoint];
105   
106    if( sameRow && [self pointInPauseRect: point]
107            && [self pointInPauseRect: fClickPoint] )
108    {
109        torrent = [fTorrents objectAtIndex: row];
110
111                if( [torrent isPaused] )
112                        [fController resumeTorrentWithIndex: [NSIndexSet indexSetWithIndex: row]];
113                else if( [torrent isActive] )
114                        [fController stopTorrentWithIndex: [NSIndexSet indexSetWithIndex: row]];
115                else;
116    }
117    else if( sameRow && [self pointInRevealRect: point]
118                && [self pointInRevealRect: fClickPoint] )
119    {
120        torrent = [fTorrents objectAtIndex: row];
121        [torrent reveal];
122    }
123        else;
124   
125        [super mouseUp: e];
126
127    fClickPoint = NSMakePoint( 0, 0 );
128    [self display];
129}
130
131- (NSMenu *) menuForEvent: (NSEvent *) e
132{
133    NSPoint point;
134    int row;
135
136    point = [self convertPoint: [e locationInWindow] fromView: nil];
137    row = [self rowAtPoint: point];
138   
139    if( row >= 0 )
140    {
141        if (![self isRowSelected: row])
142            [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row]
143                byExtendingSelection: NO];
144               
145        return fContextRow;
146    }
147    else
148    {
149        [self deselectAll: self];
150        return fContextNoRow;
151    }
152}
153
154- (void) drawRect: (NSRect) r
155{
156    unsigned i;
157    NSRect rect;
158    NSImage * image;
159    Torrent * torrent;
160
161    [super drawRect: r];
162
163    for( i = 0; i < [fTorrents count]; i++ )
164    {
165        torrent = [fTorrents objectAtIndex: i];
166        rect  = [self pauseRectForRow: i];
167        image = nil;
168
169        if( [torrent isPaused] )
170        {
171            image = NSPointInRect( fClickPoint, rect ) ?
172                [NSImage imageNamed: @"ResumeOn.png"] :
173                [NSImage imageNamed: @"ResumeOff.png"];
174        }
175        else if( [torrent isActive] )
176        {
177            image = NSPointInRect( fClickPoint, rect ) ?
178                [NSImage imageNamed: @"PauseOn.png"] :
179                [NSImage imageNamed: @"PauseOff.png"];
180        }
181        else;
182
183        if( image )
184        {
185            [image setFlipped: YES];
186            [image drawAtPoint: rect.origin fromRect:
187                NSMakeRect( 0, 0, 14, 14 ) operation:
188                NSCompositeSourceOver fraction: 1.0];
189        }
190
191        rect  = [self revealRectForRow: i];
192        image = NSPointInRect( fClickPoint, rect ) ?
193            [NSImage imageNamed: @"RevealOn.png"] :
194            [NSImage imageNamed: @"RevealOff.png"];
195        [image setFlipped: YES];
196        [image drawAtPoint: rect.origin fromRect:
197            NSMakeRect( 0, 0, 14, 14 ) operation:
198            NSCompositeSourceOver fraction: 1.0];
199    }
200}
201
202@end
Note: See TracBrowser for help on using the repository browser.