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; }
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);
{
// 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
}
}
}
+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