/*---------------------------------------------------------------------------------------------- DisplayVariant is used for times and enumerations. ----------------------------------------------------------------------------------------------*/ STDMETHODIMP CleCustDocVc::DisplayVariant(IVwEnv * pvwenv, int tag, VARIANT v, int frag, ITsString ** pptss) { BEGIN_COM_METHOD; ChkComArgPtr(pvwenv); ChkComOutPtr(pptss); ITsStrFactoryPtr qtsf; qtsf.CreateInstance(CLSID_TsStrFactory); int ws = m_qlpi->GetDbInfo()->UserWs(); if (tag == kflidCmPerson_Gender || tag == kflidCmPerson_IsResearcher) { int itss = v.intVal; int stid; switch (tag) { case kflidCmPerson_Gender: stid = kstidEnumGender; break; case kflidCmPerson_IsResearcher: stid = kstidEnumNoYes; if (itss) itss = 1; break; default: Assert(false); break; } StrUni stuEnum(stid); const wchar * pszEnum = stuEnum.Chars(); const wchar * pszEnumLim = stuEnum.Chars() + stuEnum.Length(); ITsStringPtr qtss; //ITsStrFactoryPtr qtsf; //qtsf.CreateInstance(CLSID_TsStrFactory); int itssTry = 0; while (pszEnum < pszEnumLim && itssTry <= itss) { const wchar * pszEnumNl = wcschr(pszEnum, '\n'); if (!pszEnumNl) pszEnumNl = pszEnumLim; if (itss == itssTry) { return qtsf->MakeStringRgch(pszEnum, (pszEnumNl - pszEnum), ws, pptss); } itssTry++; pszEnum = pszEnumNl + 1; } // Fall-back behavior if we couldn't find a string: use the integer value. char rgch[20]; _itoa_s(itss, rgch, 10); StrUni stu(rgch); return qtsf->MakeStringRgch(stu.Chars(), stu.Length(), ws, pptss); } return SuperClass::DisplayVariant(pvwenv, tag, v, frag, pptss); END_COM_METHOD(g_fact1, IID_IVwViewConstructor) }
/*---------------------------------------------------------------------------------------------- Add a field editor for a given field at the location and indent specified. @param hvoRoot Id of the root object that holds the fields we want to display. @param clid Class of the root object. @param nLev Level (main/sub) of the root object in the window. @param pfsp The FldSpec that defines this field. @param pcvd Pointer to the CustViewDa specifying what fields to display. @param idfe Index where the new fields are to be inserted. On return it contains an index to the field following any inserted fields. @param nInd Indent of the fields to be added. @param fAlwaysVisible If true, show field regardless of pbsp->m_eVisibility ----------------------------------------------------------------------------------------------*/ void CleDeSplitChild::AddField(HVO hvoRoot, int clid, int nLev, FldSpec * pfsp, CustViewDa * pcvd, int & idfe, int nInd, bool fAlwaysVisible) { AssertPtr(pcvd); AssertPtr(pfsp); bool fCheckMissingData = fAlwaysVisible ? false : pfsp->m_eVisibility == kFTVisIfData; // If the user never wants to see this field, skip it. if (pfsp->m_eVisibility == kFTVisNever) return; ITsStringPtr qtss; AfLpInfo * plpi = pcvd->GetLpInfo(); AssertPtr(plpi); AfStatusBarPtr qstbr = MainWindow()->GetStatusBarWnd(); Assert(qstbr); switch(pfsp->m_ft) { case kftEnum: { AfDeFeComboBox * pdecb = NewObj AfDeFeComboBox(); ITsStrFactoryPtr qtsf; qtsf.CreateInstance(CLSID_TsStrFactory); int itss; CheckHr(pcvd->get_IntProp(hvoRoot, pfsp->m_flid, &itss)); pdecb->Initialize(hvoRoot, pfsp->m_flid, nInd, pfsp->m_qtssLabel, pfsp->m_qtssHelp, this, pfsp); pdecb->Init(pfsp->m_pnt); ComVector<ITsString> * pvtss; pvtss = pdecb->GetVec(); int stid; switch (pfsp->m_flid) { case kflidCmPerson_Gender: stid = kstidEnumGender; break; #ifdef ADD_LEXTEXT_LISTS case kflidCmAnnotationDefn_AllowsComment: // Fall through. case kflidCmAnnotationDefn_AllowsFeatureStructure: // Fall through. case kflidCmAnnotationDefn_AllowsInstanceOf: // Fall through. case kflidCmAnnotationDefn_UserCanCreate: // Fall through. case kflidCmAnnotationDefn_CanCreateOrphan: // Fall through. case kflidCmAnnotationDefn_PromptUser: // Fall through. case kflidCmAnnotationDefn_CopyCutPastable: // Fall through. case kflidCmAnnotationDefn_ZeroWidth: // Fall through. case kflidCmAnnotationDefn_Multi: // Fall through. #endif case kflidMoInflAffixSlot_Optional: // Fall through. case kflidCmPerson_IsResearcher: stid = kstidEnumNoYes; if (itss) itss = 1; break; default: Assert(false); // A list must be provided above. break; } StrUni stuEnum(stid); const wchar * pszEnum = stuEnum.Chars(); const wchar * pszEnumLim = stuEnum.Chars() + stuEnum.Length(); while (pszEnum < pszEnumLim) { const wchar * pszEnumNl = wcschr(pszEnum, '\n'); if (!pszEnumNl) pszEnumNl = pszEnumLim; AfDbInfo * pdbi = plpi->GetDbInfo(); AssertPtr(pdbi); int wsUser = pdbi->UserWs(); qtsf->MakeStringRgch(pszEnum, pszEnumNl - pszEnum, wsUser, &qtss); pvtss->Push(qtss); pszEnum = pszEnumNl + 1; } pdecb->SetIndex(itss); m_vdfe.Insert(idfe++, pdecb); } return; case kftMsa: // Fall through. case kftMta: { Vector<int> vwsT; Vector<int> & vws = vwsT; // We need a special editor for name and address to catch changes to update the // tree views. if ((pfsp->m_flid == kflidCmPossibility_Name) || (pfsp->m_flid == kflidCmPossibility_Abbreviation)) { CleMainWnd * pcmw = dynamic_cast<CleMainWnd *>(MainWindow()); Assert(pcmw); // PossListInfoPtr qpli = pcmw->GetPossListInfoPtr(); int wsPL= pcmw->GetWsPssl(); switch (wsPL) { case kwsAnals: vws = plpi->AnalWss(); break; case kwsVerns: vws = plpi->VernWss(); break; case kwsAnal: vwsT.Push(plpi->AnalWs()); break; case kwsVern: vwsT.Push(plpi->VernWs()); break; case kwsAnalVerns: vws = plpi->AnalVernWss(); break; case kwsVernAnals: vws = plpi->VernAnalWss(); break; default: vwsT.Push(wsPL); break; } if (fCheckMissingData) { ITsStringPtr qtss; int iws; for (iws = vws.Size(); --iws >= 0; ) { CheckHr(pcvd->get_MultiStringAlt(hvoRoot, pfsp->m_flid, vws[iws], &qtss)); int cch; CheckHr(qtss->get_Length(&cch)); if (cch) break; } if (iws < 0) return; // All writing systems are empty. } // An extra ref cnt is created here which is eventually assigned to the vector. CleDeFeStringPtr qdfs = NewObj CleDeFeString; qdfs->Initialize(hvoRoot, pfsp->m_flid, nInd, pfsp->m_qtssLabel, pfsp->m_qtssHelp, this, pfsp); if (pfsp->m_ft == kftMta) qdfs->Init(&vws, ktptSemiEditable); else qdfs->Init(&vws, ktptIsEditable); m_vdfe.Insert(idfe++, qdfs); } else { switch (pfsp->m_ws) { case kwsAnals: vws = plpi->AnalWss(); break; case kwsVerns: vws = plpi->VernWss(); break; case kwsAnal: vwsT.Push(plpi->AnalWs()); break; case kwsVern: vwsT.Push(plpi->VernWs()); break; case kwsAnalVerns: vwsT = plpi->AnalVernWss(); break; case kwsVernAnals: vwsT = plpi->VernAnalWss(); break; default: vwsT.Push(pfsp->m_ws); Assert(pfsp->m_ws); break; } if (fCheckMissingData) { ITsStringPtr qtss; int iws; for (iws = vws.Size(); --iws >= 0; ) { CheckHr(pcvd->get_MultiStringAlt(hvoRoot, pfsp->m_flid, vws[iws], &qtss)); int cch; CheckHr(qtss->get_Length(&cch)); if (cch) break; } if (iws < 0) return; // All writing systems are empty. } // An extra ref cnt is created here which is eventually assigned to the vector. AfDeFeStringPtr qdfs = NewObj AfDeFeString; qdfs->Initialize(hvoRoot, pfsp->m_flid, nInd, pfsp->m_qtssLabel, pfsp->m_qtssHelp, this, pfsp); if (pfsp->m_ft == kftMta) qdfs->Init(&vws, ktptSemiEditable); else qdfs->Init(&vws, ktptIsEditable); m_vdfe.Insert(idfe++, qdfs); } } return; case kftExpandable: // Fall through. case kftSubItems: return; case kftObjRefAtomic: // Fall through. case kftObjRefSeq: { bool fMultiRefs; if (pfsp->m_ft == kftObjRefAtomic) { HVO hvoRef; CheckHr(pcvd->get_ObjectProp(hvoRoot, pfsp->m_flid, &hvoRef)); fMultiRefs = false; if (fCheckMissingData && !hvoRef) return; } else { fMultiRefs = true; if (fCheckMissingData) // otherwise no need to check { int chvo; CheckHr(pcvd->get_VecSize(hvoRoot, pfsp->m_flid, &chvo)); if (!chvo) return; } } AfDeFeRefs * pdfr = NewObj AfDeFeRefs; pdfr->Initialize(hvoRoot, pfsp->m_flid, nInd, pfsp->m_qtssLabel, pfsp->m_qtssHelp, this, pfsp); switch (pfsp->m_flid) { default: // Standard kftObjRefAtomic & kftObjRefSeq fields are all handled in the superclass. SuperClass::AddField(hvoRoot, clid, nLev, pfsp, pcvd, idfe, nInd, fAlwaysVisible); return; } m_vdfe.Insert(idfe++, pdfr); } return; } qstbr->StepProgressBar(10); // Standard fields are all handled in the superclass. SuperClass::AddField(hvoRoot, clid, nLev, pfsp, pcvd, idfe, nInd, fAlwaysVisible); return; }