-void wxCheckListBoxItem::Toggle()
-{
- m_bChecked = !m_bChecked;
-
- uint nHeight = m_pParent->GetItemHeight();
- uint y = m_nIndex * nHeight;
- RECT rcUpdate = { 0, y, GetDefaultMarginWidth(), y + nHeight};
- InvalidateRect((HWND)m_pParent->GetHWND(), &rcUpdate, FALSE);
-
- wxCommandEvent event(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, m_pParent->GetId());
- event.SetInt(m_nIndex);
- event.SetEventObject(m_pParent);
- m_pParent->ProcessCommand(event);
+void wxCheckListBoxItem::Check(bool check)
+{
+ m_bChecked = check;
+
+ // index may be chanegd because new items were added/deleted
+ if ( m_pParent->GetItemIndex(this) != (int)m_nIndex )
+ {
+ // update it
+ int index = m_pParent->GetItemIndex(this);
+
+ wxASSERT_MSG( index != wxNOT_FOUND, "what does this item do here?" );
+
+ m_nIndex = (size_t)index;
+ }
+
+ HWND hwndListbox = (HWND)m_pParent->GetHWND();
+
+ #ifdef __WIN32__
+ RECT rcUpdate;
+
+ if ( ::SendMessage(hwndListbox, LB_GETITEMRECT,
+ m_nIndex, (LPARAM)&rcUpdate) == LB_ERR )
+ {
+ wxLogDebug("LB_GETITEMRECT failed");
+ }
+ #else // Win16
+ // FIXME this doesn't work if the listbox is scrolled!
+ size_t nHeight = m_pParent->GetItemHeight();
+ size_t y = m_nIndex * nHeight;
+ RECT rcUpdate = { 0, y, GetDefaultMarginWidth(), y + nHeight};
+ #endif // Win32/16
+
+ InvalidateRect(hwndListbox, &rcUpdate, FALSE);
+
+ wxCommandEvent event(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, m_pParent->GetId());
+ event.SetInt(m_nIndex);
+ event.SetEventObject(m_pParent);
+ m_pParent->ProcessCommand(event);