From 3a874471c37bcd8b8f15719b7f8c3d3cb4df9b92 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 27 Jun 2020 16:57:40 +0200 Subject: [PATCH] Add helper AcceptCellEditControlIfShown() function This is just another refactoring in order to avoid duplicating calls to HideCellEditControl() and SaveEditControlValue() in several different places. Also call DoSaveEditControlValue() because if the editor is shown, it is also necessarily enabled and there is no need to check for this. --- include/wx/generic/grid.h | 4 ++++ src/generic/grid.cpp | 37 ++++++++++++++----------------------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index f258b202ec..1d47ea384f 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -2908,6 +2908,10 @@ private: ); } + // Accept the changes in the edit control, if it's currently shown, and + // dismiss it. + void AcceptCellEditControlIfShown(); + // Unlike the public SaveEditControlValue(), this method doesn't check if // the edit control is shown, but just supposes that it is. void DoSaveEditControlValue(); diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 1ad1bde99c..206ffcab4a 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -3966,11 +3966,7 @@ void wxGrid::DoStartResizeRowOrCol(int col) { // Hide the editor if it's currently shown to avoid any weird interactions // with it while dragging the row/column separator. - if ( IsCellEditControlShown() ) - { - HideCellEditControl(); - SaveEditControlValue(); - } + AcceptCellEditControlIfShown(); m_dragRowOrCol = col; } @@ -4481,11 +4477,7 @@ wxGrid::DoGridCellDrag(wxMouseEvent& event, if ( isFirstDrag ) { // Hide the edit control, so it won't interfere with drag-shrinking. - if ( IsCellEditControlShown() ) - { - HideCellEditControl(); - SaveEditControlValue(); - } + AcceptCellEditControlIfShown(); switch ( event.GetModifiers() ) { @@ -7419,6 +7411,15 @@ void wxGrid::HideCellEditControl() } } +void wxGrid::AcceptCellEditControlIfShown() +{ + if ( IsCellEditControlShown() ) + { + HideCellEditControl(); + DoSaveEditControlValue(); + } +} + void wxGrid::SaveEditControlValue() { if ( IsCellEditControlEnabled() ) @@ -9951,9 +9952,7 @@ wxGrid::AutoSizeColOrRow(int colOrRow, bool setAsMin, wxGridDirection direction) wxClientDC dc(m_gridWin); - // cancel editing of cell - HideCellEditControl(); - SaveEditControlValue(); + AcceptCellEditControlIfShown(); // initialize both of them just to avoid compiler warnings even if only // really needs to be initialized here @@ -10272,11 +10271,7 @@ void wxGrid::AutoSizeRowLabelSize( int row ) { // Hide the edit control, so it // won't interfere with drag-shrinking. - if ( IsCellEditControlShown() ) - { - HideCellEditControl(); - SaveEditControlValue(); - } + AcceptCellEditControlIfShown(); // autosize row height depending on label text SetRowSize(row, -1); @@ -10288,11 +10283,7 @@ void wxGrid::AutoSizeColLabelSize( int col ) { // Hide the edit control, so it // won't interfere with drag-shrinking. - if ( IsCellEditControlShown() ) - { - HideCellEditControl(); - SaveEditControlValue(); - } + AcceptCellEditControlIfShown(); // autosize column width depending on label text SetColSize(col, -1);