Fixed limit cases when getting the row and column a point is in

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@10684 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Nicola Pero 2001-08-12 15:09:32 +00:00
parent c57c850110
commit 4e388f9dd7

View file

@ -708,29 +708,38 @@ static SEL getSel;
BOOL betweenCols; BOOL betweenCols;
BOOL beyondRows; BOOL beyondRows;
BOOL beyondCols; BOOL beyondCols;
BOOL nullMatrix = NO;
int approxRow = point.y / (_cellSize.height + _intercell.height); int approxRow = point.y / (_cellSize.height + _intercell.height);
float approxRowsHeight = approxRow * (_cellSize.height + _intercell.height); float approxRowsHeight = approxRow * (_cellSize.height + _intercell.height);
int approxCol = point.x / (_cellSize.width + _intercell.width); int approxCol = point.x / (_cellSize.width + _intercell.width);
float approxColsWidth = approxCol * (_cellSize.width + _intercell.width); float approxColsWidth = approxCol * (_cellSize.width + _intercell.width);
/* First check the limit cases */ /* First check the limit cases - is the point outside the matrix */
beyondCols = (point.x > _bounds.size.width || point.x < 0); beyondCols = (point.x > _bounds.size.width || point.x < 0);
beyondRows = (point.y > _bounds.size.height || point.y < 0); beyondRows = (point.y > _bounds.size.height || point.y < 0);
/* Determine if the point is inside the cell */ /* Determine if the point is inside a cell - note: if the point lies
betweenRows = !(point.y > approxRowsHeight on the cell boundaries, we consider it inside the cell. to be
&& point.y <= approxRowsHeight + _cellSize.height); outside the cell (that is, in the intercell spacing) it must be
betweenCols = !(point.x > approxColsWidth completely in the intercell spacing - not on the border */
&& point.x <= approxColsWidth + _cellSize.width); /* The following is non zero if the point lies between rows (not inside
a cell) */
betweenRows = (point.y < approxRowsHeight
|| point.y > approxRowsHeight + _cellSize.height);
betweenCols = (point.x < approxColsWidth
|| point.x > approxColsWidth + _cellSize.width);
if (beyondRows || betweenRows || beyondCols || betweenCols || nullMatrix) if (beyondRows || betweenRows || beyondCols || betweenCols ||
(_numCols == 0) || (_numRows == 0))
{ {
if (row) if (row)
*row = -1; {
*row = -1;
}
if (column) if (column)
*column = -1; {
*column = -1;
}
return NO; return NO;
} }
@ -738,31 +747,31 @@ static SEL getSel;
if (row) if (row)
{ {
if (_rFlags.flipped_view == NO) if (_rFlags.flipped_view == NO)
approxRow = _numRows - approxRow - 1; {
approxRow = _numRows - approxRow - 1;
}
if (approxRow < 0) if (approxRow < 0)
approxRow = 0;
else if (approxRow >= _numRows)
approxRow = _numRows - 1;
if (_numRows == 0)
{ {
nullMatrix = YES;
approxRow = 0; approxRow = 0;
} }
else if (approxRow >= _numRows)
{
approxRow = _numRows - 1;
}
*row = approxRow; *row = approxRow;
} }
if (column) if (column)
{ {
if (approxCol < 0) if (approxCol < 0)
approxCol = 0;
else if (approxCol >= _numCols)
approxCol = _numCols - 1;
if (_numCols == 0)
{ {
nullMatrix = YES;
approxCol = 0; approxCol = 0;
} }
else if (approxCol >= _numCols)
{
approxCol = _numCols - 1;
}
*column = approxCol; *column = approxCol;
} }