From: Vadim Zeitlin Date: Tue, 12 Jun 2012 22:15:38 +0000 (+0000) Subject: Slightly improve best size calculation for wxListCtrl with wxLC_NO_HEADER. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/3aa1dc1ef5b87a3cce221ca5ea03353be06f5510?ds=inline Slightly improve best size calculation for wxListCtrl with wxLC_NO_HEADER. Use some arbitrary but relatively large width and height instead of falling back to wxControlBase best size computation which, at least in wxGTK, simply returns (1, 1) resulting in list control of unusably small size. This is, of course, still far from ideal and we should really use the items to calculate the best width but it at least allow the list control in the generic log dialog to be shown correctly in wxGTK. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71733 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/listctrlcmn.cpp b/src/common/listctrlcmn.cpp index 5edcf420f1..a4cd12f288 100644 --- a/src/common/listctrlcmn.cpp +++ b/src/common/listctrlcmn.cpp @@ -185,6 +185,9 @@ wxSize wxListCtrlBase::DoGetBestClientSize() const if ( !InReportView() ) return wxControl::DoGetBestClientSize(); + int totalWidth; + wxClientDC dc(const_cast(this)); + // In report mode, we use only the column headers, not items, to determine // the best width. The reason for this is that it's easier (we can't just // iterate over all items, especially not in a virtual control, so we'd @@ -196,15 +199,17 @@ wxSize wxListCtrlBase::DoGetBestClientSize() const // headers are just truncated if there is not enough place for them. const int columns = GetColumnCount(); if ( HasFlag(wxLC_NO_HEADER) || !columns ) - return wxControl::DoGetBestClientSize(); - - wxClientDC dc(const_cast(this)); - - // Total width of all headers determines the best control width. - int totalWidth = 0; - for ( int col = 0; col < columns; col++ ) { - totalWidth += GetColumnWidth(col); + // Use some arbitrary width. + totalWidth = 50*dc.GetCharWidth(); + } + else // We do have columns, use them to determine the best width. + { + totalWidth = 0; + for ( int col = 0; col < columns; col++ ) + { + totalWidth += GetColumnWidth(col); + } } // Use some arbitrary height, there is no good way to determine it.