void CSingleCheckListBox::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { if(nChar==VK_SPACE) { int nIndex=GetCaretIndex(); if(nIndex!=LB_ERR) { if (m_nStyle != BS_CHECKBOX && m_nStyle != BS_3STATE) { if ((GetStyle() & LBS_MULTIPLESEL) == 0) { if (IsEnabled(nIndex)) { int nCheck = GetCheck(nIndex); if(nCheck==1) return; else if(nCheck==0) { SetCheck(m_nLastChecked,0); m_nLastChecked=nIndex; } } } } } } CCheckListBox::OnKeyDown(nChar,nRepCnt,nFlags); }
// /// Toggle the "checked" state when the space is pressed. // void TCheckList::EvChar(uint key, uint /*repeatCount*/, uint /*flags*/) { TCheckListItem* item = GetItem(GetCaretIndex()); if (item && item->IsEnabled() && key == _T(' ')) { item->Toggle(); Update(); } // else /??? Eat char ??????????? // TListBox::EvChar(key, repeatCount, flags); }
// /// Toggle the "checked" state when the mouse is clicked in the checkbox. // void TCheckList::EvLButtonDown(uint modKeys, const TPoint& point) { TListBox::EvLButtonDown(modKeys, point); TCheckListItem* item = GetItem(GetCaretIndex()); if(item && item->IsEnabled() && point.x < CheckList_BoxWidth){ item->Toggle(); Update(); // Inform parent of change with BN_CLICKED message if(GetParentO()) GetParentO()->HandleMessage(WM_COMMAND, MkParam2(Attr.Id, BN_CLICKED), TParam2(GetHandle())); } }
void CCheckListBox::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { if (nChar == VK_SPACE) { int nIndex = GetCaretIndex(); CWnd* pParent = GetParent(); ASSERT_VALID(pParent); if (nIndex != LB_ERR) { if (m_nStyle != BS_CHECKBOX && m_nStyle != BS_3STATE) { if ((GetStyle() & LBS_MULTIPLESEL) != 0) { if (IsEnabled(nIndex)) { BOOL bSelected = GetSel(nIndex); if (bSelected) { int nModulo = (m_nStyle == BS_AUTO3STATE) ? 3 : 2; int nCheck = GetCheck(nIndex); nCheck = (nCheck == nModulo) ? nCheck - 1 : nCheck; SetCheck(nIndex, (nCheck + 1) % nModulo); // Inform of check pParent->SendMessage(WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(), CLBN_CHKCHANGE), (LPARAM)m_hWnd); } SetSel(nIndex, !bSelected); } else SetSel(nIndex, FALSE); // unselect disabled items return; } else { // If there is a selection, the space bar toggles that check, // all other keys are the same as a standard listbox. if (IsEnabled(nIndex)) { int nModulo = (m_nStyle == BS_AUTO3STATE) ? 3 : 2; int nCheck = GetCheck(nIndex); nCheck = (nCheck == nModulo) ? nCheck - 1 : nCheck; SetCheck(nIndex, (nCheck + 1) % nModulo); InvalidateCheck(nIndex); // Inform of check pParent->SendMessage(WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(), CLBN_CHKCHANGE), (LPARAM)m_hWnd); } else SetSel(nIndex, FALSE); // unselect disabled items return; } } } } CListBox::OnKeyDown(nChar, nRepCnt, nFlags); }