Always give all the remaining space to the first wxTreeListCtrl column.

Under GTK the columns of wxDataViewCtrl (and hence wxTreeListCtrl) are always
resized to cover the entire control width. For consistency, also do it under
the other platforms and give the remaining space to the first column and not
to the last one as GTK does by default, as the first column is more important.

Do this even if this results in reducing the size of the column: presumably,
if the entire control itself can be resized, the user wouldn't bother resizing
the columns and, on the contrary, if the user did resize the columns, the
entire control size is unlikely to change, so in practice we don't risk
overriding the user preferences and reducing as well as increasing the first
column width works much better by default as it doesn't leave the other
columns invisible after making the control wider and than reverting it back to
its initial, more narrow, state again.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69182 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2011-09-22 10:35:58 +00:00
parent 7d0cf3f9be
commit 6b719a1c09
2 changed files with 16 additions and 13 deletions

View File

@@ -1608,29 +1608,27 @@ void wxTreeListCtrl::OnSize(wxSizeEvent& event)
const wxRect rect = GetClientRect();
m_view->SetSize(rect);
// Resize the first column to take the remaining available space, if
// any.
// Resize the first column to take the remaining available space.
const unsigned numColumns = GetColumnCount();
if ( !numColumns )
return;
// There is a bug in generic wxDataViewCtrl: if the column width sums
// up to the total size, horizontal scrollbar (unnecessarily) appears,
// so subtract 10 pixels to ensure this doesn't happen.
int remainingWidth = rect.width - 10;
// so subtract a bit to ensure this doesn't happen.
int remainingWidth = rect.width - 5;
for ( unsigned n = 1; n < GetColumnCount(); n++ )
{
remainingWidth -= GetColumnWidth(n);
if ( remainingWidth < 0 )
break;
if ( remainingWidth <= 0 )
{
// There is not enough space, as we're not going to give the
// first column negative width anyhow, just don't do anything.
return;
}
}
// We don't decrease the width of the first column, even if we had
// increased it ourselves, because we want to avoid changing its size
// if the user resized it. We might want to remember if this was the
// case or if we only ever adjusted it automatically in the future.
if ( remainingWidth > GetColumnWidth(0) )
SetColumnWidth(0, remainingWidth);
SetColumnWidth(0, remainingWidth);
}
}