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, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef GRID_ICON_TEXT_HELPERS_H
21#define GRID_ICON_TEXT_HELPERS_H
22
23#include <wx/bitmap.h>
24#include <wx/bmpcbox.h>
25#include <wx/generic/gridctrl.h>
26#include <wx/generic/grideditors.h>
27#include <vector>
28#include <kicommon.h>
29
30class wxGrid;
31enum class BITMAPS : unsigned int;
32
33
34//---- Grid helpers: custom wxGridCellRenderer that renders icon and a label ------------
35
36class KICOMMON_API GRID_CELL_ICON_TEXT_RENDERER : public wxGridCellStringRenderer
37{
38public:
44 GRID_CELL_ICON_TEXT_RENDERER( const std::vector<BITMAPS>& icons, const wxArrayString& names );
45
50 GRID_CELL_ICON_TEXT_RENDERER( const wxBitmapBundle& aIcon,
51 wxSize aPreferredIconSize = wxDefaultSize );
52
53 void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC,
54 const wxRect& aRect, int aRow, int aCol, bool isSelected ) override;
55 wxSize GetBestSize( wxGrid & grid, wxGridCellAttr & attr, wxDC & dc, int row,
56 int col ) override;
57
58private:
59 std::vector<BITMAPS> m_icons;
60 wxArrayString m_names;
61
62 // For single-icon mode
63 wxBitmapBundle m_icon;
64 wxSize m_iconSize;
65};
66
67//---- Grid helpers: custom wxGridCellRenderer that renders just an icon ----------------
68//
69// Note: use with read only cells
70
71class KICOMMON_API GRID_CELL_ICON_RENDERER : public wxGridCellRenderer
72{
73public:
74 GRID_CELL_ICON_RENDERER( const wxBitmapBundle& aIcon );
75
76 void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC,
77 const wxRect& aRect, int aRow, int aCol, bool isSelected ) override;
78 wxSize GetBestSize( wxGrid & grid, wxGridCellAttr & attr, wxDC & dc, int row,
79 int col ) override;
80 wxGridCellRenderer* Clone() const override;
81
82private:
83 wxBitmapBundle m_icon;
84};
85
86//---- Grid helpers: custom wxGridCellRenderer that renders just an icon from wxArtprovider -
87//
88// Note: use with read only cells
89
90class KICOMMON_API GRID_CELL_STATUS_ICON_RENDERER : public wxGridCellRenderer
91{
92public:
93 GRID_CELL_STATUS_ICON_RENDERER( int aStatus );
94
95 void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC,
96 const wxRect& aRect, int aRow, int aCol, bool isSelected ) override;
97 wxSize GetBestSize( wxGrid & grid, wxGridCellAttr & attr, wxDC & dc, int row,
98 int col ) override;
99 wxGridCellRenderer* Clone() const override;
100
101private:
103 wxBitmapBundle m_bitmap;
104};
105
106
107
108//---- Grid helpers: custom wxGridCellEditor ------------------------------------------
109//
110// Note: this implementation is an adaptation of wxGridCellChoiceEditor
111
112class KICOMMON_API GRID_CELL_ICON_TEXT_POPUP : public wxGridCellEditor
113{
114public:
115 GRID_CELL_ICON_TEXT_POPUP( const std::vector<BITMAPS>& icons, const wxArrayString& names );
116
117 wxGridCellEditor* Clone() const override;
118 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
119
120 wxString GetValue() const override;
121
122 void SetSize( const wxRect& aRect ) override;
123
124 void BeginEdit( int aRow, int aCol, wxGrid* aGrid ) override;
125 bool EndEdit( int , int , const wxGrid* , const wxString& , wxString *aNewVal ) override;
126 void ApplyEdit( int aRow, int aCol, wxGrid* aGrid ) override;
127 void Reset() override;
128
129protected:
130 wxBitmapComboBox* Combo() const { return static_cast<wxBitmapComboBox*>( m_control ); }
131
132 std::vector<BITMAPS> m_icons;
133 wxArrayString m_names;
134 wxString m_value;
135
137};
138
139
140#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
wxSize GetBestSize(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col) override
GRID_CELL_ICON_RENDERER(const wxBitmapBundle &aIcon)
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
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:27