]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxCheckListBox::HitTest() (modified patch 594524)
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 20 Aug 2002 22:55:32 +0000 (22:55 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 20 Aug 2002 22:55:32 +0000 (22:55 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16641 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/checklst.h
src/msw/checklst.cpp

index 473cc09b76901cdf1d314f3224865f886a254e57..b8b1eb28fb22723dfdbff07250dc703145b94550 100644 (file)
@@ -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);
index 5aa72dd1e4196b5d723af61420746e4ef1f5ec7f..028e5db445ced2cf9823b2c737cead3df4efab26 100644 (file)
@@ -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