/*---------------------------------------------------------------------------------------------- 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) }
/*---------------------------------------------------------------------------------------------- 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; }