KiCad PCB EDA Suite
grid_color_swatch_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_COLOR_SWATCH_HELPERS
25 #define GRID_COLOR_SWATCH_HELPERS
26 
27 #include <wx/generic/gridctrl.h>
28 #include <wx/generic/grideditors.h>
29 #include <gal/color4d.h>
30 #include <widgets/color_swatch.h>
31 
32 
33 class wxGrid;
34 
35 //-------- Custom wxGridCellRenderers --------------------------------------------------
36 
37 class GRID_CELL_COLOR_RENDERER : public wxGridCellRenderer
38 {
39 public:
40  GRID_CELL_COLOR_RENDERER( wxWindow* aParent = nullptr, SWATCH_SIZE aSize = SWATCH_EXPAND,
41  const KIGFX::COLOR4D& aBackground = KIGFX::COLOR4D::UNSPECIFIED );
43  ~GRID_CELL_COLOR_RENDERER() override;
44 
45  wxGridCellRenderer* Clone() const override;
46  wxSize GetBestSize( wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, int row, int col ) override;
47 
48  void Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDC, const wxRect& aRect, int aRow,
49  int aCol, bool isSelected ) override;
50 
51 private:
52  wxWindow* m_parent;
53 
55 
56  wxSize m_size;
57 
59 
61 };
62 
63 
64 //-------- Custom wxGridCellEditors ----------------------------------------------------
65 //
66 // Note: this implementation is an adaptation of wxGridCellChoiceEditor
67 
68 class GRID_CELL_COLOR_SELECTOR : public wxGridCellEditor
69 {
70 public:
71  GRID_CELL_COLOR_SELECTOR( wxWindow* aParent, wxGrid* aGrid );
72 
73  wxGridCellEditor* Clone() const override;
74  void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
75 
76  wxString GetValue() const override;
77 
78  void BeginEdit( int aRow, int aCol, wxGrid* aGrid ) override;
79  bool EndEdit( int , int , const wxGrid* , const wxString& , wxString *newval ) override;
80  void ApplyEdit( int aRow, int aCol, wxGrid* aGrid ) override;
81  void Reset() override;
82 
83 protected:
84  wxWindow* m_parent;
85  wxGrid* m_grid;
87 
89 };
90 
91 #endif // GRID_COLOR_SWATCH_HELPERS
wxSize GetBestSize(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col) override
wxGridCellEditor * Clone() const override
wxString GetValue() const override
wxDECLARE_NO_COPY_CLASS(GRID_CELL_COLOR_SELECTOR)
void Draw(wxGrid &aGrid, wxGridCellAttr &aAttr, wxDC &aDC, const wxRect &aRect, int aRow, int aCol, bool isSelected) override
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition: color4d.h:372
GRID_CELL_COLOR_SELECTOR(wxWindow *aParent, wxGrid *aGrid)
void BeginEdit(int aRow, int aCol, wxGrid *aGrid) override
GRID_CELL_COLOR_RENDERER(wxWindow *aParent=nullptr, SWATCH_SIZE aSize=SWATCH_EXPAND, const KIGFX::COLOR4D &aBackground=KIGFX::COLOR4D::UNSPECIFIED)
wxGridCellRenderer * Clone() const override
void Create(wxWindow *aParent, wxWindowID aId, wxEvtHandler *aEventHandler) override
bool EndEdit(int, int, const wxGrid *, const wxString &, wxString *newval) override
void ApplyEdit(int aRow, int aCol, wxGrid *aGrid) override
SWATCH_SIZE
Definition: color_swatch.h:34
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99