Fix mouse event handling while dragging in wxGrid

Ignore all the mouse events other than "left up" while dragging to avoid
releasing the mouse and ending the dragging operation too soon.

This required non-trivial refactoring of the code which hopefully should
also make it slightly more clear by centralizing high level logic in
ProcessGridCellMouseEvent() itself and calling various helper functions
from it instead of spreading this logic over the entire call tree.

The code still remains pretty confusing and rewriting it to use
wxMouseEventsManager (which would need to be generalized first to become
a template class using arbitrary item type instead of just "int", as
now) would undoubtedly do it a lot of good.

Closes #18186.
This commit is contained in:
Vadim Zeitlin
2018-08-17 00:57:04 +02:00
parent 53972b17ee
commit bb00501e77
2 changed files with 82 additions and 67 deletions

View File

@@ -2218,10 +2218,14 @@ private:
// SetColPos() and ResetColPos())
void RefreshAfterColPosChange();
// reset the variables used during dragging operations after it ended
// because we lost mouse capture
// reset the variables used during dragging operations after it ended,
// either because we called EndDraggingIfNecessary() ourselves or because
// we lost mouse capture
void DoAfterDraggingEnd();
// release the mouse capture if it's currently captured
void EndDraggingIfNecessary();
// return the position (not index) of the column at the given logical pixel
// position
@@ -2242,8 +2246,12 @@ private:
// process row/column resizing drag event
void DoGridLineDrag(wxMouseEvent& event, const wxGridOperations& oper);
// process mouse drag event in the grid window
void DoGridDragEvent(wxMouseEvent& event, const wxGridCellCoords& coords);
// process mouse drag event in the grid window, return false if starting
// dragging was vetoed by the user-defined wxEVT_GRID_CELL_BEGIN_DRAG
// handler
bool DoGridDragEvent(wxMouseEvent& event,
const wxGridCellCoords& coords,
bool isFirstDrag);
// process different clicks on grid cells
void DoGridCellLeftDown(wxMouseEvent& event,