added a test command to show the current selection

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36746 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-01-07 00:31:32 +00:00
parent a4ebf7ba61
commit 1ecf2613d0
2 changed files with 83 additions and 0 deletions

View File

@@ -109,6 +109,7 @@ BEGIN_EVENT_TABLE( GridFrame, wxFrame )
EVT_MENU( ID_SELECT_ROW, GridFrame::SelectRow)
EVT_MENU( ID_SELECT_ALL, GridFrame::SelectAll)
EVT_MENU( ID_SELECT_UNSELECT, GridFrame::OnAddToSelectToggle)
EVT_MENU( ID_SHOW_SELECTION, GridFrame::OnShowSelection)
EVT_MENU( ID_SET_HIGHLIGHT_WIDTH, GridFrame::OnSetHighlightWidth)
EVT_MENU( ID_SET_RO_HIGHLIGHT_WIDTH, GridFrame::OnSetROHighlightWidth)
@@ -191,10 +192,14 @@ GridFrame::GridFrame()
selectMenu->Append( ID_SELECT_UNSELECT, _T("Add new cells to the selection"),
_T("When off, old selection is deselected before ")
_T("selecting the new cells"), wxITEM_CHECK );
selectMenu->Append( ID_SHOW_SELECTION,
_T("&Show current selection\tCtrl-Alt-S"));
selectMenu->AppendSeparator();
selectMenu->Append( ID_SELECT_ALL, _T("Select all"));
selectMenu->Append( ID_SELECT_ROW, _T("Select row 2"));
selectMenu->Append( ID_SELECT_COL, _T("Select col 2"));
selectMenu->Append( ID_SELECT_CELL, _T("Select cell (3, 1)"));
selectMenu->AppendSeparator();
selectMenu->Append( ID_DESELECT_ALL, _T("Deselect all"));
selectMenu->Append( ID_DESELECT_ROW, _T("Deselect row 2"));
selectMenu->Append( ID_DESELECT_COL, _T("Deselect col 2"));
@@ -833,6 +838,82 @@ void GridFrame::OnColSize( wxGridSizeEvent& ev )
}
void GridFrame::OnShowSelection(wxCommandEvent& WXUNUSED(event))
{
// max number of elements to dump -- otherwise it can take too much time
static const size_t countMax = 100;
bool rows = false;
switch ( grid->GetSelectionMode() )
{
case wxGrid::wxGridSelectCells:
{
const wxGridCellCoordsArray cells(grid->GetSelectedCells());
size_t count = cells.size();
wxLogMessage(_T("%lu cells selected:"), (unsigned long)count);
if ( count > countMax )
{
wxLogMessage(_T("[too many selected cells, ")
_T("showing only the first %lu]"),
(unsigned long)countMax);
count = countMax;
}
for ( size_t n = 0; n < count; n++ )
{
const wxGridCellCoords& c = cells[n];
wxLogMessage(_T(" selected cell %lu: (%d, %d)"),
(unsigned long)n, c.GetCol(), c.GetRow());
}
}
break;
case wxGrid::wxGridSelectRows:
rows = true;
// fall through
case wxGrid::wxGridSelectColumns:
{
const wxChar *plural, *single;
if ( rows )
{
plural = _T("rows");
single = _T("row");
}
else // columns
{
plural = _T("columns");
single = _T("column");
}
const wxArrayInt sels(rows ? grid->GetSelectedRows()
: grid->GetSelectedCols());
size_t count = sels.size();
wxLogMessage(_T("%lu %s selected:"),
(unsigned long)count, plural);
if ( count > countMax )
{
wxLogMessage(_T("[too many selected %s, ")
_T("showing only the first %lu]"),
plural, (unsigned long)countMax);
count = countMax;
}
for ( size_t n = 0; n < count; n++ )
{
wxLogMessage(_T(" selected %s %lu: %d"),
single, (unsigned long)n, sels[n]);
}
}
break;
default:
wxFAIL_MSG( _T("unknown wxGrid selection mode") );
break;
}
}
void GridFrame::OnSelectCell( wxGridEvent& ev )
{
logBuf = wxEmptyString;