Handle clicks on grid edges normally when not using drag-resizing

Clicking on (or near) the grid column or row edges was handled specially
to allow dragging them in order to resize the column or row, but this
doesn't need to be done if drag-resizing the columns or rows is not
allowed in the first place and resulted in surprising user-visible
behaviour: e.g. when using row selection, clicking mostly anywhere in
the row selected it, except if the click happened to be between the two
columns, in which case it didn't.

Fix this and always select the row in such scenario now.

Unfortunately, doing this required adding yet more CanDragXXX()
functions in addition to the already impressive panoply of them in
wxGrid, but we need CanDragGridColEdges() as none of the existing
functions checked for m_useNativeHeader (there was instead an ad hoc
check for it directly in the mouse handling code) and the row version
had to be added for symmetry.
This commit is contained in:
Vadim Zeitlin
2020-06-21 19:23:53 +02:00
parent 3fa942795e
commit 867cc2a3eb
3 changed files with 56 additions and 8 deletions

View File

@@ -4577,8 +4577,20 @@ wxGrid::DoGridCellLeftDown(wxMouseEvent& event,
MakeCellVisible(coords);
}
}
else if ( XToEdgeOfCol(pos.x) < 0 && YToEdgeOfRow(pos.y) < 0 )
else
{
// Clicking on (or very near) the separating lines shouldn't change the
// selection when it's used for resizing -- but should still do it if
// resizing is disabled (notice that we intentionally don't check for
// it being disabled for a particular row/column as it would be
// surprising to have different mouse behaviour in different parts of
// the same grid, so we only check for it being globally disabled).
if ( CanDragGridColEdges() && XToEdgeOfCol(pos.x) != wxNOT_FOUND )
return;
if ( CanDragGridRowEdges() && YToEdgeOfRow(pos.y) != wxNOT_FOUND )
return;
DisableCellEditControl();
MakeCellVisible( coords );
@@ -4718,7 +4730,7 @@ wxGrid::DoGridMouseMoveEvent(wxMouseEvent& WXUNUSED(event),
return;
}
if ( dragRow >= 0 && CanDragGridSize() && CanDragRowSize(dragRow) )
if ( dragRow >= 0 && CanDragGridRowEdges() && CanDragRowSize(dragRow) )
{
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
{
@@ -4726,11 +4738,7 @@ wxGrid::DoGridMouseMoveEvent(wxMouseEvent& WXUNUSED(event),
ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW, gridWindow, false);
}
}
// When using the native header window we can only resize the columns by
// dragging the dividers in it because we can't make it enter into the
// column resizing mode programmatically
else if ( dragCol >= 0 && !m_useNativeHeader &&
CanDragGridSize() && CanDragColSize(dragCol) )
else if ( dragCol >= 0 && CanDragGridColEdges() && CanDragColSize(dragCol) )
{
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
{