]> git.saurik.com Git - wxWidgets.git/commitdiff
support wxListCtrl::GetViewRect() in report view too; test it in the sample (#9484)
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 29 Jun 2008 00:12:12 +0000 (00:12 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 29 Jun 2008 00:12:12 +0000 (00:12 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54412 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
samples/listctrl/listtest.cpp
samples/listctrl/listtest.h
src/generic/listctrl.cpp
src/msw/listctrl.cpp

index 681a1f9cb40ca1b7246794b77e3b85a695ded0c9..6ddbf988f2853b6b7a78475ef4a4867705ff7621 100644 (file)
@@ -368,6 +368,7 @@ All (GUI):
 - Fixed wxPixelData<wxImage> compilation (Leonardo Fernandes).
 - Added wxImage::GetType() (troelsk).
 - Added wxGenericStaticBitmap suitable for display of large bitmaps.
+- Support wxListCtrl::GetViewRect() in report view too.
 
 wxGTK:
 
index 27ec7f7bbe22638ee05a09205dc0ac89fa937178..629fa4a6a7fc19f1154a764bdeef1852d9345dc3 100644 (file)
@@ -90,6 +90,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_MENU(LIST_TOGGLE_MULTI_SEL, MyFrame::OnToggleMultiSel)
     EVT_MENU(LIST_SHOW_COL_INFO, MyFrame::OnShowColInfo)
     EVT_MENU(LIST_SHOW_SEL_INFO, MyFrame::OnShowSelInfo)
+    EVT_MENU(LIST_SHOW_VIEW_RECT, MyFrame::OnShowViewRect)
     EVT_MENU(LIST_FREEZE, MyFrame::OnFreeze)
     EVT_MENU(LIST_THAW, MyFrame::OnThaw)
     EVT_MENU(LIST_TOGGLE_LINES, MyFrame::OnToggleLines)
@@ -234,6 +235,7 @@ MyFrame::MyFrame(const wxChar *title)
     menuList->AppendSeparator();
     menuList->Append(LIST_SHOW_COL_INFO, _T("Show &column info\tCtrl-C"));
     menuList->Append(LIST_SHOW_SEL_INFO, _T("Show &selected items\tCtrl-S"));
+    menuList->Append(LIST_SHOW_VIEW_RECT, _T("Show &view rect"));
     menuList->AppendSeparator();
     menuList->Append(LIST_SORT, _T("Sor&t\tCtrl-T"));
     menuList->AppendSeparator();
@@ -643,6 +645,13 @@ void MyFrame::OnShowSelInfo(wxCommandEvent& WXUNUSED(event))
     }
 }
 
+void MyFrame::OnShowViewRect(wxCommandEvent& WXUNUSED(event))
+{
+    const wxRect r = m_listCtrl->GetViewRect();
+    wxLogMessage("View rect: (%d, %d)-(%d, %d)",
+                 r.GetLeft(), r.GetTop(), r.GetRight(), r.GetBottom());
+}
+
 void MyFrame::OnShowColInfo(wxCommandEvent& WXUNUSED(event))
 {
     int count = m_listCtrl->GetColumnCount();
index 18066ea9925309eb0ae66995db56399d8ed7f93a..2b5fefb3243aa2e3d77adc16decdb6a41515f3dd 100644 (file)
@@ -135,6 +135,7 @@ protected:
     void OnToggleMultiSel(wxCommandEvent& event);
     void OnShowColInfo(wxCommandEvent& event);
     void OnShowSelInfo(wxCommandEvent& event);
+    void OnShowViewRect(wxCommandEvent& event);
     void OnFreeze(wxCommandEvent& event);
     void OnThaw(wxCommandEvent& event);
     void OnToggleLines(wxCommandEvent& event);
@@ -202,6 +203,7 @@ enum
     LIST_TOGGLE_FIRST,
     LIST_SHOW_COL_INFO,
     LIST_SHOW_SEL_INFO,
+    LIST_SHOW_VIEW_RECT,
     LIST_GOTO,
     LIST_FOCUS_LAST,
     LIST_FREEZE,
index 8c40c96c4831b094aebe2ed65bd45a3fbbb46bb3..8c886803cccd0d0938b87d6b42a12fc83412aff6 100644 (file)
@@ -4110,8 +4110,7 @@ int wxListMainWindow::GetSelectedItemCount() const
 
 wxRect wxListMainWindow::GetViewRect() const
 {
-    wxASSERT_MSG( !HasFlag(wxLC_REPORT | wxLC_LIST),
-                    _T("wxListCtrl::GetViewRect() only works in icon mode") );
+    wxASSERT_MSG( !HasFlag(wxLC_LIST), "not implemented for list view" );
 
     // we need to find the longest/tallest label
     wxCoord xMax = 0, yMax = 0;
index 364d62f0340a90b300a79ca02a12c4e3b039a021..ef81fecd0c5f665d515a2a296db4d748bd5aa5c4 100644 (file)
@@ -1082,19 +1082,40 @@ bool wxListCtrl::SetItemPtrData(long item, wxUIntPtr data)
 
 wxRect wxListCtrl::GetViewRect() const
 {
-    wxASSERT_MSG( !HasFlag(wxLC_REPORT | wxLC_LIST),
-                    _T("wxListCtrl::GetViewRect() only works in icon mode") );
+    wxRect rect;
 
-    RECT rc;
-    if ( !ListView_GetViewRect(GetHwnd(), &rc) )
+    // ListView_GetViewRect() can only be used in icon and small icon views
+    // (this is documented in MSDN and, indeed, it returns bogus results in
+    // report view, at least with comctl32.dll v6 under Windows 2003)
+    if ( HasFlag(wxLC_ICON | wxLC_SMALL_ICON) )
     {
-        wxLogDebug(_T("ListView_GetViewRect() failed."));
+        RECT rc;
+        if ( !ListView_GetViewRect(GetHwnd(), &rc) )
+        {
+            wxLogDebug(_T("ListView_GetViewRect() failed."));
 
-        wxZeroMemory(rc);
+            wxZeroMemory(rc);
+        }
+
+        wxCopyRECTToRect(rc, rect);
     }
+    else if ( HasFlag(wxLC_REPORT) )
+    {
+        const long count = GetItemCount();
+        if ( count )
+        {
+            GetItemRect(wxMin(GetTopItem() + GetCountPerPage(), count - 1), rect);
 
-    wxRect rect;
-    wxCopyRECTToRect(rc, rect);
+            // extend the rectangle to start at the top (we include the column
+            // headers, if any, for compatibility with the generic version)
+            rect.height += rect.y;
+            rect.y = 0;
+        }
+    }
+    else
+    {
+        wxFAIL_MSG( _T("not implemented in this mode") );
+    }
 
     return rect;
 }