diff --git a/common/grid_tricks.cpp b/common/grid_tricks.cpp index b0a848b2bc..0ce6399d62 100644 --- a/common/grid_tricks.cpp +++ b/common/grid_tricks.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include // It works for table data on clipboard for an Excel spreadsheet, @@ -91,7 +91,8 @@ void GRID_TRICKS::init() bool GRID_TRICKS::isTextEntry( int aRow, int aCol ) { wxGridCellEditor* editor = m_grid->GetCellEditor( aRow, aCol ); - bool retval = ( dynamic_cast( editor ) ); + bool retval = ( dynamic_cast( editor ) + || dynamic_cast( editor ) ); editor->DecRef(); return retval; diff --git a/common/widgets/grid_text_helpers.cpp b/common/widgets/grid_text_helpers.cpp index ba94fdc268..d7963e98e5 100644 --- a/common/widgets/grid_text_helpers.cpp +++ b/common/widgets/grid_text_helpers.cpp @@ -121,6 +121,44 @@ wxString GRID_CELL_STC_EDITOR::GetValue() const } +void GRID_CELL_STC_EDITOR::StartingKey( wxKeyEvent& event ) +{ + int ch; + + bool isPrintable; + +#if wxUSE_UNICODE + ch = event.GetUnicodeKey(); + + if( ch != WXK_NONE ) + isPrintable = true; + else +#endif // wxUSE_UNICODE + { + ch = event.GetKeyCode(); + isPrintable = ch >= WXK_SPACE && ch < WXK_START; + } + + switch( ch ) + { + case WXK_DELETE: + // Delete the initial character when starting to edit with DELETE. + stc_ctrl()->DeleteRange( 0, 1 ); + break; + + case WXK_BACK: + // Delete the last character when starting to edit with BACKSPACE. + stc_ctrl()->DeleteBack(); + break; + + default: + if( isPrintable ) + stc_ctrl()->WriteText( static_cast( ch ) ); + break; + } +} + + void GRID_CELL_STC_EDITOR::Show( bool aShow, wxGridCellAttr* aAttr ) { if( !aShow ) diff --git a/include/widgets/grid_text_helpers.h b/include/widgets/grid_text_helpers.h index 491650b3d0..cd4edb2311 100644 --- a/include/widgets/grid_text_helpers.h +++ b/include/widgets/grid_text_helpers.h @@ -60,6 +60,7 @@ public: wxString GetValue() const override; + void StartingKey( wxKeyEvent& event ) override; void Show( bool aShow, wxGridCellAttr *aAttr = nullptr ) override; void BeginEdit( int aRow, int aCol, wxGrid* aGrid ) override; bool EndEdit( int aRow, int aCol, const wxGrid*, const wxString&, wxString* aNewVal ) override;