added wxCheckListBox::HitTest() (modified patch 594524)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16641 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2002-08-20 22:55:32 +00:00
parent 7ca528cb60
commit 15c3723c60
2 changed files with 27 additions and 13 deletions

View File

@@ -46,6 +46,10 @@ public:
virtual bool IsChecked(size_t uiIndex) const; virtual bool IsChecked(size_t uiIndex) const;
virtual void Check(size_t uiIndex, bool bCheck = TRUE); 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 // accessors
size_t GetItemHeight() const { return m_nItemHeight; } size_t GetItemHeight() const { return m_nItemHeight; }
@@ -55,6 +59,9 @@ protected:
virtual wxOwnerDrawn *CreateItem(size_t n); virtual wxOwnerDrawn *CreateItem(size_t n);
virtual bool MSWOnMeasure(WXMEASUREITEMSTRUCT *item); 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 // pressing space or clicking the check box toggles the item
void OnKeyDown(wxKeyEvent& event); void OnKeyDown(wxKeyEvent& event);
void OnLeftClick(wxMouseEvent& event); void OnLeftClick(wxMouseEvent& event);

View File

@@ -443,20 +443,9 @@ void wxCheckListBox::OnLeftClick(wxMouseEvent& event)
{ {
// clicking on the item selects it, clicking on the checkmark toggles // clicking on the item selects it, clicking on the checkmark toggles
if ( event.GetX() <= wxOwnerDrawn::GetDefaultMarginWidth() ) { if ( event.GetX() <= wxOwnerDrawn::GetDefaultMarginWidth() ) {
#ifdef __WIN32__ int nItem = HitTest(event.GetX(), event.GetY());
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
if ( nItem < (size_t)m_noItems ) if ( nItem != wxNOT_FOUND )
GetItem(nItem)->Toggle(); GetItem(nItem)->Toggle();
//else: it's not an error, just click outside of client zone //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 #endif