Auto-start text entry for Scintilla grid cells.

This commit is contained in:
Jeff Young 2024-03-11 14:13:26 +00:00
parent 73f94175de
commit 85d0126187
3 changed files with 42 additions and 2 deletions

View File

@ -29,7 +29,7 @@
#include <wx/clipbrd.h>
#include <wx/log.h>
#include <wx/stc/stc.h>
#include <widgets/grid_readonly_text_helpers.h>
#include <widgets/grid_text_helpers.h>
// 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<wxTextEntry*>( editor ) );
bool retval = ( dynamic_cast<wxTextEntry*>( editor )
|| dynamic_cast<GRID_CELL_STC_EDITOR*>( editor ) );
editor->DecRef();
return retval;

View File

@ -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<wxChar>( ch ) );
break;
}
}
void GRID_CELL_STC_EDITOR::Show( bool aShow, wxGridCellAttr* aAttr )
{
if( !aShow )

View File

@ -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;