source: trunk/macosx/TorrentTableView.m @ 2827

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

clean code up a little

  • Property svn:keywords set to Date Rev Author Id
File size: 22.0 KB
Line 
1/******************************************************************************
2 * $Id: TorrentTableView.m 2827 2007-08-18 01:56:10Z 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    BOOL create = [menu numberOfItems] <= 0, folder;
354   
355    #warning move to submethod
356    if (menu == fUploadMenu || menu == fDownloadMenu)
357    {
358        BOOL upload = menu == fUploadMenu;
359        tr_speedlimit_t mode = [fMenuTorrent speedMode: upload];
360       
361        NSMenuItem * item = [menu itemWithTag: ACTION_MENU_LIMIT_TAG];
362        [item setState: mode == TR_SPEEDLIMIT_SINGLE ? NSOnState : NSOffState];
363        [item setTitle: [NSString stringWithFormat: NSLocalizedString(@"Limit (%d KB/s)",
364                    "torrent action context menu -> upload/download limit"), [fMenuTorrent speedLimit: upload]]];
365       
366        item = [menu itemWithTag: ACTION_MENU_UNLIMITED_TAG];
367        [item setState: mode == TR_SPEEDLIMIT_UNLIMITED ? NSOnState : NSOffState];
368       
369        item = [menu itemWithTag: ACTION_MENU_GLOBAL_TAG];
370        [item setState: mode == TR_SPEEDLIMIT_GLOBAL ? NSOnState : NSOffState];
371       
372        return;
373    }
374    else if (menu == fRatioMenu)
375    {
376        int mode = [fMenuTorrent ratioSetting];
377       
378        NSMenuItem * item = [menu itemWithTag: ACTION_MENU_LIMIT_TAG];
379        [item setState: mode == NSOnState ? NSOnState : NSOffState];
380        [item setTitle: [NSString stringWithFormat: NSLocalizedString(@"Stop at Ratio (%.2f)",
381                    "torrent action context menu -> ratio stop"), [fMenuTorrent ratioLimit]]];
382       
383        item = [menu itemWithTag: ACTION_MENU_UNLIMITED_TAG];
384        [item setState: mode == NSOffState ? NSOnState : NSOffState];
385       
386        item = [menu itemWithTag: ACTION_MENU_GLOBAL_TAG];
387        [item setState: mode == NSMixedState ? NSOnState : NSOffState];
388       
389        return;
390    }
391    else if ([menu supermenu]) //assume the menu is part of the file list
392    {
393        NSMenu * supermenu = [menu supermenu];
394        NSArray * items;
395        NSDictionary * folderDict;
396        if ((folderDict = [[supermenu itemAtIndex: [supermenu indexOfItemWithSubmenu: menu]] representedObject]))
397            items = [folderDict objectForKey: @"Children"];
398        else
399            items = [fMenuTorrent fileList];
400       
401        NSEnumerator * enumerator = [items objectEnumerator];
402        NSDictionary * dict;
403        NSMenuItem * item;
404        while ((dict = [enumerator nextObject]))
405        {
406            NSString * name = [dict objectForKey: @"Name"];
407           
408            folder = [[dict objectForKey: @"IsFolder"] boolValue];
409           
410            if (create)
411            {
412                item = [[NSMenuItem alloc] initWithTitle: name action: NULL keyEquivalent: @""];
413               
414                NSImage * icon;
415                if (!folder)
416                {
417                    icon = [[dict objectForKey: @"Icon"] copy];
418                    [icon setFlipped: NO];
419                }
420                else
421                {
422                    NSMenu * itemMenu = [[NSMenu alloc] initWithTitle: name];
423                    [itemMenu setAutoenablesItems: NO];
424                    [item setSubmenu: itemMenu];
425                    [itemMenu setDelegate: self];
426                    [itemMenu release];
427                   
428                    icon = [[[NSWorkspace sharedWorkspace] iconForFileType: NSFileTypeForHFSTypeCode('fldr')] copy];
429                }
430               
431                [item setRepresentedObject: dict];
432               
433                [icon setScalesWhenResized: YES];
434                [icon setSize: NSMakeSize(16.0, 16.0)];
435                [item setImage: icon];
436                [icon release];
437               
438                [item setAction: @selector(checkFile:)];
439               
440                [menu addItem: item];
441                [item release];
442            }
443            else
444                item = [menu itemWithTitle: name];
445           
446            NSIndexSet * indexSet = [dict objectForKey: @"Indexes"];
447            [item setState: [fMenuTorrent checkForFiles: indexSet]];
448            [item setEnabled: [fMenuTorrent canChangeDownloadCheckForFiles: indexSet]];
449        }
450    }
451    else;
452}
453
454- (void) setQuickLimitMode: (id) sender
455{
456    int tag = [sender tag];
457    tr_speedlimit_t mode;
458    if (tag == ACTION_MENU_UNLIMITED_TAG)
459        mode = TR_SPEEDLIMIT_UNLIMITED;
460    else if (tag == ACTION_MENU_LIMIT_TAG)
461        mode = TR_SPEEDLIMIT_SINGLE;
462    else
463        mode = TR_SPEEDLIMIT_GLOBAL;
464   
465    [fMenuTorrent setSpeedMode: mode upload: [sender menu] == fUploadMenu];
466   
467    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateSettings" object: nil];
468}
469
470- (void) setQuickLimit: (id) sender
471{
472    BOOL upload = [sender menu] == fUploadMenu;
473    [fMenuTorrent setSpeedMode: TR_SPEEDLIMIT_SINGLE upload: upload];
474    [fMenuTorrent setSpeedLimit: [[sender title] intValue] upload: upload];
475   
476    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateSettings" object: nil];
477}
478
479- (void) setQuickRatioMode: (id) sender
480
481{
482    int tag = [sender tag];
483    int mode;
484    if (tag == ACTION_MENU_UNLIMITED_TAG)
485        mode = NSOffState;
486    else if (tag == ACTION_MENU_LIMIT_TAG)
487        mode = NSOnState;
488    else
489        mode = NSMixedState;
490   
491    [fMenuTorrent setRatioSetting: mode];
492   
493    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateSettings" object: nil];
494}
495
496- (void) setQuickRatio: (id) sender
497{
498    [fMenuTorrent setRatioSetting: NSOnState];
499    [fMenuTorrent setRatioLimit: [[sender title] floatValue]];
500   
501    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateSettings" object: nil];
502}
503
504- (void) checkFile: (id) sender
505{
506    #warning get working
507    NSIndexSet * indexSet;
508    if ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask)
509        indexSet = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [fMenuTorrent fileCount])];
510    else
511        indexSet = [[sender representedObject] objectForKey: @"Indexes"];
512   
513    [fMenuTorrent setFileCheckState: [sender state] != NSOnState ? NSOnState : NSOffState forIndexes: indexSet];
514   
515    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateStats" object: nil];
516}
517
518- (void) drawRow: (int) row clipRect: (NSRect) rect
519{
520    [super drawRow: row clipRect: rect];
521   
522    Torrent * torrent = [fTorrents objectAtIndex: row];
523   
524    //pause/resume icon
525    NSImage * pauseImage = nil;
526    NSRect pauseRect  = [self pauseRectForRow: row];
527    if ([torrent isActive])
528    {
529        if (![torrent isChecking])
530            pauseImage = fClickIn && NSPointInRect(fClickPoint, pauseRect) ? fPauseOnIcon : fPauseOffIcon;
531    }
532    else if ([torrent isPaused])
533    {
534        BOOL inPauseRect = fClickIn && NSPointInRect(fClickPoint, pauseRect);
535        if ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask && [fDefaults boolForKey: @"Queue"])
536            pauseImage = inPauseRect ? fResumeNoWaitOnIcon : fResumeNoWaitOffIcon;
537        else if ([torrent waitingToStart])
538            pauseImage = inPauseRect ? fPauseOnIcon : fPauseOffIcon;
539        else
540            pauseImage = inPauseRect ? fResumeOnIcon : fResumeOffIcon;
541    }
542    else;
543   
544    if (pauseImage)
545        [pauseImage compositeToPoint: NSMakePoint(pauseRect.origin.x, NSMaxY(pauseRect)) operation: NSCompositeSourceOver];
546   
547    //reveal icon
548    NSRect revealRect = [self revealRectForRow: row];
549    NSImage * revealImage = fClickIn && NSPointInRect(fClickPoint, revealRect) ? fRevealOnIcon : fRevealOffIcon;
550    [revealImage compositeToPoint: NSMakePoint(revealRect.origin.x, NSMaxY(revealRect)) operation: NSCompositeSourceOver];
551   
552    //action icon
553    if (![fDefaults boolForKey: @"SmallView"])
554    {
555        NSRect actionRect = [self actionRectForRow: row];
556        NSImage * actionImage = NSPointInRect(fClickPoint, actionRect) ? fActionOnIcon : fActionOffIcon;
557        [actionImage compositeToPoint: NSMakePoint(actionRect.origin.x, NSMaxY(actionRect)) operation: NSCompositeSourceOver];
558    }
559}
560
561@end
562
563@implementation TorrentTableView (Private)
564
565- (NSRect) pauseRectForRow: (int) row
566{
567    if (row < 0)
568        return NSZeroRect;
569   
570    NSRect cellRect = [self frameOfCellAtColumn: 0 row: row];
571   
572    float buttonToTop = [fDefaults boolForKey: @"SmallView"] ? BUTTON_TO_TOP_SMALL : BUTTON_TO_TOP_REGULAR;
573   
574    return NSMakeRect(NSMaxX(cellRect) - PADDING - BUTTON_WIDTH - PADDING - BUTTON_WIDTH,
575                        cellRect.origin.y + buttonToTop, BUTTON_WIDTH, BUTTON_WIDTH);
576}
577
578- (NSRect) revealRectForRow: (int) row
579{
580    if (row < 0)
581        return NSZeroRect;
582   
583    NSRect cellRect = [self frameOfCellAtColumn: 0 row: row];
584   
585    float buttonToTop = [fDefaults boolForKey: @"SmallView"] ? BUTTON_TO_TOP_SMALL : BUTTON_TO_TOP_REGULAR;
586   
587    return NSMakeRect(NSMaxX(cellRect) - PADDING - BUTTON_WIDTH,
588                        cellRect.origin.y + buttonToTop, BUTTON_WIDTH, BUTTON_WIDTH);
589}
590
591- (NSRect) actionRectForRow: (int) row
592{
593    if (row < 0)
594        return NSZeroRect;
595   
596    TorrentCell * cell = [[self tableColumnWithIdentifier: @"Torrent"] dataCell];
597    NSRect cellRect = [self frameOfCellAtColumn: 0 row: row],
598            iconRect = [cell iconRectForBounds: cellRect];
599   
600    if ([fDefaults boolForKey: @"SmallView"])
601        return iconRect;
602    else
603        return NSMakeRect(iconRect.origin.x + (iconRect.size.width - ACTION_BUTTON_WIDTH) * 0.5,
604                        cellRect.origin.y + ACTION_BUTTON_TO_TOP, ACTION_BUTTON_WIDTH, ACTION_BUTTON_HEIGHT);
605}
606
607- (BOOL) pointInIconRect: (NSPoint) point
608{
609    int row = [self rowAtPoint: point];
610    if (row < 0)
611        return NO;
612   
613    TorrentCell * cell = [[self tableColumnWithIdentifier: @"Torrent"] dataCell];
614    return NSPointInRect(point, [cell iconRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
615}
616
617- (BOOL) pointInMinimalStatusRect: (NSPoint) point
618{
619    int row = [self rowAtPoint: point];
620    if (row < 0 || ![fDefaults boolForKey: @"SmallView"])
621        return NO;
622   
623    TorrentCell * cell = [[self tableColumnWithIdentifier: @"Torrent"] dataCell];
624    [cell setRepresentedObject: [fTorrents objectAtIndex: row]];
625    return NSPointInRect(point, [cell minimalStatusRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
626}
627
628- (BOOL) pointInPauseRect: (NSPoint) point
629{
630    int row = [self rowAtPoint: point];
631    if (row < 0)
632        return NO;
633   
634    return NSPointInRect(point, [self pauseRectForRow: row]);
635}
636
637- (BOOL) pointInRevealRect: (NSPoint) point
638{
639    int row = [self rowAtPoint: point];
640    if (row < 0)
641        return NO;
642   
643    return NSPointInRect(point, [self revealRectForRow: row]);
644}
645
646- (BOOL) pointInActionRect: (NSPoint) point
647{
648    int row = [self rowAtPoint: point];
649    if (row < 0)
650        return NO;
651   
652    return NSPointInRect(point, [self actionRectForRow: row]);
653}
654
655@end
Note: See TracBrowser for help on using the repository browser.