X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f88fc76e8f9598f32707686e8d9d7a15a3c7fd78..e388dc214c74a5ac2d3c4d5f810fcfbd5f7fa01a:/src/mac/carbon/listctrl_mac.cpp diff --git a/src/mac/carbon/listctrl_mac.cpp b/src/mac/carbon/listctrl_mac.cpp index e307203d98..337bbaa8e8 100644 --- a/src/mac/carbon/listctrl_mac.cpp +++ b/src/mac/carbon/listctrl_mac.cpp @@ -774,7 +774,8 @@ wxListCtrl::~wxListCtrl() } /*static*/ -wxVisualAttributes wxListCtrl::GetClassDefaultAttributes(wxWindowVariant variant) +wxVisualAttributes +wxListCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) { wxVisualAttributes attr; @@ -1046,31 +1047,37 @@ 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) { for (int column = 0; column < GetColumnCount(); column++) { wxListItem colInfo; - GetColumn(col, colInfo); + GetColumn(column, colInfo); colInfo.SetWidth(width); - SetColumn(col, colInfo); + SetColumn(column, colInfo); - m_dbImpl->SetColumnWidth(col, mywidth); + 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; } @@ -3328,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