KiCad PCB EDA Suite
Loading...
Searching...
No Matches
grid_icon_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 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#ifndef GRID_ICON_TEXT_HELPERS_H
25#define GRID_ICON_TEXT_HELPERS_H
26
27#include <wx/bitmap.h>
28#include <wx/bmpcbox.h>
29#include <wx/generic/gridctrl.h>
30#include <wx/generic/grideditors.h>
31#include <vector>
32#include <kicommon.h>
33
34class wxGrid;
35enum class BITMAPS : unsigned int;
36
37
38//---- Grid helpers: custom wxGridCellRenderer that renders icon and a label ------------
39
40class KICOMMON_API GRID_CELL_ICON_TEXT_RENDERER : public wxGridCellStringRenderer
41{
42public:
48 GRID_CELL_ICON_TEXT_RENDERER( const std::vector<BITMAPS>& icons, const wxArrayString& names );
49
54 GRID_CELL_ICON_TEXT_RENDERER( const wxBitmapBundle& aIcon,
55 wxSize aPreferredIconSize = wxDefaultSize );
56
57 void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC,
58 const wxRect& aRect, int aRow, int aCol, bool isSelected ) override;
59 wxSize GetBestSize( wxGrid & grid, wxGridCellAttr & attr, wxDC & dc, int row,
60 int col ) override;
61
62private:
63 std::vector<BITMAPS> m_icons;
64 wxArrayString m_names;
65
66 // For single-icon mode
67 wxBitmapBundle m_icon;
68 wxSize m_iconSize;
69};
70
71//---- Grid helpers: custom wxGridCellRenderer that renders just an icon ----------------
72//
73// Note: use with read only cells
74
75class KICOMMON_API GRID_CELL_ICON_RENDERER : public wxGridCellRenderer
76{
77public:
78 GRID_CELL_ICON_RENDERER( const wxBitmap& icon );
79
80 void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC,
81 const wxRect& aRect, int aRow, int aCol, bool isSelected ) override;
82 wxSize GetBestSize( wxGrid & grid, wxGridCellAttr & attr, wxDC & dc, int row,
83 int col ) override;
84 wxGridCellRenderer* Clone() const override;
85
86private:
87 const wxBitmap& m_icon;
88};
89
90//---- Grid helpers: custom wxGridCellRenderer that renders just an icon from wxArtprovider -
91//
92// Note: use with read only cells
93
94class KICOMMON_API GRID_CELL_STATUS_ICON_RENDERER : public wxGridCellRenderer
95{
96public:
97 GRID_CELL_STATUS_ICON_RENDERER( int aStatus );
98
99 void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC,
100 const wxRect& aRect, int aRow, int aCol, bool isSelected ) override;
101 wxSize GetBestSize( wxGrid & grid, wxGridCellAttr & attr, wxDC & dc, int row,
102 int col ) override;
103 wxGridCellRenderer* Clone() const override;
104
105private:
107 wxBitmap m_bitmap;
108};
109
110
111
112//---- Grid helpers: custom wxGridCellEditor ------------------------------------------
113//
114// Note: this implementation is an adaptation of wxGridCellChoiceEditor
115
116class KICOMMON_API GRID_CELL_ICON_TEXT_POPUP : public wxGridCellEditor
117{
118public:
119 GRID_CELL_ICON_TEXT_POPUP( const std::vector<BITMAPS>& icons, const wxArrayString& names );
120
121 wxGridCellEditor* Clone() const override;
122 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
123
124 wxString GetValue() const override;
125
126 void SetSize( const wxRect& aRect ) override;
127
128 void BeginEdit( int aRow, int aCol, wxGrid* aGrid ) override;
129 bool EndEdit( int , int , const wxGrid* , const wxString& , wxString *aNewVal ) override;
130 void ApplyEdit( int aRow, int aCol, wxGrid* aGrid ) override;
131 void Reset() override;
132
133protected:
134 wxBitmapComboBox* Combo() const { return static_cast<wxBitmapComboBox*>( m_control ); }
135
136 std::vector<BITMAPS> m_icons;
137 wxArrayString m_names;
138 wxString m_value;
139
141};
142
143
145{
146public:
148 m_isNullable( true )
149 {
150 }
151 GRID_CELL_NULLABLE_INTERFACE( bool aIsNullable ) :
152 m_isNullable( aIsNullable )
153 {
154 }
155 virtual ~GRID_CELL_NULLABLE_INTERFACE() = default;
156
157 virtual bool IsNullable() const { return m_isNullable; }
158
159protected:
160 bool m_isNullable{ false };
161};
162
163
164//---- Grid helpers: custom wxGridCellTextEditor ------------------------------------------
165//
166// Note: This is used to mark WX_GRID cell as nullable
167class GRID_CELL_MARK_AS_NULLABLE : public wxGridCellTextEditor, public GRID_CELL_NULLABLE_INTERFACE
168{
169public:
174 GRID_CELL_MARK_AS_NULLABLE( const bool aIsNullable ) :
175 GRID_CELL_NULLABLE_INTERFACE( aIsNullable )
176 {
177 }
178
179 wxGridCellEditor* Clone() const override { return new GRID_CELL_MARK_AS_NULLABLE( IsNullable() ); }
180
181 void Reset() override {}
182
183
185};
186
187
188#endif // GRID_ICON_TEXT_HELPERS_H
BITMAPS
A list of all bitmap identifiers.
wxGridCellRenderer * Clone() const override
void Draw(wxGrid &aGrid, wxGridCellAttr &aAttr, wxDC &aDC, const wxRect &aRect, int aRow, int aCol, bool isSelected) override
GRID_CELL_ICON_RENDERER(const wxBitmap &icon)
wxSize GetBestSize(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col) override
wxString GetValue() const override
wxBitmapComboBox * Combo() const
wxGridCellEditor * Clone() const override
void BeginEdit(int aRow, int aCol, wxGrid *aGrid) override
wxDECLARE_NO_COPY_CLASS(GRID_CELL_ICON_TEXT_POPUP)
void Create(wxWindow *aParent, wxWindowID aId, wxEvtHandler *aEventHandler) 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
GRID_CELL_ICON_TEXT_POPUP(const std::vector< BITMAPS > &icons, const wxArrayString &names)
void Draw(wxGrid &aGrid, wxGridCellAttr &aAttr, wxDC &aDC, const wxRect &aRect, int aRow, int aCol, bool isSelected) override
GRID_CELL_ICON_TEXT_RENDERER(const std::vector< BITMAPS > &icons, const wxArrayString &names)
Construct a renderer that maps a list of icons from the bitmap system to a list of strings.
wxSize GetBestSize(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col) override
wxGridCellEditor * Clone() const override
GRID_CELL_MARK_AS_NULLABLE(const bool aIsNullable)
wxDECLARE_NO_COPY_CLASS(GRID_CELL_MARK_AS_NULLABLE)
virtual ~GRID_CELL_NULLABLE_INTERFACE()=default
wxSize GetBestSize(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col) override
wxGridCellRenderer * Clone() const override
void Draw(wxGrid &aGrid, wxGridCellAttr &aAttr, wxDC &aDC, const wxRect &aRect, int aRow, int aCol, bool isSelected) override
void Reset() override
#define KICOMMON_API
Definition kicommon.h:28