source: trunk/macosx/TorrentTableView.m @ 2828

Last change on this file since 2828 was 2828, checked in by livings124, 15 years ago

attempt to fix stuck overlay window

  • Property svn:keywords set to Date Rev Author Id
File size: 22.0 KB
Line 
1/******************************************************************************
2 * $Id: TorrentTableView.m 2828 2007-08-18 02:11:45Z livings124 $
3 *
4 * Copyright (c) 2005-2007 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 "TorrentCell.h"
27#import "Controller.h"
28#import "Torrent.h"
29
30#define PADDING 3.0
31
32#define BUTTON_TO_TOP_REGULAR 33.0
33#define BUTTON_TO_TOP_SMALL 20.0
34
35#define ACTION_BUTTON_TO_TOP 47.0
36
37#define ACTION_MENU_GLOBAL_TAG 101
38#define ACTION_MENU_UNLIMITED_TAG 102
39#define ACTION_MENU_LIMIT_TAG 103
40
41#define ACTION_MENU_FILE_TAG 201
42
43@interface TorrentTableView (Private)
44
45- (NSRect) pauseRectForRow: (int) row;
46- (NSRect) revealRectForRow: (int) row;
47- (NSRect) actionRectForRow: (int) row;
48
49- (BOOL) pointInIconRect: (NSPoint) point;
50- (BOOL) pointInMinimalStatusRect: (NSPoint) point;
51
52- (BOOL) pointInPauseRect: (NSPoint) point;
53- (BOOL) pointInRevealRect: (NSPoint) point;
54- (BOOL) pointInActionRect: (NSPoint) point;
55
56@end
57
58@implementation TorrentTableView
59
60- (id) initWithCoder: (NSCoder *) decoder
61{
62    if ((self = [super initWithCoder: decoder]))
63    {
64        fResumeOnIcon = [NSImage imageNamed: @"ResumeOn.png"];
65        fResumeOffIcon = [NSImage imageNamed: @"ResumeOff.png"];
66        fPauseOnIcon = [NSImage imageNamed: @"PauseOn.png"];
67        fPauseOffIcon = [NSImage imageNamed: @"PauseOff.png"];
68        fResumeNoWaitOnIcon = [NSImage imageNamed: @"ResumeNoWaitOn.png"];
69        fResumeNoWaitOffIcon = [NSImage imageNamed: @"ResumeNoWaitOff.png"];
70       
71        fRevealOnIcon = [NSImage imageNamed: @"RevealOn.png"];
72        fRevealOffIcon = [NSImage imageNamed: @"RevealOff.png"];
73       
74        fActionOnIcon = [NSImage imageNamed: @"ActionOn.png"];
75        fActionOffIcon = [NSImage imageNamed: @"ActionOff.png"];
76       
77        fClickPoint = NSZeroPoint;
78        fClickIn = NO;
79       
80        fKeyStrokes = [[NSMutableArray alloc] init];
81       
82        fSmallStatusAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
83                                        [NSFont messageFontOfSize: 9.0], NSFontAttributeName, nil];
84       
85        fDefaults = [NSUserDefaults standardUserDefaults];
86       
87        [self setDelegate: self];
88    }
89   
90    return self;
91}
92   
93- (void) awakeFromNib
94{
95    [fContextRow setTitle: @"Context"];
96    [fContextNoRow setTitle: @"Context"];
97}
98
99- (void) dealloc
100{
101    [fKeyStrokes release];
102    [fSmallStatusAttributes release];
103   
104    [fMenuTorrent release];
105   
106    [super dealloc];
107}
108
109- (void) setTorrents: (NSArray *) torrents
110{
111    fTorrents = torrents;
112}
113
114- (void) tableView: (NSTableView *) tableView willDisplayCell: (id) cell
115        forTableColumn: (NSTableColumn *) tableColumn row: (int) row
116{
117    [cell setRepresentedObject: [fTorrents objectAtIndex: row]];
118}
119
120- (void) mouseDown: (NSEvent *) event
121{
122    fClickPoint = [self convertPoint: [event locationInWindow] fromView: nil];
123
124    if ([self pointInActionRect: fClickPoint])
125    {
126        int row = [self rowAtPoint: fClickPoint];
127        [self setNeedsDisplayInRect: [self rectOfRow: row]]; //ensure button is pushed down
128       
129        [self displayTorrentMenuForEvent: event];
130       
131        fClickPoint = NSZeroPoint;
132        [self setNeedsDisplayInRect: [self rectOfRow: row]];
133    }
134    else if ([self pointInPauseRect: fClickPoint] || [self pointInRevealRect: fClickPoint])
135    {
136        fClickIn = YES;
137        [self setNeedsDisplayInRect: [self rectOfRow: [self rowAtPoint: fClickPoint]]];
138    }
139    else
140    {
141        if ([event modifierFlags] & NSAlternateKeyMask)
142        {
143            [fDefaults setBool: ![fDefaults boolForKey: @"UseAdvancedBar"] forKey: @"UseAdvancedBar"];
144            fClickPoint = NSZeroPoint;
145            [self reloadData];
146        }
147        else
148        {
149            if ([self pointInMinimalStatusRect: fClickPoint])
150            {
151                [fDefaults setBool: ![fDefaults boolForKey: @"SmallStatusRegular"] forKey: @"SmallStatusRegular"];
152                fClickPoint = NSZeroPoint;
153                [self reloadData];
154            }
155
156            [super mouseDown: event];
157        }
158    }
159}
160
161- (void) mouseUp: (NSEvent *) event
162{
163    NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil];
164    int row = [self rowAtPoint: point], oldRow = [self rowAtPoint: fClickPoint];
165    BOOL sameRow = row == oldRow;
166   
167    if (sameRow && [self pointInPauseRect: point] && [self pointInPauseRect: fClickPoint])
168    {
169        Torrent * torrent = [fTorrents objectAtIndex: row];
170
171        if ([torrent isActive])
172            [fController stopTorrents: [NSArray arrayWithObject: torrent]];
173        else if ([torrent isPaused])
174        {
175            if ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask)
176                [fController resumeTorrentsNoWait: [NSArray arrayWithObject: torrent]];
177            else if ([torrent waitingToStart])
178                [fController stopTorrents: [NSArray arrayWithObject: torrent]];
179            else
180                [fController resumeTorrents: [NSArray arrayWithObject: torrent]];
181        }
182        else;
183    }
184    else if (sameRow && [self pointInRevealRect: point] && [self pointInRevealRect: fClickPoint])
185        [[fTorrents objectAtIndex: row] revealData];
186    else if ([event clickCount] == 2 && !NSEqualPoints(fClickPoint, NSZeroPoint))
187    {
188        if ([self pointInIconRect: point])
189            [[fTorrents objectAtIndex: row] revealData];
190        else if (![self pointInActionRect: point])
191            [fController showInfo: nil];
192        else;
193    }
194    else;
195   
196    [super mouseUp: event];
197
198    fClickPoint = NSZeroPoint;
199    fClickIn = NO;
200    [self setNeedsDisplayInRect: [self rectOfRow: oldRow]];
201}
202
203- (void) mouseDragged: (NSEvent *) event
204{
205    if (NSEqualPoints(fClickPoint, NSZeroPoint))
206    {
207        [super mouseDragged: event];
208        return;
209    }
210   
211    NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil];
212    int oldRow = [self rowAtPoint: fClickPoint];
213   
214    BOOL inRect;
215    if ([self pointInRevealRect: fClickPoint])
216        inRect = oldRow == [self rowAtPoint: point] && [self pointInRevealRect: point];
217    else if ([self pointInPauseRect: fClickPoint])
218        inRect = oldRow == [self rowAtPoint: point] && [self pointInPauseRect: point];
219    else
220    {
221        [super mouseDragged: event];
222        return;
223    }
224   
225    if (inRect != fClickIn)
226    {
227        fClickIn = inRect;
228        [self setNeedsDisplayInRect: [self rectOfRow: oldRow]];
229    }
230}
231
232- (NSMenu *) menuForEvent: (NSEvent *) event
233{
234    int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
235   
236    if (row >= 0)
237    {
238        if (![self isRowSelected: row])
239            [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO];
240               
241        return fContextRow;
242    }
243    else
244    {
245        [self deselectAll: self];
246        return fContextNoRow;
247    }
248}
249
250- (void) keyDown: (NSEvent *) event
251{
252    unichar newChar = [[event characters] characterAtIndex: 0];
253    if (newChar == ' ' || [[NSCharacterSet alphanumericCharacterSet] characterIsMember: newChar]
254        || [[NSCharacterSet symbolCharacterSet] characterIsMember: newChar]
255        || [[NSCharacterSet punctuationCharacterSet] characterIsMember: newChar])
256    {
257        if ([fKeyStrokes count] > 0 && [event timestamp] - [[fKeyStrokes lastObject] timestamp] > 1.0)
258            [fKeyStrokes removeAllObjects];
259        [fKeyStrokes addObject: event];
260   
261        [self interpretKeyEvents: fKeyStrokes];
262    }
263    else
264    {
265        if ([fKeyStrokes count] > 0)
266            [fKeyStrokes removeAllObjects];
267       
268        [super keyDown: event];
269    }
270}
271
272- (void) flagsChanged: (NSEvent *) event
273{
274    [self display];
275    [super flagsChanged: event];
276}
277
278- (void) insertText: (NSString *) text
279{
280    //sort torrents by name before finding closest match
281    NSSortDescriptor * nameDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: YES
282                                            selector: @selector(caseInsensitiveCompare:)] autorelease];
283    NSArray * descriptors = [[NSArray alloc] initWithObjects: nameDescriptor, nil];
284
285    NSArray * tempTorrents = [fTorrents sortedArrayUsingDescriptors: descriptors];
286    [descriptors release];
287   
288    //select torrent closest to text that isn't before text alphabetically
289    int row;
290    NSEnumerator * enumerator = [tempTorrents objectEnumerator];
291    Torrent * torrent;
292    while ((torrent = [enumerator nextObject]))
293        if ([[torrent name] caseInsensitiveCompare: text] != NSOrderedAscending)
294        {
295            row = [fTorrents indexOfObject: torrent];
296            break;
297        }
298   
299    //select last torrent alphabetically if no match found
300    if (!torrent)
301        row = [fTorrents indexOfObject: [tempTorrents lastObject]];
302   
303    [self selectRow: row byExtendingSelection: NO];
304    [self scrollRowToVisible: row];
305}
306
307- (void) displayTorrentMenuForEvent: (NSEvent *) event
308{
309    int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
310    if (row < 0)
311        return;
312   
313    //get file menu
314    fMenuTorrent = [[fTorrents objectAtIndex: row] retain];
315    NSMenu * fileMenu = [fMenuTorrent fileMenu];
316    [fileMenu setDelegate: self];
317   
318    //remove old file menu
319    NSMenuItem * oldFileMenuItem;
320    if ((oldFileMenuItem = [fActionMenu itemWithTag: ACTION_MENU_FILE_TAG]))
321        [fActionMenu removeItem: oldFileMenuItem];
322   
323    //set file menu
324    NSMenuItem * fileMenuItem = [[NSMenuItem alloc] initWithTitle: NSLocalizedString(@"Files",
325                                    "torrent action context menu -> files menu") action: NULL keyEquivalent: @""];
326    [fileMenuItem setTag: ACTION_MENU_FILE_TAG];
327    [fileMenuItem setSubmenu: fileMenu];
328    [fActionMenu addItem: fileMenuItem];
329   
330    [fileMenuItem release];
331   
332    NSRect rect = [self actionRectForRow: row];
333    NSPoint location = rect.origin;
334    location.y += rect.size.height + 5.0;
335    location = [self convertPoint: location toView: nil];
336   
337    NSEvent * newEvent = [NSEvent mouseEventWithType: [event type] location: location
338        modifierFlags: [event modifierFlags] timestamp: [event timestamp] windowNumber: [event windowNumber]
339        context: [event context] eventNumber: [event eventNumber] clickCount: [event clickCount] pressure: [event pressure]];
340   
341    [NSMenu popUpContextMenu: fActionMenu withEvent: newEvent forView: self];
342   
343    [fMenuTorrent release];
344    fMenuTorrent = nil;
345}
346
347- (void) menuNeedsUpdate: (NSMenu *) menu
348{
349    //this method seems to be called when it shouldn't be
350    if (!fMenuTorrent || ![menu supermenu])
351        return;
352   
353    if (menu == fUploadMenu || menu == fDownloadMenu)
354    {
355        BOOL upload = menu == fUploadMenu;
356        tr_speedlimit_t mode = [fMenuTorrent speedMode: upload];
357       
358        NSMenuItem * item = [menu itemWithTag: ACTION_MENU_LIMIT_TAG];
359        [item setState: mode == TR_SPEEDLIMIT_SINGLE ? NSOnState : NSOffState];
360        [item setTitle: [NSString stringWithFormat: NSLocalizedString(@"Limit (%d KB/s)",
361                    "torrent action context menu -> upload/download limit"), [fMenuTorrent speedLimit: upload]]];
362       
363        item = [menu itemWithTag: ACTION_MENU_UNLIMITED_TAG];
364        [item setState: mode == TR_SPEEDLIMIT_UNLIMITED ? NSOnState : NSOffState];
365       
366        item = [menu itemWithTag: ACTION_MENU_GLOBAL_TAG];
367        [item setState: mode == TR_SPEEDLIMIT_GLOBAL ? NSOnState : NSOffState];
368    }
369    else if (menu == fRatioMenu)
370    {
371        int mode = [fMenuTorrent ratioSetting];
372       
373        NSMenuItem * item = [menu itemWithTag: ACTION_MENU_LIMIT_TAG];
374        [item setState: mode == NSOnState ? NSOnState : NSOffState];
375        [item setTitle: [NSString stringWithFormat: NSLocalizedString(@"Stop at Ratio (%.2f)",
376                    "torrent action context menu -> ratio stop"), [fMenuTorrent ratioLimit]]];
377       
378        item = [menu itemWithTag: ACTION_MENU_UNLIMITED_TAG];
379        [item setState: mode == NSOffState ? NSOnState : NSOffState];
380       
381        item = [menu itemWithTag: ACTION_MENU_GLOBAL_TAG];
382        [item setState: mode == NSMixedState ? NSOnState : NSOffState];
383    }
384    else if ([menu supermenu]) //assume the menu is part of the file list
385    {
386        BOOL create = [menu numberOfItems] <= 0, folder;
387       
388        NSMenu * supermenu = [menu supermenu];
389        NSArray * items;
390        NSDictionary * folderDict;
391        if ((folderDict = [[supermenu itemAtIndex: [supermenu indexOfItemWithSubmenu: menu]] representedObject]))
392            items = [folderDict objectForKey: @"Children"];
393        else
394            items = [fMenuTorrent fileList];
395       
396        NSEnumerator * enumerator = [items objectEnumerator];
397        NSDictionary * dict;
398        NSMenuItem * item;
399        while ((dict = [enumerator nextObject]))
400        {
401            NSString * name = [dict objectForKey: @"Name"];
402           
403            folder = [[dict objectForKey: @"IsFolder"] boolValue];
404           
405            if (create)
406            {
407                item = [[NSMenuItem alloc] initWithTitle: name action: NULL keyEquivalent: @""];
408               
409                NSImage * icon;
410                if (!folder)
411                {
412                    icon = [[dict objectForKey: @"Icon"] copy];
413                    [icon setFlipped: NO];
414                }
415                else
416                {
417                    NSMenu * itemMenu = [[NSMenu alloc] initWithTitle: name];
418                    [itemMenu setAutoenablesItems: NO];
419                    [item setSubmenu: itemMenu];
420                    [itemMenu setDelegate: self];
421                    [itemMenu release];
422                   
423                    icon = [[[NSWorkspace sharedWorkspace] iconForFileType: NSFileTypeForHFSTypeCode('fldr')] copy];
424                }
425               
426                [item setRepresentedObject: dict];
427               
428                [icon setScalesWhenResized: YES];
429                [icon setSize: NSMakeSize(16.0, 16.0)];
430                [item setImage: icon];
431                [icon release];
432               
433                [item setAction: @selector(checkFile:)];
434               
435                [menu addItem: item];
436                [item release];
437            }
438            else
439                item = [menu itemWithTitle: name];
440           
441            NSIndexSet * indexSet = [dict objectForKey: @"Indexes"];
442            [item setState: [fMenuTorrent checkForFiles: indexSet]];
443            [item setEnabled: [fMenuTorrent canChangeDownloadCheckForFiles: indexSet]];
444        }
445    }
446    else;
447}
448
449- (void) setQuickLimitMode: (id) sender
450{
451    int tag = [sender tag];
452    tr_speedlimit_t mode;
453    if (tag == ACTION_MENU_UNLIMITED_TAG)
454        mode = TR_SPEEDLIMIT_UNLIMITED;
455    else if (tag == ACTION_MENU_LIMIT_TAG)
456        mode = TR_SPEEDLIMIT_SINGLE;
457    else
458        mode = TR_SPEEDLIMIT_GLOBAL;
459   
460    [fMenuTorrent setSpeedMode: mode upload: [sender menu] == fUploadMenu];
461   
462    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateSettings" object: nil];
463}
464
465- (void) setQuickLimit: (id) sender
466{
467    BOOL upload = [sender menu] == fUploadMenu;
468    [fMenuTorrent setSpeedMode: TR_SPEEDLIMIT_SINGLE upload: upload];
469    [fMenuTorrent setSpeedLimit: [[sender title] intValue] upload: upload];
470   
471    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateSettings" object: nil];
472}
473
474- (void) setQuickRatioMode: (id) sender
475
476{
477    int tag = [sender tag];
478    int mode;
479    if (tag == ACTION_MENU_UNLIMITED_TAG)
480        mode = NSOffState;
481    else if (tag == ACTION_MENU_LIMIT_TAG)
482        mode = NSOnState;
483    else
484        mode = NSMixedState;
485   
486    [fMenuTorrent setRatioSetting: mode];
487   
488    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateSettings" object: nil];
489}
490
491- (void) setQuickRatio: (id) sender
492{
493    [fMenuTorrent setRatioSetting: NSOnState];
494    [fMenuTorrent setRatioLimit: [[sender title] floatValue]];
495   
496    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateSettings" object: nil];
497}
498
499- (void) checkFile: (id) sender
500{
501    #warning get working
502    NSIndexSet * indexSet;
503    if ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask)
504        indexSet = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [fMenuTorrent fileCount])];
505    else
506        indexSet = [[sender representedObject] objectForKey: @"Indexes"];
507   
508    [fMenuTorrent setFileCheckState: [sender state] != NSOnState ? NSOnState : NSOffState forIndexes: indexSet];
509   
510    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateStats" object: nil];
511}
512
513- (void) drawRow: (int) row clipRect: (NSRect) rect
514{
515    [super drawRow: row clipRect: rect];
516   
517    Torrent * torrent = [fTorrents objectAtIndex: row];
518   
519    //pause/resume icon
520    NSImage * pauseImage = nil;
521    NSRect pauseRect  = [self pauseRectForRow: row];
522    if ([torrent isActive])
523    {
524        if (![torrent isChecking])
525            pauseImage = fClickIn && NSPointInRect(fClickPoint, pauseRect) ? fPauseOnIcon : fPauseOffIcon;
526    }
527    else if ([torrent isPaused])
528    {
529        BOOL inPauseRect = fClickIn && NSPointInRect(fClickPoint, pauseRect);
530        if ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask && [fDefaults boolForKey: @"Queue"])
531            pauseImage = inPauseRect ? fResumeNoWaitOnIcon : fResumeNoWaitOffIcon;
532        else if ([torrent waitingToStart])
533            pauseImage = inPauseRect ? fPauseOnIcon : fPauseOffIcon;
534        else
535            pauseImage = inPauseRect ? fResumeOnIcon : fResumeOffIcon;
536    }
537    else;
538   
539    if (pauseImage)
540        [pauseImage compositeToPoint: NSMakePoint(pauseRect.origin.x, NSMaxY(pauseRect)) operation: NSCompositeSourceOver];
541   
542    //reveal icon
543    NSRect revealRect = [self revealRectForRow: row];
544    NSImage * revealImage = fClickIn && NSPointInRect(fClickPoint, revealRect) ? fRevealOnIcon : fRevealOffIcon;
545    [revealImage compositeToPoint: NSMakePoint(revealRect.origin.x, NSMaxY(revealRect)) operation: NSCompositeSourceOver];
546   
547    //action icon
548    if (![fDefaults boolForKey: @"SmallView"])
549    {
550        NSRect actionRect = [self actionRectForRow: row];
551        NSImage * actionImage = NSPointInRect(fClickPoint, actionRect) ? fActionOnIcon : fActionOffIcon;
552        [actionImage compositeToPoint: NSMakePoint(actionRect.origin.x, NSMaxY(actionRect)) operation: NSCompositeSourceOver];
553    }
554}
555
556@end
557
558@implementation TorrentTableView (Private)
559
560- (NSRect) pauseRectForRow: (int) row
561{
562    if (row < 0)
563        return NSZeroRect;
564   
565    NSRect cellRect = [self frameOfCellAtColumn: 0 row: row];
566   
567    float buttonToTop = [fDefaults boolForKey: @"SmallView"] ? BUTTON_TO_TOP_SMALL : BUTTON_TO_TOP_REGULAR;
568   
569    return NSMakeRect(NSMaxX(cellRect) - PADDING - BUTTON_WIDTH - PADDING - BUTTON_WIDTH,
570                        cellRect.origin.y + buttonToTop, BUTTON_WIDTH, BUTTON_WIDTH);
571}
572
573- (NSRect) revealRectForRow: (int) row
574{
575    if (row < 0)
576        return NSZeroRect;
577   
578    NSRect cellRect = [self frameOfCellAtColumn: 0 row: row];
579   
580    float buttonToTop = [fDefaults boolForKey: @"SmallView"] ? BUTTON_TO_TOP_SMALL : BUTTON_TO_TOP_REGULAR;
581   
582    return NSMakeRect(NSMaxX(cellRect) - PADDING - BUTTON_WIDTH,
583                        cellRect.origin.y + buttonToTop, BUTTON_WIDTH, BUTTON_WIDTH);
584}
585
586- (NSRect) actionRectForRow: (int) row
587{
588    if (row < 0)
589        return NSZeroRect;
590   
591    TorrentCell * cell = [[self tableColumnWithIdentifier: @"Torrent"] dataCell];
592    NSRect cellRect = [self frameOfCellAtColumn: 0 row: row],
593            iconRect = [cell iconRectForBounds: cellRect];
594   
595    if ([fDefaults boolForKey: @"SmallView"])
596        return iconRect;
597    else
598        return NSMakeRect(iconRect.origin.x + (iconRect.size.width - ACTION_BUTTON_WIDTH) * 0.5,
599                        cellRect.origin.y + ACTION_BUTTON_TO_TOP, ACTION_BUTTON_WIDTH, ACTION_BUTTON_HEIGHT);
600}
601
602- (BOOL) pointInIconRect: (NSPoint) point
603{
604    int row = [self rowAtPoint: point];
605    if (row < 0)
606        return NO;
607   
608    TorrentCell * cell = [[self tableColumnWithIdentifier: @"Torrent"] dataCell];
609    return NSPointInRect(point, [cell iconRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
610}
611
612- (BOOL) pointInMinimalStatusRect: (NSPoint) point
613{
614    int row = [self rowAtPoint: point];
615    if (row < 0 || ![fDefaults boolForKey: @"SmallView"])
616        return NO;
617   
618    TorrentCell * cell = [[self tableColumnWithIdentifier: @"Torrent"] dataCell];
619    [cell setRepresentedObject: [fTorrents objectAtIndex: row]];
620    return NSPointInRect(point, [cell minimalStatusRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
621}
622
623- (BOOL) pointInPauseRect: (NSPoint) point
624{
625    int row = [self rowAtPoint: point];
626    if (row < 0)
627        return NO;
628   
629    return NSPointInRect(point, [self pauseRectForRow: row]);
630}
631
632- (BOOL) pointInRevealRect: (NSPoint) point
633{
634    int row = [self rowAtPoint: point];
635    if (row < 0)
636        return NO;
637   
638    return NSPointInRect(point, [self revealRectForRow: row]);
639}
640
641- (BOOL) pointInActionRect: (NSPoint) point
642{
643    int row = [self rowAtPoint: point];
644    if (row < 0)
645        return NO;
646   
647    return NSPointInRect(point, [self actionRectForRow: row]);
648}
649
650@end
Note: See TracBrowser for help on using the repository browser.