2013-05-08 20:47:23 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2011-11-08 16:37:25 +00:00
|
|
|
/**
|
|
|
|
* @file displlst.cpp
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <wxstruct.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <dialog_helpers.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
EDA_LIST_DIALOG::EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitle,
|
2013-03-19 01:25:19 +00:00
|
|
|
const wxArrayString& aItemHeaders,
|
|
|
|
const std::vector<wxArrayString>& aItemList,
|
|
|
|
const wxString& aRefText,
|
|
|
|
void(*aCallBackFunction)(wxString& Text),
|
2013-01-10 12:18:43 +00:00
|
|
|
bool aSortList ) :
|
|
|
|
EDA_LIST_DIALOG_BASE( aParent, wxID_ANY, aTitle )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-03-19 01:25:19 +00:00
|
|
|
m_sortList = aSortList;
|
2010-11-19 18:50:23 +00:00
|
|
|
m_callBackFct = aCallBackFunction;
|
2013-01-10 12:18:43 +00:00
|
|
|
m_itemsListCp = &aItemList;
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
for( unsigned i = 0; i < aItemHeaders.Count(); i++ )
|
|
|
|
{
|
|
|
|
wxListItem column;
|
|
|
|
column.SetId( i );
|
|
|
|
column.SetText( aItemHeaders.Item( i ) );
|
|
|
|
column.SetWidth( 300 / aItemHeaders.Count() );
|
2013-05-08 20:47:23 +00:00
|
|
|
m_listBox->InsertColumn( i, column );
|
2013-03-19 01:25:19 +00:00
|
|
|
}
|
2013-05-08 20:47:23 +00:00
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
InsertItems( aItemList, 0 );
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2012-10-18 19:31:40 +00:00
|
|
|
if( !aRefText.IsEmpty() ) // try to select the item matching aRefText
|
|
|
|
{
|
2013-03-19 01:25:19 +00:00
|
|
|
for( unsigned ii = 0; ii < aItemList.size(); ii++ )
|
2013-05-08 20:47:23 +00:00
|
|
|
{
|
2013-03-19 01:25:19 +00:00
|
|
|
if( aItemList[ii][0] == aRefText )
|
2012-10-18 19:31:40 +00:00
|
|
|
{
|
2013-03-19 01:25:19 +00:00
|
|
|
m_listBox->SetItemState( ii, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
|
2012-10-18 19:31:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-05-08 20:47:23 +00:00
|
|
|
}
|
2012-10-18 19:31:40 +00:00
|
|
|
}
|
|
|
|
|
2013-01-10 12:18:43 +00:00
|
|
|
if( m_callBackFct == NULL )
|
2009-09-02 18:12:45 +00:00
|
|
|
{
|
2013-03-19 01:25:19 +00:00
|
|
|
m_messages->Show( false );
|
|
|
|
m_staticTextMsg->Show( false );
|
2007-12-11 23:12:37 +00:00
|
|
|
}
|
|
|
|
|
2013-01-10 12:18:43 +00:00
|
|
|
m_filterBox->SetFocus();
|
2009-09-02 18:12:45 +00:00
|
|
|
|
2007-12-11 23:12:37 +00:00
|
|
|
GetSizer()->Fit( this );
|
|
|
|
GetSizer()->SetSizeHints( this );
|
2010-11-19 18:50:23 +00:00
|
|
|
Centre();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
EDA_LIST_DIALOG::~EDA_LIST_DIALOG()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-10 12:18:43 +00:00
|
|
|
void EDA_LIST_DIALOG::textChangeInFilterBox( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-01-10 12:18:43 +00:00
|
|
|
wxString filter;
|
|
|
|
wxString itemName;
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
filter = wxT( "*" ) + m_filterBox->GetLineText( 0 ).MakeLower() + wxT( "*" );
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
m_listBox->DeleteAllItems();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
for( unsigned i = 0; i < m_itemsListCp->size(); i++ )
|
2013-01-10 12:18:43 +00:00
|
|
|
{
|
2013-03-19 01:25:19 +00:00
|
|
|
itemName = (*m_itemsListCp)[i].Item( 0 );
|
2013-01-10 12:18:43 +00:00
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
if( itemName.MakeLower().Matches( filter ) )
|
2013-01-10 12:18:43 +00:00
|
|
|
{
|
2013-03-19 01:25:19 +00:00
|
|
|
Append( (*m_itemsListCp)[i] );
|
2013-01-10 12:18:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_sortList )
|
|
|
|
sortList();
|
|
|
|
}
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2013-05-08 20:47:23 +00:00
|
|
|
|
|
|
|
wxString EDA_LIST_DIALOG::GetTextSelection( int aColumn )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-05-08 20:47:23 +00:00
|
|
|
wxCHECK_MSG( aColumn < m_listBox->GetColumnCount(), wxEmptyString,
|
|
|
|
wxT( "Invalid list control column." ) );
|
|
|
|
|
|
|
|
wxListItem info;
|
|
|
|
wxString text;
|
|
|
|
long item = -1;
|
2013-03-19 01:25:19 +00:00
|
|
|
item = m_listBox->GetNextItem( item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
|
2013-05-08 20:47:23 +00:00
|
|
|
|
|
|
|
info.m_mask = wxLIST_MASK_TEXT;
|
|
|
|
info.m_itemId = item;
|
|
|
|
info.m_col = aColumn;
|
|
|
|
|
|
|
|
if( !m_listBox->GetItem( info ) )
|
|
|
|
return wxEmptyString;
|
|
|
|
|
|
|
|
return info.m_text;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
void EDA_LIST_DIALOG::Append( const wxArrayString& itemList )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-03-19 01:25:19 +00:00
|
|
|
long itemIndex = m_listBox->InsertItem( m_listBox->GetItemCount(), itemList[0] );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
m_listBox->SetItemData( itemIndex, (long) &(itemList[0]) );
|
2013-05-08 20:47:23 +00:00
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
// Adding the next columns content
|
|
|
|
for( unsigned i = 1; i < itemList.size(); i++ )
|
|
|
|
{
|
|
|
|
m_listBox->SetItem( itemIndex, i, itemList[i] );
|
|
|
|
}
|
|
|
|
}
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2013-05-08 20:47:23 +00:00
|
|
|
|
|
|
|
void EDA_LIST_DIALOG::InsertItems( const std::vector< wxArrayString >& itemList, int position )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-05-08 20:47:23 +00:00
|
|
|
for( unsigned row = 0; row < itemList.size(); row++ )
|
2013-03-19 01:25:19 +00:00
|
|
|
{
|
2013-05-08 20:47:23 +00:00
|
|
|
wxASSERT( (int) itemList[row].GetCount() == m_listBox->GetColumnCount() );
|
|
|
|
|
|
|
|
for( unsigned col = 0; col < itemList[row].GetCount(); col++ )
|
2013-03-19 01:25:19 +00:00
|
|
|
{
|
2013-05-08 20:47:23 +00:00
|
|
|
long itemIndex;
|
|
|
|
|
|
|
|
if( col == 0 )
|
|
|
|
{
|
|
|
|
itemIndex = m_listBox->InsertItem( row+position, itemList[row].Item( col ) );
|
|
|
|
m_listBox->SetItemData( itemIndex, (long) &itemList[row].Item( col ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_listBox->SetItem( itemIndex, col, itemList[row].Item( col ) );
|
|
|
|
}
|
2013-03-19 01:25:19 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-10 12:18:43 +00:00
|
|
|
|
|
|
|
if( m_sortList )
|
|
|
|
sortList();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2013-01-10 12:18:43 +00:00
|
|
|
void EDA_LIST_DIALOG::onCancelClick( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
EndModal( wxID_CANCEL );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
void EDA_LIST_DIALOG::onListItemSelected( wxListEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-05-08 20:47:23 +00:00
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
if( m_callBackFct )
|
2007-12-11 23:12:37 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
m_messages->Clear();
|
2013-03-19 01:25:19 +00:00
|
|
|
wxString text = GetTextSelection();
|
2010-11-19 18:50:23 +00:00
|
|
|
m_callBackFct( text );
|
|
|
|
m_messages->WriteText( text );
|
2007-12-11 23:12:37 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
void EDA_LIST_DIALOG::onListItemActivated( wxListEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
EndModal( wxID_OK );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-10 12:18:43 +00:00
|
|
|
void EDA_LIST_DIALOG::onOkClick( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
EndModal( wxID_OK );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-12-11 23:12:37 +00:00
|
|
|
|
2013-01-10 12:18:43 +00:00
|
|
|
void EDA_LIST_DIALOG::onClose( wxCloseEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
EndModal( wxID_CANCEL );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
/* Sort alphabetically, case insensitive.
|
2007-10-07 03:08:24 +00:00
|
|
|
*/
|
2013-03-19 01:25:19 +00:00
|
|
|
static int wxCALLBACK MyCompareFunction( long aItem1, long aItem2, long aSortData )
|
2013-05-08 20:47:23 +00:00
|
|
|
{
|
2013-03-19 01:25:19 +00:00
|
|
|
wxString* component1Name = (wxString*) aItem1;
|
|
|
|
wxString* component2Name = (wxString*) aItem2;
|
2013-05-08 20:47:23 +00:00
|
|
|
|
|
|
|
return StrNumCmp( *component1Name, *component2Name, INT_MAX, true );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2013-05-08 20:47:23 +00:00
|
|
|
|
2013-01-10 12:18:43 +00:00
|
|
|
void EDA_LIST_DIALOG::sortList()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-03-19 01:25:19 +00:00
|
|
|
m_listBox->SortItems( MyCompareFunction, 0 );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|