Added support for grids with m_numRows=0. SelectRow(i,TRUE) now sets

ControlDown to TRUE in the generated event.
Fixed stupid bug in row/column deletion in griddemo.cpp


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@6930 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Neis
2000-03-25 14:02:54 +00:00
parent afc91dbf75
commit 857a175053
2 changed files with 186 additions and 113 deletions

View File

@@ -497,9 +497,11 @@ void GridFrame::DeleteSelectedRows( wxCommandEvent& WXUNUSED(ev) )
{
if ( grid->IsSelection() )
{
for ( int n = 0; n < grid->GetNumberRows(); n++ )
for ( int n = 0; n < grid->GetNumberRows(); )
if ( grid->IsInSelection( n , 0 ) )
grid->DeleteRows( n, 1 );
else
n++;
}
}
@@ -508,9 +510,11 @@ void GridFrame::DeleteSelectedCols( wxCommandEvent& WXUNUSED(ev) )
{
if ( grid->IsSelection() )
{
for ( int n = 0; n < grid->GetNumberCols(); n++ )
for ( int n = 0; n < grid->GetNumberCols(); )
if ( grid->IsInSelection( 0 , n ) )
grid->DeleteCols( n, 1 );
else
n++;
}
}

View File

@@ -2528,7 +2528,8 @@ bool wxGridStringTable::InsertRows( size_t pos, size_t numRows )
size_t row, col;
size_t curNumRows = m_data.GetCount();
size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() : 0 );
size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() :
( GetView() ? GetView()->GetNumberCols() : 0 ) );
if ( pos >= curNumRows )
{
@@ -2565,7 +2566,8 @@ bool wxGridStringTable::AppendRows( size_t numRows )
size_t row, col;
size_t curNumRows = m_data.GetCount();
size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() : 0 );
size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() :
( GetView() ? GetView()->GetNumberCols() : 0 ) );
wxArrayString sa;
if ( curNumCols > 0 )
@@ -2644,7 +2646,8 @@ bool wxGridStringTable::InsertCols( size_t pos, size_t numCols )
size_t row, col;
size_t curNumRows = m_data.GetCount();
size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() : 0 );
size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() :
( GetView() ? GetView()->GetNumberCols() : 0 ) );
if ( pos >= curNumCols )
{
@@ -2677,6 +2680,7 @@ bool wxGridStringTable::AppendCols( size_t numCols )
size_t row, n;
size_t curNumRows = m_data.GetCount();
#if 0
if ( !curNumRows )
{
// TODO: something better than this ?
@@ -2684,6 +2688,7 @@ bool wxGridStringTable::AppendCols( size_t numCols )
wxFAIL_MSG( wxT("Unable to append cols to a grid table with no rows.\nCall AppendRows() first") );
return FALSE;
}
#endif
for ( row = 0; row < curNumRows; row++ )
{
@@ -2710,7 +2715,8 @@ bool wxGridStringTable::DeleteCols( size_t pos, size_t numCols )
size_t row, n;
size_t curNumRows = m_data.GetCount();
size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() : 0 );
size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() :
( GetView() ? GetView()->GetNumberCols() : 0 ) );
if ( pos >= curNumCols )
{
@@ -3223,12 +3229,6 @@ bool wxGrid::SetTable( wxGridTableBase *table, bool takeOwnership,
void wxGrid::Init()
{
if ( m_numRows <= 0 )
m_numRows = WXGRID_DEFAULT_NUMBER_ROWS;
if ( m_numCols <= 0 )
m_numCols = WXGRID_DEFAULT_NUMBER_COLS;
m_rowLabelWidth = WXGRID_DEFAULT_ROW_LABEL_WIDTH;
m_colLabelHeight = WXGRID_DEFAULT_COL_LABEL_HEIGHT;
@@ -3426,6 +3426,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg )
{
int i;
#if 0
// if we were using the default widths/heights so far, we must change them
// now
if ( m_colWidths.IsEmpty() )
@@ -3437,6 +3438,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg )
{
InitRowHeights();
}
#endif
switch ( msg.GetId() )
{
@@ -3444,12 +3446,16 @@ bool wxGrid::Redimension( wxGridTableMessage& msg )
{
size_t pos = msg.GetCommandInt();
int numRows = msg.GetCommandInt2();
m_numRows += numRows;
if ( !m_rowHeights.IsEmpty() )
{
for ( i = 0; i < numRows; i++ )
{
m_rowHeights.Insert( m_defaultRowHeight, pos );
m_rowBottoms.Insert( 0, pos );
}
m_numRows += numRows;
int bottom = 0;
if ( pos > 0 ) bottom = m_rowBottoms[pos-1];
@@ -3459,6 +3465,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg )
bottom += m_rowHeights[i];
m_rowBottoms[i] = bottom;
}
}
CalcDimensions();
}
return TRUE;
@@ -3466,15 +3473,17 @@ bool wxGrid::Redimension( wxGridTableMessage& msg )
case wxGRIDTABLE_NOTIFY_ROWS_APPENDED:
{
int numRows = msg.GetCommandInt();
int oldNumRows = m_numRows;
m_numRows += numRows;
if ( !m_rowHeights.IsEmpty() )
{
for ( i = 0; i < numRows; i++ )
{
m_rowHeights.Add( m_defaultRowHeight );
m_rowBottoms.Add( 0 );
}
int oldNumRows = m_numRows;
m_numRows += numRows;
int bottom = 0;
if ( oldNumRows > 0 ) bottom = m_rowBottoms[oldNumRows-1];
@@ -3483,6 +3492,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg )
bottom += m_rowHeights[i];
m_rowBottoms[i] = bottom;
}
}
CalcDimensions();
}
return TRUE;
@@ -3491,18 +3501,23 @@ bool wxGrid::Redimension( wxGridTableMessage& msg )
{
size_t pos = msg.GetCommandInt();
int numRows = msg.GetCommandInt2();
m_numRows -= numRows;
if ( !m_rowHeights.IsEmpty() )
{
for ( i = 0; i < numRows; i++ )
{
m_rowHeights.Remove( pos );
m_rowBottoms.Remove( pos );
}
m_numRows -= numRows;
if ( !m_numRows )
{
#if 0
m_numCols = 0;
m_colWidths.Clear();
m_colRights.Clear();
#endif
m_currentCellCoords = wxGridNoCellCoords;
}
else
@@ -3517,7 +3532,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg )
m_rowBottoms[i] = h;
}
}
}
CalcDimensions();
}
return TRUE;
@@ -3526,12 +3541,15 @@ bool wxGrid::Redimension( wxGridTableMessage& msg )
{
size_t pos = msg.GetCommandInt();
int numCols = msg.GetCommandInt2();
m_numCols += numCols;
if ( !m_colWidths.IsEmpty() )
{
for ( i = 0; i < numCols; i++ )
{
m_colWidths.Insert( m_defaultColWidth, pos );
m_colRights.Insert( 0, pos );
}
m_numCols += numCols;
int right = 0;
if ( pos > 0 ) right = m_colRights[pos-1];
@@ -3541,6 +3559,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg )
right += m_colWidths[i];
m_colRights[i] = right;
}
}
CalcDimensions();
}
return TRUE;
@@ -3548,15 +3567,16 @@ bool wxGrid::Redimension( wxGridTableMessage& msg )
case wxGRIDTABLE_NOTIFY_COLS_APPENDED:
{
int numCols = msg.GetCommandInt();
int oldNumCols = m_numCols;
m_numCols += numCols;
if ( !m_colWidths.IsEmpty() )
{
for ( i = 0; i < numCols; i++ )
{
m_colWidths.Add( m_defaultColWidth );
m_colRights.Add( 0 );
}
int oldNumCols = m_numCols;
m_numCols += numCols;
int right = 0;
if ( oldNumCols > 0 ) right = m_colRights[oldNumCols-1];
@@ -3565,6 +3585,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg )
right += m_colWidths[i];
m_colRights[i] = right;
}
}
CalcDimensions();
}
return TRUE;
@@ -3573,12 +3594,15 @@ bool wxGrid::Redimension( wxGridTableMessage& msg )
{
size_t pos = msg.GetCommandInt();
int numCols = msg.GetCommandInt2();
m_numCols -= numCols;
if ( !m_colWidths.IsEmpty() )
{
for ( i = 0; i < numCols; i++ )
{
m_colWidths.Remove( pos );
m_colRights.Remove( pos );
}
m_numCols -= numCols;
if ( !m_numCols )
{
@@ -3601,6 +3625,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg )
m_colRights[i] = w;
}
}
}
CalcDimensions();
}
return TRUE;
@@ -4431,7 +4456,12 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
m_selectingKeyboard = coords;
}
else
{
SetCurrentCell( coords );
if ( m_selection->GetSelectionMode()
!= wxGrid::wxGridSelectCells)
SelectBlock( coords, coords );
}
m_waitForSlowClick = TRUE;
}
}
@@ -4762,7 +4792,12 @@ bool wxGrid::InsertRows( int pos, int numRows, bool WXUNUSED(updateLabels) )
}
m_selection->UpdateRows( pos, numRows );
if ( !GetBatchCount() ) Refresh();
if ( !GetBatchCount() )
{
CalcDimensions();
m_rowLabelWin->Refresh();
m_gridWin->Refresh();
}
}
return ok;
@@ -4786,6 +4821,15 @@ bool wxGrid::AppendRows( int numRows, bool WXUNUSED(updateLabels) )
if ( m_table && m_table->AppendRows( numRows ) )
{
if ( m_numCols == 0 )
{
m_table->AppendCols( WXGRID_DEFAULT_NUMBER_COLS );
//
// TODO: perhaps instead of appending the default number of cols
// we should remember what the last non-zero number of cols was ?
//
}
if ( m_currentCellCoords == wxGridNoCellCoords )
{
// if we have just inserted cols into an empty grid the current
@@ -4797,7 +4841,12 @@ bool wxGrid::AppendRows( int numRows, bool WXUNUSED(updateLabels) )
// the table will have sent the results of the append row
// operation to this view object as a grid table message
//
if ( !GetBatchCount() ) Refresh();
if ( !GetBatchCount() )
{
CalcDimensions();
m_rowLabelWin->Refresh();
m_gridWin->Refresh();
}
return TRUE;
}
else
@@ -4829,7 +4878,12 @@ bool wxGrid::DeleteRows( int pos, int numRows, bool WXUNUSED(updateLabels) )
// operation to this view object as a grid table message
//
m_selection->UpdateRows( pos, -((int)numRows) );
if ( !GetBatchCount() ) Refresh();
if ( !GetBatchCount() )
{
CalcDimensions();
m_rowLabelWin->Refresh();
m_gridWin->Refresh();
}
return TRUE;
}
}
@@ -4868,7 +4922,12 @@ bool wxGrid::InsertCols( int pos, int numCols, bool WXUNUSED(updateLabels) )
}
m_selection->UpdateCols( pos, numCols );
if ( !GetBatchCount() ) Refresh();
if ( !GetBatchCount() )
{
CalcDimensions();
m_colLabelWin->Refresh();
m_gridWin->Refresh();
}
}
return ok;
@@ -4903,7 +4962,12 @@ bool wxGrid::AppendCols( int numCols, bool WXUNUSED(updateLabels) )
SetCurrentCell( 0, 0 );
}
if ( !GetBatchCount() ) Refresh();
if ( !GetBatchCount() )
{
CalcDimensions();
m_colLabelWin->Refresh();
m_gridWin->Refresh();
}
return TRUE;
}
else
@@ -4934,7 +4998,12 @@ bool wxGrid::DeleteCols( int pos, int numCols, bool WXUNUSED(updateLabels) )
// operation to this view object as a grid table message
//
m_selection->UpdateCols( pos, -((int)numCols) );
if ( !GetBatchCount() ) Refresh();
if ( !GetBatchCount() )
{
CalcDimensions();
m_colLabelWin->Refresh();
m_gridWin->Refresh();
}
return TRUE;
}
}
@@ -5600,7 +5669,7 @@ void wxGrid::DrawAllGridLines( wxDC& dc, const wxRegion & WXUNUSED_GTK(reg) )
void wxGrid::DrawRowLabels( wxDC& dc )
{
if ( !m_numRows || !m_numCols ) return;
if ( !m_numRows ) return;
size_t i;
size_t numLabels = m_rowLabelsExposed.GetCount();
@@ -5648,7 +5717,7 @@ void wxGrid::DrawRowLabel( wxDC& dc, int row )
void wxGrid::DrawColLabels( wxDC& dc )
{
if ( !m_numRows || !m_numCols ) return;
if ( !m_numCols ) return;
size_t i;
size_t numLabels = m_colLabelsExposed.GetCount();
@@ -7635,7 +7704,7 @@ void wxGrid::SelectRow( int row, bool addToSelected )
if ( IsSelection() && !addToSelected )
ClearSelection();
m_selection->SelectRow( row );
m_selection->SelectRow( row, FALSE, addToSelected );
}
@@ -7644,7 +7713,7 @@ void wxGrid::SelectCol( int col, bool addToSelected )
if ( IsSelection() && !addToSelected )
ClearSelection();
m_selection->SelectCol( col );
m_selection->SelectCol( col, FALSE, addToSelected );
}