Replaced internal calls to XToCol/YToRow added in 1.197 by internal macro

which treats the out of grid case in a way that's more suitable.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15292 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Neis 2002-04-28 00:39:04 +00:00
parent 40e2d13434
commit 33188aa47a

View File

@ -3502,6 +3502,23 @@ void wxGridWindow::OnEraseBackground( wxEraseEvent& WXUNUSED(event) )
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Internal Helper function for computing row or column from some
// (unscrolled) coordinate value, using either
// m_defaultRowHeight/m_defaultColWidth or binary search on array
// of m_rowBottoms/m_ColRights to speed up the search!
// Internal helper macros for simpler use of that function
static int CoordToRowOrCol(int coord, int defaultDist, int minDist,
wxArrayInt BorderArray, bool maxOnOverflow);
#define internalXToCol(x) CoordToRowOrCol(x, m_defaultColWidth, \
WXGRID_MIN_COL_WIDTH, \
m_colRights, TRUE)
#define internalYToRow(y) CoordToRowOrCol(y, m_defaultRowHeight, \
WXGRID_MIN_ROW_HEIGHT, \
m_rowBottoms, TRUE)
/////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNAMIC_CLASS( wxGrid, wxScrolledWindow ) IMPLEMENT_DYNAMIC_CLASS( wxGrid, wxScrolledWindow )
@ -4243,7 +4260,7 @@ wxArrayInt wxGrid::CalcRowLabelsExposed( const wxRegion& reg )
// find the row labels within these bounds // find the row labels within these bounds
// //
int row; int row;
for ( row = YToRow(top); row < m_numRows; row++ ) for ( row = internalYToRow(top); row < m_numRows; row++ )
{ {
if ( GetRowBottom(row) < top ) if ( GetRowBottom(row) < top )
continue; continue;
@ -4294,7 +4311,7 @@ wxArrayInt wxGrid::CalcColLabelsExposed( const wxRegion& reg )
// find the cells within these bounds // find the cells within these bounds
// //
int col; int col;
for ( col = XToCol(left); col < m_numCols; col++ ) for ( col = internalXToCol(left); col < m_numCols; col++ )
{ {
if ( GetColRight(col) < left ) if ( GetColRight(col) < left )
continue; continue;
@ -4345,7 +4362,7 @@ wxGridCellCoordsArray wxGrid::CalcCellsExposed( const wxRegion& reg )
// find the cells within these bounds // find the cells within these bounds
// //
int row, col; int row, col;
for ( row = YToRow(top); row < m_numRows; row++ ) for ( row = internalYToRow(top); row < m_numRows; row++ )
{ {
if ( GetRowBottom(row) <= top ) if ( GetRowBottom(row) <= top )
continue; continue;
@ -4353,7 +4370,7 @@ wxGridCellCoordsArray wxGrid::CalcCellsExposed( const wxRegion& reg )
if ( GetRowTop(row) > bottom ) if ( GetRowTop(row) > bottom )
break; break;
for ( col = XToCol(left); col < m_numCols; col++ ) for ( col = internalXToCol(left); col < m_numCols; col++ )
{ {
if ( GetColRight(col) <= left ) if ( GetColRight(col) <= left )
continue; continue;
@ -6293,7 +6310,7 @@ void wxGrid::DrawAllGridLines( wxDC& dc, const wxRegion & WXUNUSED(reg) )
// horizontal grid lines // horizontal grid lines
// //
int i; int i;
for ( i = YToRow(top); i < m_numRows; i++ ) for ( i = internalYToRow(top); i < m_numRows; i++ )
{ {
int bot = GetRowBottom(i) - 1; int bot = GetRowBottom(i) - 1;
@ -6311,7 +6328,7 @@ void wxGrid::DrawAllGridLines( wxDC& dc, const wxRegion & WXUNUSED(reg) )
// vertical grid lines // vertical grid lines
// //
for ( i = XToCol(left); i < m_numCols; i++ ) for ( i = internalXToCol(left); i < m_numCols; i++ )
{ {
int colRight = GetColRight(i) - 1; int colRight = GetColRight(i) - 1;
if ( colRight > right ) if ( colRight > right )
@ -6839,12 +6856,12 @@ void wxGrid::XYToCell( int x, int y, wxGridCellCoords& coords )
// of m_rowBottoms/m_ColRights to speed up the search! // of m_rowBottoms/m_ColRights to speed up the search!
static int CoordToRowOrCol(int coord, int defaultDist, int minDist, static int CoordToRowOrCol(int coord, int defaultDist, int minDist,
wxArrayInt BorderArray) wxArrayInt BorderArray, bool maxOnOverflow)
{ {
if (!defaultDist) if (!defaultDist)
defaultDist = 1; defaultDist = 1;
unsigned int i_max = coord / defaultDist, int i_max = coord / defaultDist,
i_min = 0; i_min = 0;
if (BorderArray.IsEmpty()) if (BorderArray.IsEmpty())
{ {
return i_max; return i_max;
@ -6862,15 +6879,15 @@ static int CoordToRowOrCol(int coord, int defaultDist, int minDist,
if ( i_max >= BorderArray.GetCount()) if ( i_max >= BorderArray.GetCount())
i_max = BorderArray.GetCount() - 1; i_max = BorderArray.GetCount() - 1;
} }
if ( coord > BorderArray[i_max]) if ( coord >= BorderArray[i_max])
return -1; return (maxOnOverflow ? i_max : -1);
if ( coord < BorderArray[0] ) if ( coord < BorderArray[0] )
return 0; return 0;
while ( i_max - i_min > 0 ) while ( i_max - i_min > 0 )
{ {
wxCHECK_MSG(BorderArray[i_min] <= coord && coord < BorderArray[i_max], wxCHECK_MSG(BorderArray[i_min] <= coord && coord < BorderArray[i_max],
-1, _T("wxGrid: internal error in CoordToRowOrCol")); 0, _T("wxGrid: internal error in CoordToRowOrCol"));
if (coord >= BorderArray[ i_max - 1]) if (coord >= BorderArray[ i_max - 1])
return i_max; return i_max;
else else
@ -6887,14 +6904,14 @@ static int CoordToRowOrCol(int coord, int defaultDist, int minDist,
int wxGrid::YToRow( int y ) int wxGrid::YToRow( int y )
{ {
return CoordToRowOrCol(y, m_defaultRowHeight, return CoordToRowOrCol(y, m_defaultRowHeight,
WXGRID_MIN_ROW_HEIGHT, m_rowBottoms); WXGRID_MIN_ROW_HEIGHT, m_rowBottoms, FALSE);
} }
int wxGrid::XToCol( int x ) int wxGrid::XToCol( int x )
{ {
return CoordToRowOrCol(x, m_defaultColWidth, return CoordToRowOrCol(x, m_defaultColWidth,
WXGRID_MIN_COL_WIDTH, m_colRights); WXGRID_MIN_COL_WIDTH, m_colRights, FALSE);
} }
@ -6903,18 +6920,17 @@ int wxGrid::XToCol( int x )
// //
int wxGrid::YToEdgeOfRow( int y ) int wxGrid::YToEdgeOfRow( int y )
{ {
int i, d; int i;
i = YToRow(y); i = internalYToRow(y);
if ( i > 0 )
i--; if ( GetRowHeight(i) > WXGRID_LABEL_EDGE_ZONE )
for ( ; i < m_numRows; i++ )
{ {
if ( GetRowHeight(i) > WXGRID_LABEL_EDGE_ZONE ) // We know that we are in row i, test whether we are
{ // close enough to lower or upper border, respectively.
d = abs( y - GetRowBottom(i) ); if ( abs(GetRowBottom(i) - y) < WXGRID_LABEL_EDGE_ZONE )
if ( d < WXGRID_LABEL_EDGE_ZONE ) return i;
return i; else if( i > 0 && y - GetRowTop(i) < WXGRID_LABEL_EDGE_ZONE )
} return i - 1;
} }
return -1; return -1;
@ -6926,18 +6942,17 @@ int wxGrid::YToEdgeOfRow( int y )
// //
int wxGrid::XToEdgeOfCol( int x ) int wxGrid::XToEdgeOfCol( int x )
{ {
int i, d; int i;
i = XToCol(x); i = internalXToCol(x);
if ( i > 0 )
i--; if ( GetColWidth(i) > WXGRID_LABEL_EDGE_ZONE )
for ( ; i < m_numCols; i++ )
{ {
if ( GetColWidth(i) > WXGRID_LABEL_EDGE_ZONE ) // We know that we are in column i, test whether we are
{ // close enough to right or left border, respectively.
d = abs( x - GetColRight(i) ); if ( abs(GetColRight(i) - x) < WXGRID_LABEL_EDGE_ZONE )
if ( d < WXGRID_LABEL_EDGE_ZONE ) return i;
return i; else if( i > 0 && x - GetColLeft(i) < WXGRID_LABEL_EDGE_ZONE )
} return i - 1;
} }
return -1; return -1;