-
-
Notifications
You must be signed in to change notification settings - Fork 497
/
Copy pathlistboxes.h
234 lines (190 loc) · 7.62 KB
/
listboxes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef LISTBOXES_H
#define LISTBOXES_H
#include <wx/listctrl.h>
#include <footprint_filter.h>
#include <memory>
/* Forward declarations of all top-level window classes. */
class CVPCB_MAINFRAME;
class COMPONENT;
class FOOTPRINT_LIST;
#define LISTBOX_STYLE ( wxBORDER_NONE | wxLC_NO_HEADER | wxLC_REPORT | wxLC_VIRTUAL | \
wxVSCROLL | wxHSCROLL )
/**
* Base class to display symbol and footprint lists.
*/
class ITEMS_LISTBOX_BASE : public wxListView
{
public:
ITEMS_LISTBOX_BASE( CVPCB_MAINFRAME* aParent, wxWindowID aId,
const wxPoint& aLocation = wxDefaultPosition,
const wxSize& aSize = wxDefaultSize, long aStyle = 0 );
~ITEMS_LISTBOX_BASE();
/**
* @return the index of the selected item in lists allowing only one item selected
* and the index of the first selected item in lists allowing many selection
*/
int GetSelection();
/**
* Remove all selection in lists which can have more than one item selected.
*/
void DeselectAll();
virtual CVPCB_MAINFRAME* GetParent() const;
/**
* Update the width of the column based on its contents.
*
* @param aLine is the line to calculate the width from. If positive, the
* width will only be increased if needed. If negative, we start from
* scratch and all lines are considered, i.e., the column may be shrunk.
*/
void UpdateWidth( int aLine = -1 );
private:
/**
* Calculate the width of the given line, and increase the column width
* if needed. This is effectively the wxListCtrl code for autosizing.
* NB. it relies on the caller checking the given line number is valid.
*/
void UpdateLineWidth( unsigned aLine, wxClientDC& dc );
int columnWidth;
};
class FOOTPRINTS_LISTBOX : public ITEMS_LISTBOX_BASE
{
public:
/**
* Filter setting constants. The filter type is a bitwise OR of these flags,
* and only footprints matching all selected filter types are shown.
*/
enum FP_FILTER_T: int
{
UNFILTERED_FP_LIST = 0,
FILTERING_BY_COMPONENT_FP_FILTERS = 0x0001,
FILTERING_BY_PIN_COUNT = 0x0002,
FILTERING_BY_LIBRARY = 0x0004
};
FOOTPRINTS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id );
~FOOTPRINTS_LISTBOX() override {};
int GetCount();
void SetSelection( int aIndex, bool aState = true );
void SetSelectedFootprint( const LIB_ID& aFPID );
void SetString( unsigned linecount, const wxString& text );
/**
* Populate the wxListCtrl with the footprints from \a aList that meet the filter
* criteria defined by \a aFilterType.
*
* @param aList is a #FOOTPRINT_LIST item containing the footprints.
* @param aLibName is wxString containing the name of the selected library. Can be
* wxEmptyString.
* @param aComponent is the #COMPONENT used by the filtering criteria. Can be NULL.
* @param aFootPrintFilterPattern is the filter used to filter list by names.
* @param aFilterType defines the criteria to filter \a aList.
*/
void SetFootprints( FOOTPRINT_LIST& aList, const wxString& aLibName, COMPONENT* aComponent,
const wxString& aFootPrintFilterPattern, int aFilterType );
wxString GetSelectedFootprint();
/**
* This overloaded function MUST be provided for the wxLC_VIRTUAL mode
* because real data is not handled by ITEMS_LISTBOX_BASE.
*/
wxString OnGetItemText( long item, long column ) const override;
// Events functions:
void OnLeftClick( wxListEvent& event );
void OnLeftDClick( wxListEvent& event );
void OnChar( wxKeyEvent& event );
DECLARE_EVENT_TABLE();
private:
wxArrayString m_footprintList;
};
class LIBRARY_LISTBOX : public ITEMS_LISTBOX_BASE
{
public:
LIBRARY_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id );
~LIBRARY_LISTBOX() override {};
int GetCount();
void SetSelection( int index, bool State = true );
void SetString( unsigned linecount, const wxString& text );
void AppendLine( const wxString& text );
void Finish();
void ClearList();
wxString GetSelectedLibrary();
wxString OnGetItemText( long item, long column ) const override;
void OnSelectLibrary( wxListEvent& event );
/**
* Called on a key press.
*
* Call default handler for some special keys, and for "ASCII" keys, select the first
* footprint that the name starts by the letter.
*
* This is the default behavior of a listbox, but because we use virtual lists, the
* listbox does not know anything to what is displayed, we must handle this behavior
* here. Furthermore the footprint name is not at the beginning of displayed lines
* (the first word is the line number).
*/
void OnChar( wxKeyEvent& event );
DECLARE_EVENT_TABLE();
private:
wxArrayString m_libraryList;
};
class SYMBOLS_LISTBOX : public ITEMS_LISTBOX_BASE
{
public:
SYMBOLS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id );
~SYMBOLS_LISTBOX();
void Clear();
int GetCount();
/**
* This overloaded function MUST be provided for the wxLC_VIRTUAL mode
* because real data is not handled by #ITEMS_LISTBOX_BASE.
*/
wxString OnGetItemText( long item, long column ) const override;
wxListItemAttr* OnGetItemAttr( long item) const override;
/*
* Enable or disable an item
*/
void SetSelection( int index, bool State = true );
void SetString( unsigned linecount, const wxString& text );
void AppendLine( const wxString& text );
void AppendWarning( int index );
void RemoveWarning( int index );
// Events functions:
/**
* Called on a key press.
*
* Call default handler for some special keys, and for "ASCII" keys, select the first
* component that the name starts by the letter.
*
* This is the default behavior of a listbox, but because we use virtual lists, the
* listbox does not know anything to what is displayed, we must handle this behavior
* here. Furthermore the reference of components is not at the beginning of displayed
* lines (the first word is the line number).
*/
void OnChar( wxKeyEvent& event );
void OnSelectComponent( wxListEvent& event );
DECLARE_EVENT_TABLE();
public:
wxArrayString m_SymbolList;
private:
std::vector<long> m_symbolWarning;
std::unique_ptr<wxListItemAttr> m_warningAttr;
};
#endif //#ifndef LISTBOXES_H