22#include <wx/stc/stc.h>
40 m_validator.reset(
static_cast<wxValidator*
>( validator.Clone() ) );
54 if( event.GetSkipped() )
56 wxGridCellTextEditor::StartingKey( event );
67#if defined( __WXMSW__ )
71 wxGridCellEditor::SetSize( rect );
79 wxGridCellStringRenderer()
84 const wxRect& aRect,
int aRow,
int aCol,
87 wxString unescaped =
UnescapeString( aGrid.GetCellValue( aRow, aCol ) );
93 wxGridCellRenderer::Draw( aGrid, aAttr, aDC, aRect, aRow, aCol, isSelected );
95 SetTextColoursAndFont( aGrid, aAttr, aDC, isSelected );
96 aGrid.DrawTextRectangle( aDC, unescaped, rect, wxALIGN_LEFT, wxALIGN_CENTRE );
101 wxDC & aDC,
int aRow,
int aCol )
103 wxString unescaped =
UnescapeString( aGrid.GetCellValue( aRow, aCol ) );
104 return wxGridCellStringRenderer::DoGetBestSize( aAttr, aDC, unescaped );
114 m_scintillaTricks( nullptr ),
115 m_ignoreCase( aIgnoreCase ),
116 m_onCharFn(
std::
move( onCharFn ) )
122 wxRect rect( aRect );
125#if defined( __WXMSW__ )
126 rect.Offset( -1, 1 );
127#elif defined( __WXGTK__ )
128 rect.Offset( -1, 3 );
131 wxGridCellEditor::SetSize( rect );
137 m_control =
new wxStyledTextCtrl( aParent, wxID_ANY, wxDefaultPosition, wxSize( 0, 0 ),
141 stc_ctrl()->SetBackSpaceUnIndents(
false );
143 stc_ctrl()->SetViewWhiteSpace(
false );
144 stc_ctrl()->SetIndentationGuides(
false );
147 stc_ctrl()->SetEOLMode( wxSTC_EOL_LF );
148 stc_ctrl()->AutoCompSetMaxWidth( 25 );
155 stc_ctrl()->SetScrollWidthTracking(
true );
161 [
this]( wxKeyEvent& aEvent )
163 HandleReturn( aEvent );
167 [
this]( wxStyledTextEvent& aEvent )
174 wxGridCellEditor::Create( aParent, aId, aEventHandler );
180 return static_cast<wxStyledTextCtrl*
>( m_control );
197 ch =
event.GetUnicodeKey();
204 ch =
event.GetKeyCode();
205 isPrintable = ch >= WXK_SPACE && ch < WXK_START;
222 stc_ctrl()->WriteText(
static_cast<wxChar
>( ch ) );
233 wxGridCellEditor::Show( aShow, aAttr );
239 auto evtHandler =
static_cast<wxGridCellEditorEvtHandler*
>( m_control->GetEventHandler() );
242 evtHandler->SetInSetFocus(
true );
244 m_value = aGrid->GetTable()->GetValue( aRow, aCol );
254 const wxString value =
stc_ctrl()->GetText();
270 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)