22#include <wx/stc/stc.h>
39 m_validator.reset(
static_cast<wxValidator*
>( validator.Clone() ) );
53 if( event.GetSkipped() )
55 wxGridCellTextEditor::StartingKey( event );
66#if defined( __WXMSW__ )
70 wxGridCellEditor::SetSize( rect );
78 wxGridCellStringRenderer()
83 const wxRect& aRect,
int aRow,
int aCol,
86 wxString unescaped =
UnescapeString( aGrid.GetCellValue( aRow, aCol ) );
92 wxGridCellRenderer::Draw( aGrid, aAttr, aDC, aRect, aRow, aCol, isSelected );
94 SetTextColoursAndFont( aGrid, aAttr, aDC, isSelected );
95 aGrid.DrawTextRectangle( aDC, unescaped, rect, wxALIGN_LEFT, wxALIGN_CENTRE );
100 wxDC & aDC,
int aRow,
int aCol )
102 wxString unescaped =
UnescapeString( aGrid.GetCellValue( aRow, aCol ) );
103 return wxGridCellStringRenderer::DoGetBestSize( aAttr, aDC, unescaped );
113 m_scintillaTricks( nullptr ),
114 m_ignoreCase( aIgnoreCase ),
115 m_onCharFn(
std::
move( onCharFn ) )
121 wxRect rect( aRect );
124#if defined( __WXMSW__ )
125 rect.Offset( -1, 1 );
126#elif defined( __WXGTK__ )
127 rect.Offset( -1, 3 );
130 wxGridCellEditor::SetSize( rect );
136 m_control =
new wxStyledTextCtrl( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
140 stc_ctrl()->SetBackSpaceUnIndents(
false );
142 stc_ctrl()->SetViewWhiteSpace(
false );
143 stc_ctrl()->SetIndentationGuides(
false );
146 stc_ctrl()->SetEOLMode( wxSTC_EOL_LF );
147 stc_ctrl()->AutoCompSetMaxWidth( 25 );
154 stc_ctrl()->SetScrollWidthTracking(
true );
159 [
this]( wxKeyEvent& aEvent )
161 HandleReturn( aEvent );
164 [
this]( wxStyledTextEvent& aEvent )
171 wxGridCellEditor::Create( aParent, aId, aEventHandler );
177 return static_cast<wxStyledTextCtrl*
>( m_control );
194 ch =
event.GetUnicodeKey();
201 ch =
event.GetKeyCode();
202 isPrintable = ch >= WXK_SPACE && ch < WXK_START;
219 stc_ctrl()->WriteText(
static_cast<wxChar
>( ch ) );
230 wxGridCellEditor::Show( aShow, aAttr );
236 auto evtHandler =
static_cast<wxGridCellEditorEvtHandler*
>( m_control->GetEventHandler()
240 evtHandler->SetInSetFocus(
true );
242 m_value = aGrid->GetTable()->GetValue( aRow, aCol );
252 const wxString value =
stc_ctrl()->GetText();
268 aGrid->GetTable()->SetValue( aRow, aCol,
m_value );
wxSize GetBestSize(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col) override
void Draw(wxGrid &aGrid, wxGridCellAttr &aAttr, wxDC &aDC, const wxRect &aRect, int aRow, int aCol, bool isSelected) override
GRID_CELL_ESCAPED_TEXT_RENDERER()
void SetSize(const wxRect &aRect) override
void ApplyEdit(int aRow, int aCol, wxGrid *aGrid) override
GRID_CELL_STC_EDITOR(bool aIgnoreCase, std::function< void(wxStyledTextEvent &, SCINTILLA_TRICKS *)> onCharFn)
void onFocusLoss(wxFocusEvent &aEvent)
void StartingKey(wxKeyEvent &event) override
std::function< void(wxStyledTextEvent &, SCINTILLA_TRICKS *)> m_onCharFn
bool EndEdit(int aRow, int aCol, const wxGrid *, const wxString &, wxString *aNewVal) override
void BeginEdit(int aRow, int aCol, wxGrid *aGrid) override
wxString GetValue() const override
void Create(wxWindow *aParent, wxWindowID aId, wxEvtHandler *aEventHandler) override
void Show(bool aShow, wxGridCellAttr *aAttr=nullptr) override
wxStyledTextCtrl * stc_ctrl() const
SCINTILLA_TRICKS * m_scintillaTricks
std::unique_ptr< wxValidator > m_validator
void SetSize(const wxRect &aRect) override
virtual void StartingKey(wxKeyEvent &event) override
virtual void SetValidator(const wxValidator &validator) override
Add cut/copy/paste, dark theme, autocomplete and brace highlighting to a wxStyleTextCtrl instance.
static void CellEditorTransformSizeRect(wxRect &aRect)
A helper function to tweak sizes of text-based cell editors depending on OS.
wxString UnescapeString(const wxString &aSource)