]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxListCtrl::GetViewRect()
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 14 Sep 2003 15:58:41 +0000 (15:58 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 14 Sep 2003 15:58:41 +0000 (15:58 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23574 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
docs/latex/wx/listctrl.tex
include/wx/generic/listctrl.h
include/wx/msw/listctrl.h
src/generic/listctrl.cpp
src/msw/listctrl.cpp

index 1c890d92f3c4fa1393d2a57787896fd2163247a7..fc4256c9605b4bf7546e61fbe2fe13c265611515 100644 (file)
@@ -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
 -----
 
index c1d13c0c875bdd113a8d75348d4570b5a7fff12d..b4e57c7a4fc5e0fd77ae6b47b8803cc9edd1279d 100644 (file)
@@ -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}}
index e388a13d10567d8d6a8cb44e97b5a82cf47586d0..15b8eef98c851c8d8846b4259f27b83d390ee4ab 100644 (file)
@@ -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 ) ;
index 7131dcc64701a5c1c75191618a13ff76f37f6d0d..3e780f13f25eedb977f199dcd12c605373bc1c85 100644 (file)
@@ -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;
 
index 3ef7404b3b5839b524bb1d7e12c05e3dd45ae4fc..ceb79f49f283ad6dafb68b9a2fbdb03980a152b2 100644 (file)
@@ -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 );
index 56c4430c64f9befed98b98e1ebf55810c624ccf9..020353af2a28382495b7ea0215c1c0edfec29c63 100644 (file)
@@ -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
 {