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

@@ -1675,7 +1675,27 @@ public:
void DisableRowResize(int row) { DoDisableLineResize(row, m_setFixedRows); } void DisableRowResize(int row) { DoDisableLineResize(row, m_setFixedRows); }
void DisableColResize(int col) { DoDisableLineResize(col, m_setFixedCols); } void DisableColResize(int col) { DoDisableLineResize(col, m_setFixedCols); }
// these functions return whether the given row/column can be // These function return true if resizing rows/columns by dragging
// their edges inside the grid is enabled. Note that this doesn't cover
// dragging their separators in the label windows (which can be enabled
// for the columns even if dragging inside the grid is not), nor checks
// whether a particular row/column is resizeable or not, so you should
// always check CanDrag{Row,Col}Size() below too.
bool CanDragGridRowEdges() const
{
return m_canDragGridSize && m_canDragRowSize;
}
bool CanDragGridColEdges() const
{
// When using the native header window we can only resize the columns by
// dragging the dividers in the header itself, but not by dragging them
// in the grid because we can't make the native control enter into the
// column resizing mode programmatically.
return m_canDragGridSize && m_canDragColSize && !m_useNativeHeader;
}
// These functions return whether the given row/column can be
// effectively resized: for this interactive resizing must be enabled // effectively resized: for this interactive resizing must be enabled
// and this index must not have been passed to DisableRow/ColResize() // and this index must not have been passed to DisableRow/ColResize()
bool CanDragRowSize(int row) const bool CanDragRowSize(int row) const

View File

@@ -4322,6 +4322,26 @@ public:
*/ */
bool CanDragColSize(int col) const; bool CanDragColSize(int col) const;
/**
Return @true if column edges inside the grid can be dragged to resize
the rows.
@see CanDragGridSize(), CanDragColSize()
@since 3.1.4
*/
bool CanDragGridColEdges() const;
/**
Return @true if row edges inside the grid can be dragged to resize the
rows.
@see CanDragGridSize(), CanDragRowSize()
@since 3.1.4
*/
bool CanDragGridRowEdges() const;
/** /**
Return @true if the dragging of grid lines to resize rows and columns Return @true if the dragging of grid lines to resize rows and columns
is enabled or @false otherwise. is enabled or @false otherwise.

View File

@@ -4577,8 +4577,20 @@ wxGrid::DoGridCellLeftDown(wxMouseEvent& event,
MakeCellVisible(coords); 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(); DisableCellEditControl();
MakeCellVisible( coords ); MakeCellVisible( coords );
@@ -4718,7 +4730,7 @@ wxGrid::DoGridMouseMoveEvent(wxMouseEvent& WXUNUSED(event),
return; return;
} }
if ( dragRow >= 0 && CanDragGridSize() && CanDragRowSize(dragRow) ) if ( dragRow >= 0 && CanDragGridRowEdges() && CanDragRowSize(dragRow) )
{ {
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL ) if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
{ {
@@ -4726,11 +4738,7 @@ wxGrid::DoGridMouseMoveEvent(wxMouseEvent& WXUNUSED(event),
ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW, gridWindow, false); ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW, gridWindow, false);
} }
} }
// When using the native header window we can only resize the columns by else if ( dragCol >= 0 && CanDragGridColEdges() && CanDragColSize(dragCol) )
// 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) )
{ {
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL ) if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
{ {