don't crash trying to dereference NULL m_selection (happens when showing a grid without any rows or columns)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15891 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2002-06-20 15:01:10 +00:00
parent bd9cd5343b
commit 3f3dc2efd0

View File

@@ -3604,7 +3604,8 @@ void wxGrid::Create()
// create the type registry
m_typeRegistry = new wxGridTypeRegistry;
m_selection = 0;
m_selection = NULL;
// subwindow components that make up the wxGrid
m_cornerLabelWin = new wxGridCornerLabelWindow( this,
-1,
@@ -3671,8 +3672,8 @@ bool wxGrid::SetTable( wxGridTableBase *table, bool takeOwnership,
{
// RD: Actually, this should probably be allowed. I think it would be
// nice to be able to switch multiple Tables in and out of a single
// View at runtime. Is there anything in the implmentation that would
// prevent this?
// View at runtime. Is there anything in the implementation that
// would prevent this?
// At least, you now have to cope with m_selection
wxFAIL_MSG( wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
@@ -3977,6 +3978,8 @@ bool wxGrid::Redimension( wxGridTableMessage& msg )
//
SetCurrentCell( 0, 0 );
}
if ( m_selection )
m_selection->UpdateRows( pos, numRows );
wxGridCellAttrProvider * attrProvider = m_table->GetAttrProvider();
if (attrProvider)
@@ -4060,6 +4063,8 @@ bool wxGrid::Redimension( wxGridTableMessage& msg )
if ( m_currentCellCoords.GetRow() >= m_numRows )
m_currentCellCoords.Set( 0, 0 );
}
if ( m_selection )
m_selection->UpdateRows( pos, -((int)numRows) );
wxGridCellAttrProvider * attrProvider = m_table->GetAttrProvider();
if (attrProvider) {
@@ -4114,6 +4119,8 @@ bool wxGrid::Redimension( wxGridTableMessage& msg )
//
SetCurrentCell( 0, 0 );
}
if ( m_selection )
m_selection->UpdateCols( pos, numCols );
wxGridCellAttrProvider * attrProvider = m_table->GetAttrProvider();
if (attrProvider)
@@ -4196,6 +4203,8 @@ bool wxGrid::Redimension( wxGridTableMessage& msg )
if ( m_currentCellCoords.GetCol() >= m_numCols )
m_currentCellCoords.Set( 0, 0 );
}
if ( m_selection )
m_selection->UpdateCols( pos, -((int)numCols) );
wxGridCellAttrProvider * attrProvider = m_table->GetAttrProvider();
if (attrProvider) {
@@ -4430,6 +4439,8 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
case WXGRID_CURSOR_SELECT_ROW:
if ( (row = YToRow( y )) >= 0 )
{
if ( m_selection )
{
m_selection->SelectRow( row,
event.ControlDown(),
@@ -4437,6 +4448,7 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
event.AltDown(),
event.MetaDown() );
}
}
// default label to suppress warnings about "enumeration value
// 'xxx' not handled in switch
@@ -4480,7 +4492,10 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
{
if ( !event.ShiftDown() && !event.ControlDown() )
ClearSelection();
else if ( m_selection )
{
if ( event.ShiftDown() )
{
m_selection->SelectBlock( m_currentCellCoords.GetRow(),
0,
row,
@@ -4489,12 +4504,17 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
event.ShiftDown(),
event.AltDown(),
event.MetaDown() );
}
else
{
m_selection->SelectRow( row,
event.ControlDown(),
event.ShiftDown(),
event.AltDown(),
event.MetaDown() );
}
}
ChangeCursorMode(WXGRID_CURSOR_SELECT_ROW, m_rowLabelWin);
}
}
@@ -4626,6 +4646,8 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
case WXGRID_CURSOR_SELECT_COL:
if ( (col = XToCol( x )) >= 0 )
{
if ( m_selection )
{
m_selection->SelectCol( col,
event.ControlDown(),
@@ -4633,6 +4655,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
event.AltDown(),
event.MetaDown() );
}
}
// default label to suppress warnings about "enumeration value
// 'xxx' not handled in switch
@@ -4676,7 +4699,10 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
{
if ( !event.ShiftDown() && !event.ControlDown() )
ClearSelection();
if ( m_selection )
{
if ( event.ShiftDown() )
{
m_selection->SelectBlock( 0,
m_currentCellCoords.GetCol(),
GetNumberRows() - 1, col,
@@ -4684,12 +4710,17 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
event.ShiftDown(),
event.AltDown(),
event.MetaDown() );
}
else
{
m_selection->SelectCol( col,
event.ControlDown(),
event.ShiftDown(),
event.AltDown(),
event.MetaDown() );
}
}
ChangeCursorMode(WXGRID_CURSOR_SELECT_COL, m_colLabelWin);
}
}
@@ -5020,6 +5051,8 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
if ( !event.ControlDown() )
ClearSelection();
if ( event.ShiftDown() )
{
if ( m_selection )
{
m_selection->SelectBlock( m_currentCellCoords.GetRow(),
m_currentCellCoords.GetCol(),
@@ -5030,6 +5063,7 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
event.AltDown(),
event.MetaDown() );
}
}
else if ( XToEdgeOfCol(x) < 0 &&
YToEdgeOfRow(y) < 0 )
{
@@ -5057,6 +5091,8 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
else
{
if ( event.ControlDown() )
{
if ( m_selection )
{
m_selection->ToggleCellSelection( coords.GetRow(),
coords.GetCol(),
@@ -5064,6 +5100,7 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
event.ShiftDown(),
event.AltDown(),
event.MetaDown() );
}
m_selectingTopLeft = wxGridNoCellCoords;
m_selectingBottomRight = wxGridNoCellCoords;
m_selectingKeyboard = coords;
@@ -5071,10 +5108,15 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
else
{
SetCurrentCell( coords );
if ( m_selection->GetSelectionMode()
!= wxGrid::wxGridSelectCells)
if ( m_selection )
{
if ( m_selection->GetSelectionMode() !=
wxGrid::wxGridSelectCells )
{
HighlightBlock( coords, coords );
}
}
}
m_waitForSlowClick = TRUE;
}
}
@@ -5112,6 +5154,9 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
m_winCapture->ReleaseMouse();
m_winCapture = NULL;
}
if ( m_selection )
{
m_selection->SelectBlock( m_selectingTopLeft.GetRow(),
m_selectingTopLeft.GetCol(),
m_selectingBottomRight.GetRow(),
@@ -5120,6 +5165,8 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
event.ShiftDown(),
event.AltDown(),
event.MetaDown() );
}
m_selectingTopLeft = wxGridNoCellCoords;
m_selectingBottomRight = wxGridNoCellCoords;
}
@@ -5774,6 +5821,8 @@ void wxGrid::OnKeyDown( wxKeyEvent& event )
case WXK_SPACE:
if ( event.ControlDown() )
{
if ( m_selection )
{
m_selection->ToggleCellSelection( m_currentCellCoords.GetRow(),
m_currentCellCoords.GetCol(),
@@ -5781,6 +5830,7 @@ void wxGrid::OnKeyDown( wxKeyEvent& event )
event.ShiftDown(),
event.AltDown(),
event.MetaDown() );
}
break;
}
if ( !IsEditable() )
@@ -5844,6 +5894,9 @@ void wxGrid::OnKeyUp( wxKeyEvent& event )
{
if ( m_selectingTopLeft != wxGridNoCellCoords &&
m_selectingBottomRight != wxGridNoCellCoords )
{
if ( m_selection )
{
m_selection->SelectBlock( m_selectingTopLeft.GetRow(),
m_selectingTopLeft.GetCol(),
m_selectingBottomRight.GetRow(),
@@ -5852,6 +5905,9 @@ void wxGrid::OnKeyUp( wxKeyEvent& event )
TRUE,
event.AltDown(),
event.MetaDown() );
}
}
m_selectingTopLeft = wxGridNoCellCoords;
m_selectingBottomRight = wxGridNoCellCoords;
m_selectingKeyboard = wxGridNoCellCoords;
@@ -5913,6 +5969,8 @@ void wxGrid::HighlightBlock( int topRow, int leftCol, int bottomRow, int rightCo
int temp;
wxGridCellCoords updateTopLeft, updateBottomRight;
if ( m_selection )
{
if ( m_selection->GetSelectionMode() == wxGrid::wxGridSelectRows )
{
leftCol = 0;
@@ -5923,6 +5981,8 @@ void wxGrid::HighlightBlock( int topRow, int leftCol, int bottomRow, int rightCo
topRow = 0;
bottomRow = GetNumberRows() - 1;
}
}
if ( topRow > bottomRow )
{
temp = topRow;
@@ -8761,6 +8821,7 @@ void wxGrid::SelectRow( int row, bool addToSelected )
if ( IsSelection() && !addToSelected )
ClearSelection();
if ( m_selection )
m_selection->SelectRow( row, FALSE, addToSelected );
}
@@ -8770,6 +8831,7 @@ void wxGrid::SelectCol( int col, bool addToSelected )
if ( IsSelection() && !addToSelected )
ClearSelection();
if ( m_selection )
m_selection->SelectCol( col, FALSE, addToSelected );
}
@@ -8780,6 +8842,7 @@ void wxGrid::SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
if ( IsSelection() && !addToSelected )
ClearSelection();
if ( m_selection )
m_selection->SelectBlock( topRow, leftCol, bottomRow, rightCol,
FALSE, addToSelected );
}
@@ -8788,7 +8851,10 @@ void wxGrid::SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
void wxGrid::SelectAll()
{
if ( m_numRows > 0 && m_numCols > 0 )
{
if ( m_selection )
m_selection->SelectBlock( 0, 0, m_numRows-1, m_numCols-1 );
}
}
//
@@ -8797,6 +8863,9 @@ void wxGrid::SelectAll()
void wxGrid::DeselectRow( int row )
{
if ( !m_selection )
return;
if ( m_selection->GetSelectionMode() == wxGrid::wxGridSelectRows )
{
if ( m_selection->IsInSelection(row, 0 ) )
@@ -8815,6 +8884,9 @@ void wxGrid::DeselectRow( int row )
void wxGrid::DeselectCol( int col )
{
if ( !m_selection )
return;
if ( m_selection->GetSelectionMode() == wxGrid::wxGridSelectColumns )
{
if ( m_selection->IsInSelection(0, col ) )
@@ -8833,30 +8905,31 @@ void wxGrid::DeselectCol( int col )
void wxGrid::DeselectCell( int row, int col )
{
if ( m_selection->IsInSelection(row, col) )
if ( m_selection && m_selection->IsInSelection(row, col) )
m_selection->ToggleCellSelection(row, col);
}
bool wxGrid::IsSelection()
{
return ( m_selection->IsSelection() ||
return ( m_selection && (m_selection->IsSelection() ||
( m_selectingTopLeft != wxGridNoCellCoords &&
m_selectingBottomRight != wxGridNoCellCoords ) );
m_selectingBottomRight != wxGridNoCellCoords) ) );
}
bool wxGrid::IsInSelection( int row, int col )
{
return ( m_selection->IsInSelection( row, col ) ||
return ( m_selection && (m_selection->IsInSelection( row, col ) ||
( row >= m_selectingTopLeft.GetRow() &&
col >= m_selectingTopLeft.GetCol() &&
row <= m_selectingBottomRight.GetRow() &&
col <= m_selectingBottomRight.GetCol() ) );
col <= m_selectingBottomRight.GetCol() )) );
}
void wxGrid::ClearSelection()
{
m_selectingTopLeft = wxGridNoCellCoords;
m_selectingBottomRight = wxGridNoCellCoords;
if ( m_selection )
m_selection->ClearSelection();
}