diff --git a/macosx/FileNameCell.h b/macosx/FileNameCell.h index fbff68e43..70ded6991 100644 --- a/macosx/FileNameCell.h +++ b/macosx/FileNameCell.h @@ -31,4 +31,6 @@ NSMutableDictionary * fTitleAttributes, * fStatusAttributes; } +- (NSRect) imageRectForBounds: (NSRect) bounds; + @end diff --git a/macosx/FileNameCell.m b/macosx/FileNameCell.m index bd358c0ad..3d03802a5 100644 --- a/macosx/FileNameCell.m +++ b/macosx/FileNameCell.m @@ -120,18 +120,6 @@ return result; } -- (NSRect) titleRectForBounds: (NSRect) bounds -{ - return [self rectForTitleWithString: [self attributedTitle] inBounds: bounds]; -} - -- (NSRect) statusRectForBounds: (NSRect) bounds -{ - return [self rectForStatusWithString: [self attributedStatus] - withTitleRect: [(FileListNode *)[self objectValue] isFolder] ? [self titleRectForBounds: bounds] : NSZeroRect - inBounds: bounds]; -} - - (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) controlView { //icon diff --git a/macosx/TorrentCell.h b/macosx/TorrentCell.h index d0f2fd41c..63e675ee1 100644 --- a/macosx/TorrentCell.h +++ b/macosx/TorrentCell.h @@ -35,15 +35,6 @@ } - (NSRect) iconRectForBounds: (NSRect) bounds; -- (NSRect) titleRectForBounds: (NSRect) bounds; -- (NSRect) progressRectForBounds: (NSRect) bounds; -- (NSRect) barRectForBounds: (NSRect) bounds; -- (NSRect) statusRectForBounds: (NSRect) bounds; -- (NSRect) minimalStatusRectForBounds: (NSRect) bounds; - -- (NSRect) controlButtonRectForBounds: (NSRect) bounds; -- (NSRect) revealButtonRectForBounds: (NSRect) bounds; -- (NSRect) actionButtonRectForBounds: (NSRect) bounds; - (void) addTrackingAreasForView: (NSView *) controlView inRect: (NSRect) cellFrame withUserInfo: (NSDictionary *) userInfo mouseLocation: (NSPoint) mouseLocation; diff --git a/macosx/TorrentCell.m b/macosx/TorrentCell.m index d4b1da12d..ce3852acd 100644 --- a/macosx/TorrentCell.m +++ b/macosx/TorrentCell.m @@ -73,6 +73,11 @@ inBounds: (NSRect) bounds; - (NSRect) rectForProgressWithString: (NSAttributedString *) string inBounds: (NSRect) bounds; - (NSRect) rectForStatusWithString: (NSAttributedString *) string inBounds: (NSRect) bounds; +- (NSRect) barRectForBounds: (NSRect) bounds; + +- (NSRect) controlButtonRectForBounds: (NSRect) bounds; +- (NSRect) revealButtonRectForBounds: (NSRect) bounds; +- (NSRect) actionButtonRectForBounds: (NSRect) bounds; - (NSAttributedString *) attributedTitle; - (NSAttributedString *) attributedStatusString: (NSString *) string; @@ -113,7 +118,7 @@ - (NSRect) iconRectForBounds: (NSRect) bounds { - CGFloat imageSize = [fDefaults boolForKey: @"SmallView"] ? IMAGE_SIZE_MIN : IMAGE_SIZE_REG; + const CGFloat imageSize = [fDefaults boolForKey: @"SmallView"] ? IMAGE_SIZE_MIN : IMAGE_SIZE_REG; NSRect result = bounds; result.origin.x += PADDING_HORIZONTAL; @@ -123,103 +128,6 @@ return result; } -- (NSRect) titleRectForBounds: (NSRect) bounds -{ - return [self rectForTitleWithString: [self attributedTitle] - basedOnMinimalStatusRect: [self minimalStatusRectForBounds: bounds] inBounds: bounds]; -} - -- (NSRect) minimalStatusRectForBounds: (NSRect) bounds -{ - if (![fDefaults boolForKey: @"SmallView"]) - return NSZeroRect; - - return [self rectForMinimalStatusWithString: [self attributedStatusString: [self minimalStatusString]] - inBounds: bounds]; -} - -- (NSRect) progressRectForBounds: (NSRect) bounds -{ - if ([fDefaults boolForKey: @"SmallView"]) - return NSZeroRect; - - return [self rectForProgressWithString: [self attributedStatusString: [[self representedObject] progressString]] - inBounds: bounds]; -} - -- (NSRect) barRectForBounds: (NSRect) bounds -{ - const BOOL minimal = [fDefaults boolForKey: @"SmallView"]; - - NSRect result = bounds; - result.size.height = BAR_HEIGHT; - result.origin.x += (minimal ? IMAGE_SIZE_MIN : IMAGE_SIZE_REG) + PADDING_BETWEEN_IMAGE_AND_BAR; - - result.origin.y += PADDING_ABOVE_TITLE + HEIGHT_TITLE; - if (minimal) - result.origin.y += PADDING_BETWEEN_TITLE_AND_BAR_MIN; - else - result.origin.y += PADDING_BETWEEN_TITLE_AND_PROGRESS + HEIGHT_STATUS + PADDING_BETWEEN_PROGRESS_AND_BAR; - - result.size.width = floor(NSMaxX(bounds) - result.origin.x - PADDING_HORIZONTAL - 2.0 * (PADDING_HORIZONTAL + NORMAL_BUTTON_WIDTH)); - - return result; -} - -- (NSRect) statusRectForBounds: (NSRect) bounds -{ - if ([fDefaults boolForKey: @"SmallView"]) - return NSZeroRect; - - return [self rectForStatusWithString: [self attributedStatusString: [self statusString]] inBounds: bounds]; -} - -- (NSRect) controlButtonRectForBounds: (NSRect) bounds -{ - NSRect result = bounds; - result.size.height = NORMAL_BUTTON_WIDTH; - result.size.width = NORMAL_BUTTON_WIDTH; - result.origin.x = NSMaxX(bounds) - 2.0f * (PADDING_HORIZONTAL + NORMAL_BUTTON_WIDTH); - - result.origin.y += PADDING_ABOVE_TITLE + HEIGHT_TITLE - (NORMAL_BUTTON_WIDTH - BAR_HEIGHT) * 0.5f; - if ([fDefaults boolForKey: @"SmallView"]) - result.origin.y += PADDING_BETWEEN_TITLE_AND_BAR_MIN; - else - result.origin.y += PADDING_BETWEEN_TITLE_AND_PROGRESS + HEIGHT_STATUS + PADDING_BETWEEN_PROGRESS_AND_BAR; - - return result; -} - -- (NSRect) revealButtonRectForBounds: (NSRect) bounds -{ - NSRect result = bounds; - result.size.height = NORMAL_BUTTON_WIDTH; - result.size.width = NORMAL_BUTTON_WIDTH; - result.origin.x = NSMaxX(bounds) - (PADDING_HORIZONTAL + NORMAL_BUTTON_WIDTH); - - result.origin.y += PADDING_ABOVE_TITLE + HEIGHT_TITLE - (NORMAL_BUTTON_WIDTH - BAR_HEIGHT) * 0.5f; - if ([fDefaults boolForKey: @"SmallView"]) - result.origin.y += PADDING_BETWEEN_TITLE_AND_BAR_MIN; - else - result.origin.y += PADDING_BETWEEN_TITLE_AND_PROGRESS + HEIGHT_STATUS + PADDING_BETWEEN_PROGRESS_AND_BAR; - - return result; -} - -- (NSRect) actionButtonRectForBounds: (NSRect) bounds -{ - NSRect result = [self iconRectForBounds: bounds]; - if (![fDefaults boolForKey: @"SmallView"]) - { - result.origin.x += (result.size.width - ACTION_BUTTON_WIDTH) * 0.5f; - result.origin.y += (result.size.height - ACTION_BUTTON_WIDTH) * 0.5f; - result.size.width = ACTION_BUTTON_WIDTH; - result.size.height = ACTION_BUTTON_WIDTH; - } - - return result; -} - - (NSUInteger) hitTestForEvent: (NSEvent *) event inRect: (NSRect) cellFrame ofView: (NSView *) controlView { NSPoint point = [controlView convertPoint: [event locationInWindow] fromView: nil]; @@ -757,6 +665,71 @@ return result; } +- (NSRect) barRectForBounds: (NSRect) bounds +{ + const BOOL minimal = [fDefaults boolForKey: @"SmallView"]; + + NSRect result = bounds; + result.size.height = BAR_HEIGHT; + result.origin.x += (minimal ? IMAGE_SIZE_MIN : IMAGE_SIZE_REG) + PADDING_BETWEEN_IMAGE_AND_BAR; + + result.origin.y += PADDING_ABOVE_TITLE + HEIGHT_TITLE; + if (minimal) + result.origin.y += PADDING_BETWEEN_TITLE_AND_BAR_MIN; + else + result.origin.y += PADDING_BETWEEN_TITLE_AND_PROGRESS + HEIGHT_STATUS + PADDING_BETWEEN_PROGRESS_AND_BAR; + + result.size.width = floor(NSMaxX(bounds) - result.origin.x - PADDING_HORIZONTAL - 2.0 * (PADDING_HORIZONTAL + NORMAL_BUTTON_WIDTH)); + + return result; +} + +- (NSRect) controlButtonRectForBounds: (NSRect) bounds +{ + NSRect result = bounds; + result.size.height = NORMAL_BUTTON_WIDTH; + result.size.width = NORMAL_BUTTON_WIDTH; + result.origin.x = NSMaxX(bounds) - 2.0f * (PADDING_HORIZONTAL + NORMAL_BUTTON_WIDTH); + + result.origin.y += PADDING_ABOVE_TITLE + HEIGHT_TITLE - (NORMAL_BUTTON_WIDTH - BAR_HEIGHT) * 0.5f; + if ([fDefaults boolForKey: @"SmallView"]) + result.origin.y += PADDING_BETWEEN_TITLE_AND_BAR_MIN; + else + result.origin.y += PADDING_BETWEEN_TITLE_AND_PROGRESS + HEIGHT_STATUS + PADDING_BETWEEN_PROGRESS_AND_BAR; + + return result; +} + +- (NSRect) revealButtonRectForBounds: (NSRect) bounds +{ + NSRect result = bounds; + result.size.height = NORMAL_BUTTON_WIDTH; + result.size.width = NORMAL_BUTTON_WIDTH; + result.origin.x = NSMaxX(bounds) - (PADDING_HORIZONTAL + NORMAL_BUTTON_WIDTH); + + result.origin.y += PADDING_ABOVE_TITLE + HEIGHT_TITLE - (NORMAL_BUTTON_WIDTH - BAR_HEIGHT) * 0.5f; + if ([fDefaults boolForKey: @"SmallView"]) + result.origin.y += PADDING_BETWEEN_TITLE_AND_BAR_MIN; + else + result.origin.y += PADDING_BETWEEN_TITLE_AND_PROGRESS + HEIGHT_STATUS + PADDING_BETWEEN_PROGRESS_AND_BAR; + + return result; +} + +- (NSRect) actionButtonRectForBounds: (NSRect) bounds +{ + NSRect result = [self iconRectForBounds: bounds]; + if (![fDefaults boolForKey: @"SmallView"]) + { + result.origin.x += (result.size.width - ACTION_BUTTON_WIDTH) * 0.5f; + result.origin.y += (result.size.height - ACTION_BUTTON_WIDTH) * 0.5f; + result.size.width = ACTION_BUTTON_WIDTH; + result.size.height = ACTION_BUTTON_WIDTH; + } + + return result; +} + - (NSAttributedString *) attributedTitle { NSString * title = [[self representedObject] name];