22#include <wx/stc/stc.h>
41 m_validator.reset(
static_cast<wxValidator*
>( validator.Clone() ) );
55 if( event.GetSkipped() )
57 wxGridCellTextEditor::StartingKey( event );
68#if defined( __WXMSW__ )
70#elif defined( __WXMAC__ )
72 rect.SetHeight( rect.GetHeight() - 4 );
75 wxGridCellEditor::SetSize( rect );
83 wxGridCellStringRenderer()
88 int aRow,
int aCol,
bool isSelected )
92 if( !
table || !
table->IsExpanderColumn( aCol ) )
93 return wxGridCellStringRenderer::Draw( aGrid, aAttr, aDC, aRect, aRow, aCol, isSelected );
95 wxString value = aGrid.GetCellValue( aRow, aCol );
101 wxGridCellRenderer::Draw( aGrid, aAttr, aDC, aRect, aRow, aCol, isSelected );
104 int leftCut = aDC.FromDIP( 4 );
113 wxBitmap bitmap =
static_cast<WX_GRID&
>( aGrid ).GetRowIconProvider()->GetIndicatorIcon( state );
116 aDC.DrawBitmap( bitmap,
117 rect.GetLeft() + leftCut,
118 rect.GetTop() + ( rect.GetHeight() - bitmap.GetLogicalHeight() ) / 2,
121 leftCut += bitmap.GetLogicalWidth();
123 leftCut += aDC.FromDIP( 4 );
126 leftCut += aDC.FromDIP( 12 );
129 rect.width -= leftCut;
132 SetTextColoursAndFont( aGrid, aAttr, aDC, isSelected );
133 aGrid.DrawTextRectangle( aDC, value, rect, wxALIGN_LEFT, wxALIGN_CENTRE );
141 if( !
table || !
table->IsExpanderColumn( col ) )
142 return wxGridCellStringRenderer::GetBestSize(
grid, attr, dc, row, col );
145 wxBitmap bitmap =
static_cast<WX_GRID&
>(
grid ).GetRowIconProvider()->GetIndicatorIcon( state );
149 wxString
text =
grid.GetCellValue( row, col );
150 wxSize size = wxGridCellStringRenderer::DoGetBestSize( attr, dc,
text );
152 size.x += bitmap.GetLogicalWidth() + dc.FromDIP( 8 );
155 size.x += dc.FromDIP( 12 );
157 size.y = std::max( size.y, dc.FromDIP( 2 ) );
167 wxGridCellStringRenderer()
171 int aRow,
int aCol,
bool isSelected )
173 wxString unescaped =
UnescapeString( aGrid.GetCellValue( aRow, aCol ) );
179 wxGridCellRenderer::Draw( aGrid, aAttr, aDC, aRect, aRow, aCol, isSelected );
181 SetTextColoursAndFont( aGrid, aAttr, aDC, isSelected );
182 aGrid.DrawTextRectangle( aDC, unescaped, rect, wxALIGN_LEFT, wxALIGN_CENTRE );
189 wxString unescaped =
UnescapeString( aGrid.GetCellValue( aRow, aCol ) );
190 return wxGridCellStringRenderer::DoGetBestSize( aAttr, aDC, unescaped );
208 wxRect rect( aRect );
211#if defined( __WXMSW__ )
212#if !wxCHECK_VERSION( 3, 3, 0 )
213 rect.Offset( -1, 0 );
215 rect.SetHeight( rect.GetHeight() + 6 );
219#elif defined( __WXGTK__ )
220 rect.Offset( -1, 3 );
223 rect.SetWidth( rect.GetWidth() - 1 );
224 rect.SetHeight( rect.GetHeight() - 4 );
226 wxGridCellEditor::SetSize( rect );
232 m_control =
new wxStyledTextCtrl( aParent, wxID_ANY, wxDefaultPosition, wxSize( 0, 0 ),
236 stc_ctrl()->SetBackSpaceUnIndents(
false );
238 stc_ctrl()->SetViewWhiteSpace(
false );
239 stc_ctrl()->SetIndentationGuides(
false );
242 stc_ctrl()->SetEOLMode( wxSTC_EOL_LF );
243 stc_ctrl()->AutoCompSetMaxWidth( 25 );
250 stc_ctrl()->SetScrollWidthTracking(
true );
256 [
this]( wxKeyEvent& aEvent )
258 HandleReturn( aEvent );
262 [
this]( wxStyledTextEvent& aEvent )
269 wxGridCellEditor::Create( aParent, aId, aEventHandler );
275 return static_cast<wxStyledTextCtrl*
>( m_control );
292 ch =
event.GetUnicodeKey();
299 ch =
event.GetKeyCode();
300 isPrintable = ch >= WXK_SPACE && ch < WXK_START;
317 stc_ctrl()->WriteText(
static_cast<wxChar
>( ch ) );
328 wxGridCellEditor::Show( aShow, aAttr );
334 auto evtHandler =
static_cast<wxGridCellEditorEvtHandler*
>( m_control->GetEventHandler() );
337 evtHandler->SetInSetFocus(
true );
339 m_value = aGrid->GetTable()->GetValue( aRow, aCol );
349 const wxString value =
stc_ctrl()->GetText();
365 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
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
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
void Draw(wxGrid &aGrid, wxGridCellAttr &aAttr, wxDC &aDC, const wxRect &aRect, int aRow, int aCol, bool isSelected) override
GRID_CELL_TEXT_RENDERER()
wxSize GetBestSize(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col) override
int ICON_ID
An id that refers to a certain icon state.
@ CLOSED
Tree control closed.
@ OFF
Row "off" or "deselected".
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)