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