Esempio n. 1
0
void CReportCtrl::RemoveEditOptions(CXTPReportRecordItem *pItem,DWORD_PTR dwData)
{
	CXTPReportRecordItemEditOptions *pEditOptions = pItem->GetEditOptions(NULL);
	ASSERT(pEditOptions != NULL);

	CXTPReportRecordItemConstraints *pConstraints = pEditOptions->GetConstraints();
	ASSERT(pConstraints != NULL);

	CXTPReportRecordItemConstraint *pConstraint = pEditOptions->FindConstraint(dwData);
	ASSERT (pConstraint != NULL);

	CDWordArray dwDatas;
	CStringArray strConstraints;

	for (int i=0; i<pConstraints->GetCount(); ++i)
	{
		CXTPReportRecordItemConstraint *pConstraint = pConstraints->GetAt(i);
		if (pConstraint->m_dwData != dwData)
		{
			dwDatas.Add(pConstraint->m_dwData);
			strConstraints.Add(pConstraint->m_strConstraint);
		}
	}

	pConstraints->RemoveAll();
	for (int i=0; i<dwDatas.GetCount(); ++i)
		pEditOptions->AddConstraint(strConstraints[i],dwDatas[i]);
}
void CXTPReportInplaceList::OnSelectionChanged(int nLBIndex)
{
	CString strActual, str;
	CListBox::GetText(nLBIndex,strActual);

	CXTPReportRecordItemEditOptions* pEditOptions = pItem->GetEditOptions(pColumn);
	CXTPReportRecordItemConstraints* pConstraints = pEditOptions->GetConstraints();

	int nCount = pConstraints->GetCount();
	for (int nIndex = 0; nIndex < nCount; nIndex++)
	{
		CXTPReportRecordItemConstraint* pConstraint = pConstraints->GetAt(nIndex);
		str = pConstraint->m_strConstraint;

		if (strActual.CompareNoCase(str) == 0)
		{
			((CXTPReportControl*) pControl)->OnConstraintSelecting(pRow, pItem, pColumn, pConstraint);
			break;
		}
	}

	//BOOL bAllowEdit = pEditOptions->m_bAllowEdit;
	BOOL bConstraintEdit = pEditOptions->m_bConstraintEdit;

	CXTPReportInplaceButton* pButton = pEditOptions->GetButton(0);
	if (pButton)
	{
		if (bConstraintEdit)
			pButton->m_bDraw = TRUE; //to eliminate flickering
		else
			pButton->m_bDraw = FALSE;
	}
}
//old code
CString CXTPReportRecordItemVariant::GetCaption(CXTPReportColumn* pColumn)
{
	if (!m_strCaption.IsEmpty())
		return m_strCaption;

	COleVariant var(m_oleValue);

	CXTPReportRecordItemEditOptions* pEditOptions = NULL;
	if (m_pEditOptions)
		pEditOptions = m_pEditOptions;
	else if (pColumn)
		pEditOptions = pColumn->GetEditOptions();

	BOOL bConstraintEdit = FALSE;
	if (pEditOptions)
		bConstraintEdit = pEditOptions->m_bConstraintEdit;

	TRY
	{
		if (var.vt == VT_DATE && !bConstraintEdit && m_strFormatString != _T("%s"))
		{
			COleDateTime dt(var);
			//return dt.Format(m_strFormatString);
			return CXTPReportControlLocale::FormatDateTime(dt, m_strFormatString);
		}
		if (var.vt == VT_NULL)
		{
			var.vt = VT_I4;
			var.lVal = 0;
		}
		else
		{
			if (bConstraintEdit)
				CXTPReportControlLocale::VariantChangeTypeEx(var, VT_I4);
			else
				CXTPReportControlLocale::VariantChangeTypeEx(var, VT_BSTR);
		}
	}
	CATCH_ALL(e)
	{
	}
	END_CATCH_ALL

	if (bConstraintEdit)
	{
		CXTPReportRecordItemConstraint* pConstraint = pEditOptions ? pEditOptions->FindConstraint(var.lVal) : NULL;
		return pConstraint ? pConstraint->m_strConstraint : _T("");
	}

	if (var.vt != VT_BSTR) //this function expected VT_BSTR only !?
		return _T("");

	CString strVariant(var.bstrVal);
	if (m_strFormatString == _T("%s"))
		return strVariant;

	CString strCaption;
	strCaption.Format(m_strFormatString, (LPCTSTR)strVariant);
	return strCaption;
}
void CXTPReportInplaceList::OnSelectionChanged(int nLBIndex)
{
	CString strActual, str;
	CListBox::GetText(nLBIndex,strActual);

	CXTPReportRecordItemEditOptions* pEditOptions = pItem->GetEditOptions(pColumn);
	CXTPReportRecordItemConstraints* pConstraints = pEditOptions->GetConstraints();

	int nCount = pConstraints->GetCount();
	for (int nIndex = 0; nIndex < nCount; nIndex++)
	{
		CXTPReportRecordItemConstraint* pConstraint = pConstraints->GetAt(nIndex);
		str = pConstraint->m_strConstraint;

		if (strActual.CompareNoCase(str) == 0)
		{
			((CXTPReportControl*) pControl)->OnConstraintSelecting(pRow, pItem, pColumn, pConstraint);
			break;
		}
	}
}
void CXTPReportInplaceEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	CXTPReportControl* _pControl = pControl;
	if (!_pControl)
		return;

	if (nChar == VK_TAB)
	{
		_pControl->SetFocus();
		_pControl->SendMessage(WM_CHAR, nChar);
		return;
	}
	if (nChar == VK_ESCAPE)
	{
		SetWindowText(m_strValue);
		return;
	}
	else if (nChar == VK_F5)
	{
		_pControl->Recalc(TRUE);
		return;
	}
	else if (nChar == VK_RETURN)
	{
		if ((GetStyle() & ES_WANTRETURN) == 0)
			return;

		if (GetKeyState(VK_CONTROL) < 0) // ES_WANTRETURN is set and Ctrl+Enter is pressed
		{
			pControl->EditItem(NULL);
			return;
		}
	}
	else if (nChar == VK_UP || nChar == VK_DOWN || nChar == VK_PRIOR || nChar == VK_NEXT)
	{
		if (pItem && pColumn && pItem->GetEditOptions(pColumn)->m_bConstraintEdit)
		{
			CXTPReportRecordItemConstraint* pConstraint;
			CXTPReportRecordItemEditOptions* pEditOptions = pItem->GetEditOptions(pColumn);
			CXTPReportRecordItemConstraints* pConstraints = pEditOptions->GetConstraints();

			int nCount = pConstraints->GetCount();
			if (nCount > 1)
			{
				CString strActual, str;
				GetWindowText(strActual);

				int nIndex = 0;          // the first item

				if (nChar == VK_NEXT)
				{
					nIndex = nCount - 1; // the last item
				}
				else if (nChar != VK_PRIOR)
				{
					// look for the actually selected item
					for (int i = 0; i < nCount; i++)
					{
						pConstraint = pConstraints->GetAt(i);

						if (strActual.CompareNoCase(pConstraint->m_strConstraint) == 0)
						{
							if (nChar == VK_UP)
								nIndex = max(0, i - 1);
							else if (nChar == VK_DOWN)
								nIndex = min(nCount-1, i + 1);

							break;
						}
					}
				}

				pConstraint = pConstraints->GetAt(max(0, min(nIndex, nCount-1)));
				str = pConstraint->m_strConstraint;
				m_pSelectedConstraint = pConstraint;

				// set the default font, because user could change the font (for ex. to striked one)
				SetFont(pControl->GetPaintManager()->GetTextFont());
				SetWindowText(str);
				SetSel(0, -1);

				if (strActual.CompareNoCase(str) != 0)
					((CXTPReportControl*)pControl)->OnConstraintSelecting(pRow, pItem, pColumn, pConstraint);

				return;
			}
		}
	}

	CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CXTPReportInplaceEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	if (!pControl)
		return;

	if (nChar == VK_TAB) return;
	if (nChar == VK_ESCAPE)
	{
		pControl->EditItem(NULL);
		return;
	}
	if (nChar == VK_RETURN)
	{
		if ((GetStyle() & ES_WANTRETURN) == 0)
		{
			pControl->EditItem(NULL);
		}
		else
		{
			CEdit::OnChar(nChar, nRepCnt, nFlags);
		}
		return;
	}
	if (pItem && pColumn && pItem->GetEditOptions(pColumn)->m_bConstraintEdit)
	{
		CXTPReportRecordItemEditOptions* pEditOptions = pItem->GetEditOptions(pColumn);

		CXTPReportRecordItemConstraints* pConstraints = pEditOptions->GetConstraints();
		int nCount = pConstraints->GetCount();
		if (nCount > 0)
		{

			CString str, strActual;
			GetWindowText(str);
			strActual = str;

			CXTPReportRecordItemConstraint* pConstraint = (m_pSelectedConstraint == NULL) ?
				pEditOptions->FindConstraint(str): m_pSelectedConstraint;

			int nIndexStart, nIndex;
			nIndexStart = nIndex = (pConstraint == NULL ? nCount - 1 : pConstraint->GetIndex());

			CString strSeach ((TCHAR)nChar);

			do
			{
				nIndex = nIndex < nCount - 1 ? nIndex + 1 : 0;

				pConstraint = pConstraints->GetAt(nIndex);
				str = pConstraint->m_strConstraint;

				if (strSeach.CompareNoCase(str.Left(1)) == 0)
				{
					m_pSelectedConstraint = pConstraint;
					SetWindowText(str);
					SetSel(0, -1);

					if (strActual.CompareNoCase(str) != 0)
						((CXTPReportControl*)pControl)->OnConstraintSelecting(pRow, pItem, pColumn, pConstraint);

					return;
				}

			} while (nIndex != nIndexStart);

			return;
		}
	}
	if (nChar == 1 && nFlags == 30) //Ctrl+A case
	{
		SetSel(0, -1);
	}
	CEdit::OnChar(nChar, nRepCnt, nFlags);
}