Auto-start text entry for Scintilla grid cells.
This commit is contained in:
parent
73f94175de
commit
85d0126187
|
@ -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;
|
||||
|
|
|
@ -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 )
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue