From 4f7ed07f5eaeac695d16454701ae3ca0d3f7f947 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 12 Apr 2020 18:39:34 +0200 Subject: [PATCH] Don't use row/column headers for selection incompatible with mode Mouse events in row/column headers should be just ignored when the current selection mode disallows row/column selection. This wasn't the case before, and while actually selecting the line corresponding to the header was disallowed further down the call chain, clicking it still unexpectedly cleared the existing selection and dragging mouse in the header window selected the entire grid. Fix this by just never entering the corresponding cursor mode in the first place if it's incompatible with the current selection mode. --- src/generic/grid.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index e4b6117ba6..754bca5f16 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -3720,7 +3720,11 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event, wxGridRowLabelWindo if ( row >= 0 && !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK, row, -1, event ) ) { - if ( m_selection && m_numRows > 0 && m_numCols > 0 ) + // Check if row selection is possible and allowed, before doing + // anything else, including changing the cursor mode to "select + // row". + if ( m_selection && m_numRows > 0 && m_numCols > 0 && + m_selection->GetSelectionMode() != wxGridSelectColumns ) { bool selectNewRow = false; @@ -3756,9 +3760,9 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event, wxGridRowLabelWindo SetCurrentCell(row, GetFirstFullyVisibleColumn()); } - } - ChangeCursorMode(WXGRID_CURSOR_SELECT_ROW, rowLabelWin); + ChangeCursorMode(WXGRID_CURSOR_SELECT_ROW, rowLabelWin); + } } } } @@ -4118,7 +4122,8 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event, wxGridColLabelWindo } else { - if ( m_selection && m_numRows > 0 && m_numCols > 0 ) + if ( m_selection && m_numRows > 0 && m_numCols > 0 && + m_selection->GetSelectionMode() != wxGridSelectRows ) { bool selectNewCol = false; @@ -4154,9 +4159,9 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event, wxGridColLabelWindo SetCurrentCell(GetFirstFullyVisibleRow(), col); } - } - ChangeCursorMode(WXGRID_CURSOR_SELECT_COL, colLabelWin); + ChangeCursorMode(WXGRID_CURSOR_SELECT_COL, colLabelWin); + } } } }