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

@@ -319,7 +319,9 @@ public:
@param width @param width
The width of the column in pixels or the special The width of the column in pixels or the special
wxCOL_WIDTH_AUTOSIZE value indicating that the column should adjust wxCOL_WIDTH_AUTOSIZE value indicating that the column should adjust
to its contents. to its contents. Notice that the first column is special and will
be always resized to fill all the space not taken by the other
columns, i.e. the width specified here is ignored for it.
@param align @param align
Alignment of both the column header and its items. Alignment of both the column header and its items.
@param flags @param flags
@@ -360,6 +362,9 @@ public:
Set column width to either the given value in pixels or to the value Set column width to either the given value in pixels or to the value
large enough to fit all of the items if width is wxCOL_WIDTH_AUTOSIZE. large enough to fit all of the items if width is wxCOL_WIDTH_AUTOSIZE.
Notice that setting the width of the first column is ignored as this
column is always resized to fill the space left by the other columns.
*/ */
void SetColumnWidth(unsigned col, int width); void SetColumnWidth(unsigned col, int width);

View File

@@ -1608,29 +1608,27 @@ void wxTreeListCtrl::OnSize(wxSizeEvent& event)
const wxRect rect = GetClientRect(); const wxRect rect = GetClientRect();
m_view->SetSize(rect); m_view->SetSize(rect);
// Resize the first column to take the remaining available space, if // Resize the first column to take the remaining available space.
// any.
const unsigned numColumns = GetColumnCount(); const unsigned numColumns = GetColumnCount();
if ( !numColumns ) if ( !numColumns )
return; return;
// There is a bug in generic wxDataViewCtrl: if the column width sums // There is a bug in generic wxDataViewCtrl: if the column width sums
// up to the total size, horizontal scrollbar (unnecessarily) appears, // up to the total size, horizontal scrollbar (unnecessarily) appears,
// so subtract 10 pixels to ensure this doesn't happen. // so subtract a bit to ensure this doesn't happen.
int remainingWidth = rect.width - 10; int remainingWidth = rect.width - 5;
for ( unsigned n = 1; n < GetColumnCount(); n++ ) for ( unsigned n = 1; n < GetColumnCount(); n++ )
{ {
remainingWidth -= GetColumnWidth(n); remainingWidth -= GetColumnWidth(n);
if ( remainingWidth < 0 ) if ( remainingWidth <= 0 )
break; {
// 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 SetColumnWidth(0, remainingWidth);
// 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);
} }
} }