Cvpcb: fix bug Bug #1386933 (Horizontal scrollbars not appearing in CvPcb)

This commit is contained in:
unknown 2014-11-12 11:46:40 +01:00 committed by jean-pierre charras
parent 9e6ed2b75f
commit 9524ad1f17
6 changed files with 75 additions and 51 deletions

View File

@ -47,7 +47,6 @@ COMPONENTS_LISTBOX::~COMPONENTS_LISTBOX()
BEGIN_EVENT_TABLE( COMPONENTS_LISTBOX, ITEMS_LISTBOX_BASE ) BEGIN_EVENT_TABLE( COMPONENTS_LISTBOX, ITEMS_LISTBOX_BASE )
EVT_SIZE( ITEMS_LISTBOX_BASE::OnSize )
EVT_CHAR( COMPONENTS_LISTBOX::OnChar ) EVT_CHAR( COMPONENTS_LISTBOX::OnChar )
EVT_LIST_ITEM_SELECTED( ID_CVPCB_COMPONENT_LIST, COMPONENTS_LISTBOX::OnSelectComponent ) EVT_LIST_ITEM_SELECTED( ID_CVPCB_COMPONENT_LIST, COMPONENTS_LISTBOX::OnSelectComponent )
END_EVENT_TABLE() END_EVENT_TABLE()
@ -72,14 +71,19 @@ void COMPONENTS_LISTBOX::SetString( unsigned linecount, const wxString& text )
linecount = m_ComponentList.Count() - 1; linecount = m_ComponentList.Count() - 1;
if( m_ComponentList.Count() > 0 ) if( m_ComponentList.Count() > 0 )
{
m_ComponentList[linecount] = text; m_ComponentList[linecount] = text;
UpdateWidth( linecount );
}
} }
void COMPONENTS_LISTBOX::AppendLine( const wxString& text ) void COMPONENTS_LISTBOX::AppendLine( const wxString& text )
{ {
m_ComponentList.Add( text ); m_ComponentList.Add( text );
SetItemCount( m_ComponentList.Count() ); int lines = m_ComponentList.Count();
SetItemCount( lines );
UpdateWidth( lines - 1 );
} }

View File

@ -67,6 +67,7 @@ void FOOTPRINTS_LISTBOX::SetString( unsigned linecount, const wxString& text )
linecount = count - 1; linecount = count - 1;
m_footprintList[linecount] = text; m_footprintList[linecount] = text;
} }
UpdateWidth( linecount );
} }
@ -90,7 +91,9 @@ wxString FOOTPRINTS_LISTBOX::GetSelectedFootprint()
void FOOTPRINTS_LISTBOX::AppendLine( const wxString& text ) void FOOTPRINTS_LISTBOX::AppendLine( const wxString& text )
{ {
m_footprintList.Add( text ); m_footprintList.Add( text );
SetItemCount( m_footprintList.Count() ); int lines = m_footprintList.Count();
SetItemCount( lines );
UpdateWidth( lines - 1 );
} }
@ -179,24 +182,12 @@ void FOOTPRINTS_LISTBOX::SetFootprints( FOOTPRINT_LIST& aList, const wxString& a
SetItemCount( m_footprintList.GetCount() ); SetItemCount( m_footprintList.GetCount() );
SetSelection( selection, true ); SetSelection( selection, true );
RefreshItems( 0L, m_footprintList.GetCount()-1 ); RefreshItems( 0L, m_footprintList.GetCount()-1 );
UpdateWidth();
#if defined (__WXGTK__ ) //&& wxMINOR_VERSION == 8
// @bug On GTK and wxWidgets 2.8.x, this will assert in debug builds because the
// column parameter is -1. This was the only way to prevent GTK3 from
// ellipsizing long strings down to a few characters. It still doesn't set
// the scroll bars correctly (too short) but it's better than any of the
// other alternatives. If someone knows how to fix this, please do.
SetColumnWidth( -1, wxLIST_AUTOSIZE );
#else
SetColumnWidth( 0, wxLIST_AUTOSIZE );
#endif
} }
} }
BEGIN_EVENT_TABLE( FOOTPRINTS_LISTBOX, ITEMS_LISTBOX_BASE ) BEGIN_EVENT_TABLE( FOOTPRINTS_LISTBOX, ITEMS_LISTBOX_BASE )
EVT_SIZE( ITEMS_LISTBOX_BASE::OnSize )
EVT_CHAR( FOOTPRINTS_LISTBOX::OnChar ) EVT_CHAR( FOOTPRINTS_LISTBOX::OnChar )
EVT_LIST_ITEM_SELECTED( ID_CVPCB_FOOTPRINT_LIST, FOOTPRINTS_LISTBOX::OnLeftClick ) EVT_LIST_ITEM_SELECTED( ID_CVPCB_FOOTPRINT_LIST, FOOTPRINTS_LISTBOX::OnLeftClick )
EVT_LIST_ITEM_ACTIVATED( ID_CVPCB_FOOTPRINT_LIST, FOOTPRINTS_LISTBOX::OnLeftDClick ) EVT_LIST_ITEM_ACTIVATED( ID_CVPCB_FOOTPRINT_LIST, FOOTPRINTS_LISTBOX::OnLeftDClick )

View File

@ -66,6 +66,7 @@ void LIBRARY_LISTBOX::SetString( unsigned linecount, const wxString& text )
if( linecount >= count ) if( linecount >= count )
linecount = count - 1; linecount = count - 1;
m_libraryList[linecount] = text; m_libraryList[linecount] = text;
UpdateWidth( linecount );
} }
} }
@ -87,7 +88,9 @@ wxString LIBRARY_LISTBOX::GetSelectedLibrary()
void LIBRARY_LISTBOX::AppendLine( const wxString& text ) void LIBRARY_LISTBOX::AppendLine( const wxString& text )
{ {
m_libraryList.Add( text ); m_libraryList.Add( text );
SetItemCount( m_libraryList.Count() ); int lines = m_libraryList.Count();
SetItemCount( lines );
UpdateWidth( lines - 1 );
} }
@ -129,23 +132,12 @@ void LIBRARY_LISTBOX::SetLibraryList( const wxArrayString& aList )
if( m_libraryList.Count() ) if( m_libraryList.Count() )
{ {
RefreshItems( 0L, m_libraryList.Count()-1 ); RefreshItems( 0L, m_libraryList.Count()-1 );
UpdateWidth();
#if defined (__WXGTK__ ) && wxMINOR_VERSION == 8
// @bug On GTK and wxWidgets 2.8.x, this will assert in debug builds because the
// column parameter is -1. This was the only way to prevent GTK3 from
// ellipsizing long strings down to a few characters. It still doesn't set
// the scroll bars correctly (too short) but it's better than any of the
// other alternatives. If someone knows how to fix this, please do.
SetColumnWidth( -1, wxLIST_AUTOSIZE );
#else
SetColumnWidth( 0, wxLIST_AUTOSIZE );
#endif
} }
} }
BEGIN_EVENT_TABLE( LIBRARY_LISTBOX, ITEMS_LISTBOX_BASE ) BEGIN_EVENT_TABLE( LIBRARY_LISTBOX, ITEMS_LISTBOX_BASE )
EVT_SIZE( ITEMS_LISTBOX_BASE::OnSize )
EVT_CHAR( LIBRARY_LISTBOX::OnChar ) EVT_CHAR( LIBRARY_LISTBOX::OnChar )
EVT_LIST_ITEM_SELECTED( ID_CVPCB_LIBRARY_LIST, LIBRARY_LISTBOX::OnSelectLibrary ) EVT_LIST_ITEM_SELECTED( ID_CVPCB_LIBRARY_LIST, LIBRARY_LISTBOX::OnSelectLibrary )
END_EVENT_TABLE() END_EVENT_TABLE()

View File

@ -445,6 +445,10 @@ bool CVPCB_MAINFRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, i
UpdateTitle(); UpdateTitle();
// Resize the components list box. This is needed in case the
// contents have shrunk compared to the previous netlist.
m_compListBox->UpdateWidth();
// OSX need it since some objects are "rebuild" just make aware AUI // OSX need it since some objects are "rebuild" just make aware AUI
// Fixes #1258081 // Fixes #1258081
m_auimgr.Update(); m_auimgr.Update();
@ -949,17 +953,7 @@ void CVPCB_MAINFRAME::BuildCmpListBox()
m_compListBox->SetItemCount( m_compListBox->m_ComponentList.Count() ); m_compListBox->SetItemCount( m_compListBox->m_ComponentList.Count() );
m_compListBox->SetSelection( 0, true ); m_compListBox->SetSelection( 0, true );
m_compListBox->RefreshItems( 0L, m_compListBox->m_ComponentList.Count()-1 ); m_compListBox->RefreshItems( 0L, m_compListBox->m_ComponentList.Count()-1 );
m_compListBox->UpdateWidth();
#if defined (__WXGTK__ )
// @bug On GTK and wxWidgets 2.8.x, this will assert in debug builds because the
// column parameter is -1. This was the only way to prevent GTK3 from
// ellipsizing long strings down to a few characters. It still doesn't set
// the scroll bars correctly (too short) but it's better than any of the
// other alternatives. If someone knows how to fix this, please do.
m_compListBox->SetColumnWidth( -1, wxLIST_AUTOSIZE );
#else
m_compListBox->SetColumnWidth( 0, wxLIST_AUTOSIZE );
#endif
} }
} }

View File

@ -50,9 +50,23 @@ public:
~ITEMS_LISTBOX_BASE(); ~ITEMS_LISTBOX_BASE();
int GetSelection(); int GetSelection();
void OnSize( wxSizeEvent& event );
virtual CVPCB_MAINFRAME* GetParent() const; virtual CVPCB_MAINFRAME* GetParent() const;
/* Function UpdateWidth
*
* Update the width of the column based on its contents.
*
* @param aLine is the line to calculate the width from. If positive, the
* width will only be increased if needed. If negative, we start from
* scratch and all lines are considered, i.e., the column may be shrunk.
*/
void UpdateWidth( int aLine = -1 );
private:
void UpdateLineWidth( unsigned aLine );
int columnWidth;
}; };

View File

@ -44,10 +44,9 @@
ITEMS_LISTBOX_BASE::ITEMS_LISTBOX_BASE( CVPCB_MAINFRAME* aParent, wxWindowID aId, ITEMS_LISTBOX_BASE::ITEMS_LISTBOX_BASE( CVPCB_MAINFRAME* aParent, wxWindowID aId,
const wxPoint& aLocation, const wxSize& aSize, const wxPoint& aLocation, const wxSize& aSize,
long aStyle) : long aStyle) :
wxListView( aParent, aId, aLocation, aSize, LISTB_STYLE | aStyle ) wxListView( aParent, aId, aLocation, aSize, LISTB_STYLE | aStyle ), columnWidth(0)
{ {
InsertColumn( 0, wxEmptyString ); InsertColumn( 0, wxEmptyString );
SetColumnWidth( 0, wxLIST_AUTOSIZE );
} }
@ -56,17 +55,47 @@ ITEMS_LISTBOX_BASE::~ITEMS_LISTBOX_BASE()
} }
/* void ITEMS_LISTBOX_BASE::UpdateWidth( int aLine )
* Adjust the column width to the entire available window width
*/
void ITEMS_LISTBOX_BASE::OnSize( wxSizeEvent& event )
{ {
wxSize size = GetClientSize(); // Less than zero: recalculate width of all items.
int width = 0; if( aLine < 0 )
{
columnWidth = 0;
for( int ii = 0; ii < GetItemCount(); ii++ )
{
UpdateLineWidth( (unsigned)ii );
}
}
SetColumnWidth( 0, std::max( width, size.x ) ); // Zero or above: update from a single line.
else
{
if( aLine < GetItemCount() )
UpdateLineWidth( (unsigned)aLine );
}
}
event.Skip();
/*
* 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 );
}
} }