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