KiCad PCB EDA Suite
Loading...
Searching...
No Matches
grid_text_helpers.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 * @author Jon Evans <[email protected]>
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#pragma once
22
23#include <functional>
24#include <memory>
25#include <wx/generic/gridctrl.h>
26
27class wxGrid;
28class wxStyledTextCtrl;
29class wxStyledTextEvent;
31
32
37class GRID_CELL_TEXT_EDITOR : public wxGridCellTextEditor
38{
39public:
41
42 void SetSize( const wxRect& aRect ) override;
43
44 virtual void SetValidator( const wxValidator& validator ) override;
45 virtual void StartingKey( wxKeyEvent& event ) override;
46
47protected:
48 std::unique_ptr<wxValidator> m_validator;
49};
50
51
56class GRID_CELL_TEXT_RENDERER : public wxGridCellStringRenderer
57{
58public:
60
61 void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC, const wxRect& aRect, int aRow,
62 int aCol, bool isSelected ) override;
63
64 wxSize GetBestSize( wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, int row, int col ) override;
65};
66
67
72class GRID_CELL_ESCAPED_TEXT_RENDERER : public wxGridCellStringRenderer
73{
74public:
76
77 void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC, const wxRect& aRect, int aRow,
78 int aCol, bool isSelected ) override;
79
80 wxSize GetBestSize( wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, int row, int col ) override;
81};
82
83
84class GRID_CELL_STC_EDITOR : public wxGridCellEditor
85{
86public:
87 GRID_CELL_STC_EDITOR( bool aIgnoreCase, bool aSingleLine,
88 std::function<void( wxStyledTextEvent&, SCINTILLA_TRICKS* )> onCharFn );
89
90 void SetSize( const wxRect& aRect ) override;
91 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
92
93 wxGridCellEditor* Clone() const override
94 {
96 }
97
98 wxString GetValue() const override;
99
100 void StartingKey( wxKeyEvent& event ) override;
101 void Show( bool aShow, wxGridCellAttr *aAttr = nullptr ) override;
102 void BeginEdit( int aRow, int aCol, wxGrid* aGrid ) override;
103 bool EndEdit( int aRow, int aCol, const wxGrid*, const wxString&, wxString* aNewVal ) override;
104 void ApplyEdit( int aRow, int aCol, wxGrid* aGrid ) override;
105 void Reset() override {}
106
107protected:
108 void onFocusLoss( wxFocusEvent& aEvent );
109
110 wxStyledTextCtrl* stc_ctrl() const;
111
112protected:
116 wxString m_value;
117
118 std::function<void( wxStyledTextEvent&, SCINTILLA_TRICKS* )> m_onCharFn;
119};
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
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
wxGridCellEditor * Clone() 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
wxSize GetBestSize(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col) override
Add cut/copy/paste, dark theme, autocomplete and brace highlighting to a wxStyleTextCtrl instance.