From 15c3723c6092669f91c9251382f4a1521deeceeb Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 20 Aug 2002 22:55:32 +0000 Subject: [PATCH] added wxCheckListBox::HitTest() (modified patch 594524) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16641 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/checklst.h | 7 +++++++ src/msw/checklst.cpp | 33 ++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/include/wx/msw/checklst.h b/include/wx/msw/checklst.h index 473cc09b76..b8b1eb28fb 100644 --- a/include/wx/msw/checklst.h +++ b/include/wx/msw/checklst.h @@ -46,6 +46,10 @@ public: virtual bool IsChecked(size_t uiIndex) const; virtual void Check(size_t uiIndex, bool bCheck = TRUE); + // return the index of the item at this position or wxNOT_FOUND + int HitTest(const wxPoint& pt) const { return DoHitTestItem(pt.x, pt.y); } + int HitTest(wxCoord x, wxCoord y) const { return DoHitTestItem(x, y); } + // accessors size_t GetItemHeight() const { return m_nItemHeight; } @@ -55,6 +59,9 @@ protected: virtual wxOwnerDrawn *CreateItem(size_t n); virtual bool MSWOnMeasure(WXMEASUREITEMSTRUCT *item); + // this can't be called DoHitTest() because wxWindow already has this method + int DoHitTestItem(wxCoord x, wxCoord y) const; + // pressing space or clicking the check box toggles the item void OnKeyDown(wxKeyEvent& event); void OnLeftClick(wxMouseEvent& event); diff --git a/src/msw/checklst.cpp b/src/msw/checklst.cpp index 5aa72dd1e4..028e5db445 100644 --- a/src/msw/checklst.cpp +++ b/src/msw/checklst.cpp @@ -443,20 +443,9 @@ void wxCheckListBox::OnLeftClick(wxMouseEvent& event) { // clicking on the item selects it, clicking on the checkmark toggles if ( event.GetX() <= wxOwnerDrawn::GetDefaultMarginWidth() ) { - #ifdef __WIN32__ - size_t nItem = (size_t)::SendMessage - ( - (HWND)GetHWND(), - LB_ITEMFROMPOINT, - 0, - MAKELPARAM(event.GetX(), event.GetY()) - ); - #else // Win16 - // FIXME this doesn't work when the listbox is scrolled! - size_t nItem = ((size_t)event.GetY()) / m_nItemHeight; - #endif // Win32/16 + int nItem = HitTest(event.GetX(), event.GetY()); - if ( nItem < (size_t)m_noItems ) + if ( nItem != wxNOT_FOUND ) GetItem(nItem)->Toggle(); //else: it's not an error, just click outside of client zone } @@ -466,5 +455,23 @@ void wxCheckListBox::OnLeftClick(wxMouseEvent& event) } } +int wxCheckListBox::DoHitTestItem(wxCoord x, wxCoord y) const +{ + #ifdef __WIN32__ + int nItem = (int)::SendMessage + ( + (HWND)GetHWND(), + LB_ITEMFROMPOINT, + 0, + MAKELPARAM(x, y) + ); + #else // Win16 + // FIXME this doesn't work when the listbox is scrolled! + int nItem = y / m_nItemHeight; + #endif // Win32/16 + + return nItem >= m_noItems ? wxNOT_FOUND : nItem; +} + #endif -- 2.45.2