From: Václav Slavík Date: Sun, 20 Apr 2008 22:10:23 +0000 (+0000) Subject: implement wxLIST_AUTOSIZE support in wxMac's wxListCtrl X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/916989dfb95b7e4a72234d946b8e078235046e05 implement wxLIST_AUTOSIZE support in wxMac's wxListCtrl git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53276 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/mac/carbon/listctrl.h b/include/wx/mac/carbon/listctrl.h index 16ccc810fa..c2aad6d74f 100644 --- a/include/wx/mac/carbon/listctrl.h +++ b/include/wx/mac/carbon/listctrl.h @@ -414,6 +414,8 @@ protected: int m_count; // for virtual lists, store item count private: + int CalcColumnAutoWidth(int col) const; + DECLARE_EVENT_TABLE() }; diff --git a/src/mac/carbon/listctrl_mac.cpp b/src/mac/carbon/listctrl_mac.cpp index 21b7bd0b84..337bbaa8e8 100644 --- a/src/mac/carbon/listctrl_mac.cpp +++ b/src/mac/carbon/listctrl_mac.cpp @@ -1047,9 +1047,10 @@ bool wxListCtrl::SetColumnWidth(int col, int width) if (m_dbImpl) { - int mywidth = width; - if (width == wxLIST_AUTOSIZE || width == wxLIST_AUTOSIZE_USEHEADER) - mywidth = 150; + if ( width == wxLIST_AUTOSIZE_USEHEADER ) + { + width = 150; // FIXME + } if (col == -1) { @@ -1061,17 +1062,22 @@ bool wxListCtrl::SetColumnWidth(int col, int width) colInfo.SetWidth(width); SetColumn(column, colInfo); + const int mywidth = (width == wxLIST_AUTOSIZE) + ? CalcColumnAutoWidth(column) : width; m_dbImpl->SetColumnWidth(column, mywidth); } } else { + if ( width == wxLIST_AUTOSIZE ) + width = CalcColumnAutoWidth(col); + wxListItem colInfo; GetColumn(col, colInfo); colInfo.SetWidth(width); SetColumn(col, colInfo); - m_dbImpl->SetColumnWidth(col, mywidth); + m_dbImpl->SetColumnWidth(col, width); } return true; } @@ -3329,5 +3335,36 @@ void wxMacListCtrlItem::SetColumnInfo( unsigned int column, wxListItem* item ) } } +int wxListCtrl::CalcColumnAutoWidth(int col) const +{ + int width = 0; + + for ( int i = 0; i < GetItemCount(); i++ ) + { + wxListItem info; + info.SetMask(wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE); + info.SetId(i); + info.SetColumn(col); + GetItem(info); + + const wxFont font = info.GetFont(); + + int w = 0; + if ( font.IsOk() ) + GetTextExtent(info.GetText(), &w, NULL, NULL, NULL, &font); + else + GetTextExtent(info.GetText(), &w, NULL); + + w += 2 * kItemPadding; + + if ( info.GetImage() != -1 ) + w += kIconWidth; + + width = wxMax(width, w); + } + + return width; +} + #endif // wxUSE_LISTCTRL