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__ )
69#elif defined( __WXMAC__ )
71 rect.SetHeight( rect.GetHeight() - 4 );
74 wxGridCellEditor::SetSize( rect );
82 wxGridCellStringRenderer()
87 const wxRect& aRect,
int aRow,
int aCol,
90 wxString unescaped =
UnescapeString( aGrid.GetCellValue( aRow, aCol ) );
96 wxGridCellRenderer::Draw( aGrid, aAttr, aDC, aRect, aRow, aCol, isSelected );
98 SetTextColoursAndFont( aGrid, aAttr, aDC, isSelected );
99 aGrid.DrawTextRectangle( aDC, unescaped, rect, wxALIGN_LEFT, wxALIGN_CENTRE );
104 wxDC & aDC,
int aRow,
int aCol )
106 wxString unescaped =
UnescapeString( aGrid.GetCellValue( aRow, aCol ) );
107 return wxGridCellStringRenderer::DoGetBestSize( aAttr, aDC, unescaped );
117 m_scintillaTricks( nullptr ),
118 m_ignoreCase( aIgnoreCase ),
119 m_onCharFn(
std::
move( onCharFn ) )
125 wxRect rect( aRect );
128#if defined( __WXMSW__ )
129 rect.Offset( -1, 1 );
130#elif defined( __WXGTK__ )
131 rect.Offset( -1, 3 );
134 rect.SetHeight( rect.GetHeight() - 6 );
137 wxGridCellEditor::SetSize( rect );
143 m_control =
new wxStyledTextCtrl( aParent, wxID_ANY, wxDefaultPosition, wxSize( 0, 0 ),
147 stc_ctrl()->SetBackSpaceUnIndents(
false );
149 stc_ctrl()->SetViewWhiteSpace(
false );
150 stc_ctrl()->SetIndentationGuides(
false );
153 stc_ctrl()->SetEOLMode( wxSTC_EOL_LF );
154 stc_ctrl()->AutoCompSetMaxWidth( 25 );
161 stc_ctrl()->SetScrollWidthTracking(
true );
167 [
this]( wxKeyEvent& aEvent )
169 HandleReturn( aEvent );
173 [
this]( wxStyledTextEvent& aEvent )
180 wxGridCellEditor::Create( aParent, aId, aEventHandler );
186 return static_cast<wxStyledTextCtrl*
>( m_control );
203 ch =
event.GetUnicodeKey();
210 ch =
event.GetKeyCode();
211 isPrintable = ch >= WXK_SPACE && ch < WXK_START;
228 stc_ctrl()->WriteText(
static_cast<wxChar
>( ch ) );
239 wxGridCellEditor::Show( aShow, aAttr );
245 auto evtHandler =
static_cast<wxGridCellEditorEvtHandler*
>( m_control->GetEventHandler() );
248 evtHandler->SetInSetFocus(
true );
250 m_value = aGrid->GetTable()->GetValue( aRow, aCol );
260 const wxString value =
stc_ctrl()->GetText();
276 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)