diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index c81e3fc9dd..3bf340e0ba 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -2482,6 +2482,10 @@ private: void SetNativeHeaderColCount(); void SetNativeHeaderColOrder(); + // Unlike the public SaveEditControlValue(), this method doesn't check if + // the edit control is shown, but just supposes that it is. + void DoSaveEditControlValue(); + // these sets contain the indices of fixed, i.e. non-resizable // interactively, grid rows or columns and are NULL if there are no fixed // elements (which is the default) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 3b2b8cfbe7..f554f09411 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -6858,10 +6858,14 @@ void wxGrid::EnableCellEditControl( bool enable ) SendEvent(wxEVT_GRID_EDITOR_HIDDEN); HideCellEditControl(); - SaveEditControlValue(); - // do it after HideCellEditControl() - m_cellEditCtrlEnabled = enable; + // do it after HideCellEditControl() but before invoking + // user-defined handlers invoked by DoSaveEditControlValue() to + // ensure that we don't enter infinite loop if any of them try to + // disable the edit control again. + m_cellEditCtrlEnabled = false; + + DoSaveEditControlValue(); } } } @@ -7115,36 +7119,41 @@ void wxGrid::SaveEditControlValue() { if ( IsCellEditControlEnabled() ) { - int row = m_currentCellCoords.GetRow(); - int col = m_currentCellCoords.GetCol(); - - wxString oldval = GetCellValue(row, col); - - wxGridCellAttr* attr = GetCellAttr(row, col); - wxGridCellEditor* editor = attr->GetEditor(this, row, col); - - wxString newval; - bool changed = editor->EndEdit(row, col, this, oldval, &newval); - - if ( changed && SendEvent(wxEVT_GRID_CELL_CHANGING, newval) != -1 ) - { - editor->ApplyEdit(row, col, this); - - // for compatibility reasons dating back to wx 2.8 when this event - // was called wxEVT_GRID_CELL_CHANGE and wxEVT_GRID_CELL_CHANGING - // didn't exist we allow vetoing this one too - if ( SendEvent(wxEVT_GRID_CELL_CHANGED, oldval) == -1 ) - { - // Event has been vetoed, set the data back. - SetCellValue(row, col, oldval); - } - } - - editor->DecRef(); - attr->DecRef(); + DoSaveEditControlValue(); } } +void wxGrid::DoSaveEditControlValue() +{ + int row = m_currentCellCoords.GetRow(); + int col = m_currentCellCoords.GetCol(); + + wxString oldval = GetCellValue(row, col); + + wxGridCellAttr* attr = GetCellAttr(row, col); + wxGridCellEditor* editor = attr->GetEditor(this, row, col); + + wxString newval; + bool changed = editor->EndEdit(row, col, this, oldval, &newval); + + if ( changed && SendEvent(wxEVT_GRID_CELL_CHANGING, newval) != -1 ) + { + editor->ApplyEdit(row, col, this); + + // for compatibility reasons dating back to wx 2.8 when this event + // was called wxEVT_GRID_CELL_CHANGE and wxEVT_GRID_CELL_CHANGING + // didn't exist we allow vetoing this one too + if ( SendEvent(wxEVT_GRID_CELL_CHANGED, oldval) == -1 ) + { + // Event has been vetoed, set the data back. + SetCellValue(row, col, oldval); + } + } + + editor->DecRef(); + attr->DecRef(); +} + void wxGrid::OnHideEditor(wxCommandEvent& WXUNUSED(event)) { DisableCellEditControl();