source: branches/new_api/macosx/TorrentTableView.m @ 149

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

Fixed Alt-Click to switch to Advanced Bar

File size: 5.6 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
26@implementation TorrentTableView
27
28- (void) pauseOrResume: (int) row
29{
30#if 0
31    if( fStat[row].status & TR_STATUS_PAUSE )
32    {
33        [fController resumeTorrentWithIndex: row];
34    }
35    else if( fStat[row].status & ( TR_STATUS_CHECK |
36              TR_STATUS_DOWNLOAD | TR_STATUS_SEED ) )
37    {
38        [fController stopTorrentWithIndex: row];
39    }                                                                   
40#endif
41}
42
43- (void) mouseDown: (NSEvent *) e
44{
45    fClickPoint = [self convertPoint: [e locationInWindow] fromView: NULL];
46    [self display];
47}
48
49- (NSRect) pauseRectForRow: (int) row
50{
51    int col;
52    NSRect cellRect, rect;
53
54    col      = [self columnWithIdentifier: @"Name"];
55    cellRect = [self frameOfCellAtColumn: col row: row];
56    rect     = NSMakeRect( cellRect.origin.x + cellRect.size.width - 19,
57                           cellRect.origin.y + cellRect.size.height - 38,
58                           14, 14 );
59
60    return rect;
61}
62
63- (NSRect) revealRectForRow: (int) row
64{
65    int col;
66    NSRect cellRect, rect;
67
68    col      = [self columnWithIdentifier: @"Name"];
69    cellRect = [self frameOfCellAtColumn: col row: row];
70    rect     = NSMakeRect( cellRect.origin.x + cellRect.size.width - 19,
71                           cellRect.origin.y + cellRect.size.height - 19,
72                           14, 14 );
73
74    return rect;
75}
76
77- (BOOL) pointInPauseRect: (NSPoint) point
78{
79    return NSPointInRect( point, [self pauseRectForRow:
80                                    [self rowAtPoint: point]] );
81}
82
83- (BOOL) pointInRevealRect: (NSPoint) point
84{
85    return NSPointInRect( point, [self revealRectForRow:
86                                    [self rowAtPoint: point]] );
87}
88
89- (void) mouseUp: (NSEvent *) e
90{
91    NSPoint point;
92    int row, col;
93
94    point = [self convertPoint: [e locationInWindow] fromView: NULL];
95    row   = [self rowAtPoint: point];
96    col   = [self columnAtPoint: point];
97
98    if( row < 0 )
99    {
100        [self deselectAll: NULL];
101    }
102    else if( [self pointInPauseRect: point] )
103    {
104        [self pauseOrResume: row];
105    }
106    else if( [self pointInRevealRect: point] )
107    {
108#if 0
109        [fController finderReveal: [NSString stringWithFormat:
110            @"%@/%@", [NSString stringWithUTF8String: fStat[row].folder],
111            [NSString stringWithUTF8String: fStat[row].info.name]]];
112        [self display];
113#endif
114    }
115    else if( row >= 0 && ( [e modifierFlags] & NSAlternateKeyMask ) )
116    {
117        [fController advancedChanged: self];
118    }
119    else
120    {
121        [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row]
122            byExtendingSelection: NO];
123    }
124
125    fClickPoint = NSMakePoint( 0, 0 );
126}
127
128- (NSMenu *) menuForEvent: (NSEvent *) e
129{
130    NSPoint point;
131    int row;
132
133    point = [self convertPoint: [e locationInWindow] fromView: NULL];
134    row = [self rowAtPoint: point];
135   
136    [self selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
137
138    return row >= 0 ? fContextRow : fContextNoRow;
139}
140
141- (void) drawRect: (NSRect) r
142{
143    int i;
144    NSRect rect;
145    NSPoint point;
146    NSImage * image;
147
148    [super drawRect: r];
149
150#if 0
151    for( i = 0; i < [self numberOfRows]; i++ )
152    {
153        rect  = [self pauseRectForRow: i];
154        image = NULL;
155        if( fStat[i].status & TR_STATUS_PAUSE )
156        {
157            image = NSPointInRect( fClickPoint, rect ) ?
158                [NSImage imageNamed: @"ResumeOn.png"] :
159                [NSImage imageNamed: @"ResumeOff.png"];
160        }
161        else if( fStat[i].status &
162                 ( TR_STATUS_CHECK | TR_STATUS_DOWNLOAD | TR_STATUS_SEED ) )
163        {
164            image = NSPointInRect( fClickPoint, rect ) ?
165                [NSImage imageNamed: @"PauseOn.png"] :
166                [NSImage imageNamed: @"PauseOff.png"];
167        }
168        if( image )
169        {
170            point = NSMakePoint( rect.origin.x, rect.origin.y + 14 );
171            [image compositeToPoint: point operation: NSCompositeSourceOver];
172        }
173
174        rect  = [self revealRectForRow: i];
175        image = NSPointInRect( fClickPoint, rect ) ?
176            [NSImage imageNamed: @"RevealOn.png"] :
177            [NSImage imageNamed: @"RevealOff.png"];
178        point = NSMakePoint( rect.origin.x, rect.origin.y + 14 );
179        [image compositeToPoint: point operation: NSCompositeSourceOver];
180    }
181#endif
182}
183
184@end
Note: See TracBrowser for help on using the repository browser.