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 (C) 2020-2023 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#ifndef KICAD_GRID_TEXT_HELPERS_H
22#define KICAD_GRID_TEXT_HELPERS_H
23
24#include <functional>
25#include <memory>
26#include <wx/generic/gridctrl.h>
27
28class wxGrid;
29class wxStyledTextCtrl;
30class wxStyledTextEvent;
32
33
38class GRID_CELL_TEXT_EDITOR : public wxGridCellTextEditor
39{
40public:
42
43 void SetSize( const wxRect& aRect ) override;
44
45 virtual void SetValidator( const wxValidator& validator ) override;
46 virtual void StartingKey( wxKeyEvent& event ) override;
47
48protected:
49 std::unique_ptr<wxValidator> m_validator;
50};
51
52
57class GRID_CELL_ESCAPED_TEXT_RENDERER : public wxGridCellStringRenderer
58{
59public:
61
62 void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC, const wxRect& aRect, int aRow,
63 int aCol, bool isSelected ) override;
64
65 wxSize GetBestSize( wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, int row, int col ) override;
66};
67
68
69class GRID_CELL_STC_EDITOR : public wxGridCellEditor
70{
71public:
72 GRID_CELL_STC_EDITOR( bool aIgnoreCase,
73 std::function<void( wxStyledTextEvent&, SCINTILLA_TRICKS* )> onCharFn );
74
75 void SetSize( const wxRect& aRect ) override;
76 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
77
78 wxGridCellEditor* Clone() const override
79 {
81 }
82
83 wxString GetValue() const override;
84
85 void StartingKey( wxKeyEvent& event ) override;
86 void Show( bool aShow, wxGridCellAttr *aAttr = nullptr ) override;
87 void BeginEdit( int aRow, int aCol, wxGrid* aGrid ) override;
88 bool EndEdit( int aRow, int aCol, const wxGrid*, const wxString&, wxString* aNewVal ) override;
89 void ApplyEdit( int aRow, int aCol, wxGrid* aGrid ) override;
90 void Reset() override {}
91
92protected:
93 void onFocusLoss( wxFocusEvent& aEvent );
94
95 wxStyledTextCtrl* stc_ctrl() const;
96
97protected:
100 wxString m_value;
101
102 std::function<void( wxStyledTextEvent&, SCINTILLA_TRICKS* )> m_onCharFn;
103};
104
105
106#endif // KICAD_GRID_TEXT_HELPERS_H
A text renderer that can unescape text for display This is useful where it's desired to keep the unde...
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
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
void Reset() override
This class works around a bug in wxGrid where the first keystroke doesn't get sent through the valida...
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.