Enforce valid drag column/row index in DoGridDragResize()
Add an assert to this function checking that the index is valid before using it with wxGridOperations::GetLineStartPos(), and actually avoid calling the function when this is not the case to avoid assertion failures when wxEVT_GRID_CELL_LEFT_CLICK is handled in user code. Also add comments clarifying the preconditions for calling various drag-related functions. Closes #19218.
This commit is contained in:
@@ -2951,6 +2951,8 @@ private:
|
||||
wxGridWindow* gridWindow);
|
||||
|
||||
// Update the width/height of the column/row being drag-resized.
|
||||
// Should be only called when m_dragRowOrCol != -1, i.e. dragging is
|
||||
// actually in progress.
|
||||
void DoGridDragResize(const wxPoint& position,
|
||||
const wxGridOperations& oper,
|
||||
wxGridWindow* gridWindow);
|
||||
@@ -2989,6 +2991,8 @@ private:
|
||||
void DoStartResizeRowOrCol(int col);
|
||||
void DoStartMoveCol(int col);
|
||||
|
||||
// These functions should only be called when actually resizing/moving,
|
||||
// i.e. m_dragRowOrCol and m_dragMoveCol, respectively, are valid.
|
||||
void DoEndDragResizeRow(const wxMouseEvent& event, wxGridWindow *gridWindow);
|
||||
void DoEndDragResizeCol(const wxMouseEvent& event, wxGridWindow *gridWindow);
|
||||
void DoEndMoveCol(int pos);
|
||||
|
@@ -4707,11 +4707,13 @@ bool wxGrid::DoGridDragEvent(wxMouseEvent& event,
|
||||
return DoGridCellDrag(event, coords, isFirstDrag);
|
||||
|
||||
case WXGRID_CURSOR_RESIZE_ROW:
|
||||
DoGridDragResize(event.GetPosition(), wxGridRowOperations(), gridWindow);
|
||||
if ( m_dragRowOrCol != -1 )
|
||||
DoGridDragResize(event.GetPosition(), wxGridRowOperations(), gridWindow);
|
||||
break;
|
||||
|
||||
case WXGRID_CURSOR_RESIZE_COL:
|
||||
DoGridDragResize(event.GetPosition(), wxGridColumnOperations(), gridWindow);
|
||||
if ( m_dragRowOrCol != -1 )
|
||||
DoGridDragResize(event.GetPosition(), wxGridColumnOperations(), gridWindow);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -4864,12 +4866,14 @@ wxGrid::DoGridCellLeftUp(wxMouseEvent& event,
|
||||
else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW )
|
||||
{
|
||||
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
|
||||
DoEndDragResizeRow(event, gridWindow);
|
||||
if ( m_dragRowOrCol != -1 )
|
||||
DoEndDragResizeRow(event, gridWindow);
|
||||
}
|
||||
else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_COL )
|
||||
{
|
||||
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
|
||||
DoEndDragResizeCol(event, gridWindow);
|
||||
if ( m_dragRowOrCol != -1 )
|
||||
DoEndDragResizeCol(event, gridWindow);
|
||||
}
|
||||
|
||||
m_dragLastPos = -1;
|
||||
@@ -5047,6 +5051,9 @@ void wxGrid::DoGridDragResize(const wxPoint& position,
|
||||
const wxGridOperations& oper,
|
||||
wxGridWindow* gridWindow)
|
||||
{
|
||||
wxCHECK_RET( m_dragRowOrCol != -1,
|
||||
"shouldn't be called when not drag resizing" );
|
||||
|
||||
// Get the logical position from the physical one we're passed.
|
||||
const wxPoint
|
||||
logicalPos = CalcGridWindowUnscrolledPosition(position, gridWindow);
|
||||
|
Reference in New Issue
Block a user