diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index 948aba4d0b..3215eece14 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -1675,7 +1675,27 @@ public: void DisableRowResize(int row) { DoDisableLineResize(row, m_setFixedRows); } 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 // and this index must not have been passed to DisableRow/ColResize() bool CanDragRowSize(int row) const diff --git a/interface/wx/grid.h b/interface/wx/grid.h index 24d2dc8e0e..aa9a6b4a45 100644 --- a/interface/wx/grid.h +++ b/interface/wx/grid.h @@ -4322,6 +4322,26 @@ public: */ 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 is enabled or @false otherwise. diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index ec8aeaddbc..5a92397095 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -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 ) {