Browse Source

ListBox perf improvements

On Windows, reduces trips through the windows message system, substantially increasing performance of long list boxes (such as in the footprint assignment tool)
7.0
Brian Fiete 3 years ago
committed by Wayne Stambaugh
parent
commit
0e758d6bc2
  1. 28
      cvpcb/listbox_base.cpp
  2. 2
      cvpcb/listboxes.h

28
cvpcb/listbox_base.cpp

@ -48,33 +48,43 @@ ITEMS_LISTBOX_BASE::~ITEMS_LISTBOX_BASE()
void ITEMS_LISTBOX_BASE::UpdateWidth( int aLine )
{
wxClientDC dc( this );
int itemCount = GetItemCount();
// Less than zero: recalculate width of all items.
if( aLine < 0 )
{
columnWidth = 0;
for( int ii = 0; ii < GetItemCount(); ii++ )
for( int ii = 0; ii < itemCount; ii++ )
{
UpdateLineWidth( (unsigned)ii );
UpdateLineWidth( (unsigned)ii, dc );
}
}
// Zero or above: update from a single line.
else
{
if( aLine < GetItemCount() )
UpdateLineWidth( (unsigned)aLine );
if( aLine < itemCount )
UpdateLineWidth( (unsigned)aLine, dc );
}
}
void ITEMS_LISTBOX_BASE::UpdateLineWidth( unsigned aLine )
void ITEMS_LISTBOX_BASE::UpdateLineWidth( unsigned aLine, wxClientDC& dc )
{
wxClientDC dc( this );
wxCoord w;
int newWidth = 10; // Value of AUTOSIZE_COL_MARGIN from wxWidgets source.
wxString str;
dc.SetFont( GetFont() );
dc.GetTextExtent( GetItemText( aLine, 0 ) + " ", &w, nullptr );
if( IsVirtual() )
str = OnGetItemText( aLine, 0 );
else
str = GetItemText( aLine, 0 );
str += " ";
dc.GetTextExtent( str, &w, nullptr );
newWidth += w;
if( newWidth > columnWidth )
@ -93,8 +103,10 @@ int ITEMS_LISTBOX_BASE::GetSelection()
void ITEMS_LISTBOX_BASE::DeselectAll()
{
for( int i = 0; i < GetItemCount(); i++ )
for( int i = GetFirstSelected(); i >= 0; i = GetNextSelected(i))
{
Select( i, false );
}
}

2
cvpcb/listboxes.h

@ -76,7 +76,7 @@ private:
* if needed. This is effectively the wxListCtrl code for autosizing.
* NB. it relies on the caller checking the given line number is valid.
*/
void UpdateLineWidth( unsigned aLine );
void UpdateLineWidth( unsigned aLine, wxClientDC& dc );
int columnWidth;
};

Loading…
Cancel
Save