From: Vadim Zeitlin Date: Sun, 14 Sep 2003 15:58:41 +0000 (+0000) Subject: added wxListCtrl::GetViewRect() X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/11ebea162a1d99032aa98ac649d61aaf08e428e8 added wxListCtrl::GetViewRect() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23574 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index 1c890d92f3..fc4256c960 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -40,6 +40,18 @@ versions, please update your code to not use them. OTHER CHANGES ============= +2.5.1 +----- + +wxMSW: + +- fixed wxTE_*WRAP styles handling + +All (GUI): + +- added wxListCtrl::GetViewRect() + + 2.5.0 ----- diff --git a/docs/latex/wx/listctrl.tex b/docs/latex/wx/listctrl.tex index c1d13c0c87..b4e57c7a4f 100644 --- a/docs/latex/wx/listctrl.tex +++ b/docs/latex/wx/listctrl.tex @@ -463,6 +463,19 @@ Gets the text colour of the list control. Gets the index of the topmost visible item when in list or report view. + +\membersection{wxRect}{wxListCtrl::GetViewRect}\label{wxlistctrlgetviewrect} + +\constfunc{wxRect}{GetViewRect}{\void} + +Returns the rectangle taken by all items in the control. In other words, if the +controls client size were equal to the size of this rectangle, no scrollbars +would be needed and no free space would be left. + +Note that this function only works in the icon and small icon views, not in +list or report views (this is a limitation of the native Win32 control). + + \membersection{wxListCtrl::HitTest}\label{wxlistctrlhittest} \func{long}{HitTest}{\param{const wxPoint\& }{point}, \param{int\& }{flags}} diff --git a/include/wx/generic/listctrl.h b/include/wx/generic/listctrl.h index e388a13d10..15b8eef98c 100644 --- a/include/wx/generic/listctrl.h +++ b/include/wx/generic/listctrl.h @@ -91,6 +91,7 @@ public: int GetColumnWidth( int col ) const; bool SetColumnWidth( int col, int width); int GetCountPerPage() const; // not the same in wxGLC as in Windows, I think + wxRect GetViewRect() const; bool GetItem( wxListItem& info ) const; bool SetItem( wxListItem& info ) ; diff --git a/include/wx/msw/listctrl.h b/include/wx/msw/listctrl.h index 7131dcc647..3e780f13f2 100644 --- a/include/wx/msw/listctrl.h +++ b/include/wx/msw/listctrl.h @@ -138,6 +138,9 @@ public: // or small icon view) int GetCountPerPage() const; + // return the total area occupied by all the items (icon/small icon only) + wxRect GetViewRect() const; + // Gets the edit control for editing labels. wxTextCtrl* GetEditControl() const; diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 3ef7404b3b..ceb79f49f2 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -3773,6 +3773,41 @@ int wxListMainWindow::GetSelectedItemCount() const // item position/size // ---------------------------------------------------------------------------- +wxRect wxListMainWindow::GetViewRect() const +{ + wxASSERT_MSG( !HasFlag(wxLC_REPORT | wxLC_LIST), + _T("wxListCtrl::GetViewRect() only works in icon mode") ); + + // we need to find the longest/tallest label + wxCoord xMax = 0, + yMax = 0; + const int count = GetItemCount(); + if ( count ) + { + for ( int i = 0; i < count; i++ ) + { + wxRect r; + GetItemRect(i, r); + + wxCoord x = r.GetRight(), + y = r.GetBottom(); + + if ( x > xMax ) + xMax = x; + if ( y > yMax ) + yMax = y; + } + } + +#if 0 + // account for the scrollbar + yMax += wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y); + xMax += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); +#endif + + return wxRect(0, 0, xMax, yMax); +} + void wxListMainWindow::GetItemRect( long index, wxRect &rect ) const { wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(), @@ -4683,6 +4718,11 @@ bool wxGenericListCtrl::SetItemData( long item, long data ) return TRUE; } +wxRect wxGenericListCtrl::GetViewRect() const +{ + return m_mainWin->GetViewRect(); +} + bool wxGenericListCtrl::GetItemRect( long item, wxRect &rect, int WXUNUSED(code) ) const { m_mainWin->GetItemRect( item, rect ); diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 56c4430c64..020353af2a 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -1032,6 +1032,32 @@ bool wxListCtrl::SetItemData(long item, long data) return SetItem(info); } +wxRect wxListCtrl::GetViewRect() const +{ + wxASSERT_MSG( !HasFlag(wxLC_REPORT | wxLC_LIST), + _T("wxListCtrl::GetViewRect() only works in icon mode") ); + + RECT rc; + if ( !ListView_GetViewRect(GetHwnd(), &rc) ) + { + wxLogDebug(_T("ListView_GetViewRect() failed.")); + + wxZeroMemory(rc); + } + else + { + // VZ: I have no idea why is this needed but without it the listbook + // control shows a tiny vertical scrollbar, make sure that it works + // correctly if you decide to change this + rc.bottom += 5; + } + + wxRect rect; + wxCopyRECTToRect(rc, rect); + + return rect; +} + // Gets the item rectangle bool wxListCtrl::GetItemRect(long item, wxRect& rect, int code) const {