From: Vadim Zeitlin Date: Wed, 9 May 2012 14:24:47 +0000 (+0000) Subject: Implement constrained best size calculation in wxMSW wxListCtrl. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/1e20681c9e71a8ed8bb2822015f341253a0ba60d Implement constrained best size calculation in wxMSW wxListCtrl. This fixes wxListbook controller size to avoid spurious scrollbars. Closes #13898. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71394 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index 7e47a6716a..3f795ed867 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -566,6 +566,7 @@ MSW: - Fix coordinate handling in wxDC::Blit() when source DC is a DIB. - Fix handling of composite windows in wxToolTip (Armel Asselin). - Add VT_I8 support to wxAutomationObject (PB). +- Fix wxListbook size calculations to avoid spurious scrollbars. OSX: diff --git a/include/wx/msw/listctrl.h b/include/wx/msw/listctrl.h index 75c30270be..a873d07546 100644 --- a/include/wx/msw/listctrl.h +++ b/include/wx/msw/listctrl.h @@ -384,6 +384,14 @@ protected: // common part of all ctors void Init(); + // Implement constrained best size calculation. + virtual int DoGetBestClientHeight(int width) const + { return MSWGetBestViewRect(width, -1).y; } + virtual int DoGetBestClientWidth(int height) const + { return MSWGetBestViewRect(-1, height).x; } + + wxSize MSWGetBestViewRect(int x, int y) const; + // Implement base class pure virtual methods. long DoInsertColumn(long col, const wxListItem& info); diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 3c3e797059..1b0a6c74ac 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -1333,6 +1333,29 @@ void wxListCtrl::AssignImageList(wxImageList *imageList, int which) m_ownsImageListState = true; } +// ---------------------------------------------------------------------------- +// Geometry +// ---------------------------------------------------------------------------- + +wxSize wxListCtrl::MSWGetBestViewRect(int x, int y) const +{ + const DWORD rc = ListView_ApproximateViewRect(GetHwnd(), x, y, -1); + + wxSize size(LOWORD(rc), HIWORD(rc)); + + // We have to add space for the scrollbars ourselves, they're not taken + // into account by ListView_ApproximateViewRect(), at least not with + // commctrl32.dll v6. + const DWORD mswStyle = ::GetWindowLong(GetHwnd(), GWL_STYLE); + + if ( mswStyle & WS_HSCROLL ) + size.y += wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y); + if ( mswStyle & WS_VSCROLL ) + size.x += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); + + return size; +} + // ---------------------------------------------------------------------------- // Operations // ----------------------------------------------------------------------------