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 <kicommon.h>
24#include <functional>
25#include <memory>
26#include <wx/generic/gridctrl.h>
27#include <wx/combo.h>
28
29class wxGrid;
30class wxStyledTextCtrl;
31class wxStyledTextEvent;
33
34
39class KICOMMON_API GRID_CELL_TEXT_EDITOR : public wxGridCellTextEditor
40{
41public:
43
44 void SetSize( const wxRect& aRect ) override;
45
46 virtual void SetValidator( const wxValidator& validator ) override;
47 virtual void StartingKey( wxKeyEvent& event ) override;
48
49protected:
50 std::unique_ptr<wxValidator> m_validator;
51};
52
53
58class KICOMMON_API GRID_CELL_TEXT_RENDERER : public wxGridCellStringRenderer
59{
60public:
62
63 void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC, const wxRect& aRect, int aRow,
64 int aCol, bool isSelected ) override;
65
66 wxSize GetBestSize( wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, int row, int col ) override;
67};
68
69
74class KICOMMON_API GRID_CELL_ESCAPED_TEXT_RENDERER : public wxGridCellStringRenderer
75{
76public:
78
79 void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC, const wxRect& aRect, int aRow,
80 int aCol, bool isSelected ) override;
81
82 wxSize GetBestSize( wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, int row, int col ) override;
83};
84
85
86class KICOMMON_API GRID_CELL_STC_EDITOR : public wxGridCellEditor
87{
88public:
89 GRID_CELL_STC_EDITOR( bool aIgnoreCase, bool aSingleLine,
90 std::function<void( wxStyledTextEvent&, SCINTILLA_TRICKS* )> onCharFn );
91
92 void SetSize( const wxRect& aRect ) override;
93 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
94
95 wxGridCellEditor* Clone() const override
96 {
98 }
99
100 wxString GetValue() const override;
101
102 void StartingKey( wxKeyEvent& event ) override;
103 void Show( bool aShow, wxGridCellAttr *aAttr = nullptr ) override;
104 void BeginEdit( int aRow, int aCol, wxGrid* aGrid ) override;
105 bool EndEdit( int aRow, int aCol, const wxGrid*, const wxString&, wxString* aNewVal ) override;
106 void ApplyEdit( int aRow, int aCol, wxGrid* aGrid ) override;
107 void Reset() override {}
108
109protected:
110 void onFocusLoss( wxFocusEvent& aEvent );
111
112 wxStyledTextCtrl* stc_ctrl() const;
113
114protected:
118 wxString m_value;
119
120 std::function<void( wxStyledTextEvent&, SCINTILLA_TRICKS* )> m_onCharFn;
121};
122
123
124class KICOMMON_API GRID_CELL_TEXT_BUTTON : public wxGridCellEditor
125{
126public:
128
129 wxString GetValue() const override;
130
131 void SetSize( const wxRect& aRect ) override;
132
133 void StartingKey( wxKeyEvent& event ) override;
134 void BeginEdit( int aRow, int aCol, wxGrid* aGrid ) override;
135 bool EndEdit( int , int , const wxGrid* , const wxString& , wxString *aNewVal ) override;
136 void ApplyEdit( int aRow, int aCol, wxGrid* aGrid ) override;
137 void Reset() override;
138
139#if wxUSE_VALIDATORS
140 void SetValidator( const wxValidator& validator );
141#endif
142
143protected:
144 wxComboCtrl* Combo() const { return static_cast<wxComboCtrl*>( m_control ); }
145
146#if wxUSE_VALIDATORS
147 std::unique_ptr< wxValidator > m_validator;
148#endif
149
150 wxString m_value;
151
153};
154
155
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
std::function< void(wxStyledTextEvent &, SCINTILLA_TRICKS *)> m_onCharFn
GRID_CELL_STC_EDITOR(bool aIgnoreCase, bool aSingleLine, std::function< void(wxStyledTextEvent &, SCINTILLA_TRICKS *)> onCharFn)
wxGridCellEditor * Clone() const override
void Create(wxWindow *aParent, wxWindowID aId, wxEvtHandler *aEventHandler) override
SCINTILLA_TRICKS * m_scintillaTricks
wxDECLARE_NO_COPY_CLASS(GRID_CELL_TEXT_BUTTON)
wxComboCtrl * Combo() const
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.
void Reset() override
#define KICOMMON_API
Definition kicommon.h:28