Bugfixes; added selection modes demo to griddemo

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6439 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Neis
2000-03-04 19:56:39 +00:00
parent a56fcaaf46
commit 043d16b225
5 changed files with 63 additions and 19 deletions

View File

@@ -997,7 +997,9 @@ public:
void DoEndDragResizeCol(); void DoEndDragResizeCol();
wxGridTableBase * GetTable() const { return m_table; } wxGridTableBase * GetTable() const { return m_table; }
bool SetTable( wxGridTableBase *table, bool takeOwnership=FALSE ); bool SetTable( wxGridTableBase *table, bool takeOwnership=FALSE,
wxGrid::wxGridSelectionModes selmode =
wxGrid::wxGridSelectCells );
void ClearGrid(); void ClearGrid();
bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE ); bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );

View File

@@ -83,6 +83,9 @@ BEGIN_EVENT_TABLE( GridFrame, wxFrame )
EVT_MENU( ID_DELETEROW, GridFrame::DeleteSelectedRows ) EVT_MENU( ID_DELETEROW, GridFrame::DeleteSelectedRows )
EVT_MENU( ID_DELETECOL, GridFrame::DeleteSelectedCols ) EVT_MENU( ID_DELETECOL, GridFrame::DeleteSelectedCols )
EVT_MENU( ID_CLEARGRID, GridFrame::ClearGrid ) EVT_MENU( ID_CLEARGRID, GridFrame::ClearGrid )
EVT_MENU( ID_SELCELLS, GridFrame::SelectCells )
EVT_MENU( ID_SELROWS, GridFrame::SelectRows )
EVT_MENU( ID_SELCOLS, GridFrame::SelectCols )
EVT_MENU( ID_SET_CELL_FG_COLOUR, GridFrame::SetCellFgColour ) EVT_MENU( ID_SET_CELL_FG_COLOUR, GridFrame::SetCellFgColour )
EVT_MENU( ID_SET_CELL_BG_COLOUR, GridFrame::SetCellBgColour ) EVT_MENU( ID_SET_CELL_BG_COLOUR, GridFrame::SetCellBgColour )
@@ -159,6 +162,16 @@ GridFrame::GridFrame()
editMenu->Append( ID_DELETECOL, "Delete selected co&ls" ); editMenu->Append( ID_DELETECOL, "Delete selected co&ls" );
editMenu->Append( ID_CLEARGRID, "Cl&ear grid cell contents" ); editMenu->Append( ID_CLEARGRID, "Cl&ear grid cell contents" );
wxMenu *selectionMenu = new wxMenu;
editMenu->Append( ID_CHANGESEL, "Change &selection mode",
selectionMenu,
"Change selection mode" );
selectionMenu->Append( ID_SELCELLS, "Select &Cells" );
selectionMenu->Append( ID_SELROWS, "Select &Rows" );
selectionMenu->Append( ID_SELCOLS, "Select C&ols" );
wxMenu *helpMenu = new wxMenu; wxMenu *helpMenu = new wxMenu;
helpMenu->Append( ID_ABOUT, "&About wxGrid demo" ); helpMenu->Append( ID_ABOUT, "&About wxGrid demo" );
@@ -482,27 +495,23 @@ void GridFrame::InsertCol( wxCommandEvent& WXUNUSED(ev) )
void GridFrame::DeleteSelectedRows( wxCommandEvent& WXUNUSED(ev) ) void GridFrame::DeleteSelectedRows( wxCommandEvent& WXUNUSED(ev) )
{ {
#if 0
if ( grid->IsSelection() ) if ( grid->IsSelection() )
{ {
int topRow, bottomRow, leftCol, rightCol; for ( int n = 0; n < grid->GetNumberRows(); n++ )
grid->GetSelection( &topRow, &leftCol, &bottomRow, &rightCol ); if ( grid->IsInSelection( n , 0 ) )
grid->DeleteRows( topRow, bottomRow - topRow + 1 ); grid->DeleteRows( n, 1 );
} }
#endif
} }
void GridFrame::DeleteSelectedCols( wxCommandEvent& WXUNUSED(ev) ) void GridFrame::DeleteSelectedCols( wxCommandEvent& WXUNUSED(ev) )
{ {
#if 0
if ( grid->IsSelection() ) if ( grid->IsSelection() )
{ {
int topRow, bottomRow, leftCol, rightCol; for ( int n = 0; n < grid->GetNumberCols(); n++ )
grid->GetSelection( &topRow, &leftCol, &bottomRow, &rightCol ); if ( grid->IsInSelection( 0 , n ) )
grid->DeleteCols( leftCol, rightCol - leftCol + 1 ); grid->DeleteCols( n, 1 );
} }
#endif
} }
@@ -511,6 +520,21 @@ void GridFrame::ClearGrid( wxCommandEvent& WXUNUSED(ev) )
grid->ClearGrid(); grid->ClearGrid();
} }
void GridFrame::SelectCells( wxCommandEvent& WXUNUSED(ev) )
{
grid->SetSelectionMode( wxGrid::wxGridSelectCells );
}
void GridFrame::SelectRows( wxCommandEvent& WXUNUSED(ev) )
{
grid->SetSelectionMode( wxGrid::wxGridSelectRows );
}
void GridFrame::SelectCols( wxCommandEvent& WXUNUSED(ev) )
{
grid->SetSelectionMode( wxGrid::wxGridSelectColumns );
}
void GridFrame::SetCellFgColour( wxCommandEvent& WXUNUSED(ev) ) void GridFrame::SetCellFgColour( wxCommandEvent& WXUNUSED(ev) )
{ {
wxColour col = wxGetColourFromUser(this); wxColour col = wxGetColourFromUser(this);

View File

@@ -56,6 +56,9 @@ class GridFrame : public wxFrame
void DeleteSelectedRows( wxCommandEvent& ); void DeleteSelectedRows( wxCommandEvent& );
void DeleteSelectedCols( wxCommandEvent& ); void DeleteSelectedCols( wxCommandEvent& );
void ClearGrid( wxCommandEvent& ); void ClearGrid( wxCommandEvent& );
void SelectCells( wxCommandEvent& );
void SelectRows( wxCommandEvent& );
void SelectCols( wxCommandEvent& );
void OnLabelLeftClick( wxGridEvent& ); void OnLabelLeftClick( wxGridEvent& );
void OnCellLeftClick( wxGridEvent& ); void OnCellLeftClick( wxGridEvent& );
@@ -99,6 +102,10 @@ public:
ID_DELETEROW, ID_DELETEROW,
ID_DELETECOL, ID_DELETECOL,
ID_CLEARGRID, ID_CLEARGRID,
ID_CHANGESEL,
ID_SELCELLS,
ID_SELROWS,
ID_SELCOLS,
ID_SET_CELL_FG_COLOUR, ID_SET_CELL_FG_COLOUR,
ID_SET_CELL_BG_COLOUR, ID_SET_CELL_BG_COLOUR,
ID_ABOUT, ID_ABOUT,

View File

@@ -3165,9 +3165,9 @@ bool wxGrid::CreateGrid( int numRows, int numCols,
m_table->SetView( this ); m_table->SetView( this );
m_ownTable = TRUE; m_ownTable = TRUE;
Init(); Init();
m_selection = new wxGridSelection( this, selmode );
m_created = TRUE; m_created = TRUE;
} }
m_selection = new wxGridSelection( this, selmode );
return m_created; return m_created;
} }
@@ -3181,7 +3181,8 @@ void wxGrid::SetSelectionMode(wxGrid::wxGridSelectionModes selmode)
m_selection->SetSelectionMode( selmode ); m_selection->SetSelectionMode( selmode );
} }
bool wxGrid::SetTable( wxGridTableBase *table, bool takeOwnership ) bool wxGrid::SetTable( wxGridTableBase *table, bool takeOwnership,
wxGrid::wxGridSelectionModes selmode )
{ {
if ( m_created ) if ( m_created )
{ {
@@ -3190,6 +3191,7 @@ bool wxGrid::SetTable( wxGridTableBase *table, bool takeOwnership )
// View at runtime. Is there anything in the implmentation that would // View at runtime. Is there anything in the implmentation that would
// prevent this? // prevent this?
// At least, you now have to copy with m_selection
wxFAIL_MSG( wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") ); wxFAIL_MSG( wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
return FALSE; return FALSE;
} }
@@ -3203,6 +3205,7 @@ bool wxGrid::SetTable( wxGridTableBase *table, bool takeOwnership )
if (takeOwnership) if (takeOwnership)
m_ownTable = TRUE; m_ownTable = TRUE;
Init(); Init();
m_selection = new wxGridSelection( this, selmode );
m_created = TRUE; m_created = TRUE;
} }
@@ -4391,10 +4394,10 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
if ( m_selectingTopLeft != wxGridNoCellCoords && if ( m_selectingTopLeft != wxGridNoCellCoords &&
m_selectingBottomRight != wxGridNoCellCoords ) m_selectingBottomRight != wxGridNoCellCoords )
{ {
m_selection->SelectBlock( m_selectingTopLeft.GetRow(), m_selection->SelectBlock( m_selectingTopLeft.GetRow(),
m_selectingTopLeft.GetCol(), m_selectingTopLeft.GetCol(),
m_selectingBottomRight.GetRow(), m_selectingBottomRight.GetRow(),
m_selectingBottomRight.GetCol() ); m_selectingBottomRight.GetCol() );
if (m_winCapture) if (m_winCapture)
{ {
m_winCapture->ReleaseMouse(); m_winCapture->ReleaseMouse();

View File

@@ -147,9 +147,10 @@ void wxGridSelection::SetSelectionMode(wxGrid::wxGridSelectionModes selmode)
else // selmode == wxGridSelectColumns) else // selmode == wxGridSelectColumns)
SelectCol( col ); SelectCol( col );
} }
while( ( n = m_blockSelectionTopLeft.GetCount() ) > 0)
for (n = 0; n < m_blockSelectionTopLeft.GetCount(); n++)
// Note that m_blockSelectionTopLeft's size may be changing!
{ {
n--;
wxGridCellCoords& coords = m_blockSelectionTopLeft[n]; wxGridCellCoords& coords = m_blockSelectionTopLeft[n];
int topRow = coords.GetRow(); int topRow = coords.GetRow();
int leftCol = coords.GetCol(); int leftCol = coords.GetCol();
@@ -177,6 +178,7 @@ void wxGridSelection::SetSelectionMode(wxGrid::wxGridSelectionModes selmode)
} }
} }
} }
m_selectionMode = selmode;
} }
} }
@@ -457,9 +459,15 @@ void wxGridSelection::SelectBlock( int topRow, int leftCol, int bottomRow, int r
void wxGridSelection::SelectCell( int row, int col) void wxGridSelection::SelectCell( int row, int col)
{ {
if ( m_selectionMode == wxGrid::wxGridSelectRows ) if ( m_selectionMode == wxGrid::wxGridSelectRows )
{
SelectBlock(row, 0, row, m_grid->GetNumberCols() - 1 ); SelectBlock(row, 0, row, m_grid->GetNumberCols() - 1 );
return;
}
else if ( m_selectionMode == wxGrid::wxGridSelectColumns ) else if ( m_selectionMode == wxGrid::wxGridSelectColumns )
{
SelectBlock(0, col, m_grid->GetNumberRows() - 1, col ); SelectBlock(0, col, m_grid->GetNumberRows() - 1, col );
return;
}
else if ( IsInSelection ( row, col ) ) else if ( IsInSelection ( row, col ) )
return; return;
m_cellSelection.Add( wxGridCellCoords( row, col ) ); m_cellSelection.Add( wxGridCellCoords( row, col ) );