void CReportCtrlEx2::_MouseClkMonitor(UINT nMsg, UINT nFlags, CPoint point, BOOL bTriggerEdit) { LVHITTESTINFO hti; hti.pt = point; const int IDX = SubItemHitTest(&hti); const BOOL BEFORE = CListCtrl::GetCheck(IDX) > 0; const BOOL WAS_EDIT = _IsEditVisible(); EndItem(TRUE); const BOOL WASACTIVE = bTriggerEdit ? ExamItemStates(IDX, RC_ITEM_FOCUSED | RC_ITEM_SELECTED) : FALSE; switch (nMsg) { case WM_LBUTTONDOWN: CListCtrl::OnLButtonDown(nFlags, point); break; case WM_LBUTTONDBLCLK: CListCtrl::OnLButtonDblClk(nFlags, point); break; case WM_MBUTTONDOWN: CListCtrl::OnMButtonDown(nFlags, point); break; case WM_MBUTTONDBLCLK: CListCtrl::OnMButtonDblClk(nFlags, point); break; case WM_RBUTTONDOWN: CListCtrl::OnRButtonDown(nFlags, point); break; case WM_RBUTTONDBLCLK: CListCtrl::OnRButtonDblClk(nFlags, point); break; default: break; } const BOOL STATSCHANGED = _ItemCheckMonitor(IDX, BEFORE, CListCtrl::GetCheck(IDX) > 0, nMsg); if (bTriggerEdit && m_bAllowEdit && !STATSCHANGED && !WAS_EDIT && WASACTIVE) { if (hti.iSubItem == 4 || hti.iSubItem == 5) { m_bEdit = FALSE; StartDateTimeCtrl(IDX, hti.iSubItem); } else { m_bEdit = TRUE; StartEdit(IDX, hti.iSubItem); } } }
BOOL CReportCtrl::EndEdit(BOOL bCommit) { if (!_IsEditVisible()) return FALSE; CString str; m_pWndEdit->GetWindowText(str); BOOL bChanged = bCommit && str.Compare(GetItemText(m_ptEditting.x, m_ptEditting.y)) != 0; if (bChanged) { // update the list item CListCtrl::SetItemText(m_ptEditting.x, m_ptEditting.y, str); _UnsetSortedColumn(); GetParent()->SendMessage(WM_EDIT_COMMITTED, (WPARAM)m_ptEditting.x, (LPARAM)m_ptEditting.y); } m_pWndEdit->ShowWindow(SW_HIDE); m_ptEditting.x = -1; m_ptEditting.y = -1; return bChanged; }
BOOL CReportCtrl::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if (pMsg->message == WM_KEYDOWN) { if (!_IsEditVisible()) { // disable user from check/uncheck the checkboxes using space key // things get nasty if the user is HOLDING the space bar down if (pMsg->wParam == VK_SPACE) return TRUE; } else { POINT pt = m_ptEditting; switch (pMsg->wParam) { case VK_ESCAPE: // Cancel edit EndEdit(FALSE); return TRUE; case VK_RETURN: // Commit edit EndEdit(TRUE); return TRUE; case VK_TAB: // switch edit sub items if (pt.y == GetColumnCount() - 1) pt.y = 0; else pt.y++; EndEdit(TRUE); StartEdit(pt.x, pt.y); return TRUE; case VK_UP: // edit upper item if (pt.x > 0) { pt.x--; EndEdit(TRUE); StartEdit(pt.x, pt.y); EnsureVisible(pt.x, FALSE); return TRUE; } break; case VK_DOWN: // edit lower item if (pt.x < CListCtrl::GetItemCount() - 1) { pt.x++; EndEdit(TRUE); StartEdit(pt.x, pt.y); EnsureVisible(pt.x, FALSE); return TRUE; } break; default: break; } } } return CListCtrl::PreTranslateMessage(pMsg); }
BOOL CReportCtrlEx2::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if (pMsg->message == WM_KEYDOWN) { if (!_IsEditVisible()) { // disable user from check/uncheck the checkboxes using space key // things get nasty if the user is HOLDING the space bar down if (pMsg->wParam == VK_SPACE) return TRUE; } else { POINT pt = m_ptEditting; switch (pMsg->wParam) { case VK_ESCAPE: // Cancel edit EndItem(FALSE); return TRUE; case VK_RETURN: // Commit edit EndItem(TRUE); return TRUE; case VK_TAB: // switch edit sub items if (pt.y == GetColumnCount() - 1) { pt.y = 0; if (pt.x < CListCtrl::GetItemCount() - 1) pt.x++; else pt.x = 0; } else pt.y++; EndItem(TRUE); // Si es el primer elemento hacemos el scroll hacia la izquierda if (pt.y == 0) SendMessage( WM_HSCROLL, SB_LEFT, 0 ); // Si llegamos al elemento no visible se hace scroll a la derecha if (pt.y == 8) SendMessage( WM_HSCROLL, SB_RIGHT, 0 ); EnsureVisible(pt.x, FALSE); if (pt.y == 4 || pt.y == 5) { m_bEdit = FALSE; StartDateTimeCtrl(pt.x, pt.y); } else { m_bEdit = TRUE; StartEdit(pt.x, pt.y); } //if (m_bEdit && !m_pWndEdit->IsWindowVisible()) // SendMessage( WM_HSCROLL, /*SB_LINERIGHT*/SB_RIGHT, 0 ); return TRUE; case VK_UP: // edit upper item if (pt.x > 0) { pt.x--; EndItem(TRUE); EnsureVisible(pt.x, FALSE); if (pt.y == 4 || pt.y == 5) { m_bEdit = FALSE; StartDateTimeCtrl(pt.x, pt.y); } else { m_bEdit = TRUE; StartEdit(pt.x, pt.y); } //EnsureVisible(pt.x, FALSE); return TRUE; } break; case VK_DOWN: // edit lower item if (pt.x < CListCtrl::GetItemCount() - 1) { pt.x++; EndItem(TRUE); EnsureVisible(pt.x, FALSE); if (pt.y == 4 || pt.y == 5) { m_bEdit = FALSE; StartDateTimeCtrl(pt.x, pt.y); } else { m_bEdit = TRUE; StartEdit(pt.x, pt.y); } //EnsureVisible(pt.x, FALSE); return TRUE; } break; case VK_RIGHT: // edit lower item // Si estamos en la columna de la descripcion no se puede navegar por el // liscontrol a la derecha puesto que nos movemos dentro del texto if (pt.y != 11) { if (pt.y < GetColumnCount() - 1) { pt.y++; } else { pt.y = 0; if (pt.x < CListCtrl::GetItemCount() - 1) pt.x++; else pt.x = 0; } EndItem(TRUE); // Si es el primer elemento hacemos el scroll hacia la izquierda if (pt.y == 0) SendMessage( WM_HSCROLL, SB_LEFT, 0); // Si llegamos al elemento no visible se hace scroll a la derecha if (pt.y == 8) SendMessage( WM_HSCROLL, SB_RIGHT, 0 ); EnsureVisible(pt.x, FALSE); if (pt.y == 4 || pt.y == 5) { m_bEdit = FALSE; StartDateTimeCtrl(pt.x, pt.y); } else { m_bEdit = TRUE; StartEdit(pt.x, pt.y); } return TRUE; } break; case VK_LEFT: // edit lower item // Si estamos en la columna de la descripcion no se puede navegar por el // liscontrol a la izquierda puesto que nos movemos dentro del texto if (pt.y != 11) { if (pt.y > 0) { pt.y--; } else { pt.y = GetColumnCount()-1; if (pt.x == 0) { pt.y = 0; pt.x = CListCtrl::GetItemCount()-1; } else pt.x--; } EndItem(TRUE); // Si estamos en el 3 elemento del CListCtrl se hace scroll a la izquierda // porque es el primero que deja de ser visible if (pt.y == 3) SendMessage( WM_HSCROLL, SB_LEFT, 0 ); // Si es el último elemento hacemos el scroll hacia la derecha if (pt.y == GetColumnCount()-1) SendMessage( WM_HSCROLL, SB_RIGHT, 0); EnsureVisible(pt.x, FALSE); if (pt.y == 4 || pt.y == 5) { m_bEdit = FALSE; StartDateTimeCtrl(pt.x, pt.y); } else { m_bEdit = TRUE; StartEdit(pt.x, pt.y); } return TRUE; } break; default: break; } } } return CListCtrl::PreTranslateMessage(pMsg); }