KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 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, 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() ? wxColour( 112, 96, 32 )
42 : wxColour( 255, 248, 212 ) );
43}
44
45
46BEGIN_EVENT_TABLE( SYMBOLS_LISTBOX, ITEMS_LISTBOX_BASE )
47 EVT_CHAR( SYMBOLS_LISTBOX::OnChar )
49END_EVENT_TABLE()
50
51
52void SYMBOLS_LISTBOX::Clear()
53{
54 m_SymbolList.Clear();
55 SetItemCount( 0 );
56}
57
58
60{
61 return m_SymbolList.Count();
62}
63
64
65void SYMBOLS_LISTBOX::SetString( unsigned linecount, const wxString& text )
66{
67 if( linecount >= m_SymbolList.Count() )
68 linecount = m_SymbolList.Count() - 1;
69
70 if( m_SymbolList.Count() > 0 )
71 {
72 m_SymbolList[linecount] = text;
73 UpdateWidth( linecount );
74 }
75}
76
77
78void SYMBOLS_LISTBOX::AppendLine( const wxString& text )
79{
80 m_SymbolList.Add( text );
81 int lines = m_SymbolList.Count();
82 SetItemCount( lines );
83 UpdateWidth( lines - 1 );
84}
85
86
88{
89 if( !std::count( m_symbolWarning.begin(), m_symbolWarning.end(), index ) )
90 {
91 m_symbolWarning.emplace_back( index );
92 }
93}
94
95
97{
98 if( auto const found{ std::find( m_symbolWarning.begin(), m_symbolWarning.end(), index ) };
99 found != m_symbolWarning.end() )
100 {
101 m_symbolWarning.erase( found );
102 }
103}
104
105
106wxString SYMBOLS_LISTBOX::OnGetItemText( long item, long column ) const
107{
108 return m_SymbolList.Item( item );
109}
110
111
112wxListItemAttr* SYMBOLS_LISTBOX::OnGetItemAttr( long item ) const
113{
114 if( std::count( m_symbolWarning.begin(), m_symbolWarning.end(), item ) )
115 return m_warningAttr.get();
116
117 return nullptr;
118}
119
120
121void SYMBOLS_LISTBOX::SetSelection( int index, bool State )
122{
123 if( index >= GetCount() )
124 index = GetCount() - 1;
125
126 if( (index >= 0) && (GetCount() > 0) )
127 {
128 Select( index, State );
129 EnsureVisible( index );
130
131#ifdef __WXMAC__
132 Update();
133#endif
134 }
135}
136
137
138void SYMBOLS_LISTBOX::OnChar( wxKeyEvent& event )
139{
140 if( m_isClosing )
141 return;
142
143 wxLogTrace( kicadTraceKeyEvent, wxS( "SYMBOLS_LISTBOX::OnChar %s" ), dump( event ) );
144
145 int key = event.GetKeyCode();
146
147 switch( key )
148 {
149 case WXK_HOME:
150 case WXK_END:
151 case WXK_UP:
152 case WXK_DOWN:
153 case WXK_PAGEUP:
154 case WXK_PAGEDOWN:
155 event.Skip();
156 return;
157
158
159 default:
160 break;
161 }
162
163 // Search for an item name starting by the key code:
164 key = toupper( key );
165
166 for( unsigned ii = 0; ii < m_SymbolList.GetCount(); ii++ )
167 {
168 wxString text = m_SymbolList.Item( ii );
169
170 // Search for the start char of the footprint name. Skip the line number.
171 text.Trim( false ); // Remove leading spaces in line
172 unsigned jj = 0;
173
174 for( ; jj < text.Len(); jj++ )
175 { // skip line number
176 if( text[jj] == ' ' )
177 break;
178 }
179
180 for( ; jj < text.Len(); jj++ )
181 { // skip blanks
182 if( text[jj] != ' ' )
183 break;
184 }
185
186 int start_char = toupper( text[jj] );
187
188 if( key == start_char )
189 {
190 SetSelection( (int) ii, true ); // Ensure visible
191 break;
192 }
193 }
194
195 event.Skip();
196}
197
198
199void SYMBOLS_LISTBOX::OnSelectComponent( wxListEvent& event )
200{
201 if( m_isClosing )
202 return;
203
204 SetFocus();
205 GetParent()->OnSelectComponent( event );
206}
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:234
void OnChar(wxKeyEvent &event)
Called on a key press.
wxListItemAttr * OnGetItemAttr(long item) const override
wxArrayString m_SymbolList
Definition: listboxes.h:231
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:235
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: wxgtk/ui.cpp:48
STL namespace.
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
wxLogTrace helper definitions.