KiCad PCB EDA Suite
symbols_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-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
28#include <trace_helpers.h>
29
30#include <kiplatform/ui.h>
31#include <cvpcb_mainframe.h>
32#include <listboxes.h>
33#include <cvpcb_id.h>
34#include <wx/log.h>
35
36
38 ITEMS_LISTBOX_BASE( parent, id ),
39 m_warningAttr( std::make_unique<wxListItemAttr>() )
40{
41 m_warningAttr->SetBackgroundColour( KIPLATFORM::UI::IsDarkTheme()
42 ? wxColour( 112, 96, 32 )
43 : *wxYELLOW );
44}
45
46
48{
49}
50;
51
52BEGIN_EVENT_TABLE( SYMBOLS_LISTBOX, ITEMS_LISTBOX_BASE )
53 EVT_CHAR( SYMBOLS_LISTBOX::OnChar )
55END_EVENT_TABLE()
56
57
58void SYMBOLS_LISTBOX::Clear()
59{
60 m_SymbolList.Clear();
61 SetItemCount( 0 );
62}
63
64
66{
67 return m_SymbolList.Count();
68}
69
70
71void SYMBOLS_LISTBOX::SetString( unsigned linecount, const wxString& text )
72{
73 if( linecount >= m_SymbolList.Count() )
74 linecount = m_SymbolList.Count() - 1;
75
76 if( m_SymbolList.Count() > 0 )
77 {
78 m_SymbolList[linecount] = text;
79 UpdateWidth( linecount );
80 }
81}
82
83
84void SYMBOLS_LISTBOX::AppendLine( const wxString& text )
85{
86 m_SymbolList.Add( text );
87 int lines = m_SymbolList.Count();
88 SetItemCount( lines );
89 UpdateWidth( lines - 1 );
90}
91
92
94{
95 if( !std::count( m_symbolWarning.begin(), m_symbolWarning.end(), index ) )
96 {
97 m_symbolWarning.emplace_back( index );
98 }
99}
100
101
103{
104 if( auto const found{ std::find( m_symbolWarning.begin(), m_symbolWarning.end(), index ) };
105 found != m_symbolWarning.end() )
106 {
107 m_symbolWarning.erase( found );
108 }
109}
110
111
112wxString SYMBOLS_LISTBOX::OnGetItemText( long item, long column ) const
113{
114 return m_SymbolList.Item( item );
115}
116
117
118wxListItemAttr* SYMBOLS_LISTBOX::OnGetItemAttr( long item ) const
119{
120 if( std::count( m_symbolWarning.begin(), m_symbolWarning.end(), item ) )
121 {
122 return m_warningAttr.get();
123 }
124 return nullptr;
125}
126
127
128void SYMBOLS_LISTBOX::SetSelection( int index, bool State )
129{
130 if( index >= GetCount() )
131 index = GetCount() - 1;
132
133 if( (index >= 0) && (GetCount() > 0) )
134 {
135 Select( index, State );
136 EnsureVisible( index );
137
138#ifdef __WXMAC__
139 Update();
140#endif
141 }
142}
143
144
145void SYMBOLS_LISTBOX::OnChar( wxKeyEvent& event )
146{
147 wxLogTrace( kicadTraceKeyEvent, wxS( "SYMBOLS_LISTBOX::OnChar %s" ), dump( event ) );
148
149 int key = event.GetKeyCode();
150
151 switch( key )
152 {
153 case WXK_HOME:
154 case WXK_END:
155 case WXK_UP:
156 case WXK_DOWN:
157 case WXK_PAGEUP:
158 case WXK_PAGEDOWN:
159 event.Skip();
160 return;
161
162
163 default:
164 break;
165 }
166
167 // Search for an item name starting by the key code:
168 key = toupper( key );
169
170 for( unsigned ii = 0; ii < m_SymbolList.GetCount(); ii++ )
171 {
172 wxString text = m_SymbolList.Item( ii );
173
174 // Search for the start char of the footprint name. Skip the line number.
175 text.Trim( false ); // Remove leading spaces in line
176 unsigned jj = 0;
177
178 for( ; jj < text.Len(); jj++ )
179 { // skip line number
180 if( text[jj] == ' ' )
181 break;
182 }
183
184 for( ; jj < text.Len(); jj++ )
185 { // skip blanks
186 if( text[jj] != ' ' )
187 break;
188 }
189
190 int start_char = toupper( text[jj] );
191
192 if( key == start_char )
193 {
194 SetSelection( (int) ii, true ); // Ensure visible
195 break;
196 }
197 }
198
199 event.Skip();
200}
201
202
203void SYMBOLS_LISTBOX::OnSelectComponent( wxListEvent& event )
204{
205 SetFocus();
206 GetParent()->OnSelectComponent( event );
207}
The CvPcb application main window.
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
wxString OnGetItemText(long item, long column) const override
This overloaded function MUST be provided for the wxLC_VIRTUAL mode because real data is not handled ...
std::vector< long > m_symbolWarning
Definition: listboxes.h:230
void OnChar(wxKeyEvent &event)
Called on a key press.
wxListItemAttr * OnGetItemAttr(long item) const override
wxArrayString m_SymbolList
Definition: listboxes.h:227
void OnSelectComponent(wxListEvent &event)
void SetString(unsigned linecount, const wxString &text)
SYMBOLS_LISTBOX(CVPCB_MAINFRAME *parent, wxWindowID id)
void SetSelection(int index, bool State=true)
void AppendWarning(int index)
std::unique_ptr< wxListItemAttr > m_warningAttr
Definition: listboxes.h:231
void RemoveWarning(int index)
void AppendLine(const wxString &text)
@ ID_CVPCB_COMPONENT_LIST
Definition: cvpcb_id.h:31
const wxChar *const kicadTraceKeyEvent
Flag to enable wxKeyEvent debug tracing.
bool IsDarkTheme()
Determine if the desktop interface is currently using a dark theme or a light theme.
Definition: gtk/ui.cpp:31
Definition: bitmap.cpp:64
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
wxLogTrace helper definitions.