Exemplo n.º 1
0
/*----------------------------------------------------------------------------------------------
	This is the main interesting method of displaying objects and fragments of them.
	Here a text is displayed by displaying its paragraphs;
	and a paragraph is displayed by invoking its style rule, making a paragraph,
	and displaying its contents.
----------------------------------------------------------------------------------------------*/
STDMETHODIMP TestStVc::Display(IVwEnv * pvwenv, HVO hvo, int frag)
{
	try
	{
		switch(frag)
		{
		case kfrText:
			{// BLOCK for var skip warnings
				// We need to show something, since the current view code can't handle a property
				// containing no boxes.
				// Review JohnT: should we show an empty string or something?
				// Should we prevent the occurrence of texts with no paragraphs?
				int cpara = 0;
				ISilDataAccessPtr qsda;
				CheckHr(pvwenv->get_DataAccess(&qsda));
				if (hvo)
					CheckHr(qsda->get_VecSize(hvo, kflidStText_Paragraphs, &cpara));
				if (!cpara)
				{
					// Either we have no ST object at all, or it is empty of paragraphs. The
					// current view code can't handle either, so stick something in.
					ITsStrFactoryPtr qtsf;
					qtsf.CreateInstance(CLSID_TsStrFactory);
					ITsStringPtr qtssMissing;
					CheckHr(qtsf->MakeStringRgch(L"<no paragraphs>", 15, 0, &qtssMissing));
					CheckHr(pvwenv->AddString(qtssMissing));
					break;
				}
				CheckHr(pvwenv->AddObjVecItems(kflidStText_Paragraphs, this, kfrPara));
			}
			break;
		case kfrPara:
			{ // BLOCK
				// Invoke the paragraph's style rule if any
				ISilDataAccessPtr qsda;
				CheckHr(pvwenv->get_DataAccess(&qsda));
				ITsTextPropsPtr qttp;
				CheckHr(qsda->get_UnknownProp(hvo, kflidStPara_StyleRules, IID_ITsTextProps,
					(void **) &qttp));
				if (qttp)
					CheckHr(pvwenv->put_Props(qttp));
				// And make the paragraph containing the paragraph contents.
				CheckHr(pvwenv->OpenParagraph());
				CheckHr(pvwenv->AddStringProp(kflidStTxtPara_Contents));
				CheckHr(pvwenv->CloseParagraph());
			}
			break;
		}
	}
	catch (Throwable & thr)
	{
		return thr.Error();
	}
	catch (...)
	{
		return WarnHr(E_FAIL);
	}
	return S_OK;
}
Exemplo n.º 2
0
/*----------------------------------------------------------------------------------------------
	Check whether the content of this edit field has changed.
----------------------------------------------------------------------------------------------*/
bool AfDeFeSt::IsDirty()
{
	if (!m_fDirty)
	{
		if (!SuperClass::IsDirty() && m_qvcdMissing)
		{
			ComBool fDirty;
			ISilDataAccessPtr qsda;
			CheckHr(m_qvcdMissing->QueryInterface(IID_ISilDataAccess, (void **)&qsda));
			qsda->IsDirty(&fDirty);
			if (fDirty)
				m_fDirty = true;
		}
	}
	return m_fDirty;
}
Exemplo n.º 3
0
void AfDeFeSt::MakeRoot(IVwGraphics * pvg, ILgWritingSystemFactory * pwsf, IVwRootBox ** pprootb)
{
	AssertPtrN(pwsf);
	*pprootb = NULL;

	// Do we have a real text object? If not, make a fake one.
	int cpara = 0;
	ISilDataAccessPtr qsda = m_qcvd;
	if (m_hvoText)
		CheckHr(qsda->get_VecSize(m_hvoText, kflidStText_Paragraphs, &cpara));
	if (!cpara)
	{
		// We make a dummy text that is complete enough to edit, in a separate data access
		// object. On loss of focus, if this data access is dirty, we make corresponding
		// real objects.
		if (!m_hvoText)
			m_hvoText = -1;
		HVO hvoPara = -2;
		m_qvcdMissing.CreateInstance(CLSID_VwCacheDa);
		CheckHr(m_qvcdMissing->QueryInterface(IID_ISilDataAccess, (void **)&qsda));
		m_qvcdMissing->CacheVecProp(m_hvoText, kflidStText_Paragraphs, &hvoPara,1);
		ITsStrFactoryPtr qtsf;
		qtsf.CreateInstance(CLSID_TsStrFactory);
		ITsStringPtr qtssMissing;
		CheckHr(qtsf->MakeStringRgch(L"", 0, m_ws, &qtssMissing));
		m_qvcdMissing->CacheStringProp(hvoPara, kflidStTxtPara_Contents, qtssMissing);
	}

	IVwRootBoxPtr qrootb;
	qrootb.CreateInstance(CLSID_VwRootBox);
	CheckHr(qrootb->SetSite(this)); // pass root site
	int frag = kfrText;
	IVwViewConstructor * pvvc = m_qstvc;
	if (pwsf)
		CheckHr(qsda->putref_WritingSystemFactory(pwsf));
	CheckHr(qrootb->putref_DataAccess(qsda));
	CheckHr(qrootb->SetRootObjects(&m_hvoText, &pvvc, &frag,
		GetLpInfo()->GetAfStylesheet(), 1));
	*pprootb = qrootb;
	(*pprootb)->AddRef();

	RecMainWnd * prmw = dynamic_cast<RecMainWnd *>(m_qadsc->MainWindow());
	if (prmw)
		prmw->RegisterRootBox(qrootb);
}
Exemplo n.º 4
0
/*----------------------------------------------------------------------------------------------
	Insert material as appropriate to display the specified object.
	This method has not yet been tested...maybe not even compiled?
----------------------------------------------------------------------------------------------*/
STDMETHODIMP VwBaseVc::DisplayEmbeddedObject(IVwEnv * pvwenv, HVO hvo)
{
	BEGIN_COM_METHOD;
	ChkComArgPtr(pvwenv);
	// See if it is a CmPicture.
	ISilDataAccessPtr qsda;
	CheckHr(pvwenv->get_DataAccess(&qsda));
	int clsid;
	CheckHr(qsda->get_IntProp(hvo, kflidCmObject_Class, &clsid));
	if (clsid != kclidCmPicture)
		return S_OK; // don't know how to deal with it.
	StrUni stuRootDir = DirectoryFinder::FwRootDataDir();
	HVO hvoFile;
	CheckHr(qsda->get_ObjectProp(hvo, kflidCmPicture_PictureFile, &hvoFile));
	if (hvoFile == 0)
		return S_OK;
	SmartBstr sbstrFileName;
	CheckHr(qsda->get_UnicodeProp(hvoFile, kflidCmFile_InternalPath, &sbstrFileName));
	if (sbstrFileName.Length() == 0)
		return S_OK;
	StrUni stuPath;
	stuPath.Format(L"%s,%s,%s", stuRootDir.Chars(), L"\\", sbstrFileName.Chars());
	IPicturePtr qpic;
	try
	{
		IStreamPtr qstrm;
		FileStream::Create(stuPath, STGM_READ, &qstrm);
		STATSTG stg;
		CheckHr(qstrm->Stat(&stg, STATFLAG_NONAME));
		LONG cbdata = (LONG)stg.cbSize.QuadPart;
		CheckHr(::OleLoadPicture(qstrm, cbdata, FALSE, IID_IPicture, (LPVOID *)&qpic));
		CheckHr(pvwenv->AddPicture(qpic, ktagNotAnAttr, 0, 0));
	}
	catch (...)
	{
		return S_OK; // if anything goes wrong (e.g., file not found), just give up for now.
		// Todo: insert a 'file XXX not found string.
	}
	// Todo: also add the caption.

	END_COM_METHOD(g_fact, IID_IVwViewConstructor);
}
Exemplo n.º 5
0
/*----------------------------------------------------------------------------------------------
	Close the current editor, saving changes that were made. hwnd is the editor hwnd.
	@param fForce True if we want to force the editor closed without making any
		validity checks or saving any changes.
----------------------------------------------------------------------------------------------*/
void AfDeFeSt::EndEdit(bool fForce)
{
	if (m_qvcdMissing && !fForce)
	{
		ComBool fDirty;
		ISilDataAccessPtr qsdaTemp;
		CheckHr(m_qvcdMissing->QueryInterface(IID_ISilDataAccess, (void **)&qsdaTemp));
		qsdaTemp->IsDirty(&fDirty);
		if (fDirty)
		{
			// The text got edited. So, make a real text and copy the relevant info.
			// First get the paragraph list
			HvoVec vhvoParas;
			int chvoParas;

			// If we already had a text, we will notify it of new paragraphs.
			bool fNotifyText = m_hvoText > 0;

			CheckHr(qsdaTemp->get_VecSize(m_hvoText, kflidStText_Paragraphs, &chvoParas));
			int ihvo; // used twice
			for (ihvo = 0; ihvo < chvoParas; ihvo++)
			{
				HVO hvoPara;
				CheckHr(qsdaTemp->get_VecItem(m_hvoText, kflidStText_Paragraphs, ihvo,
					&hvoPara));
				vhvoParas.Push(hvoPara);
			}
			// Actually, we may have had a real text...if so, skip this step
			if (m_hvoText < 0)
			{
				m_qcvd->MakeNewObject(kclidStText, m_hvoObj, m_flid, -2, &m_hvoText);
			}
			else
			{
				// Check if the record has been edited by someone else since we first loaded
				// the data.
				HRESULT hrTemp;
				if ((hrTemp = m_qcvd->CheckTimeStamp(m_hvoText)) != 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.
					SuperClass::EndEdit(fForce);
					// REVIEW KenZ (PaulP):  There may need to be a refresh call made here.
					// It's difficult to know, however, since I haven't tracked down when
					// this method actually gets called.
					m_fDirty = false;
					return;
				}
			}

			// Now make real paragraph objects and set their properties.
			for (ihvo = 0; ihvo < chvoParas; ihvo++)
			{
				HVO hvoPara = vhvoParas[ihvo];
				ITsStringPtr qtss;
				ITsTextPropsPtr qttp;
				IUnknownPtr qunkTtp;
				CheckHr(qsdaTemp->get_UnknownProp(hvoPara, kflidStStyle_Rules, &qunkTtp));
				CheckHr(qunkTtp->QueryInterface(IID_ITsTextProps, (void **) &qttp));
				CheckHr(qsdaTemp->get_StringProp(hvoPara, kflidStTxtPara_Contents,
						&qtss));
				CheckHr(m_qcvd->MakeNewObject(kclidStTxtPara, m_hvoText, kflidStText_Paragraphs,
					ihvo, &hvoPara));
				if (qttp)
					CheckHr(m_qcvd->SetUnknown(hvoPara, kflidStPara_StyleRules, qttp));
				CheckHr(m_qcvd->SetString(hvoPara, kflidStTxtPara_Contents, qtss));
			}
			m_qvcdMissing.Clear();
			// Update the root object to point at the real text we just made.
			int frag = kfrText;
			IVwViewConstructor * pvvc = m_qstvc;
			CheckHr(m_qrootb->putref_DataAccess(m_qcvd));
			CheckHr(m_qrootb->SetRootObjects(&m_hvoText, &pvvc, &frag,
				GetLpInfo()->GetAfStylesheet(), 1));
			m_qadsc->UpdateAllDEWindows(m_hvoObj, m_flid);
			if (fNotifyText)
			{
				CheckHr(m_qcvd->PropChanged(m_qrootb, kpctNotifyAllButMe, m_hvoText,
					kflidStText_Paragraphs, 0,
							chvoParas, chvoParas));
			}
			else
			{
				CheckHr(m_qcvd->PropChanged(m_qrootb, kpctNotifyAllButMe, m_hvoObj, m_flid, 0,
							1, 1));
			}
		}
	}
	// Do this after the changes above, otherwise, our hwnd is no longer the child of a main
	// window, and we can't find the style sheet for the SetRootObjects call.
	SuperClass::EndEdit(fForce);
	m_fDirty = false;
}
Exemplo n.º 6
0
/*----------------------------------------------------------------------------------------------
	This is the main interesting method of displaying objects and fragments of them.
	Here a CmPossibilityList is displayed by displaying its Records.
	So far we only handle records that are objects of type CmPossibility (or a subclass).
	A CmPossibility (or derived object) is displayed according to the stored specifications.
----------------------------------------------------------------------------------------------*/
STDMETHODIMP CleCustDocVc::Display(IVwEnv * pvwenv, HVO hvo, int frag)
{
	BEGIN_COM_METHOD;
	ChkComArgPtr(pvwenv);

	bool fFlat = m_qcmw->IsFilterActive() || m_qcmw->IsSortMethodActive();

	// Constant fragments
	switch(frag)
	{
	case kfrcdSubItem:	// Override for special treatment.
		Assert(false); // sub-items are handled as main items; see below.
		break;
	case kfrcdMainItem:	// Override for special treatment.
		{
			// Get the complete list of the items in the order in which they are displayed.
			ISilDataAccessPtr qsda;
			CheckHr(pvwenv->get_DataAccess(&qsda));
			RecMainWndPtr qrmw = dynamic_cast<RecMainWnd *>(m_qcmw.Ptr());
			HVO hvoMain = qrmw->GetFilterId();
			int flidMain = qrmw->GetFilterFlid();
			Assert(qrmw);
			int chvoMain;
			Vector<HVO> vhvoMain;
			CheckHr(qsda->get_VecSize(hvoMain, flidMain, &chvoMain));
			for (int ihvo = 0; ihvo < chvoMain; ihvo++)
			{
				HVO hvoTmp;
				CheckHr(qsda->get_VecItem(hvoMain, flidMain, ihvo, &hvoTmp));
				vhvoMain.Push(hvoTmp);
			}

			ITsTextPropsPtr qttp;
			PossItemInfo * ppii;
			PossListInfoPtr qpli;
			m_qlpi->GetPossListAndItem(hvo, m_qlpi->AnalWs(), &ppii, &qpli);
			int ilevel; ilevel = ppii->GetLevel(qpli);
			int ipss;
			for (ipss = 0; ipss < vhvoMain.Size(); ipss++)
			{
				if (hvo == vhvoMain[ipss])
					break;
			}
			Assert(ipss < vhvoMain.Size());

			if (fFlat)
				qttp = m_qttpMainFlat;
			else if (ilevel > 0)
			{
				if (ipss == qpli->GetCount() - 1)
					qttp = m_qttpSubLast;
				else
					qttp = m_qttpSub;
				// Adjust the indentation to match the current level.
				ITsPropsBldrPtr qtpb;
				CheckHr(qttp->GetBldr(&qtpb));
				CheckHr(qtpb->SetIntPropValues(ktptPadLeading, ktpvMilliPoint,
					(ilevel * kdzmpInch / 5)));  // indent 1/5" per level
				CheckHr(qtpb->GetTextProps(&qttp));
			}
			else if (ipss == 0) // first item
				qttp = m_qttpMainFirst;
			else if (ipss == qpli->GetCount() - 1)
				qttp = m_qttpMainLast;
			else
				qttp = m_qttpMain;
			CheckHr(pvwenv->put_Props(qttp));
			BodyOfRecord(pvwenv, hvo, qttp);
			break;
		}
	default:
		return SuperClass::Display(pvwenv, hvo, frag);
	}
	return S_OK;

	END_COM_METHOD(g_fact1, IID_IVwViewConstructor)
}
Exemplo n.º 7
0
/*----------------------------------------------------------------------------------------------
	This is the method for displaying the name of a single reference. This view shows the
	name for an RnGenericRec consisting of the type of record, hyphen, title, hyphen,
	creation date. "Subevent - Fishing for pirana - 3/22/2001"
	@param pvwenv Pointer to the view environment.
	@param hvo The id of the object we are displaying.
	@param frag Identifies the part of the view we are currently displaying.
	@return HRESULT indicating success (S_OK), or failure (E_FAIL).
----------------------------------------------------------------------------------------------*/
STDMETHODIMP CleRecVc::Display(IVwEnv * pvwenv, HVO hvo, int frag)
{
	BEGIN_COM_METHOD;
	ChkComArgPtr(pvwenv);

	Assert(false);  // Is this needed for poss lists?

	switch (frag)
	{
	case kfrRefName:
	case kfrListName:
		{
			SmartBstr bstrClass = L"UnLoaded";
			ITsStringPtr qtss;
			ITsStringPtr qtssTitle;

			// Make sure data is loaded.
			LoadDataFor(pvwenv, hvo, frag);
			AfMainWnd * pafw = AfApp::Papp()->GetCurMainWnd();
			AssertPtr(pafw);
			AfLpInfo * plpi = pafw->GetLpInfo();
			AssertPtr(plpi);
			AfDbInfo * pdbi = plpi->GetDbInfo();
			AssertPtr(pdbi);

#define HYPERLINK_CHANGE
#ifdef HYPERLINK_CHANGE
			// Update the string with the new object.
			GUID uid;
			if (!pdbi->GetGuidFromId(hvo, uid))
				ReturnHr(E_FAIL);

			StrUni stuData;
			OLECHAR * prgchData;
			// Make large enough for a guid plus the type character at the start.
			stuData.SetSize(isizeof(GUID) / isizeof(OLECHAR) + 1, &prgchData);
			*prgchData = kodtNameGuidHot;
			memmove(prgchData + 1, &uid, isizeof(uid));

			ITsPropsFactoryPtr qtpf;
			ITsPropsBldrPtr qtpb;
			ITsTextPropsPtr qttp;
			ITsStrFactoryPtr qtsf;

			qtpf.CreateInstance(CLSID_TsPropsFactory);
			CheckHr(qtpf->GetPropsBldr(&qtpb));
			CheckHr(qtpb->SetIntPropValues(ktptWs, ktpvDefault, pdbi->UserWs()));
			CheckHr(qtpb->SetStrPropValue(ktptObjData, stuData.Bstr()));
			CheckHr(qtpb->GetTextProps(&qttp));
			qtsf.CreateInstance(CLSID_TsStrFactory);
			OLECHAR chObj = kchObject;
			CheckHr(qtsf->MakeStringWithPropsRgch(&chObj, 1, qttp, &qtss));

			CheckHr(pvwenv->OpenSpan());
			// REVIEW KenZ(RandyR) Whey are DN flids in this app?
			int flid = kflidRnGenericRec_Title;
			CheckHr(pvwenv->NoteDependency(&hvo, &flid, 1));
			CheckHr(pvwenv->AddString(qtss)); // The class name.
			CheckHr(pvwenv->CloseSpan());
#else // !HYPERLINK_CHANGE
			int clid;
			HVO hvoOwn;
			int64 ntim;
			int ws = pdbi->UserWs();
			ISilDataAccessPtr qsda;
			CheckHr(pvwenv->get_DataAccess(&qsda));
			AssertPtr(qsda);
			CheckHr(qsda->get_IntProp(hvo, kflidCmObject_Class, &clid));
			CheckHr(qsda->get_ObjectProp(hvo, kflidCmObject_Owner, &hvoOwn));
			// REVIEW KenZ(RandyR) Whey are DN flids in this app?
			CheckHr(qsda->get_TimeProp(hvo, kflidRnGenericRec_DateCreated, &ntim));
			CheckHr(qsda->get_StringProp(hvo, kflidRnGenericRec_Title, &qtssTitle));

			int stid;
			// Sharon! Not needed?
//			if (clid == kclidRnEvent)
//			{
//				if (plpi->GetRnId() == hvoOwn)
//					stid = kstidEvent;
//				else
//					stid = kstidSubevent;
//			}
//			else if (clid == kclidRnAnalysis)
//			{
//				if (plpi->GetRnId() == hvoOwn)
//					stid = kstidAnalysis;
//				else
//					stid = kstidSubanalysis;
//			}
			StrUni stu(stid);
			StrUni stuSep(kstidSpHyphenSp);
			ITsStrFactoryPtr qtsf;
			qtsf.CreateInstance(CLSID_TsStrFactory);
			CheckHr(qtsf->MakeStringRgch(stu.Chars(), stu.Length(), ws, &qtss));

			CheckHr(pvwenv->OpenSpan());
			CheckHr(pvwenv->AddString(qtss)); // The class name.
			CheckHr(qtsf->MakeStringRgch(stuSep.Chars(), stuSep.Length(), ws, &qtss));
			CheckHr(pvwenv->AddString(qtss)); // The separator
			//CheckHr(pvwenv->AddString(qtssTitle)); // The title.
			// The following gives the title of the owning object instead of the ref.
			CheckHr(pvwenv->AddStringProp(kflidRnGenericRec_Title, this)); // The title.
			CheckHr(pvwenv->AddString(qtss)); // The separator
			// Leave the date blank if a date doesn't exist.
			if (ntim)
			{
				// Convert the date to a system date.
				SilTime tim = ntim;
				SYSTEMTIME stim;
				stim.wYear = (unsigned short) tim.Year();
				stim.wMonth = (unsigned short) tim.Month();
				stim.wDay = (unsigned short) tim.Date();

				// Then format it to a time based on the current user locale.
				char rgchDate[50]; // Tuesday, August 15, 2000		mardi 15 août 2000
				::GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &stim, NULL, rgchDate, 50);
				stu = rgchDate;
				CheckHr(qtsf->MakeStringRgch(stu.Chars(), stu.Length(), ws, &qtss));
				CheckHr(pvwenv->AddString(qtss)); // The date.
			}
			CheckHr(pvwenv->CloseSpan());
#endif // HYPERLINK_CHANGE

			break;
		}
	}

	return S_OK;

	END_COM_METHOD(g_fact2, IID_IVwViewConstructor)
}
Exemplo n.º 8
0
/*----------------------------------------------------------------------------------------------
	Load the data needed to display this view. In this case, we need to load the class, owner
	(so we can tell whether it is a subitem), the title, and create date. If all of these are
	already in the cache, don't reload it.
	@param pvwenv Pointer to the view environment.
	@param hvo The id of the object we are displaying.
	@param frag Identifies the part of the view we are currently displaying.
	@return HRESULT indicating success (S_OK), or failure (E_FAIL).
----------------------------------------------------------------------------------------------*/
STDMETHODIMP CleRecVc::LoadDataFor(IVwEnv * pvwenv, HVO hvo, int frag)
{
	BEGIN_COM_METHOD;
	ChkComArgPtr(pvwenv);

	Assert(false);  // TODO: rework

	StrUni stuSql;
	ISilDataAccessPtr qsda;
	CheckHr(pvwenv->get_DataAccess(&qsda));
	bool fLoaded = false;
	int clid;
	CheckHr(qsda->get_IntProp(hvo, kflidCmObject_Class, &clid));
	if (clid)
	{
		HVO hvoOwn;
		CheckHr(qsda->get_ObjectProp(hvo, kflidCmObject_Owner, &hvoOwn));
		if (hvoOwn)
		{
			int64 tim;
			// REVIEW KenZ(RandyR) Whey are DN flids in this app?
			CheckHr(qsda->get_TimeProp(hvo, kflidRnGenericRec_DateCreated, &tim));
			if (tim)
			{
				ITsStringPtr qtss;
				CheckHr(qsda->get_StringProp(hvo, kflidRnGenericRec_Title, &qtss));
				if (qtss)
				{
					int cch;
					CheckHr(qtss->get_Length(&cch));
					if (cch)
						fLoaded = true;
				}
			}
		}
	}

	if (!fLoaded)
	{
		// If any field is missing from the cache, load everything.
		IDbColSpecPtr qdcs;
		IVwOleDbDaPtr qda;
		CheckHr(qsda->QueryInterface(IID_IVwOleDbDa, (void**)&qda));
		stuSql.Format(L"select id, Class$, Owner$, DateCreated, Title, Title_Fmt "
			L"from RnGenericRec_ "
			L"where id = %d", hvo);
		qdcs.CreateInstance(CLSID_DbColSpec);
		CheckHr(qdcs->Push(koctBaseId, 0, 0, 0));
		CheckHr(qdcs->Push(koctInt, 1, kflidCmObject_Class, 0));
		CheckHr(qdcs->Push(koctObj, 1, kflidCmObject_Owner, 0));
			// REVIEW KenZ(RandyR) Whey are DN flids in this app?
		CheckHr(qdcs->Push(koctTime, 1, kflidRnGenericRec_DateCreated, 0));
		CheckHr(qdcs->Push(koctString, 1, kflidRnGenericRec_Title, 0));
		CheckHr(qdcs->Push(koctFmt, 1, kflidRnGenericRec_Title, 0));

		AfMainWnd * pafw = AfApp::Papp()->GetCurMainWnd();
		AssertPtr(pafw);
		AfStatusBar * pstbr = pafw->GetStatusBarWnd();
		AssertPtr(pstbr);
		bool fProgBar = pstbr->IsProgressBarActive();
		if (!fProgBar)
		{
			StrApp strMsg(kstidStBar_LoadingData);
			pstbr->StartProgressBar(strMsg.Chars(), 0, 70, 1);
		}

		// Execute the query and store results in the cache.
		CheckHr(qda->Load(stuSql.Bstr(), qdcs, hvo, 0, pstbr, NULL));
		if (!fProgBar)
			pstbr->EndProgressBar();
	}

	return S_OK;

	END_COM_METHOD(g_fact2, IID_IVwViewConstructor)
}
Exemplo n.º 9
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;
		}
	}
}