implement wxLIST_AUTOSIZE support in wxMac's wxListCtrl
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@53275 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -188,6 +188,7 @@ wxMac:
|
|||||||
|
|
||||||
- Fixed cursor for wxBusyCursor and wxContextHelp.
|
- Fixed cursor for wxBusyCursor and wxContextHelp.
|
||||||
- Fixed wxListCtrl to respect items' non-default fonts.
|
- Fixed wxListCtrl to respect items' non-default fonts.
|
||||||
|
- wxListCtrl::SetColumnWidth() now supports wxLIST_AUTOSIZE.
|
||||||
|
|
||||||
|
|
||||||
2.8.7
|
2.8.7
|
||||||
|
@@ -420,6 +420,9 @@ protected:
|
|||||||
|
|
||||||
int m_count; // for virtual lists, store item count
|
int m_count; // for virtual lists, store item count
|
||||||
|
|
||||||
|
private:
|
||||||
|
int CalcColumnAutoWidth(int col) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
@@ -1052,9 +1052,10 @@ bool wxListCtrl::SetColumnWidth(int col, int width)
|
|||||||
|
|
||||||
if (m_dbImpl)
|
if (m_dbImpl)
|
||||||
{
|
{
|
||||||
int mywidth = width;
|
if ( width == wxLIST_AUTOSIZE_USEHEADER )
|
||||||
if (width == wxLIST_AUTOSIZE || width == wxLIST_AUTOSIZE_USEHEADER)
|
{
|
||||||
mywidth = 150;
|
width = 150; // FIXME
|
||||||
|
}
|
||||||
|
|
||||||
if (col == -1)
|
if (col == -1)
|
||||||
{
|
{
|
||||||
@@ -1066,17 +1067,22 @@ bool wxListCtrl::SetColumnWidth(int col, int width)
|
|||||||
colInfo.SetWidth(width);
|
colInfo.SetWidth(width);
|
||||||
SetColumn(column, colInfo);
|
SetColumn(column, colInfo);
|
||||||
|
|
||||||
|
const int mywidth = (width == wxLIST_AUTOSIZE)
|
||||||
|
? CalcColumnAutoWidth(column) : width;
|
||||||
m_dbImpl->SetColumnWidth(column, mywidth);
|
m_dbImpl->SetColumnWidth(column, mywidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if ( width == wxLIST_AUTOSIZE )
|
||||||
|
width = CalcColumnAutoWidth(col);
|
||||||
|
|
||||||
wxListItem colInfo;
|
wxListItem colInfo;
|
||||||
GetColumn(col, colInfo);
|
GetColumn(col, colInfo);
|
||||||
|
|
||||||
colInfo.SetWidth(width);
|
colInfo.SetWidth(width);
|
||||||
SetColumn(col, colInfo);
|
SetColumn(col, colInfo);
|
||||||
m_dbImpl->SetColumnWidth(col, mywidth);
|
m_dbImpl->SetColumnWidth(col, width);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -3339,5 +3345,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
|
#endif // wxUSE_LISTCTRL
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user