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
51 GRID_CELL_ICON_TEXT_RENDERER( const wxBitmapBundle& aIcon,
52 wxSize aPreferredIconSize = wxDefaultSize );
53
54 void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC,
55 const wxRect& aRect, int aRow, int aCol, bool isSelected ) override;
56 wxSize GetBestSize( wxGrid & grid, wxGridCellAttr & attr, wxDC & dc, int row,
57 int col ) override;
58
59private:
60 std::vector<BITMAPS> m_icons;
61 wxArrayString m_names;
62
63 // For single-icon mode
64 wxBitmapBundle m_icon;
65 wxSize m_iconSize;
66};
67
68//---- Grid helpers: custom wxGridCellRenderer that renders just an icon ----------------
69//
70// Note: use with read only cells
71
72class KICOMMON_API GRID_CELL_ICON_RENDERER : public wxGridCellRenderer
73{
74public:
75 GRID_CELL_ICON_RENDERER( const wxBitmapBundle& aIcon );
76
77 void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC,
78 const wxRect& aRect, int aRow, int aCol, bool isSelected ) override;
79 wxSize GetBestSize( wxGrid & grid, wxGridCellAttr & attr, wxDC & dc, int row,
80 int col ) override;
81 wxGridCellRenderer* Clone() const override;
82
83private:
84 wxBitmapBundle m_icon;
85};
86
87//---- Grid helpers: custom wxGridCellRenderer that renders just an icon from wxArtprovider -
88//
89// Note: use with read only cells
90
91class KICOMMON_API GRID_CELL_STATUS_ICON_RENDERER : public wxGridCellRenderer
92{
93public:
94 GRID_CELL_STATUS_ICON_RENDERER( int aStatus );
95
96 void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC,
97 const wxRect& aRect, int aRow, int aCol, bool isSelected ) override;
98 wxSize GetBestSize( wxGrid & grid, wxGridCellAttr & attr, wxDC & dc, int row,
99 int col ) override;
100 wxGridCellRenderer* Clone() const override;
101
102private:
104 wxBitmapBundle m_bitmap;
105};
106
107
108
109//---- Grid helpers: custom wxGridCellEditor ------------------------------------------
110//
111// Note: this implementation is an adaptation of wxGridCellChoiceEditor
112
113class KICOMMON_API GRID_CELL_ICON_TEXT_POPUP : public wxGridCellEditor
114{
115public:
116 GRID_CELL_ICON_TEXT_POPUP( const std::vector<BITMAPS>& icons, const wxArrayString& names );
117
118 wxGridCellEditor* Clone() const override;
119 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
120
121 wxString GetValue() const override;
122
123 void SetSize( const wxRect& aRect ) override;
124
125 void BeginEdit( int aRow, int aCol, wxGrid* aGrid ) override;
126 bool EndEdit( int , int , const wxGrid* , const wxString& , wxString *aNewVal ) override;
127 void ApplyEdit( int aRow, int aCol, wxGrid* aGrid ) override;
128 void Reset() override;
129
130protected:
131 wxBitmapComboBox* Combo() const { return static_cast<wxBitmapComboBox*>( m_control ); }
132
133 std::vector<BITMAPS> m_icons;
134 wxArrayString m_names;
135 wxString m_value;
136
138};
139
140
141#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