From 0698da3d6bb07c3545d061e23a3403f9b020735d Mon Sep 17 00:00:00 2001 From: Carl Godkin Date: Tue, 27 Dec 2016 17:23:00 +0100 Subject: [PATCH] Resize name column in wxFileListCtrl to be as wide as possible To avoid truncating the names of the files shown in this column, allocate all the available space to it. Closes #17757. --- include/wx/generic/filectrlg.h | 1 + src/generic/filectrlg.cpp | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/wx/generic/filectrlg.h b/include/wx/generic/filectrlg.h index d460fd3e99..c7bb9ddf4a 100644 --- a/include/wx/generic/filectrlg.h +++ b/include/wx/generic/filectrlg.h @@ -160,6 +160,7 @@ public: void OnListDeleteAllItems( wxListEvent &event ); void OnListEndLabelEdit( wxListEvent &event ); void OnListColClick( wxListEvent &event ); + void OnSize( wxSizeEvent &event ); virtual void SortItems(wxFileData::fileListFieldType field, bool forward); bool GetSortDirection() const { return m_sort_forward; } diff --git a/src/generic/filectrlg.cpp b/src/generic/filectrlg.cpp index 4c030d2b14..ab960b4677 100644 --- a/src/generic/filectrlg.cpp +++ b/src/generic/filectrlg.cpp @@ -364,6 +364,7 @@ wxBEGIN_EVENT_TABLE(wxFileListCtrl,wxListCtrl) EVT_LIST_DELETE_ALL_ITEMS(wxID_ANY, wxFileListCtrl::OnListDeleteAllItems) EVT_LIST_END_LABEL_EDIT(wxID_ANY, wxFileListCtrl::OnListEndLabelEdit) EVT_LIST_COL_CLICK(wxID_ANY, wxFileListCtrl::OnListColClick) + EVT_SIZE (wxFileListCtrl::OnSize) wxEND_EVENT_TABLE() @@ -809,6 +810,25 @@ void wxFileListCtrl::OnListColClick( wxListEvent &event ) SortItems(m_sort_field, m_sort_forward); } +void wxFileListCtrl::OnSize( wxSizeEvent &event ) +{ + event.Skip(); + + if ( InReportView() ) + { + // In report mode, set name column to use remaining width. + int newNameWidth = GetClientSize().GetWidth(); + for ( int i = 1; i < GetColumnCount(); i++ ) + { + newNameWidth -= GetColumnWidth(i); + if ( newNameWidth <= 0 ) + return; + } + + SetColumnWidth(0, newNameWidth); + } +} + void wxFileListCtrl::SortItems(wxFileData::fileListFieldType field, bool forward) { m_sort_field = field;