Fix problems due to deleting grid cells in the event handlers
Deleting last grid rows or column in a few event handlers could result in asserts/crashes in wxGrid code if the event handler also called event.Skip(), as wxGrid still tried to perform the default action using the deleted cell, when these events happened in the last row or column. It's not totally clear whether calling event.Skip() after performing an action modifying the grid should be allowed at all, but, in doubt, at least avoid crashing if it does happen, by considering the event as being handled (and even vetoed) if its handler deleted the cell in which it was generated. Closes #18731.
This commit is contained in:
parent
5cdcfddc61
commit
e6e6dbe077
@ -2553,8 +2553,10 @@ protected:
|
|||||||
bool Redimension( wxGridTableMessage& );
|
bool Redimension( wxGridTableMessage& );
|
||||||
|
|
||||||
|
|
||||||
// Send the given grid event and return -1 if it was vetoed, 1 if
|
// Send the given grid event and return -1 if it was vetoed or, as a
|
||||||
// it was processed (but not vetoed) and 0 if it wasn't processed.
|
// special exception, if an event for a particular cell resulted in this
|
||||||
|
// cell being deleted, 1 if it was processed (but not vetoed) and 0 if it
|
||||||
|
// wasn't processed.
|
||||||
int DoSendEvent(wxGridEvent& gridEvt);
|
int DoSendEvent(wxGridEvent& gridEvt);
|
||||||
|
|
||||||
// Generate an event of the given type and call DoSendEvent().
|
// Generate an event of the given type and call DoSendEvent().
|
||||||
|
@ -5294,7 +5294,7 @@ wxGrid::SendGridSizeEvent(wxEventType type,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process the event and return
|
// Process the event and return
|
||||||
// -1 if the event was vetoed
|
// -1 if the event was vetoed or if event cell was deleted
|
||||||
// +1 if the event was processed (but not vetoed)
|
// +1 if the event was processed (but not vetoed)
|
||||||
// 0 if the event wasn't handled
|
// 0 if the event wasn't handled
|
||||||
int wxGrid::DoSendEvent(wxGridEvent& gridEvt)
|
int wxGrid::DoSendEvent(wxGridEvent& gridEvt)
|
||||||
@ -5305,6 +5305,14 @@ int wxGrid::DoSendEvent(wxGridEvent& gridEvt)
|
|||||||
if ( !gridEvt.IsAllowed() )
|
if ( !gridEvt.IsAllowed() )
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
// We also return -1 if the event cell was deleted, as this allows to have
|
||||||
|
// checks in several functions that generate an event and then proceed
|
||||||
|
// doing something by default with the selected cell: this shouldn't be
|
||||||
|
// done if the user-defined handler deleted this cell.
|
||||||
|
if ( gridEvt.GetRow() >= GetNumberRows() ||
|
||||||
|
gridEvt.GetCol() >= GetNumberCols() )
|
||||||
|
return -1;
|
||||||
|
|
||||||
return claimed ? 1 : 0;
|
return claimed ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user