summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
02822c8)
* ensure CoordToRowOrCol() range is 0 -> nMax if clipOnMinMax is set
and -1 -> nMax if clipOnMinMax is not set
* check on uses of YToRow() / XToCol() and replace with
calls internalYToRow() / internalXToCol() removing any external
overflow handling where appropriate.
* Add tests for overflow to prevent sending 'off grid' label events,
would be indistinguishable from CornerLabel events.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19972
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
static int CoordToRowOrCol(int coord, int defaultDist, int minDist,
const wxArrayInt& BorderArray, int nMax,
static int CoordToRowOrCol(int coord, int defaultDist, int minDist,
const wxArrayInt& BorderArray, int nMax,
#define internalXToCol(x) CoordToRowOrCol(x, m_defaultColWidth, \
WXGRID_MIN_COL_WIDTH, \
#define internalXToCol(x) CoordToRowOrCol(x, m_defaultColWidth, \
WXGRID_MIN_COL_WIDTH, \
if ( row < 0 )
{
row = YToRow(y);
if ( row < 0 )
{
row = YToRow(y);
- SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, row, -1, event );
+ if ( row >=0 &&
+ !SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, row, -1, event ) )
+ {
+ // no default action at the moment
+ }
else if ( event.RightDown() )
{
row = YToRow(y);
else if ( event.RightDown() )
{
row = YToRow(y);
- if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, row, -1, event ) )
+ if ( row >=0 &&
+ !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, row, -1, event ) )
{
// no default action at the moment
}
{
// no default action at the moment
}
else if ( event.RightDClick() )
{
row = YToRow(y);
else if ( event.RightDClick() )
{
row = YToRow(y);
- if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, row, -1, event ) )
+ if ( row >= 0 &&
+ !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, row, -1, event ) )
{
// no default action at the moment
}
{
// no default action at the moment
}
if ( col < 0 )
{
col = XToCol(x);
if ( col < 0 )
{
col = XToCol(x);
- SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, -1, col, event );
+ if ( col >= 0 &&
+ ! SendEvent( wxEVT_GRID_LABEL_LEFT_DCLICK, -1, col, event ) )
+ {
+ // no default action at the moment
+ }
else if ( event.RightDown() )
{
col = XToCol(x);
else if ( event.RightDown() )
{
col = XToCol(x);
- if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, -1, col, event ) )
+ if ( col >= 0 &&
+ !SendEvent( wxEVT_GRID_LABEL_RIGHT_CLICK, -1, col, event ) )
{
// no default action at the moment
}
{
// no default action at the moment
}
else if ( event.RightDClick() )
{
col = XToCol(x);
else if ( event.RightDClick() )
{
col = XToCol(x);
- if ( !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, col, event ) )
+ if ( col >= 0 &&
+ !SendEvent( wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, col, event ) )
{
// no default action at the moment
}
{
// no default action at the moment
}
{
int i, cell_rows, cell_cols, subtract_rows = 0;
int leftCol = XToCol(left);
{
int i, cell_rows, cell_cols, subtract_rows = 0;
int leftCol = XToCol(left);
- int rightCol = XToCol(left+cw);
+ int rightCol = internalXToCol(left+cw);
- if (rightCol < 0) rightCol = m_numCols;
for (i=leftCol; i<rightCol; i++)
{
GetCellSize(m_dragRowOrCol, i, &cell_rows, &cell_cols);
for (i=leftCol; i<rightCol; i++)
{
GetCellSize(m_dragRowOrCol, i, &cell_rows, &cell_cols);
{
int i, cell_rows, cell_cols, subtract_cols = 0;
int topRow = YToRow(top);
{
int i, cell_rows, cell_cols, subtract_cols = 0;
int topRow = YToRow(top);
- int bottomRow = YToRow(top+cw);
+ int bottomRow = internalYToRow(top+cw);
- if (bottomRow < 0) bottomRow = m_numRows;
for (i=topRow; i<bottomRow; i++)
{
GetCellSize(i, m_dragRowOrCol, &cell_rows, &cell_cols);
for (i=topRow; i<bottomRow; i++)
{
GetCellSize(i, m_dragRowOrCol, &cell_rows, &cell_cols);
bottom = wxMin( bottom, GetRowBottom(m_numRows - 1) );
// no gridlines inside multicells, clip them out
bottom = wxMin( bottom, GetRowBottom(m_numRows - 1) );
// no gridlines inside multicells, clip them out
- int leftCol = XToCol(left);
- int topRow = YToRow(top);
- int rightCol = XToCol(right);
- int bottomRow = YToRow(bottom);
+ int leftCol = internalXToCol(left);
+ int topRow = internalYToRow(top);
+ int rightCol = internalXToCol(right);
+ int bottomRow = internalYToRow(bottom);
wxRegion clippedcells(0, 0, cw, ch);
wxRegion clippedcells(0, 0, cw, ch);
- if ((leftCol >= 0) && (topRow >= 0))
- {
- if (rightCol < 0) rightCol = m_numCols;
- if (bottomRow < 0) bottomRow = m_numRows;
- int i, j, cell_rows, cell_cols;
- wxRect rect;
+ int i, j, cell_rows, cell_cols;
+ wxRect rect;
- for (j=topRow; j<bottomRow; j++)
+ for (j=topRow; j<bottomRow; j++)
+ {
+ for (i=leftCol; i<rightCol; i++)
- for (i=leftCol; i<rightCol; i++)
+ GetCellSize( j, i, &cell_rows, &cell_cols );
+ if ((cell_rows > 1) || (cell_cols > 1))
- GetCellSize( j, i, &cell_rows, &cell_cols );
- if ((cell_rows > 1) || (cell_cols > 1))
- {
- rect = CellToRect(j,i);
- CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
- clippedcells.Subtract(rect);
- }
- else if ((cell_rows < 0) || (cell_cols < 0))
- {
- rect = CellToRect(j+cell_rows, i+cell_cols);
- CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
- clippedcells.Subtract(rect);
- }
+ rect = CellToRect(j,i);
+ CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
+ clippedcells.Subtract(rect);
+ }
+ else if ((cell_rows < 0) || (cell_cols < 0))
+ {
+ rect = CellToRect(j+cell_rows, i+cell_cols);
+ CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
+ clippedcells.Subtract(rect);
// horizontal grid lines
//
// horizontal grid lines
//
+ // already declared above - int i;
for ( i = internalYToRow(top); i < m_numRows; i++ )
{
int bot = GetRowBottom(i) - 1;
for ( i = internalYToRow(top); i < m_numRows; i++ )
{
int bot = GetRowBottom(i) - 1;
static int CoordToRowOrCol(int coord, int defaultDist, int minDist,
const wxArrayInt& BorderArray, int nMax,
static int CoordToRowOrCol(int coord, int defaultDist, int minDist,
const wxArrayInt& BorderArray, int nMax,
+
+ if (coord < 0)
+ return clipToMinMax && (nMax > 0) ? 0 : -1;
+
+
if (!defaultDist)
defaultDist = 1;
if (!defaultDist)
defaultDist = 1;
size_t i_max = coord / defaultDist,
i_min = 0;
size_t i_max = coord / defaultDist,
i_min = 0;
{
if((int) i_max < nMax)
return i_max;
{
if((int) i_max < nMax)
return i_max;
- return maxOnOverflow ? nMax - 1 : -1;
+ return clipToMinMax ? nMax - 1 : -1;
}
if ( i_max >= BorderArray.GetCount())
}
if ( i_max >= BorderArray.GetCount())
i_max = BorderArray.GetCount() - 1;
}
if ( coord >= BorderArray[i_max])
i_max = BorderArray.GetCount() - 1;
}
if ( coord >= BorderArray[i_max])
- return maxOnOverflow ? (int)i_max : -1;
+ return clipToMinMax ? (int)i_max : -1;
if ( coord < BorderArray[0] )
return 0;
if ( coord < BorderArray[0] )
return 0;
m_gridWin->GetClientSize( &cw, &ch );
int y = GetRowTop(row);
m_gridWin->GetClientSize( &cw, &ch );
int y = GetRowTop(row);
- int newRow = YToRow( y - ch + 1 );
- if ( newRow < 0 )
- {
- newRow = 0;
- }
- else if ( newRow == row )
+ int newRow = internalYToRow( y - ch + 1 );
+
+ if ( newRow == row )
+ //row > 0 , so newrow can never be less than 0 here.
m_gridWin->GetClientSize( &cw, &ch );
int y = GetRowTop(row);
m_gridWin->GetClientSize( &cw, &ch );
int y = GetRowTop(row);
- int newRow = YToRow( y + ch );
- if ( newRow == -1 )
- {
- newRow = m_numRows - 1;
- }
- else if ( newRow == row )
+ int newRow = internalYToRow( y + ch );
+ if ( newRow == row )
+ // row < m_numRows , so newrow can't overflow here.
+ newRow = row + 1;
}
MakeCellVisible( newRow, m_currentCellCoords.GetCol() );
}
MakeCellVisible( newRow, m_currentCellCoords.GetCol() );