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
33class wxGrid;
34enum class BITMAPS : unsigned int;
35
36
37//---- Grid helpers: custom wxGridCellRenderer that renders icon and a label ------------
38
39class GRID_CELL_ICON_TEXT_RENDERER : public wxGridCellStringRenderer
40{
41public:
47 GRID_CELL_ICON_TEXT_RENDERER( const std::vector<BITMAPS>& icons, const wxArrayString& names );
48
53 GRID_CELL_ICON_TEXT_RENDERER( const wxBitmapBundle& aIcon,
54 wxSize aPreferredIconSize = wxDefaultSize );
55
56 void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC,
57 const wxRect& aRect, int aRow, int aCol, bool isSelected ) override;
58 wxSize GetBestSize( wxGrid & grid, wxGridCellAttr & attr, wxDC & dc, int row,
59 int col ) override;
60
61private:
62 std::vector<BITMAPS> m_icons;
63 wxArrayString m_names;
64
65 // For single-icon mode
66 wxBitmapBundle m_icon;
67 wxSize m_iconSize;
68};
69
70//---- Grid helpers: custom wxGridCellRenderer that renders just an icon ----------------
71//
72// Note: use with read only cells
73
74class GRID_CELL_ICON_RENDERER : public wxGridCellRenderer
75{
76public:
77 GRID_CELL_ICON_RENDERER( const wxBitmap& icon );
78
79 void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC,
80 const wxRect& aRect, int aRow, int aCol, bool isSelected ) override;
81 wxSize GetBestSize( wxGrid & grid, wxGridCellAttr & attr, wxDC & dc, int row,
82 int col ) override;
83 wxGridCellRenderer* Clone() const override;
84
85private:
86 const wxBitmap& m_icon;
87};
88
89//---- Grid helpers: custom wxGridCellRenderer that renders just an icon from wxArtprovider -
90//
91// Note: use with read only cells
92
93class GRID_CELL_STATUS_ICON_RENDERER : public wxGridCellRenderer
94{
95public:
96 GRID_CELL_STATUS_ICON_RENDERER( int aStatus );
97
98 void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC,
99 const wxRect& aRect, int aRow, int aCol, bool isSelected ) override;
100 wxSize GetBestSize( wxGrid & grid, wxGridCellAttr & attr, wxDC & dc, int row,
101 int col ) override;
102 wxGridCellRenderer* Clone() const override;
103
104private:
106 wxBitmap m_bitmap;
107};
108
109
110
111//---- Grid helpers: custom wxGridCellEditor ------------------------------------------
112//
113// Note: this implementation is an adaptation of wxGridCellChoiceEditor
114
115class GRID_CELL_ICON_TEXT_POPUP : public wxGridCellEditor
116{
117public:
118 GRID_CELL_ICON_TEXT_POPUP( const std::vector<BITMAPS>& icons, const wxArrayString& names );
119
120 wxGridCellEditor* Clone() const override;
121 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
122
123 wxString GetValue() const override;
124
125 void SetSize( const wxRect& aRect ) override;
126
127 void BeginEdit( int aRow, int aCol, wxGrid* aGrid ) override;
128 bool EndEdit( int , int , const wxGrid* , const wxString& , wxString *aNewVal ) override;
129 void ApplyEdit( int aRow, int aCol, wxGrid* aGrid ) override;
130 void Reset() override;
131
132protected:
133 wxBitmapComboBox* Combo() const { return static_cast<wxBitmapComboBox*>( m_control ); }
134
135 std::vector<BITMAPS> m_icons;
136 wxArrayString m_names;
137 wxString m_value;
138
140};
141
142
143//---- Grid helpers: custom wxGridCellTextEditor ------------------------------------------
144//
145// Note: This is used to mark WX_GRID cell as nullable
146class GRID_CELL_MARK_AS_NULLABLE : public wxGridCellTextEditor
147{
148public:
150 GRID_CELL_MARK_AS_NULLABLE( bool aIsNullable ) : m_isNullable( aIsNullable ) {}
151
152 wxGridCellEditor* Clone() const override
153 {
155 }
156
157 void Reset() override {}
158
159 bool IsNullable() { return m_isNullable; }
160
161protected:
163
165};
166
167
168#endif // GRID_ICON_TEXT_HELPERS_H
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
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
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)
std::vector< BITMAPS > m_icons
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
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
wxGridCellEditor * Clone() const override
wxDECLARE_NO_COPY_CLASS(GRID_CELL_MARK_AS_NULLABLE)
GRID_CELL_MARK_AS_NULLABLE(bool aIsNullable)
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