KiCad PCB EDA Suite
Loading...
Searching...
No Matches
wx_grid.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-2023 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 3
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 KICAD_WX_GRID_H
25#define KICAD_WX_GRID_H
26
27#include <memory>
28#include <vector>
29#include <memory>
30#include <bitset>
31#include <wx/event.h>
32#include <wx/grid.h>
33#include <wx/version.h>
34#include <units_provider.h>
36
37class wxTextEntryBase;
38
39
40class WX_GRID_TABLE_BASE : public wxGridTableBase
41{
42protected:
43 wxGridCellAttr* enhanceAttr( wxGridCellAttr* aInputAttr, int aRow, int aCol,
44 wxGridCellAttr::wxAttrKind aKind );
45};
46
47
48class WX_GRID : public wxGrid
49{
50public:
51 // Constructor has to be wxFormBuilder-compatible
52 WX_GRID( wxWindow *parent, wxWindowID id,
53 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
54 long style = wxWANTS_CHARS, const wxString& name = wxGridNameStr );
55
56 ~WX_GRID() override;
57
63 void SetColLabelSize( int aHeight ); // Yes, we're hiding a non-virtual method
64
69 void SetLabelFont( const wxFont& aFont ); // Yes, we're hiding a non-virtual method
70
77 void EnableAlternateRowColors( bool aEnable = true );
78
83 wxString GetShownColumnsAsString();
84 std::bitset<64> GetShownColumns();
85
89 void ShowHideColumns( const wxString& shownColumns );
90
94 void ShowHideColumns( const std::bitset<64>& aShownColumns );
95
100 void SetTable( wxGridTableBase* table, bool aTakeOwnership = false );
101
106 void DestroyTable( wxGridTableBase* aTable );
107
113 bool CommitPendingChanges( bool aQuietMode = false );
115
120 void SetUnitsProvider( UNITS_PROVIDER* aProvider, int aCol = 0 );
121
122 void SetAutoEvalCols( const std::vector<int>& aCols ) { m_autoEvalCols = aCols; }
123
128 int GetUnitValue( int aRow, int aCol );
129
133 void SetUnitValue( int aRow, int aCol, int aValue );
134
144 int GetVisibleWidth( int aCol, bool aHeader = true, bool aContents = true, bool aKeep = false );
145
151
158 void ShowEditorOnMouseUp() { m_waitForSlowClick = true; }
159
166 {
167 if( GetNumberRows() )
168 DeleteRows( 0, GetNumberRows() );
169 }
170
174 static void CellEditorSetMargins( wxTextEntryBase* aEntry );
175
179 static void CellEditorTransformSizeRect( wxRect& aRect );
180
181protected:
186 void DrawColLabel( wxDC& dc, int col ) override;
187
191 void DrawRowLabel( wxDC& dc, int row ) override;
192
196 void DrawCornerLabel( wxDC& dc ) override;
197
198 void onGridColMove( wxGridEvent& aEvent );
199 void onGridCellSelect( wxGridEvent& aEvent );
200 void onCellEditorShown( wxGridEvent& aEvent );
201 void onCellEditorHidden( wxGridEvent& aEvent );
202
203 void onDPIChanged(wxDPIChangedEvent& event);
204
205protected:
207
208 std::map<int, UNITS_PROVIDER*> m_unitsProviders;
209 std::unique_ptr<NUMERIC_EVALUATOR> m_eval;
210 std::vector<int> m_autoEvalCols;
211
212 std::map< std::pair<int, int>, std::pair<wxString, wxString> > m_evalBeforeAfter;
213};
214
215#endif //KICAD_WX_GRID_H
const char * name
Definition: DXF_plotter.cpp:57
wxGridCellAttr * enhanceAttr(wxGridCellAttr *aInputAttr, int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind)
Definition: wx_grid.cpp:42
int GetVisibleWidth(int aCol, bool aHeader=true, bool aContents=true, bool aKeep=false)
Calculates the specified column based on the actual size of the text on screen.
Definition: wx_grid.cpp:687
void onGridCellSelect(wxGridEvent &aEvent)
Definition: wx_grid.cpp:317
~WX_GRID() override
Definition: wx_grid.cpp:222
void SetLabelFont(const wxFont &aFont)
Hide wxGrid's SetLabelFont() because for some reason on MSW it's a one-shot and subsequent calls to i...
Definition: wx_grid.cpp:257
bool m_weOwnTable
Definition: wx_grid.h:206
void onDPIChanged(wxDPIChangedEvent &event)
Definition: wx_grid.cpp:233
void ShowHideColumns(const wxString &shownColumns)
Show/hide the grid columns based on a tokenized string of shown column indexes.
Definition: wx_grid.cpp:440
std::map< int, UNITS_PROVIDER * > m_unitsProviders
Definition: wx_grid.h:208
void SetTable(wxGridTableBase *table, bool aTakeOwnership=false)
Hide wxGrid's SetTable() method with one which doesn't mess up the grid column widths when setting th...
Definition: wx_grid.cpp:263
void DestroyTable(wxGridTableBase *aTable)
Work-around for a bug in wxGrid which crashes when deleting the table if the cell edit control was no...
Definition: wx_grid.cpp:396
bool CancelPendingChanges()
Definition: wx_grid.cpp:562
void SetColLabelSize(int aHeight)
Hide wxGrid's SetColLabelSize() method with one which makes sure the size is tall enough for the syst...
Definition: wx_grid.cpp:243
void SetUnitValue(int aRow, int aCol, int aValue)
Set a unitized cell's value.
Definition: wx_grid.cpp:669
int GetUnitValue(int aRow, int aCol)
Apply standard KiCad unit and eval services to a numeric cell.
Definition: wx_grid.cpp:648
std::vector< int > m_autoEvalCols
Definition: wx_grid.h:210
std::map< std::pair< int, int >, std::pair< wxString, wxString > > m_evalBeforeAfter
Definition: wx_grid.h:212
void DrawCornerLabel(wxDC &dc) override
A re-implementation of wxGrid::DrawCornerLabel which draws flat borders.
Definition: wx_grid.cpp:470
void onCellEditorHidden(wxGridEvent &aEvent)
Definition: wx_grid.cpp:359
void ShowEditorOnMouseUp()
WxWidgets has a bunch of bugs in its handling of wxGrid mouse events which close cell editors right a...
Definition: wx_grid.h:158
void onGridColMove(wxGridEvent &aEvent)
Definition: wx_grid.cpp:680
void onCellEditorShown(wxGridEvent &aEvent)
Definition: wx_grid.cpp:344
void EnsureColLabelsVisible()
Ensure the height of the row displaying the column labels is enough, even if labels are multiline tex...
Definition: wx_grid.cpp:727
wxString GetShownColumnsAsString()
Get a tokenized string containing the shown column indexes.
Definition: wx_grid.cpp:410
void DrawRowLabel(wxDC &dc, int row) override
A re-implementation of wxGrid::DrawRowLabel which draws flat borders.
Definition: wx_grid.cpp:530
std::bitset< 64 > GetShownColumns()
Definition: wx_grid.cpp:429
static void CellEditorSetMargins(wxTextEntryBase *aEntry)
A helper function to set OS-specific margins for text-based cell editors.
Definition: wx_grid.cpp:74
void SetAutoEvalCols(const std::vector< int > &aCols)
Definition: wx_grid.h:122
void EnableAlternateRowColors(bool aEnable=true)
Enable alternate row highlighting, where every odd row has a different background color than the even...
Definition: wx_grid.cpp:298
void SetUnitsProvider(UNITS_PROVIDER *aProvider, int aCol=0)
Set a UNITS_PROVIDER to enable use of unit- and eval-based Getters.
Definition: wx_grid.cpp:639
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
Definition: wx_grid.h:165
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:590
std::unique_ptr< NUMERIC_EVALUATOR > m_eval
Definition: wx_grid.h:209
void DrawColLabel(wxDC &dc, int col) override
A re-implementation of wxGrid::DrawColLabel which left-aligns the first column and draws flat borders...
Definition: wx_grid.cpp:491
static void CellEditorTransformSizeRect(wxRect &aRect)
A helper function to tweak sizes of text-based cell editors depending on OS.
Definition: wx_grid.cpp:81