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.
This commit is contained in:
Vadim Zeitlin 2020-02-23 14:47:42 +01:00
parent 05c5891bf6
commit 52b7267aac
2 changed files with 13 additions and 8 deletions

View File

@ -2298,6 +2298,10 @@ protected:
bool m_canDragGridSize; bool m_canDragGridSize;
bool m_canDragCell; 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 // 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 // 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 // dragged by the user or -1 of there is no drag operation in progress

View File

@ -2673,6 +2673,7 @@ void wxGrid::Init()
m_canDragColSize = true; m_canDragColSize = true;
m_canDragGridSize = true; m_canDragGridSize = true;
m_canDragCell = false; m_canDragCell = false;
m_dragMoveCol = -1;
m_dragLastPos = -1; m_dragLastPos = -1;
m_dragRowOrCol = -1; m_dragRowOrCol = -1;
m_isDragging = false; m_isDragging = false;
@ -3837,7 +3838,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event, wxGridColLabelWindo
const wxColour *color; const wxColour *color;
//Moving to the same place? Don't draw a marker //Moving to the same place? Don't draw a marker
if ( colNew == m_dragRowOrCol ) if ( colNew == m_dragMoveCol )
color = wxLIGHT_GREY; color = wxLIGHT_GREY;
else else
color = wxBLUE; color = wxBLUE;
@ -3963,7 +3964,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event, wxGridColLabelWindo
break; break;
case WXGRID_CURSOR_MOVE_COL: 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 // the column didn't actually move anywhere
if ( col != -1 ) if ( col != -1 )
@ -3989,7 +3990,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event, wxGridColLabelWindo
const bool onNearPart = (x <= middle); const bool onNearPart = (x <= middle);
// adjust for the column being dragged itself // adjust for the column being dragged itself
if ( pos < GetColPos(m_dragRowOrCol) ) if ( pos < GetColPos(m_dragMoveCol) )
pos++; pos++;
// and if it's on the near part of the target column, // 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) void wxGrid::DoStartMoveCol(int col)
{ {
m_dragRowOrCol = col; m_dragMoveCol = col;
} }
void wxGrid::DoEndMoveCol(int pos) 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 ) if ( SendEvent(wxEVT_GRID_COL_MOVE, -1, m_dragMoveCol) != -1 )
SetColPos(m_dragRowOrCol, pos); SetColPos(m_dragMoveCol, pos);
//else: vetoed by user //else: vetoed by user
m_dragRowOrCol = -1; m_dragMoveCol = -1;
} }
void wxGrid::RefreshAfterColPosChange() void wxGrid::RefreshAfterColPosChange()