From fd57610b1f3c8e1922b022b7ce6d5f31b6dd1207 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Sat, 8 Jan 2011 18:15:57 +0000 Subject: Improve column autosizing: - Use the parent scrollview width rather than the table width to calculate available space; fixes issues with the table width reflecting the previous selected table - Take account of cell spacing and scrollbar width to avoid horizontal scrolling where possible --- Source/SPCopyTable.m | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'Source') diff --git a/Source/SPCopyTable.m b/Source/SPCopyTable.m index 827672b5..cb7e08c5 100644 --- a/Source/SPCopyTable.m +++ b/Source/SPCopyTable.m @@ -698,6 +698,10 @@ NSInteger kBlobAsImageFile = 4; NSUInteger columnWidth; NSUInteger allColumnWidths = 0; + // Determine the available size + NSScrollView *parentScrollView = [[self superview] superview]; + CGFloat visibleTableWidth = [parentScrollView bounds].size.width - [NSScroller scrollerWidth] - [columnDefinitions count] * 3.5; + for (NSDictionary *columnDefinition in columnDefinitions) { if ([[NSThread currentThread] isCancelled]) return nil; @@ -707,7 +711,7 @@ NSInteger kBlobAsImageFile = 4; } // Compare the column widths to the table width. If wider, narrow down wide columns as necessary - if (allColumnWidths > [self bounds].size.width) { + if (allColumnWidths > visibleTableWidth) { NSUInteger availableWidthToReduce = 0; // Look for columns that are wider than the multi-column max @@ -717,7 +721,7 @@ NSInteger kBlobAsImageFile = 4; } // Determine how much width can be reduced - NSUInteger widthToReduce = allColumnWidths - [self bounds].size.width; + NSUInteger widthToReduce = allColumnWidths - visibleTableWidth; if (availableWidthToReduce < widthToReduce) widthToReduce = availableWidthToReduce; // Proportionally decrease the column sizes -- cgit v1.2.3