2013-06-06 15:37:48 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2018-01-28 08:51:28 +00:00
|
|
|
* Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-06-06 15:37:48 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2013-09-17 00:52:08 +00:00
|
|
|
* @file class_components_listbox.cpp
|
2013-06-06 15:37:48 +00:00
|
|
|
*/
|
2009-08-20 11:44:06 +00:00
|
|
|
|
2019-08-08 22:11:59 +00:00
|
|
|
#include <trace_helpers.h>
|
2009-08-20 11:44:06 +00:00
|
|
|
|
2022-12-17 18:51:17 +00:00
|
|
|
#include <kiplatform/ui.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <cvpcb_mainframe.h>
|
2018-01-28 08:51:28 +00:00
|
|
|
#include <listboxes.h>
|
2013-06-06 15:37:48 +00:00
|
|
|
#include <cvpcb_id.h>
|
2021-06-03 12:11:15 +00:00
|
|
|
#include <wx/log.h>
|
2009-08-20 11:44:06 +00:00
|
|
|
|
|
|
|
|
2021-09-27 11:55:53 +00:00
|
|
|
SYMBOLS_LISTBOX::SYMBOLS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id ) :
|
2023-01-17 04:14:38 +00:00
|
|
|
ITEMS_LISTBOX_BASE( parent, id ),
|
2022-09-29 19:27:08 +00:00
|
|
|
m_warningAttr( std::make_unique<wxListItemAttr>() )
|
2009-08-20 11:44:06 +00:00
|
|
|
{
|
2023-02-13 10:13:08 +00:00
|
|
|
m_warningAttr->SetBackgroundColour( KIPLATFORM::UI::IsDarkTheme() ? wxColour( 112, 96, 32 )
|
|
|
|
: wxColour( 255, 248, 212 ) );
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-27 11:55:53 +00:00
|
|
|
SYMBOLS_LISTBOX::~SYMBOLS_LISTBOX()
|
2009-08-20 11:44:06 +00:00
|
|
|
{
|
|
|
|
}
|
2022-12-17 18:51:17 +00:00
|
|
|
;
|
2009-08-20 11:44:06 +00:00
|
|
|
|
2021-09-27 11:55:53 +00:00
|
|
|
BEGIN_EVENT_TABLE( SYMBOLS_LISTBOX, ITEMS_LISTBOX_BASE )
|
|
|
|
EVT_CHAR( SYMBOLS_LISTBOX::OnChar )
|
|
|
|
EVT_LIST_ITEM_SELECTED( ID_CVPCB_COMPONENT_LIST, SYMBOLS_LISTBOX::OnSelectComponent )
|
2009-08-20 11:44:06 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
2021-09-27 11:55:53 +00:00
|
|
|
void SYMBOLS_LISTBOX::Clear()
|
2009-08-20 11:44:06 +00:00
|
|
|
{
|
2021-09-27 11:55:53 +00:00
|
|
|
m_SymbolList.Clear();
|
2009-08-20 11:44:06 +00:00
|
|
|
SetItemCount( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-27 11:55:53 +00:00
|
|
|
int SYMBOLS_LISTBOX::GetCount()
|
2009-08-20 11:44:06 +00:00
|
|
|
{
|
2021-09-27 11:55:53 +00:00
|
|
|
return m_SymbolList.Count();
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-27 11:55:53 +00:00
|
|
|
void SYMBOLS_LISTBOX::SetString( unsigned linecount, const wxString& text )
|
2009-08-20 11:44:06 +00:00
|
|
|
{
|
2021-09-27 11:55:53 +00:00
|
|
|
if( linecount >= m_SymbolList.Count() )
|
|
|
|
linecount = m_SymbolList.Count() - 1;
|
2013-06-06 15:37:48 +00:00
|
|
|
|
2021-09-27 11:55:53 +00:00
|
|
|
if( m_SymbolList.Count() > 0 )
|
2014-11-12 10:46:40 +00:00
|
|
|
{
|
2021-09-27 11:55:53 +00:00
|
|
|
m_SymbolList[linecount] = text;
|
2014-11-12 10:46:40 +00:00
|
|
|
UpdateWidth( linecount );
|
|
|
|
}
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-27 11:55:53 +00:00
|
|
|
void SYMBOLS_LISTBOX::AppendLine( const wxString& text )
|
2009-08-20 11:44:06 +00:00
|
|
|
{
|
2021-09-27 11:55:53 +00:00
|
|
|
m_SymbolList.Add( text );
|
|
|
|
int lines = m_SymbolList.Count();
|
2014-11-12 10:46:40 +00:00
|
|
|
SetItemCount( lines );
|
|
|
|
UpdateWidth( lines - 1 );
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-29 19:27:08 +00:00
|
|
|
void SYMBOLS_LISTBOX::AppendWarning( int index )
|
|
|
|
{
|
|
|
|
if( !std::count( m_symbolWarning.begin(), m_symbolWarning.end(), index ) )
|
|
|
|
{
|
|
|
|
m_symbolWarning.emplace_back( index );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SYMBOLS_LISTBOX::RemoveWarning( int index )
|
|
|
|
{
|
2023-01-17 04:14:38 +00:00
|
|
|
if( auto const found{ std::find( m_symbolWarning.begin(), m_symbolWarning.end(), index ) };
|
2022-09-29 19:27:08 +00:00
|
|
|
found != m_symbolWarning.end() )
|
|
|
|
{
|
|
|
|
m_symbolWarning.erase( found );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-27 11:55:53 +00:00
|
|
|
wxString SYMBOLS_LISTBOX::OnGetItemText( long item, long column ) const
|
2009-08-20 11:44:06 +00:00
|
|
|
{
|
2021-09-27 11:55:53 +00:00
|
|
|
return m_SymbolList.Item( item );
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-29 19:27:08 +00:00
|
|
|
wxListItemAttr* SYMBOLS_LISTBOX::OnGetItemAttr( long item ) const
|
|
|
|
{
|
|
|
|
if( std::count( m_symbolWarning.begin(), m_symbolWarning.end(), item ) )
|
|
|
|
{
|
|
|
|
return m_warningAttr.get();
|
|
|
|
}
|
2023-01-17 04:14:38 +00:00
|
|
|
return nullptr;
|
2022-09-29 19:27:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-27 11:55:53 +00:00
|
|
|
void SYMBOLS_LISTBOX::SetSelection( int index, bool State )
|
2009-08-20 11:44:06 +00:00
|
|
|
{
|
2014-06-04 17:34:23 +00:00
|
|
|
if( index >= GetCount() )
|
2009-08-20 11:44:06 +00:00
|
|
|
index = GetCount() - 1;
|
|
|
|
|
|
|
|
if( (index >= 0) && (GetCount() > 0) )
|
|
|
|
{
|
|
|
|
Select( index, State );
|
|
|
|
EnsureVisible( index );
|
2013-06-06 15:37:48 +00:00
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
#ifdef __WXMAC__
|
2012-11-19 21:34:25 +00:00
|
|
|
Update();
|
2009-08-20 11:44:06 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-27 11:55:53 +00:00
|
|
|
void SYMBOLS_LISTBOX::OnChar( wxKeyEvent& event )
|
2009-08-20 11:44:06 +00:00
|
|
|
{
|
2023-01-17 04:14:38 +00:00
|
|
|
wxLogTrace( kicadTraceKeyEvent, wxS( "SYMBOLS_LISTBOX::OnChar %s" ), dump( event ) );
|
2019-08-08 22:11:59 +00:00
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
int key = event.GetKeyCode();
|
2013-06-06 15:37:48 +00:00
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
switch( key )
|
|
|
|
{
|
2013-06-06 15:37:48 +00:00
|
|
|
case WXK_HOME:
|
|
|
|
case WXK_END:
|
|
|
|
case WXK_UP:
|
|
|
|
case WXK_DOWN:
|
|
|
|
case WXK_PAGEUP:
|
|
|
|
case WXK_PAGEDOWN:
|
|
|
|
event.Skip();
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Search for an item name starting by the key code:
|
2013-06-06 15:37:48 +00:00
|
|
|
key = toupper( key );
|
|
|
|
|
2021-09-27 11:55:53 +00:00
|
|
|
for( unsigned ii = 0; ii < m_SymbolList.GetCount(); ii++ )
|
2009-08-20 11:44:06 +00:00
|
|
|
{
|
2021-09-27 11:55:53 +00:00
|
|
|
wxString text = m_SymbolList.Item( ii );
|
2013-06-06 15:37:48 +00:00
|
|
|
|
|
|
|
// Search for the start char of the footprint name. Skip the line number.
|
|
|
|
text.Trim( false ); // Remove leading spaces in line
|
2009-08-20 11:44:06 +00:00
|
|
|
unsigned jj = 0;
|
2013-06-06 15:37:48 +00:00
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
for( ; jj < text.Len(); jj++ )
|
|
|
|
{ // skip line number
|
|
|
|
if( text[jj] == ' ' )
|
|
|
|
break;
|
|
|
|
}
|
2013-06-06 15:37:48 +00:00
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
for( ; jj < text.Len(); jj++ )
|
|
|
|
{ // skip blanks
|
|
|
|
if( text[jj] != ' ' )
|
|
|
|
break;
|
|
|
|
}
|
2013-06-06 15:37:48 +00:00
|
|
|
|
|
|
|
int start_char = toupper( text[jj] );
|
|
|
|
|
|
|
|
if( key == start_char )
|
2009-08-20 11:44:06 +00:00
|
|
|
{
|
2014-06-04 17:34:23 +00:00
|
|
|
SetSelection( (int) ii, true ); // Ensure visible
|
2009-08-20 11:44:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-10-14 13:18:48 +00:00
|
|
|
|
|
|
|
event.Skip();
|
2013-06-06 15:37:48 +00:00
|
|
|
}
|
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
|
2021-09-27 11:55:53 +00:00
|
|
|
void SYMBOLS_LISTBOX::OnSelectComponent( wxListEvent& event )
|
2013-06-06 15:37:48 +00:00
|
|
|
{
|
|
|
|
SetFocus();
|
|
|
|
GetParent()->OnSelectComponent( event );
|
2009-08-20 11:44:06 +00:00
|
|
|
}
|