コード例 #1
0
/*----------------------------------------------------------------------------------------------
	Set things up for editing with a temporary data cache by marking the point to return to
	in the undo stack. Also returns the action handler which should be installed in the
	temporary cache. This can be called multiple times. If the mark is already set, it does
	nothing.
	@return
----------------------------------------------------------------------------------------------*/
IActionHandler * AfDeFeEdBoxBut::BeginTempEdit()
{
	// Get your action handler.
	CustViewDaPtr qcvd;
	GetDataAccess(&qcvd);
	IActionHandlerPtr qacth;
	CheckHr(qcvd->GetActionHandler(&qacth));
	if (!m_hMark)
		CheckHr(qacth->Mark(&m_hMark));
	return qacth;
}
コード例 #2
0
/*----------------------------------------------------------------------------------------------
	@return true if any changes have been made.
----------------------------------------------------------------------------------------------*/
bool AfDeFeCliRef::IsDirty()
{
	if (!m_hwnd)
		return false; // Editor not active.
	HVO hvoOrig;
	CustViewDaPtr qcvd;
	GetDataAccess(&qcvd);
	AssertPtr(qcvd);
	CheckHr(qcvd->get_ObjectProp(m_hvoObj, m_flid, &hvoOrig));
	return hvoOrig != m_pss;
}
コード例 #3
0
/*----------------------------------------------------------------------------------------------
	Refresh the field from the data cache.
----------------------------------------------------------------------------------------------*/
void AfDeFeCliRef::UpdateField()
{
	// Get the item info from the cache.
	CustViewDaPtr qcvd;
	GetDataAccess(&qcvd);
	AssertPtr(qcvd);
	HVO hvoPss;
	CheckHr(qcvd->get_ObjectProp(m_hvoObj, m_flid, &hvoPss));
	m_pss = hvoPss;

	// Get the string from the poss cache.
	ITsStringPtr qtss;
	ITsStrFactoryPtr qtsf;
	StrUni stu;
	PossListInfoPtr qpli;
	PossItemInfo * ppii;
	int ipss;

	qtsf.CreateInstance(CLSID_TsStrFactory);
	int ws = m_ws;
	if (m_pss)
	{
		GetLpInfo()->LoadPossList(m_hvoPssl, m_wsMagic, &qpli);
		AssertPtr(qpli);
		ipss = qpli->GetIndexFromId(m_pss);
		if (ipss >= 0)
		{
			ppii = qpli->GetPssFromIndex(ipss);
			AssertPtr(ppii);
			if (m_fHier)
				ppii->GetHierName(qpli, stu, m_pnt);
			else
				ppii->GetName(stu, m_pnt);
			ws = ppii->GetWs();
		}
	}
	qtsf->MakeStringRgch(stu.Chars(), stu.Length(), ws, &qtss);
	m_qtss = qtss;

	// If we have an edit box, update the contents.
	if (m_hwnd)
	{
		// Setting the property causes a recursive call to OnChange, so we want to block it
		// from making a further change. (e.g., when you backspace to set the string to null
		// then tab to the next field, we want it to stay null, not go to the first item in
		// the list.)
		m_fRecurse = true;
		::SendMessage(m_hwnd, FW_EM_SETTEXT, 0, (LPARAM)m_qtss.Ptr());
	}
}
コード例 #4
0
/*----------------------------------------------------------------------------------------------
	Check the requirments of the FldSpec, and verify that data in the field meets the
	requirement. It returns:
		kFTReqNotReq if the all requirements are met.
		kFTReqWs if data is missing, but it is encouraged.
		kFTReqReq if data is missing, but it is required.
----------------------------------------------------------------------------------------------*/
FldReq AfDeFeSt::HasRequiredData()
{
	if (m_qfsp->m_fRequired == kFTReqNotReq)
		return kFTReqNotReq;
	CustViewDaPtr qcvd;
	GetDataAccess(&qcvd);
	AssertPtr(qcvd);
	bool fEmpty = true;
	ITsStringPtr qtss;
	int cch = 0;
	HVO hvoPara;
	int iPara;

	if (!m_hvoText)
		goto LExit;

	int cPara;
	CheckHr(qcvd->get_VecSize(m_hvoText, kflidStText_Paragraphs, &cPara));
	if (!cPara)
		goto LExit;

	// Make sure at least some paragraph has data.
	for (iPara = 0; iPara < cPara; ++iPara)
	{
		CheckHr(qcvd->get_VecItem(m_hvoText, kflidStText_Paragraphs, iPara, &hvoPara));
		// At some point we may need to handle something other than StTxtPara.
		CheckHr(qcvd->get_StringProp(hvoPara, kflidStTxtPara_Contents, &qtss));
		if (qtss)
			CheckHr(qtss->get_Length(&cch));
		if (cch)
			break; // Have a valid string
	}

	fEmpty = iPara == cPara;

LExit:
	if (fEmpty)
		return m_qfsp->m_fRequired;
	else
		return kFTReqNotReq;
}
コード例 #5
0
/*----------------------------------------------------------------------------------------------
	End editing with a temporary data cache by clearing stuff out down to the mark created by
	BeginTempEdit. This can be called any number of times. If a mark is not in progress, it
	does nothing.
	@return
----------------------------------------------------------------------------------------------*/
IActionHandler * AfDeFeEdBoxBut::EndTempEdit()
{
	// Get your action handler.
	CustViewDaPtr qcvd;
	GetDataAccess(&qcvd);
	IActionHandlerPtr qacth;
	CheckHr(qcvd->GetActionHandler(&qacth));
	// Clear out any temporary Undo items relating to this window.
	if (m_hMark)
	{
		// Calling DiscardToMark() when the depth is greater than zero crashes.  (See DN-786.)
		int nDepth;
		CheckHr(qacth->get_CurrentDepth(&nDepth));
		if (nDepth == 0)
		{
			CheckHr(qacth->DiscardToMark(0));
			m_hMark = 0;
		}
	}
	return qacth;
}
コード例 #6
0
/*----------------------------------------------------------------------------------------------
	Save changes that have been made to the current editor.
	@return true if edit saved successfully
----------------------------------------------------------------------------------------------*/
bool AfDeFeCliRef::SaveEdit()
{
	if (m_fDelFromDialog)
	{
		m_fDelFromDialog = false;
		return true;
	}
	EndTempEdit();
	if (IsDirty())
	{
		CustViewDaPtr qcvd;
		GetDataAccess(&qcvd);
		AssertPtr(qcvd);
		// Check if the record has been edited by someone else since we first loaded the data.
		HRESULT hr;
		CheckHr(hr = qcvd->CheckTimeStamp(m_hvoObj));
		if (hr != S_OK)
		{
			// If it was changed and the user does not want to overwrite it, perform a refresh
			// so the displayed field will revert to it's original value.
			m_qadsc->UpdateAllDEWindows(m_hvoObj, m_flid);
			qcvd->PropChanged(NULL, kpctNotifyAll, m_hvoObj, m_flid, 0, 1, 1);
		}
		else
		{
			// Update the value in the cache and refresh views.
			BeginChangesToLabel();
			qcvd->SetObjProp(m_hvoObj, m_flid, m_pss);
			m_qadsc->UpdateAllDEWindows(m_hvoObj, m_flid);
			qcvd->PropChanged(NULL, kpctNotifyAll, m_hvoObj, m_flid, 0, 1, 1);
			CheckHr(qcvd->EndUndoTask());
		}
	}
	// We need to leave in a state that cancels undo actions since this may be called
	// without actually closing the edit box.
	BeginTempEdit();
	return true;
}
コード例 #7
0
/*----------------------------------------------------------------------------------------------
	Saves changes but keeps the editing window open. In this method we need to convert dummy
	items into real items if there are any people present. We also need to delete
	RnRoledPartic and convert the field into a dummy if all of the people have been
	deleted. Otherwise, there is no way for the user to get rid of RnRoledPartic.
	@return True if successful.
----------------------------------------------------------------------------------------------*/
bool RnDeFeRoleParts::SaveEdit()
{
	// See if any items are present.
	int cpss;
	HVO hvopssl = m_vpssl[0];
	ISilDataAccessPtr qsdaTemp;
	HRESULT hr = m_qvcd->QueryInterface(IID_ISilDataAccess, (void **)&qsdaTemp);
	if (FAILED(hr))
		ThrowInternalError(E_INVALIDARG);
	CheckHr(qsdaTemp->get_VecSize(hvopssl, kflidPssIds, &cpss));
	CustViewDaPtr qcvd;
	GetDataAccess(&qcvd);
	AssertPtr(qcvd);

	if (cpss > 1) // Don't count the dummy at the end.
	{
		if (m_hvoObj == khvoDummyRnRoledPartic)
		{
			// We have a dummy RnRoledParticipant with at least one item, so we need to
			// turn the dummy into a real object.
			HVO hvo;
			BeginChangesToLabel();
			CheckHr(qcvd->MakeNewObject(kclidRnRoledPartic, m_hvoOwner, kflidRnEvent_Participants,
				-1, &hvo));
			Assert(hvo);
			m_hvoObj = hvo;

			// If someone deleted the role we are interested in while we are displaying
			// this field, we can't set the object prop or we'll get an error from the
			// database. So before doing a save, make sure our role hasn't been deleted.
			if (m_pssRole)
				CheckHr(qcvd->SetObjProp(hvo, kflidRnRoledPartic_Role, m_pssRole));

			SuperClass::SaveEdit();
			CheckHr(qcvd->EndUndoTask());
			// Need to notify this property after the participants were added in the superclass
			// for this to properly update document views.
			CheckHr(qcvd->PropChanged(m_qrootb, kpctNotifyAllButMe, m_hvoOwner,
				kflidRnEvent_Participants, 1, 1, 0));
			return true;
		}
		else
		{
			// We have a real RnRoledParticipant with at least one item, so handle it as usual.
			bool fDirty = m_fDirty;
			if (!SuperClass::SaveEdit())
				return false;
			if (fDirty)
			{
				// Database triggers/procs do not update the entry, so we must do it here.
				qcvd->SetTimeStamp(m_hvoOwner);
				qcvd->CacheCurrTimeStamp(m_hvoOwner);
			}
			return true;
		}
	}
	else
	{
		if (m_hvoObj == khvoDummyRnRoledPartic)
		{
			// We have a dummy RnRoledParticipant without any people. Do nothing so the
			// field will go away when we move to the next record.
			return true;
		}
		else
		{
			// We have a real RnRoledParticipant with no items, so we need to change this
			// into a dummy RnRoledParticipant and remove it from the database.
			CustViewDaPtr qcvd;
			GetDataAccess(&qcvd);
			AssertPtr(qcvd);
			int ihvo;
			BeginChangesToLabel();
			CheckHr(qcvd->GetObjIndex(m_hvoOwner, kflidRnEvent_Participants, m_hvoObj, &ihvo));
			CheckHr(qcvd->DeleteObjOwner(m_hvoOwner, m_hvoObj, kflidRnEvent_Participants, ihvo));
			CheckHr(qcvd->EndUndoTask());
			m_hvoObj = khvoDummyRnRoledPartic;
			CheckHr(qcvd->PropChanged(m_qrootb, kpctNotifyAllButMe, m_hvoOwner,
				kflidRnEvent_Participants, 1, 0, 1));
			return true;
		}
	}
}
コード例 #8
0
/*----------------------------------------------------------------------------------------------
	Check to see if the edit box has valid data.  if so return true.  If not then put up a
	message to the user, then return false.
----------------------------------------------------------------------------------------------*/
bool CleDeFeString::IsOkToClose(bool fWarn)
{
	CleMainWnd * pcmw = dynamic_cast<CleMainWnd *>(m_qadsc->MainWindow());
	Assert(pcmw);

	IVwSelectionPtr qvwsel;
	CheckHr(m_qrootb->get_Selection(&qvwsel));
	if (qvwsel)
	{
		ComBool fOk;
		CheckHr(qvwsel->Commit(&fOk));
	}

	PossListInfoPtr qpli = pcmw->GetPossListInfoPtr();
	int ipss = qpli->GetIndexFromId(m_hvoObj);
	StrUni stuNew;

	const OLECHAR * prgwch;
	int cch;
	ITsStringPtr qtss;
	CustViewDaPtr qcvd;

	GetDataAccess(&qcvd);
	AssertPtr(qcvd);
	int ws = m_qsvc->WritingSystems()[0];

	CheckHr(qcvd->get_MultiStringAlt(m_hvoObj, m_flid, ws, &qtss));
	Assert(qtss);
	qtss->LockText(&prgwch, &cch);
	qtss->UnlockText(prgwch);

	// Trim leading and trailing space characters.
	UnicodeString ust(prgwch, cch);
	ust.trim();
	stuNew.Assign(ust.getBuffer(), ust.length());

	//  Obtain pointer to IOleDbEncap interface.
	IOleDbEncapPtr qode;
	IOleDbCommandPtr qodc;
	StrUni stuSql;
	ComBool fIsNull;
	ComBool fMoreRows;
	AssertPtr(m_qadsc->MainWindow());
	AfLpInfo * plpi = m_qadsc->MainWindow()->GetLpInfo();
	AssertPtr(plpi);
	AfDbInfo * pdbi = plpi->GetDbInfo();
	AssertPtr(pdbi);
	pdbi->GetDbAccess(&qode);
	AssertPtr(qode);
	CheckHr(qode->CreateCommand(&qodc));
	int cpii = qpli->GetCount();

	if ((m_flid == kflidCmPossibility_Name) || (m_flid == kflidCmPossibility_Abbreviation))
	{
		// Make sure it does not have a ":" or a " - " in the string
		int ich = stuNew.FindStr(L":");
		StrUni stuTmp;
		bool fFixed = false;
		while (ich > 0)
		{
			stuNew.Replace(ich,ich + 1,"-");
			fFixed = true;
			ich = stuNew.FindStr(L":");
		}
		ich = stuNew.FindStr(L" - ");
		while (ich > 0)
		{
			stuNew.Replace(ich,ich + 3,"-");
			fFixed = true;
			ich = stuNew.FindStr(L" - ");
		}
		if (fFixed)
		{
			if (fWarn)
			{
				ITsStrFactoryPtr qtsf;
				qtsf.CreateInstance(CLSID_TsStrFactory);
				qtsf->MakeStringRgch(stuNew.Chars(), stuNew.Length(), pcmw->UserWs(), &qtss);
				CheckHr(qcvd->SetMultiStringAlt(m_hvoObj, m_flid, ws, qtss));
				CheckHr(qcvd->PropChanged(NULL, kpctNotifyAll, m_hvoObj, m_flid, 0, 1, 1));
				StrApp strMsg(kstidFixedStr);
				StrApp strTitle(kstidFixedStrTitle);
				::MessageBox(m_hwnd, strMsg.Chars(), strTitle.Chars(),
					MB_OK | MB_ICONINFORMATION);
			}
			return false;
		}
	}

	if (qpli->GetAllowDup())
		return true;

	ILgWritingSystemFactoryPtr qwsf;
	pdbi->GetLgWritingSystemFactory(&qwsf);
	AssertPtr(qwsf);
	switch (m_flid)
	{
		case kflidCmPossibility_Name:
		{
			for (int ipii = 0; ipii < cpii; ipii++)
			{
				if (ipii == ipss)
					continue;
				PossItemInfo * ppii = qpli->GetPssFromIndex(ipii);
				AssertPtr(ppii);
				StrUni stu;
				ppii->GetName(stu, kpntName);
				if (stu == stuNew)
				{
					stuSql.Format(L"select ws from CmPossibility_Name "
						L"where obj = %d and ws = %d",
						ppii->GetPssId(), ws);
					CheckHr(qode->CreateCommand(&qodc));
					CheckHr(qodc->ExecCommand(stuSql.Bstr(), knSqlStmtSelectWithOneRowset));
					CheckHr(qodc->GetRowset(0));
					CheckHr(qodc->NextRow(&fMoreRows));

					if (fMoreRows)
					{
						if (fWarn)
						{
							// this name already exists
							IWritingSystemPtr qws;
							CheckHr(qwsf->get_EngineOrNull(ws, &qws));
							AssertPtr(qws);
							SmartBstr sbstr;
							qws->get_Name(ws, &sbstr);

							StrUni stu(kstidDupItemName);
							StrUni stuMsg;
							stuMsg.Format(stu,sbstr.Chars());
							StrApp str(stuMsg);
							StrApp strTitle(kstidDupItemTitle);
							::MessageBox(m_hwnd, str.Chars(), strTitle.Chars(),
								MB_OK | MB_ICONINFORMATION);
						}
						return false;
					}
				}
			}
			break;
		}
		case kflidCmPossibility_Abbreviation:
		{
			for (int ipii = 0; ipii < cpii; ipii++)
			{
				if (ipii == ipss)
					continue;
				PossItemInfo * ppii = qpli->GetPssFromIndex(ipii);
				AssertPtr(ppii);
				StrUni stu;
				ppii->GetName(stu, kpntAbbreviation);
				if (stu == stuNew)
				{
					stuSql.Format(L"select ws from CmPossibility_Abbreviation "
						L"where obj = %d and ws = %d",
						ppii->GetPssId(), ws);
					CheckHr(qode->CreateCommand(&qodc));
					CheckHr(qodc->ExecCommand(stuSql.Bstr(), knSqlStmtSelectWithOneRowset));
					CheckHr(qodc->GetRowset(0));
					CheckHr(qodc->NextRow(&fMoreRows));

					if (fMoreRows)
					{
						if (fWarn)
						{
							// this abbreviation already exists
							IWritingSystemPtr qws;
							CheckHr(qwsf->get_EngineOrNull(ws, &qws));
							AssertPtr(qws);
							SmartBstr sbstr;
							qws->get_Name(ws, &sbstr);

							StrUni stu(kstidDupItemAbbr);
							StrUni stuMsg;
							stuMsg.Format(stu,sbstr.Chars());
							StrApp str(stuMsg);
							StrApp strTitle(kstidDupItemTitle);
							::MessageBox(m_hwnd, str.Chars(), strTitle.Chars(),
								MB_OK | MB_ICONINFORMATION);
						}
						return false;
					}
				}
			}
			break;
		}
	}
	return true;
}