source: trunk/macosx/TorrentTableView.m @ 168

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

Set click point before displaying so that mouse up on a button instantly
deselects it.
Store application icon when first loaded so it doesn't have badges on it.
Move a few things into the nib file
Put ellipis at end of name / tracker / announce if it doesn't fit

File size: 5.9 KB
Line 
1/******************************************************************************
2 * Copyright (c) 2005-2006 Transmission authors and contributors
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 *****************************************************************************/
22
23#import "TorrentTableView.h"
24#import "Controller.h"
25#import "Torrent.h"
26
27@implementation TorrentTableView
28
29- (void) setTorrents: (NSArray *) torrents
30{
31    fTorrents = torrents;
32}
33
34- (void) pauseOrResume: (int) row
35{
36    Torrent * torrent = [fTorrents objectAtIndex: row];
37
38    if( [torrent isPaused] )
39    {
40        [fController resumeTorrentWithIndex: row];
41    }
42    else if( [torrent isActive] )
43    {
44        [fController stopTorrentWithIndex: row];
45    }
46    else;
47}
48
49- (NSRect) pauseRectForRow: (int) row
50{
51    int col;
52    NSRect cellRect, rect;
53
54    col      = [self columnWithIdentifier: @"Torrent"];
55    cellRect = [self frameOfCellAtColumn: col row: row];
56    rect     = NSMakeRect( cellRect.origin.x + cellRect.size.width - 39,
57                           cellRect.origin.y + 3, 14, 14 );
58
59    return rect;
60}
61
62- (NSRect) revealRectForRow: (int) row
63{
64    int col;
65    NSRect cellRect, rect;
66
67    col      = [self columnWithIdentifier: @"Torrent"];
68    cellRect = [self frameOfCellAtColumn: col row: row];
69    rect     = NSMakeRect( cellRect.origin.x + cellRect.size.width - 20,
70                           cellRect.origin.y + 3, 14, 14 );
71
72    return rect;
73}
74
75- (BOOL) pointInPauseRect: (NSPoint) point
76{
77    return NSPointInRect( point, [self pauseRectForRow:
78                                    [self rowAtPoint: point]] );
79}
80
81- (BOOL) pointInRevealRect: (NSPoint) point
82{
83    return NSPointInRect( point, [self revealRectForRow:
84                                    [self rowAtPoint: point]] );
85}
86
87
88- (void) mouseDown: (NSEvent *) e
89{
90    fClickPoint = [self convertPoint: [e locationInWindow] fromView: nil];
91    int row = [self rowAtPoint: fClickPoint];
92
93    if( [e modifierFlags] & NSAlternateKeyMask )
94    {
95        [fController advancedChanged: self];
96        fClickPoint = NSMakePoint( 0, 0 );
97    }
98    else if( ![self pointInPauseRect: fClickPoint] &&
99             ![self pointInRevealRect: fClickPoint] )
100    {
101        if( row >= 0 )
102        {
103            [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row]
104                byExtendingSelection: NO];
105        }
106        else
107        {
108            [self deselectAll: self];
109        }
110    }
111    else;
112
113    [self display];
114}
115
116- (void) mouseUp: (NSEvent *) e
117{
118    NSPoint point;
119    int row;
120    bool sameRow;
121    Torrent * torrent;
122
123    point = [self convertPoint: [e locationInWindow] fromView: nil];
124    row   = [self rowAtPoint: point];
125    sameRow = row == [self rowAtPoint: fClickPoint];
126   
127    if( sameRow && [self pointInPauseRect: point]
128            && [self pointInPauseRect: fClickPoint] )
129    {
130        [self pauseOrResume: row];
131    }
132    else if( sameRow && [self pointInRevealRect: point]
133                && [self pointInRevealRect: fClickPoint] )
134    {
135        torrent = [fTorrents objectAtIndex: row];
136        [torrent reveal];
137    }
138    else;
139
140    fClickPoint = NSMakePoint( 0, 0 );
141    [self display];
142}
143
144- (NSMenu *) menuForEvent: (NSEvent *) e
145{
146    NSPoint point;
147    int row;
148
149    point = [self convertPoint: [e locationInWindow] fromView: nil];
150    row = [self rowAtPoint: point];
151   
152    if( row >= 0 )
153    {
154        [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row]
155            byExtendingSelection: NO];
156        return fContextRow;
157    }
158    else
159    {
160        [self deselectAll: self];
161        return fContextNoRow;
162    }
163}
164
165- (void) drawRect: (NSRect) r
166{
167    unsigned i;
168    NSRect rect;
169    NSImage * image;
170    Torrent * torrent;
171
172    [super drawRect: r];
173
174    for( i = 0; i < [fTorrents count]; i++ )
175    {
176        torrent = [fTorrents objectAtIndex: i];
177        rect  = [self pauseRectForRow: i];
178        image = nil;
179
180        if( [torrent isPaused] )
181        {
182            image = NSPointInRect( fClickPoint, rect ) ?
183                [NSImage imageNamed: @"ResumeOn.png"] :
184                [NSImage imageNamed: @"ResumeOff.png"];
185        }
186        else if( [torrent isActive] )
187        {
188            image = NSPointInRect( fClickPoint, rect ) ?
189                [NSImage imageNamed: @"PauseOn.png"] :
190                [NSImage imageNamed: @"PauseOff.png"];
191        }
192        else;
193
194        if( image )
195        {
196            [image setFlipped: YES];
197            [image drawAtPoint: rect.origin fromRect:
198                NSMakeRect( 0, 0, 14, 14 ) operation:
199                NSCompositeSourceOver fraction: 1.0];
200        }
201
202        rect  = [self revealRectForRow: i];
203        image = NSPointInRect( fClickPoint, rect ) ?
204            [NSImage imageNamed: @"RevealOn.png"] :
205            [NSImage imageNamed: @"RevealOff.png"];
206        [image setFlipped: YES];
207        [image drawAtPoint: rect.origin fromRect:
208            NSMakeRect( 0, 0, 14, 14 ) operation:
209            NSCompositeSourceOver fraction: 1.0];
210    }
211}
212
213@end
Note: See TracBrowser for help on using the repository browser.