2013-04-25 16:29:35 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-07-16 20:13:26 +00:00
|
|
|
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-04-25 16:29:35 +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
|
|
|
|
*/
|
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file listboxes.cpp
|
2021-03-29 10:46:05 +00:00
|
|
|
* @brief Implementation of class for displaying footprint and symbol lists.
|
2011-09-23 13:57:12 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <cvpcb_mainframe.h>
|
2018-01-28 08:51:28 +00:00
|
|
|
#include <listboxes.h>
|
2021-05-01 07:50:29 +00:00
|
|
|
#include <wx/dcclient.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-02-05 16:15:48 +00:00
|
|
|
ITEMS_LISTBOX_BASE::ITEMS_LISTBOX_BASE( CVPCB_MAINFRAME* aParent, wxWindowID aId,
|
2012-09-26 15:36:48 +00:00
|
|
|
const wxPoint& aLocation, const wxSize& aSize,
|
2021-07-16 20:13:26 +00:00
|
|
|
long aStyle ) :
|
2020-01-11 21:14:09 +00:00
|
|
|
wxListView( aParent, aId, aLocation, aSize, LISTBOX_STYLE | aStyle ),
|
|
|
|
columnWidth( 0 )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-10-29 08:22:45 +00:00
|
|
|
InsertColumn( 0, wxEmptyString );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
ITEMS_LISTBOX_BASE::~ITEMS_LISTBOX_BASE()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-10-29 08:22:45 +00:00
|
|
|
|
2014-11-12 10:46:40 +00:00
|
|
|
void ITEMS_LISTBOX_BASE::UpdateWidth( int aLine )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2022-10-22 15:05:55 +00:00
|
|
|
wxClientDC dc( this );
|
|
|
|
int itemCount = GetItemCount();
|
|
|
|
|
2014-11-12 10:46:40 +00:00
|
|
|
// Less than zero: recalculate width of all items.
|
|
|
|
if( aLine < 0 )
|
|
|
|
{
|
|
|
|
columnWidth = 0;
|
2022-10-22 15:05:55 +00:00
|
|
|
for( int ii = 0; ii < itemCount; ii++ )
|
2014-11-12 10:46:40 +00:00
|
|
|
{
|
2022-10-22 15:05:55 +00:00
|
|
|
UpdateLineWidth( (unsigned)ii, dc );
|
2014-11-12 10:46:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Zero or above: update from a single line.
|
|
|
|
else
|
|
|
|
{
|
2022-10-22 15:05:55 +00:00
|
|
|
if( aLine < itemCount )
|
|
|
|
UpdateLineWidth( (unsigned)aLine, dc );
|
2014-11-12 10:46:40 +00:00
|
|
|
}
|
|
|
|
}
|
2007-10-29 08:22:45 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2022-10-22 15:05:55 +00:00
|
|
|
void ITEMS_LISTBOX_BASE::UpdateLineWidth( unsigned aLine, wxClientDC& dc )
|
2014-11-12 10:46:40 +00:00
|
|
|
{
|
|
|
|
wxCoord w;
|
|
|
|
int newWidth = 10; // Value of AUTOSIZE_COL_MARGIN from wxWidgets source.
|
2022-10-22 15:05:55 +00:00
|
|
|
wxString str;
|
2014-11-12 10:46:40 +00:00
|
|
|
|
|
|
|
dc.SetFont( GetFont() );
|
2022-10-22 15:05:55 +00:00
|
|
|
|
|
|
|
if( IsVirtual() )
|
|
|
|
str = OnGetItemText( aLine, 0 );
|
|
|
|
else
|
|
|
|
str = GetItemText( aLine, 0 );
|
|
|
|
str += " ";
|
|
|
|
|
|
|
|
dc.GetTextExtent( str, &w, nullptr );
|
2014-11-12 10:46:40 +00:00
|
|
|
newWidth += w;
|
|
|
|
|
|
|
|
if( newWidth > columnWidth )
|
|
|
|
{
|
|
|
|
columnWidth = newWidth;
|
|
|
|
SetColumnWidth( 0, columnWidth );
|
2015-06-05 13:46:05 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
int ITEMS_LISTBOX_BASE::GetSelection()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-10-29 08:22:45 +00:00
|
|
|
return GetFirstSelected();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2015-07-01 10:55:41 +00:00
|
|
|
void ITEMS_LISTBOX_BASE::DeselectAll()
|
|
|
|
{
|
2022-10-22 15:05:55 +00:00
|
|
|
for( int i = GetFirstSelected(); i >= 0; i = GetNextSelected(i))
|
|
|
|
{
|
2015-07-01 10:55:41 +00:00
|
|
|
Select( i, false );
|
2022-10-22 15:05:55 +00:00
|
|
|
}
|
2015-07-01 10:55:41 +00:00
|
|
|
}
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2014-05-04 17:08:36 +00:00
|
|
|
CVPCB_MAINFRAME* ITEMS_LISTBOX_BASE::GetParent() const
|
2009-05-21 17:42:42 +00:00
|
|
|
{
|
2011-02-05 16:15:48 +00:00
|
|
|
return (CVPCB_MAINFRAME*) wxListView::GetParent();
|
2009-05-21 17:42:42 +00:00
|
|
|
}
|