From: Vadim Zeitlin Date: Sun, 29 Jun 2008 00:12:12 +0000 (+0000) Subject: support wxListCtrl::GetViewRect() in report view too; test it in the sample (#9484) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/929b79014a38bc4d2b7fac4e25286c0f4a0b5ab7?ds=sidebyside support wxListCtrl::GetViewRect() in report view too; test it in the sample (#9484) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54412 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index 681a1f9cb4..6ddbf988f2 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -368,6 +368,7 @@ All (GUI): - Fixed wxPixelData compilation (Leonardo Fernandes). - Added wxImage::GetType() (troelsk). - Added wxGenericStaticBitmap suitable for display of large bitmaps. +- Support wxListCtrl::GetViewRect() in report view too. wxGTK: diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index 27ec7f7bbe..629fa4a6a7 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -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(); diff --git a/samples/listctrl/listtest.h b/samples/listctrl/listtest.h index 18066ea992..2b5fefb324 100644 --- a/samples/listctrl/listtest.h +++ b/samples/listctrl/listtest.h @@ -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, diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 8c40c96c48..8c886803cc 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -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; diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 364d62f034..ef81fecd0c 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -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; }