Clean up code in table column resizing paths in preparation for fixing it.

This commit is contained in:
Alexander Ljungberg
2010-08-02 12:40:06 -04:00
committed by Aparajita Fishman
parent 9e2a7ea776
commit d9162d1d8d
+95 -94
View File
@@ -545,7 +545,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
return;
_intercellSpacing = _CGSizeMakeCopy(aSize);
_dirtyTableColumnRangeIndex = 0; // so that _recalculateTableColumnRanges will work
[self _recalculateTableColumnRanges];
@@ -1424,10 +1424,10 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
rectOfRow = [self rectOfRow:aRow],
leftInset = FLOOR(_intercellSpacing.width / 2.0),
topInset = FLOOR(_intercellSpacing.height / 2.0);
return _CGRectMake(tableColumnRange.location + leftInset,
_CGRectGetMinY(rectOfRow) + topInset,
tableColumnRange.length - _intercellSpacing.width,
return _CGRectMake(tableColumnRange.location + leftInset,
_CGRectGetMinY(rectOfRow) + topInset,
tableColumnRange.length - _intercellSpacing.width,
_CGRectGetHeight(rectOfRow) - _intercellSpacing.height);
}
@@ -1452,114 +1452,115 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
{
var superview = [self superview];
if (!superview)
return;
if (!superview)
return;
var superviewSize = [superview bounds].size;
var superviewSize = [superview bounds].size;
UPDATE_COLUMN_RANGES_IF_NECESSARY();
UPDATE_COLUMN_RANGES_IF_NECESSARY();
var count = NUMBER_OF_COLUMNS(),
visColumns = [[CPArray alloc] init],
totalWidth = 0,
i = 0;
var count = NUMBER_OF_COLUMNS(),
visColumns = [[CPArray alloc] init],
totalWidth = 0,
i = 0;
for(; i < count; i++)
{
if(![_tableColumns[i] isHidden])
{
for(; i < count; i++)
{
if(![_tableColumns[i] isHidden])
{
[visColumns addObject:i];
totalWidth += [_tableColumns[i] width];
}
}
}
}
count = [visColumns count];
count = [visColumns count];
//if there are rows
if (count > 0)
{
var columnToResize = _tableColumns[visColumns[0]];
var newWidth = superviewSize.width - totalWidth;// - [columnToResize width];
newWidth += [columnToResize width];
newWidth = (newWidth < [columnToResize minWidth]) ? [columnToResize minWidth] : newWidth;
newWidth = (newWidth > [columnToResize maxWidth]) ? [columnToResize maxWidth] : newWidth;
//if there are rows
if (count > 0)
{
var columnToResize = _tableColumns[visColumns[0]],
newWidth = superviewSize.width - totalWidth;// - [columnToResize width];
[columnToResize setWidth:FLOOR(newWidth)];
}
newWidth += [columnToResize width];
newWidth = MAX([columnToResize minWidth], newWidth);
newWidth = MIN([columnToResize maxWidth], newWidth);
[self setNeedsLayout];
[columnToResize setWidth:FLOOR(newWidth)];
}
[self setNeedsLayout];
}
- (void)_resizeAllColumnUniformlyWithOldSize:(CGSize)oldSize
{
var superview = [self superview];
var superview = [self superview];
if (!superview)
if (!superview)
return;
var superviewSize = [superview bounds].size;
if (_dirtyTableColumnRangeIndex !== CPNotFound) [self _recalculateTableColumnRanges];//UPDATE_COLUMN_RANGES_IF_NECESSARY();
var count = _tableColumns.length,//NUMBER_OF_COLUMNS(),
visColumns = [[CPArray alloc] init],
buffer = 0.0;
// Fixme: cache resizable columns because they won't changes betwwen two calls to this method.
for(var i=0; i < count; i++)
{
var tableColumn = _tableColumns[i];
if(![tableColumn isHidden] && ([tableColumn resizingMask] & CPTableColumnAutoresizingMask))
[visColumns addObject:i];
}
// redefine count
count = [visColumns count];
//if there are columns
if (count > 0)
{
var maxXofColumns = CGRectGetMaxX([self rectOfColumn:visColumns[count - 1]]);
// If the x value of the end of the last column is between the current bounds and the previous bounds we should snap.
if (!_lastColumnShouldSnap && (maxXofColumns >= superviewSize.width && maxXofColumns <= oldSize.width || maxXofColumns <= superviewSize.width && maxXofColumns >= oldSize.width))
{
//set the snap mask
_lastColumnShouldSnap = YES;
//then we need to make sure everything is set correctly.
[self _resizeAllColumnUniformlyWithOldSize:CGSizeMake(maxXofColumns, 0)];
}
if(!_lastColumnShouldSnap)
return;
var superviewSize = [superview bounds].size;
// FIX ME: This is wrong because this should continue to resize all columns
// If the last column reaches it's max/min it will simply stop resizing,
// correct behavior is to resize all columns until they reach their min/max
if (_dirtyTableColumnRangeIndex !== CPNotFound) [self _recalculateTableColumnRanges];//UPDATE_COLUMN_RANGES_IF_NECESSARY();
var count = _tableColumns.length,//NUMBER_OF_COLUMNS(),
visColumns = [[CPArray alloc] init],
buffer = 0.0;
// Fixme: cache resizable columns because they won't changes betwwen two calls to this method.
for(var i=0; i < count; i++)
for (var i = 0; i < count; i++)
{
var tableColumn = _tableColumns[i];
if(![tableColumn isHidden] && ([tableColumn resizingMask] & CPTableColumnAutoresizingMask))
[visColumns addObject:i];
var column = visColumns[i];
columnToResize = _tableColumns[column],
currentBuffer = buffer / (count - i),
realNewWidth = ([columnToResize width] / oldSize.width * [superview bounds].size.width) + currentBuffer,
newWidth = realNewWidth;
newWidth = MAX([columnToResize minWidth], newWidth);
newWidth = MIN([columnToResize maxWidth], newWidth);
buffer -= currentBuffer;
// the buffer takes into account the min/max width of the column
buffer += realNewWidth - newWidth;
[columnToResize setWidth:newWidth];
}
// redefine count
count = [visColumns count];
// if there is space left over that means column resize was too long or too short
if(buffer !== 0)
_lastColumnShouldSnap = NO;
}
//if there are columns
if (count > 0)
{
var maxXofColumns = CGRectGetMaxX([self rectOfColumn:visColumns[count - 1]]);
// If the x value of the end of the last column is between the current bounds and the previous bounds we should snap.
if (!_lastColumnShouldSnap && (maxXofColumns >= superviewSize.width && maxXofColumns <= oldSize.width || maxXofColumns <= superviewSize.width && maxXofColumns >= oldSize.width))
{
//set the snap mask
_lastColumnShouldSnap = YES;
//then we need to make sure everything is set correctly.
[self _resizeAllColumnUniformlyWithOldSize:CGSizeMake(maxXofColumns, 0)];
}
if(!_lastColumnShouldSnap)
return;
// FIX ME: This is wrong because this should continue to resize all columns
// If the last column reaches it's max/min it will simply stop resizing,
// correct behavior is to resize all columns until they reach their min/max
for (var i = 0; i < count; i++)
{
var column = visColumns[i];
columnToResize = _tableColumns[column],
currentBuffer = buffer / (count - i),
realNewWidth = ([columnToResize width] / oldSize.width * [superview bounds].size.width) + currentBuffer ,
newWidth = MAX([columnToResize minWidth], realNewWidth);
newWidth = MIN([columnToResize maxWidth], realNewWidth);
buffer -= currentBuffer;
// the buffer takes into account the min/max width of the column
buffer += realNewWidth - newWidth;
[columnToResize setWidth:newWidth];
}
// if there is space left over that means column resize was too long or too short
if(buffer !== 0)
_lastColumnShouldSnap = NO;
}
[self setNeedsLayout];
[self setNeedsLayout];
}
/*!
@@ -1601,8 +1602,8 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
//if the last row exists
if (count >= 0)
{
var columnToResize = _tableColumns[count];
var newSize = MAX(0.0, superviewSize.width - CGRectGetMinX([self rectOfColumn:count]));
var columnToResize = _tableColumns[count],
newSize = MAX(0.0, superviewSize.width - CGRectGetMinX([self rectOfColumn:count]));
if (newSize > 0)
{
@@ -3118,7 +3119,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
{
// We don't use rowAtPoint here because the drag indicator can appear below the last row
// and rowAtPoint doesn't return rows that are larger than numberOfRows
// FIX ME: this is going to break when we implement variable row heights...
// FIX ME: this is going to break when we implement variable row heights...
var row = FLOOR(dragPoint.y / ( _rowHeight + _intercellSpacing.height )),
// Determine if the mouse is currently closer to this row or the row below it
lowerRow = row + 1,