22#include <wx/stc/stc.h>
53 if( event.GetSkipped() )
55 wxGridCellTextEditor::StartingKey( event );
66#if defined( __WXMSW__ )
68#elif defined( __WXMAC__ )
70 rect.SetHeight( rect.GetHeight() - 4 );
73 wxGridCellEditor::SetSize( rect );
81 wxGridCellStringRenderer()
85 int aRow,
int aCol,
bool isSelected )
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 );
103 wxString unescaped =
UnescapeString( aGrid.GetCellValue( aRow, aCol ) );
104 return wxGridCellStringRenderer::DoGetBestSize( aAttr, aDC, unescaped );
122 wxRect rect( aRect );
125#if defined( __WXMSW__ )
126#if !wxCHECK_VERSION( 3, 3, 0 )
127 rect.Offset( -1, 0 );
129 rect.SetHeight( rect.GetHeight() + 6 );
133#elif defined( __WXGTK__ )
134 rect.Offset( -1, 3 );
137 rect.SetWidth( rect.GetWidth() - 1 );
138 rect.SetHeight( rect.GetHeight() - 4 );
140 wxGridCellEditor::SetSize( rect );
146 m_control =
new wxStyledTextCtrl( aParent, wxID_ANY, wxDefaultPosition, wxSize( 0, 0 ),
150 stc_ctrl()->SetBackSpaceUnIndents(
false );
152 stc_ctrl()->SetViewWhiteSpace(
false );
153 stc_ctrl()->SetIndentationGuides(
false );
156 stc_ctrl()->SetEOLMode( wxSTC_EOL_LF );
161 stc_ctrl()->SetWrapMode( wxSTC_WRAP_WORD );
162 stc_ctrl()->SetWrapVisualFlags( wxSTC_WRAPVISUALFLAG_END );
163 stc_ctrl()->SetWrapIndentMode( wxSTC_WRAPINDENT_INDENT );
166 stc_ctrl()->AutoCompSetMaxWidth( 25 );
173 stc_ctrl()->SetScrollWidthTracking(
true );
179 [
this]( wxKeyEvent& aEvent )
181 HandleReturn( aEvent );
185 [
this]( wxStyledTextEvent& aEvent )
192 wxGridCellEditor::Create( aParent, aId, aEventHandler );
198 return static_cast<wxStyledTextCtrl*
>( m_control );
215 ch =
event.GetUnicodeKey();
222 ch =
event.GetKeyCode();
223 isPrintable = ch >= WXK_SPACE && ch < WXK_START;
240 stc_ctrl()->WriteText(
static_cast<wxChar
>( ch ) );
251 wxGridCellEditor::Show( aShow, aAttr );
257 auto evtHandler =
static_cast<wxGridCellEditorEvtHandler*
>( m_control->GetEventHandler() );
260 evtHandler->SetInSetFocus(
true );
262 m_value = aGrid->GetTable()->GetValue( aRow, aCol );
272 const wxString value =
stc_ctrl()->GetText();
288 aGrid->GetTable()->SetValue( aRow, aCol,
m_value );
311 return Combo()->GetValue();
317 wxRect rect( aRect );
320 wxGridCellEditor::SetSize( rect );
334 wxTextEntry* textEntry =
static_cast<wxTextEntry*
>(
Combo() );
340 ch =
event.GetUnicodeKey();
347 ch =
event.GetKeyCode();
348 isPrintable = ch >= WXK_SPACE && ch < WXK_START;
355 textEntry->Remove( 0, 1 );
361 const long pos = textEntry->GetLastPosition();
362 textEntry->Remove( pos - 1, pos );
368 textEntry->WriteText(
static_cast<wxChar
>( ch ) );
381 auto evtHandler =
static_cast< wxGridCellEditorEvtHandler*
>( m_control->GetEventHandler() );
384 evtHandler->SetInSetFocus(
true );
386 m_value = aGrid->GetTable()->GetValue( aRow, aCol );
402 m_grid->GetEventHandler()->ProcessEvent( evt );
416 const wxString value =
Combo()->GetValue();
432 aGrid->GetTable()->SetValue( aRow, aCol,
m_value );
443void GRID_CELL_TEXT_BUTTON::SetValidator(
const wxValidator&
validator )
445 m_validator.reset(
static_cast< wxValidator*
>(
validator.Clone() ) );
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
void onFocusLoss(wxFocusEvent &aEvent)
void StartingKey(wxKeyEvent &event) override
std::function< void(wxStyledTextEvent &, SCINTILLA_TRICKS *)> m_onCharFn
GRID_CELL_STC_EDITOR(bool aIgnoreCase, bool aSingleLine, std::function< void(wxStyledTextEvent &, SCINTILLA_TRICKS *)> 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
wxString GetValue() const override
wxComboCtrl * Combo() const
void StartingKey(wxKeyEvent &event) override
void BeginEdit(int aRow, int aCol, wxGrid *aGrid) override
bool EndEdit(int, int, const wxGrid *, const wxString &, wxString *aNewVal) override
void ApplyEdit(int aRow, int aCol, wxGrid *aGrid) override
void SetSize(const wxRect &aRect) override
void OnTextChange(wxCommandEvent &event)
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)
JSON_SCHEMA_VALIDATOR validator(schema)