From 6d4df74a03dcd0f9cba4421468d2c34308e4dbc9 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 13 Apr 2020 18:37:47 +0200 Subject: [PATCH] Simplify and improve wxGrid::DoGridCellDrag() return value logic Remove the "performDefault" variable which didn't really seem to help, as the actual meaning of the return value is whether we should start drag-selecting or not and the name of this variable didn't reflect this anyhow. Return false if we are over an invalid cell: this shouldn't change anything when we're already dragging, but would prevent us from starting to drag from an invalid cell which seems more correct, even if it's not clear if this can happen in practice. Also move hiding the edit control inside "isFirstDrag" check, there is no reason to do it on every drag. --- src/generic/grid.cpp | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 40bbaf678e..e6a95b51f2 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -4471,29 +4471,24 @@ wxGrid::DoGridCellDrag(wxMouseEvent& event, const wxGridCellCoords& coords, bool isFirstDrag) { - bool performDefault = true ; - if ( coords == wxGridNoCellCoords ) - return performDefault; // we're outside any valid cell + return false; // we're outside any valid cell - // Hide the edit control, so it won't interfere with drag-shrinking. - if ( IsCellEditControlShown() ) + if ( isFirstDrag ) { - HideCellEditControl(); - SaveEditControlValue(); - } - - if ( !event.HasAnyModifiers() ) - { - if ( CanDragCell() ) + // Hide the edit control, so it won't interfere with drag-shrinking. + if ( IsCellEditControlShown() ) { - if ( isFirstDrag ) + HideCellEditControl(); + SaveEditControlValue(); + } + + if ( !event.HasAnyModifiers() ) + { + if ( CanDragCell() ) { // if event is handled by user code, no further processing - if ( SendEvent(wxEVT_GRID_CELL_BEGIN_DRAG, coords, event) != 0 ) - performDefault = false; - - return performDefault; + return SendEvent(wxEVT_GRID_CELL_BEGIN_DRAG, coords, event) == 0; } } } @@ -4502,7 +4497,7 @@ wxGrid::DoGridCellDrag(wxMouseEvent& event, if ( m_selection ) m_selection->ExtendCurrentBlock(m_currentCellCoords, coords, event); - return performDefault; + return true; } bool wxGrid::DoGridDragEvent(wxMouseEvent& event,