From 52b7267aacb41deb9747e72bb042da47c893965b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 23 Feb 2020 14:47:42 +0100 Subject: [PATCH] Add wxGrid::m_dragMoveCol field separate from m_dragRowOrCol Don't reuse the same m_dragRowOrCol variable for both the index of the row or column being drag-resized and for the index of the column being drag-moved. Reusing it was confusing and made it more difficult what the code was doing and what invariants were preserved in it, and just wasn't worth saving a few bytes per wxGrid object. No real changes. --- include/wx/generic/grid.h | 4 ++++ src/generic/grid.cpp | 17 +++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index d3b076783e..6175ef2580 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -2298,6 +2298,10 @@ protected: bool m_canDragGridSize; bool m_canDragCell; + // Index of the column being drag-moved or -1 if there is no move operation + // in progress. + int m_dragMoveCol; + // the last position (horizontal or vertical depending on whether the user // is resizing a column or a row) where a row or column separator line was // dragged by the user or -1 of there is no drag operation in progress diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 3199afe5ce..22674b4696 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -2673,6 +2673,7 @@ void wxGrid::Init() m_canDragColSize = true; m_canDragGridSize = true; m_canDragCell = false; + m_dragMoveCol = -1; m_dragLastPos = -1; m_dragRowOrCol = -1; m_isDragging = false; @@ -3837,7 +3838,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event, wxGridColLabelWindo const wxColour *color; //Moving to the same place? Don't draw a marker - if ( colNew == m_dragRowOrCol ) + if ( colNew == m_dragMoveCol ) color = wxLIGHT_GREY; else color = wxBLUE; @@ -3963,7 +3964,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event, wxGridColLabelWindo break; case WXGRID_CURSOR_MOVE_COL: - if ( m_dragLastPos == -1 || col == m_dragRowOrCol ) + if ( m_dragLastPos == -1 || col == m_dragMoveCol ) { // the column didn't actually move anywhere if ( col != -1 ) @@ -3989,7 +3990,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event, wxGridColLabelWindo const bool onNearPart = (x <= middle); // adjust for the column being dragged itself - if ( pos < GetColPos(m_dragRowOrCol) ) + if ( pos < GetColPos(m_dragMoveCol) ) pos++; // and if it's on the near part of the target column, @@ -4763,18 +4764,18 @@ void wxGrid::DoEndDragResizeCol(const wxMouseEvent& event, wxGridWindow* gridWin void wxGrid::DoStartMoveCol(int col) { - m_dragRowOrCol = col; + m_dragMoveCol = col; } void wxGrid::DoEndMoveCol(int pos) { - wxASSERT_MSG( m_dragRowOrCol != -1, "no matching DoStartMoveCol?" ); + wxASSERT_MSG( m_dragMoveCol != -1, "no matching DoStartMoveCol?" ); - if ( SendEvent(wxEVT_GRID_COL_MOVE, -1, m_dragRowOrCol) != -1 ) - SetColPos(m_dragRowOrCol, pos); + if ( SendEvent(wxEVT_GRID_COL_MOVE, -1, m_dragMoveCol) != -1 ) + SetColPos(m_dragMoveCol, pos); //else: vetoed by user - m_dragRowOrCol = -1; + m_dragMoveCol = -1; } void wxGrid::RefreshAfterColPosChange()