From 56615d1653e40672ef4747631449a4f2a5ab9001 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Tue, 26 Nov 2013 11:08:07 -0600 Subject: [PATCH] FIX: work around for wx 2.8 bug affecting wxListCtrl column resizing. --- common/displlst.cpp | 61 ++++++++++++++++++++++++++-------------- include/dialog_helpers.h | 3 +- 2 files changed, 42 insertions(+), 22 deletions(-) diff --git a/common/displlst.cpp b/common/displlst.cpp index e03910ee55..6f100d4a17 100644 --- a/common/displlst.cpp +++ b/common/displlst.cpp @@ -56,15 +56,39 @@ EDA_LIST_DIALOG::EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitl InsertItems( aItemList, 0 ); - for( unsigned i = 0; i < aItemHeaders.Count(); i++ ) - m_listBox->SetColumnWidth( i, wxLIST_AUTOSIZE ); - if( m_callBackFct == NULL ) { m_messages->Show( false ); m_staticTextMsg->Show( false ); } + for( unsigned col = 0; col < aItemHeaders.Count(); ++col ) + { + m_listBox->SetColumnWidth( col, wxLIST_AUTOSIZE ); + +#if !wxCHECK_VERSION( 2, 9, 0 ) + // include the column header in the width decision, wx 2.8 forgets this: + wxListItem col_info; + + m_listBox->GetColumn( col, col_info ); + + wxString header = col_info.GetText(); + int headerz = GetTextSize( header, m_listBox ).x; + + // A reasonable column header has about 14 pixels of whitespace + // in addition to the width of the text itself. + headerz += 14; + + if( headerz > col_info.GetWidth() ) + { + col_info.SetWidth( headerz ); + + m_listBox->SetColumn( col, col_info ); + } +#endif + } + + #if !wxCHECK_VERSION( 2, 9, 0 ) // wx 2.8.x has bug in wxListCtrl WRT honoring the omission of wxHSCROLL, at least // on gtk2. Fix by setting minimum width so horizontal wxListCtrl scrolling is @@ -77,8 +101,6 @@ EDA_LIST_DIALOG::EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitl width += m_listBox->GetColumnWidth( col ) + 2; } - //width += 40; // vert scroll bar. - wxSize sz = m_listBox->GetSize(); sz.SetWidth( width ); @@ -112,11 +134,6 @@ EDA_LIST_DIALOG::EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitl } -EDA_LIST_DIALOG::~EDA_LIST_DIALOG() -{ -} - - void EDA_LIST_DIALOG::textChangeInFilterBox( wxCommandEvent& event ) { wxString filter; @@ -143,22 +160,24 @@ void EDA_LIST_DIALOG::textChangeInFilterBox( wxCommandEvent& event ) wxString EDA_LIST_DIALOG::GetTextSelection( int aColumn ) { - wxCHECK_MSG( aColumn < m_listBox->GetColumnCount(), wxEmptyString, + wxCHECK_MSG( unsigned( aColumn ) < unsigned( m_listBox->GetColumnCount() ), wxEmptyString, wxT( "Invalid list control column." ) ); - wxListItem info; - wxString text; - long item = -1; - item = m_listBox->GetNextItem( item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); + long item = m_listBox->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); - info.m_mask = wxLIST_MASK_TEXT; - info.m_itemId = item; - info.m_col = aColumn; + if( item >= 0 ) // if something is selected. + { + wxListItem info; - if( !m_listBox->GetItem( info ) ) - return wxEmptyString; + info.m_mask = wxLIST_MASK_TEXT; + info.m_itemId = item; + info.m_col = aColumn; - return info.m_text; + if( m_listBox->GetItem( info ) ) + return info.m_text; + } + + return wxEmptyString; } diff --git a/include/dialog_helpers.h b/include/dialog_helpers.h index dc621cab8a..9b33e23d37 100644 --- a/include/dialog_helpers.h +++ b/include/dialog_helpers.h @@ -74,7 +74,8 @@ public: const wxString& aRefText, void(*aCallBackFunction)(wxString& Text) = NULL, bool aSortList = false ); - ~EDA_LIST_DIALOG(); + + // ~EDA_LIST_DIALOG() {} void Append( const wxArrayString& aItemStr ); void InsertItems( const std::vector& aItemList, int aPosition = 0 );