BOOL CReportCtrl::_ItemCheckMonitor(int nIndex, BOOL bBefore, BOOL bAfter, UINT nMsg) { if (!_IsValidIndex(nIndex) || m_nChkStyle == RC_CHKBOX_NONE || (bBefore && bAfter) || (!bBefore && !bAfter)) { return FALSE; } if (m_nChkStyle == RC_CHKBOX_SINGLE) { // Only one item can be checked if (!bBefore && bAfter) { SetAllItemStates(RC_ITEM_CHECKED, RC_ITEM_UNCHECKED); // uncheck all SetItemStates(nIndex, RC_ITEM_CHECKED); } } else if (m_nChkStyle == RC_CHKBOX_DISABLED) { // Cannot change the item checked/unchecked states by mouse clicks SetItemStates(nIndex, bBefore ? RC_ITEM_CHECKED : RC_ITEM_UNCHECKED); return TRUE; } SetAllItemStates(RC_ITEM_SELECTED, RC_ITEM_UNSELECTED); // unselect all SetItemStates(nIndex, RC_ITEM_SELECTED | RC_ITEM_FOCUSED); GetParent()->SendMessage(WM_ON_CHKBOX, (WPARAM)nIndex, (LPARAM)nMsg); return TRUE; }
BOOL CReportCtrlEx2::StartEdit(int nItem, int nSubItem) { // Get the grid width and height if (!m_bAllowEdit || /*!_IsValidIndex(nItem) ||*/ nSubItem < 0 || nSubItem >= GetColumnCount()) return FALSE; if (m_ptEditting.x == nItem && m_ptEditting.y == nSubItem) return TRUE; EndItem(TRUE); m_ptEditting.x = nItem; m_ptEditting.y = nSubItem; SetAllItemStates(RC_ITEM_SELECTED, RC_ITEM_UNSELECTED); // unselect all //SetItemStates(m_ptEditting.x, RC_ITEM_SELECTED | RC_ITEM_FOCUSED); // determine editbox font and alignment const DWORD FMT = _GetHeaderTextFormat(nSubItem); if (FMT != m_dwPrevEditFmt) { m_dwPrevEditFmt = FMT; // Funny thing: // Changing CEdit style among ES_LEFT, ES_CENTER, ES_RIGHT at runtime works // sometimes and fails other times. It just cannot guarantee to be succeed. // So I decided to destroy and recreate the CEdit every time when the text // format changes. if (m_pWndEdit->GetSafeHwnd() != NULL) m_pWndEdit->DestroyWindow(); if (!m_pWndEdit->Create(ES_AUTOHSCROLL | ES_NOHIDESEL | WS_CHILD | WS_BORDER | FMT, CRect(0, 0, 1, 1), this, 0)) return FALSE; } else { if (m_pWndEdit->GetSafeHwnd() == NULL && !m_pWndEdit->Create(ES_AUTOHSCROLL | ES_NOHIDESEL | WS_CHILD | WS_BORDER | FMT, CRect(0, 0, 1, 1), this, 0)) { return FALSE; } } m_pWndEdit->SetFont(GetFont()); CRect rcEdit; ListView_GetSubItemRect(GetSafeHwnd(), m_ptEditting.x, m_ptEditting.y, LVIR_LABEL, &rcEdit); if (m_ptEditting.y > 0 && GetImageList() != NULL && GetItemImage(m_ptEditting.x, m_ptEditting.y) >= 0) rcEdit.DeflateRect(16, 0, 0, 0); // Move the editbox to that grid, obtain text from the grid, display the // editbox, and, finally, highlights all text in the editbox and set the // windows focus to the editbox. m_pWndEdit->MoveWindow(&rcEdit); m_pWndEdit->SetWindowText(GetItemText(m_ptEditting.x, m_ptEditting.y)); m_pWndEdit->ShowWindow(SW_SHOW); m_pWndEdit->SetSel(0, -1); m_pWndEdit->SetFocus(); return TRUE; }
BOOL CReportCtrlEx2::StartDateTimeCtrl(int nItem, int nSubItem) { // Get the grid width and height if (!m_bAllowEdit || /*!_IsValidIndex(nItem) ||*/ nSubItem < 0 || nSubItem >= GetColumnCount()) return FALSE; if (m_ptEditting.x == nItem && m_ptEditting.y == nSubItem) return TRUE; EndItem(TRUE); m_ptEditting.x = nItem; m_ptEditting.y = nSubItem; SetAllItemStates(RC_ITEM_SELECTED, RC_ITEM_UNSELECTED); // unselect all //SetItemStates(m_ptEditting.x, RC_ITEM_SELECTED | RC_ITEM_FOCUSED); if (m_pDateTimeCtrlReport->GetSafeHwnd() != NULL) m_pDateTimeCtrlReport->DestroyWindow(); CRect rcDateTimeCtrl; ListView_GetSubItemRect(GetSafeHwnd(), m_ptEditting.x, m_ptEditting.y, LVIR_BOUNDS, &rcDateTimeCtrl); m_pDateTimeCtrlReport->Create(WS_VISIBLE | WS_CHILD | WS_TABSTOP | /*DTS_SHOWNONE |*/ DTS_SHORTDATEFORMAT, rcDateTimeCtrl, this, 1006); CString strDate = CListCtrl::GetItemText(nItem, nSubItem); if (!strDate.IsEmpty()) { int iDay = atoi(strDate.Left(2)); int iMes = atoi(strDate.Mid(3, 2)); int iAgno = atoi(strDate.Right(4)); CTime date(iAgno, iMes, iDay, 0, 0, 0); m_pDateTimeCtrlReport->SetTime(&date); } m_pDateTimeCtrlReport->MoveWindow(&rcDateTimeCtrl); m_pDateTimeCtrlReport->ShowWindow(SW_SHOW); m_pDateTimeCtrlReport->SetFocus(); return TRUE; }
BOOL CReportCtrlEx::StartCombo(int nItem, int nSubItem) { // Get the grid width and height if (!m_bAllowEdit || /*!_IsValidIndex(nItem) ||*/ nSubItem < 0 || nSubItem >= GetColumnCount()) return FALSE; if (m_ptEditting.x == nItem && m_ptEditting.y == nSubItem) return TRUE; /* CRect rectEditBox; m_pWndEdit->GetWindowRect(&rectEditBox);*/ EndItem(TRUE); m_ptEditting.x = nItem; m_ptEditting.y = nSubItem; SetAllItemStates(RC_ITEM_SELECTED, RC_ITEM_UNSELECTED); // unselect all //SetItemStates(m_ptEditting.x, RC_ITEM_SELECTED | RC_ITEM_FOCUSED); if (m_pWndCombo->GetSafeHwnd() != NULL) m_pWndCombo->DestroyWindow(); if (!m_pWndCombo->Create(WS_CHILD|WS_VISIBLE|WS_VSCROLL|CBS_DROPDOWN|CBS_SIMPLE/*CBS_DROPDOWNLIST*/, CRect(0, 0, 1, 1), this, 0)) return FALSE; m_pWndCombo->SetFont(GetFont()); CRect rcCombo; ListView_GetSubItemRect(GetSafeHwnd(), m_ptEditting.x, m_ptEditting.y, LVIR_BOUNDS, &rcCombo); rcCombo.bottom = rcCombo.bottom + 70; // Se añade espacio para la lista desplegable // Según la columna que sea se cargan unos datos u otro if (nSubItem == 3) { m_pWndCombo->AddString(ALQUILER); m_pWndCombo->AddString(VENTA); m_pWndCombo->AddString(OTROS); m_pWndCombo->AddString(ENTREGA); m_pWndCombo->AddString(RECOGIDA); } else if (nSubItem == 4) { // Si es el combo del tipo de Alquiler, sólo se activa si el tipo es Alquiler CString strTipo = GetItemText(nItem, 3); if (strTipo == ALQUILER) { m_pWndCombo->AddString(MENSUAL); m_pWndCombo->AddString(DIA_LABORABLE); m_pWndCombo->AddString(DIA_NATURAL); //m_pWndCombo->AddString("Sábado"); } } // Move the comboBox to that grid, obtain text from the grid, display the // comboBox, and, finally, highlights all text in the editbox and set the // windows focus to the editbox. m_pWndCombo->MoveWindow(&rcCombo); int iIndex = m_pWndCombo->FindString(0, GetItemText(m_ptEditting.x, m_ptEditting.y)); m_pWndCombo->SetCurSel(iIndex); m_pWndCombo->ShowWindow(SW_SHOW); m_pWndCombo->SetFocus(); return TRUE; }