diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index 6256cefa7c..d78a836773 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -1457,7 +1457,8 @@ public: wxGridSelectCells = 0, // allow selecting anything wxGridSelectRows = 1, // allow selecting only entire rows wxGridSelectColumns = 2, // allow selecting only entire columns - wxGridSelectRowsOrColumns = wxGridSelectRows | wxGridSelectColumns + wxGridSelectRowsOrColumns = wxGridSelectRows | wxGridSelectColumns, + wxGridSelectNone = 4 // disallow selecting anything }; // Different behaviour of the TAB key when the end (or the beginning, for diff --git a/interface/wx/grid.h b/interface/wx/grid.h index f24fe4df53..9e33e41e4d 100644 --- a/interface/wx/grid.h +++ b/interface/wx/grid.h @@ -2945,7 +2945,16 @@ public: @since 2.9.1 */ - wxGridSelectRowsOrColumns + wxGridSelectRowsOrColumns, + + /** + The selection mode allowing no selections to be made at all. + + The user won't be able to select any cells in this mode. + + @since 3.1.5 + */ + wxGridSelectNone }; /** diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 184010743c..edffab4e97 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -4631,6 +4631,7 @@ wxGrid::DoGridCellLeftDown(wxMouseEvent& event, // mode and is compatible with 2.8 behaviour (see #12062). switch ( m_selection->GetSelectionMode() ) { + case wxGridSelectNone: case wxGridSelectCells: case wxGridSelectRowsOrColumns: // nothing to do in these cases diff --git a/src/generic/gridsel.cpp b/src/generic/gridsel.cpp index af0dced594..e6ac723923 100644 --- a/src/generic/gridsel.cpp +++ b/src/generic/gridsel.cpp @@ -98,6 +98,13 @@ void wxGridSelection::SetSelectionMode( wxGrid::wxGridSelectionModes selmode ) if (selmode == m_selectionMode) return; + if (selmode == wxGrid::wxGridSelectNone) + { + ClearSelection(); + m_selectionMode = selmode; + return; + } + if ( m_selectionMode != wxGrid::wxGridSelectCells ) { // if changing form row to column selection @@ -127,6 +134,7 @@ void wxGridSelection::SetSelectionMode( wxGrid::wxGridSelectionModes selmode ) switch ( selmode ) { case wxGrid::wxGridSelectCells: + case wxGrid::wxGridSelectNone: wxFAIL_MSG("unreachable"); break; @@ -160,7 +168,8 @@ void wxGridSelection::SetSelectionMode( wxGrid::wxGridSelectionModes selmode ) void wxGridSelection::SelectRow(int row, const wxKeyboardState& kbd) { - if ( m_selectionMode == wxGrid::wxGridSelectColumns ) + if ( m_selectionMode == wxGrid::wxGridSelectColumns || + m_selectionMode == wxGrid::wxGridSelectNone ) return; Select(wxGridBlockCoords(row, 0, row, m_grid->GetNumberCols() - 1), @@ -169,7 +178,8 @@ void wxGridSelection::SelectRow(int row, const wxKeyboardState& kbd) void wxGridSelection::SelectCol(int col, const wxKeyboardState& kbd) { - if ( m_selectionMode == wxGrid::wxGridSelectRows ) + if ( m_selectionMode == wxGrid::wxGridSelectRows || + m_selectionMode == wxGrid::wxGridSelectNone ) return; Select(wxGridBlockCoords(0, col, m_grid->GetNumberRows() - 1, col), @@ -214,6 +224,10 @@ void wxGridSelection::SelectBlock( int topRow, int leftCol, else allowed = 0; break; + + case wxGrid::wxGridSelectNone: + allowed = 0; + break; } wxASSERT_MSG(allowed != -1, "unknown selection mode?"); @@ -246,6 +260,10 @@ wxGridSelection::DeselectBlock(const wxGridBlockCoords& block, const wxKeyboardState& kbd, wxEventType eventType) { + // In wxGridSelectNone mode, all blocks should already be deselected. + if ( m_selectionMode == wxGrid::wxGridSelectNone ) + return; + const wxGridBlockCoords canonicalizedBlock = block.Canonicalize(); size_t count, n; @@ -312,6 +330,10 @@ wxGridSelection::DeselectBlock(const wxGridBlockCoords& block, else splitOrientation = wxVERTICAL; break; + + case wxGrid::wxGridSelectNone: + wxFAIL_MSG("unreachable"); + break; } wxASSERT_MSG( splitOrientation != -1, "unknown selection mode" ); @@ -517,10 +539,14 @@ bool wxGridSelection::ExtendCurrentBlock(const wxGridCellCoords& blockStart, wxASSERT( blockStart.GetRow() != -1 && blockStart.GetCol() != -1 && blockEnd.GetRow() != -1 && blockEnd.GetCol() != -1 ); + if ( m_selectionMode == wxGrid::wxGridSelectNone ) + return false; + // If selection doesn't contain the current cell (which also covers the // special case of nothing being selected yet), we have to create a new // block containing it because it doesn't make sense to extend any existing // block to non-selected current cell. + if ( !IsInSelection(m_grid->GetGridCursorCoords()) ) { SelectBlock(blockStart, blockEnd, kbd, eventType); @@ -574,6 +600,10 @@ bool wxGridSelection::ExtendCurrentBlock(const wxGridCellCoords& blockStart, canChangeCol = true; } break; + + case wxGrid::wxGridSelectNone: + wxFAIL_MSG("unreachable"); + break; } if ( canChangeRow ) @@ -754,7 +784,8 @@ wxGridCellCoordsArray wxGridSelection::GetBlockSelectionBottomRight() const // is, anyhow, the best we can do. wxArrayInt wxGridSelection::GetRowSelection() const { - if ( m_selectionMode == wxGrid::wxGridSelectColumns ) + if ( m_selectionMode == wxGrid::wxGridSelectColumns || + m_selectionMode == wxGrid::wxGridSelectNone ) return wxArrayInt(); wxIntSortedArray uniqueRows; @@ -785,7 +816,8 @@ wxArrayInt wxGridSelection::GetRowSelection() const // See comments for GetRowSelection(). wxArrayInt wxGridSelection::GetColSelection() const { - if ( m_selectionMode == wxGrid::wxGridSelectRows ) + if ( m_selectionMode == wxGrid::wxGridSelectRows || + m_selectionMode == wxGrid::wxGridSelectNone ) return wxArrayInt(); wxIntSortedArray uniqueCols;