Support checkboxes in virtual wxListCtrl

This commit is contained in:
Maarten Bent
2019-05-05 14:25:06 +02:00
parent 353b0aabba
commit c20060745f
2 changed files with 35 additions and 1 deletions

View File

@@ -1681,6 +1681,7 @@ void wxListMainWindow::CacheLineData(size_t line)
ld->SetImage(col, listctrl->OnGetItemColumnImage(line, col)); ld->SetImage(col, listctrl->OnGetItemColumnImage(line, col));
} }
ld->Check(listctrl->OnGetItemIsChecked(line));
ld->SetAttr(listctrl->OnGetItemAttr(line)); ld->SetAttr(listctrl->OnGetItemAttr(line));
} }

View File

@@ -2480,6 +2480,33 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
event.m_item.m_data = GetItemData(iItem); event.m_item.m_data = GetItemData(iItem);
break; break;
case NM_CLICK:
processed = false;
// In virtual mode, check if user clicks on a checkbox.
if ( IsVirtual() && HasCheckBoxes() )
{
LV_HITTESTINFO lvhti;
wxZeroMemory(lvhti);
wxGetCursorPosMSW(&(lvhti.pt));
::ScreenToClient(GetHwnd(), &lvhti.pt);
if ( ListView_SubItemHitTest(GetHwnd(), &lvhti) != -1 )
{
if ( (lvhti.flags & LVHT_ONITEMSTATEICON) && (lvhti.iSubItem == 0) )
{
event.m_itemIndex = lvhti.iItem;
if ( OnGetItemIsChecked(event.m_itemIndex) )
eventType = wxEVT_LIST_ITEM_UNCHECKED;
else
eventType = wxEVT_LIST_ITEM_CHECKED;
processed = true;
}
}
}
break;
case NM_RCLICK: case NM_RCLICK:
// if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(), // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(),
// don't do anything else // don't do anything else
@@ -2669,8 +2696,14 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
// can get messages with LVIF_STATE in lvi.mask under Vista // can get messages with LVIF_STATE in lvi.mask under Vista
if ( lvi.mask & LVIF_STATE ) if ( lvi.mask & LVIF_STATE )
{ {
// we don't have anything to return from here...
lvi.stateMask = 0; lvi.stateMask = 0;
if ( HasCheckBoxes() && (lvi.iSubItem == 0) )
{
const bool checked = OnGetItemIsChecked(item);
lvi.state = INDEXTOSTATEIMAGEMASK(checked ? 2 : 1);
lvi.stateMask = LVIS_STATEIMAGEMASK;
}
} }
return true; return true;