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