KiCad PCB EDA Suite
Loading...
Searching...
No Matches
library_listbox.cpp
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, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <trace_helpers.h>
21
22#include <cvpcb_mainframe.h>
23#include <cvpcb_id.h>
24#include <wx/log.h>
26
27
28/***************************************/
29/* ListBox handling the library list */
30/***************************************/
31
33 ITEMS_LISTBOX_BASE( parent, id, wxDefaultPosition, wxDefaultSize, wxLC_SINGLE_SEL )
34{
35}
36
37
39{
40 return (int) m_libraryList.Count();
41}
42
43
44void LIBRARY_LISTBOX::SetString( unsigned linecount, const wxString& text )
45{
46 unsigned count = m_libraryList.Count();
47
48 if( count > 0 )
49 {
50 if( linecount >= count )
51 linecount = count - 1;
52
53 m_libraryList[linecount] = text;
54 UpdateWidth( linecount );
55 }
56}
57
58
60{
61 wxString libName;
62 int ii = GetFirstSelected();
63
64 if( ii >= 0 )
65 {
66 libName = m_libraryList[ii];
67 libName.Trim( false );
68
69 if( libName.StartsWith( LIB_TREE_MODEL_ADAPTER::GetPinningSymbol() ) )
70 libName = libName.substr( LIB_TREE_MODEL_ADAPTER::GetPinningSymbol().length() );
71 }
72
73 return libName;
74}
75
76
77void LIBRARY_LISTBOX::AppendLine( const wxString& text )
78{
79 m_libraryList.Add( wxT( " " ) + text );
80 int lines = m_libraryList.Count();
81 SetItemCount( lines );
82}
83
84
85wxString LIBRARY_LISTBOX::OnGetItemText( long item, long column ) const
86{
87 return m_libraryList.Item( item );
88}
89
90
91void LIBRARY_LISTBOX::SetSelection( int index, bool State )
92{
93 if( index >= GetCount() )
94 index = GetCount() - 1;
95
96 if( (index >= 0) && (GetCount() > 0) )
97 {
98#ifndef __WXMAC__
99 Select( index, State );
100#endif
101 EnsureVisible( index );
102#ifdef __WXMAC__
103 Refresh();
104#endif
105 }
106}
107
108
110{
111 if( m_libraryList.Count() )
112 {
113 RefreshItems( 0L, m_libraryList.Count() - 1 );
114 UpdateWidth();
115 }
116}
117
118
120{
121 m_libraryList.clear();
122}
123
124
125BEGIN_EVENT_TABLE( LIBRARY_LISTBOX, ITEMS_LISTBOX_BASE )
126 EVT_CHAR( LIBRARY_LISTBOX::OnChar )
128END_EVENT_TABLE()
129
130
131void LIBRARY_LISTBOX::OnChar( wxKeyEvent& event )
132{
133 wxLogTrace( kicadTraceKeyEvent, wxS( "LIBRARY_LISTBOX::OnChar %s" ), dump( event ) );
134
135 int key = event.GetKeyCode();
136
137 switch( key )
138 {
139 case WXK_HOME:
140 case WXK_END:
141 case WXK_UP:
142 case WXK_DOWN:
143 case WXK_PAGEUP:
144 case WXK_PAGEDOWN:
145 event.Skip();
146 return;
147
148 default:
149 break;
150 }
151
152 // Search for an item name starting by the key code:
153 key = toupper(key);
154
155 for( unsigned ii = 0; ii < m_libraryList.GetCount(); ii++ )
156 {
157 wxString text = m_libraryList.Item( ii );
158
159 // Search for the start char of the footprint name. Skip the line number.
160 text.Trim( false ); // Remove leading spaces in line
161 unsigned jj = 0;
162
163 for( ; jj < text.Len(); jj++ )
164 {
165 // skip line number
166 if( text[jj] == ' ' )
167 break;
168 }
169
170 for( ; jj < text.Len(); jj++ )
171 {
172 // skip blanks
173 if( text[jj] != ' ' )
174 break;
175 }
176
177 int start_char = toupper( text[jj] );
178
179 if( key == start_char )
180 {
181 SetSelection( ii, true ); // Ensure visible
182 break;
183 }
184 }
185
186 event.Skip();
187}
188
189
190void LIBRARY_LISTBOX::OnSelectLibrary( wxListEvent& event )
191{
192 // Apply the filter
195
196 SetFocus();
197 GetParent()->OnSelectComponent( event );
198}
int index
The CvPcb application main window.
@ FILTER_ENABLE
Turn on the filter.
void SetFootprintFilter(FOOTPRINTS_LISTBOX::FP_FILTER_T aFilter, CVPCB_MAINFRAME::CVPCB_FILTER_ACTION aAction)
Set a filter criteria to either on/off or toggle the criteria.
void OnSelectComponent(wxListEvent &event)
Called when clicking on a component in component list window:
Base class to display symbol and footprint lists.
Definition listboxes.h:39
void UpdateWidth(int aLine=-1)
Update the width of the column based on its contents.
ITEMS_LISTBOX_BASE(CVPCB_MAINFRAME *aParent, wxWindowID aId, const wxPoint &aLocation=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, long aStyle=0)
virtual CVPCB_MAINFRAME * GetParent() const
void SetString(unsigned linecount, const wxString &text)
wxArrayString m_libraryList
Definition listboxes.h:178
wxString OnGetItemText(long item, long column) const override
void OnChar(wxKeyEvent &event)
Called on a key press.
void OnSelectLibrary(wxListEvent &event)
void AppendLine(const wxString &text)
LIBRARY_LISTBOX(CVPCB_MAINFRAME *parent, wxWindowID id)
void SetSelection(int index, bool State=true)
wxString GetSelectedLibrary()
static const wxString GetPinningSymbol()
@ ID_CVPCB_LIBRARY_LIST
Definition cvpcb_id.h:29
const wxChar *const kicadTraceKeyEvent
Flag to enable wxKeyEvent debug tracing.
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
wxLogTrace helper definitions.