2013-04-25 16:29:35 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2012 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-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file listboxes.cpp
|
|
|
|
* @brief Implementation of class for displaying footprint list and component lists.
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <wxstruct.h>
|
|
|
|
#include <macros.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <cvpcb.h>
|
|
|
|
#include <cvpcb_mainframe.h>
|
2016-02-25 09:52:29 +00:00
|
|
|
#include <listview_classes.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <cvpcb_id.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* Basic class (from wxListView) to display component and footprint lists
|
|
|
|
* Not directly used: the 2 list boxes actually used are derived from it
|
|
|
|
******************************************************************************/
|
2007-10-29 08:22:45 +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,
|
|
|
|
long aStyle) :
|
2015-06-05 13:46:05 +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
|
|
|
{
|
2014-11-12 10:46:40 +00:00
|
|
|
// Less than zero: recalculate width of all items.
|
|
|
|
if( aLine < 0 )
|
|
|
|
{
|
|
|
|
columnWidth = 0;
|
|
|
|
for( int ii = 0; ii < GetItemCount(); ii++ )
|
|
|
|
{
|
|
|
|
UpdateLineWidth( (unsigned)ii );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Zero or above: update from a single line.
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( aLine < GetItemCount() )
|
|
|
|
UpdateLineWidth( (unsigned)aLine );
|
|
|
|
}
|
|
|
|
}
|
2007-10-29 08:22:45 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2014-11-12 10:46:40 +00:00
|
|
|
/*
|
|
|
|
* Calculate the width of the given line, and increase the column width
|
|
|
|
* if needed. This is effectively the wxListCtrl code for autosizing.
|
|
|
|
* NB. it relies on the caller checking the given line number is valid.
|
|
|
|
*/
|
|
|
|
void ITEMS_LISTBOX_BASE::UpdateLineWidth( unsigned aLine )
|
|
|
|
{
|
|
|
|
wxClientDC dc( this );
|
|
|
|
wxCoord w;
|
|
|
|
int newWidth = 10; // Value of AUTOSIZE_COL_MARGIN from wxWidgets source.
|
|
|
|
|
|
|
|
dc.SetFont( GetFont() );
|
|
|
|
dc.GetTextExtent( GetItemText( aLine, 0 ) + " ", &w, NULL );
|
|
|
|
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-05-06 11:55:36 +00:00
|
|
|
/*
|
|
|
|
* Return an index for the selected item
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
2015-07-01 10:55:41 +00:00
|
|
|
/* Removes all selection in list
|
|
|
|
*/
|
|
|
|
void ITEMS_LISTBOX_BASE::DeselectAll()
|
|
|
|
{
|
|
|
|
for( int i = 0; i < GetItemCount(); i++ )
|
|
|
|
Select( i, false );
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|