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 (C) 1992-2012 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
29#include <trace_helpers.h>
30
31#include <cvpcb_mainframe.h>
32#include <listboxes.h>
33#include <cvpcb_id.h>
34#include <wx/log.h>
36
37
38/***************************************/
39/* ListBox handling the library list */
40/***************************************/
41
43 ITEMS_LISTBOX_BASE( parent, id, wxDefaultPosition, wxDefaultSize, wxLC_SINGLE_SEL )
44{
45}
46
47
49{
50}
51
52
54{
55 return m_libraryList.Count();
56}
57
58
59void LIBRARY_LISTBOX::SetString( unsigned linecount, const wxString& text )
60{
61 unsigned count = m_libraryList.Count();
62 if( count > 0 )
63 {
64 if( linecount >= count )
65 linecount = count - 1;
66
67 m_libraryList[linecount] = text;
68 UpdateWidth( linecount );
69 }
70}
71
72
74{
75 wxString libName;
76 int ii = GetFirstSelected();
77
78 if( ii >= 0 )
79 {
80 libName = m_libraryList[ii];
81 libName.Trim( false );
82
83 if( libName.StartsWith( LIB_TREE_MODEL_ADAPTER::GetPinningSymbol() ) )
84 libName = libName.substr( LIB_TREE_MODEL_ADAPTER::GetPinningSymbol().length() );
85 }
86
87 return libName;
88}
89
90
91void LIBRARY_LISTBOX::AppendLine( const wxString& text )
92{
93 m_libraryList.Add( wxT( " " ) + text );
94 int lines = m_libraryList.Count();
95 SetItemCount( lines );
96}
97
98
99wxString LIBRARY_LISTBOX::OnGetItemText( long item, long column ) const
100{
101 return m_libraryList.Item( item );
102}
103
104
105void LIBRARY_LISTBOX::SetSelection( int index, bool State )
106{
107 if( index >= GetCount() )
108 index = GetCount() - 1;
109
110 if( (index >= 0) && (GetCount() > 0) )
111 {
112#ifndef __WXMAC__
113 Select( index, State );
114#endif
115 EnsureVisible( index );
116#ifdef __WXMAC__
117 Refresh();
118#endif
119 }
120}
121
122
124{
125 if( m_libraryList.Count() )
126 {
127 RefreshItems( 0L, m_libraryList.Count()-1 );
128 UpdateWidth();
129 }
130}
131
133{
134 m_libraryList.clear();
135}
136
137BEGIN_EVENT_TABLE( LIBRARY_LISTBOX, ITEMS_LISTBOX_BASE )
138 EVT_CHAR( LIBRARY_LISTBOX::OnChar )
140END_EVENT_TABLE()
141
142
143void LIBRARY_LISTBOX::OnChar( wxKeyEvent& event )
144{
145 wxLogTrace( kicadTraceKeyEvent, wxS( "LIBRARY_LISTBOX::OnChar %s" ), dump( event ) );
146
147 int key = event.GetKeyCode();
148
149 switch( key )
150 {
151 case WXK_HOME:
152 case WXK_END:
153 case WXK_UP:
154 case WXK_DOWN:
155 case WXK_PAGEUP:
156 case WXK_PAGEDOWN:
157 event.Skip();
158 return;
159
160 default:
161 break;
162 }
163
164 // Search for an item name starting by the key code:
165 key = toupper(key);
166
167 for( unsigned ii = 0; ii < m_libraryList.GetCount(); ii++ )
168 {
169 wxString text = m_libraryList.Item( ii );
170
171 // Search for the start char of the footprint name. Skip the line number.
172 text.Trim( false ); // Remove leading spaces in line
173 unsigned jj = 0;
174
175 for( ; jj < text.Len(); jj++ )
176 {
177 // skip line number
178 if( text[jj] == ' ' )
179 break;
180 }
181
182 for( ; jj < text.Len(); jj++ )
183 { // skip blanks
184 if( text[jj] != ' ' )
185 break;
186 }
187
188 int start_char = toupper( text[jj] );
189
190 if( key == start_char )
191 {
192 SetSelection( ii, true ); // Ensure visible
193 break;
194 }
195 }
196
197 event.Skip();
198}
199
200
201void LIBRARY_LISTBOX::OnSelectLibrary( wxListEvent& event )
202{
203 // Apply the filter
206
207 SetFocus();
208 GetParent()->OnSelectComponent( event );
209}
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:43
void UpdateWidth(int aLine=-1)
Update the width of the column based on its contents.
virtual CVPCB_MAINFRAME * GetParent() const
void SetString(unsigned linecount, const wxString &text)
wxArrayString m_libraryList
Definition: listboxes.h:177
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:33
const wxChar *const kicadTraceKeyEvent
Flag to enable wxKeyEvent debug tracing.
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
wxLogTrace helper definitions.