/*---------------------------------------------------------------------------------------------- Load the data from the given file into an empty window. ----------------------------------------------------------------------------------------------*/ void WpDa::LoadIntoEmpty(StrAnsi staFileName, WpChildWnd * pwcw) { Assert(staFileName != ""); int ctss; CheckHr(get_VecSize(1, kflidStText_Paragraphs, &ctss)); Assert(ctss <= 1); Vector<StrUni> vstu; ReadTextFromFile(staFileName, vstu); HVO * prghvoPara = NewObj HVO[vstu.Size()]; for (int istu = 0; istu < vstu.Size(); istu++) prghvoPara[istu] = istu + 2; CacheVecProp(1, kflidStText_Paragraphs, prghvoPara, vstu.Size()); ITsStrFactoryPtr qtsf; qtsf.CreateInstance(CLSID_TsStrFactory); int enc = 100; // replace by the right number when we figure out what it is for (istu = 0; istu < vstu.Size(); istu++) { StrUni stuPara = vstu[istu]; ITsStringPtr qtss; CheckHr(qtsf->MakeStringRgch(stuPara.Chars(), stuPara.Length(), enc, &qtss)); CacheStringProp(istu + 2, kflidStTxtPara_Contents, qtss); } ITsPropsBldrPtr qtpb; qtpb.CreateInstance(CLSID_TsPropsBldr); StrUni stuNormal = L"Normal"; CheckHr(qtpb->SetStrPropValue(kspNamedStyle, stuNormal.Bstr())); delete[] prghvoPara; pwcw->ChangeNumberOfStrings(vstu.Size()); }
/*---------------------------------------------------------------------------------------------- Initialize the data from the given file, or create a new empty string. ----------------------------------------------------------------------------------------------*/ void WpDa::InitNew(StrAnsi staFileName) { if (staFileName == "") { InitNewEmpty(); return; } Vector<StrUni> vstu; ReadTextFromFile(staFileName, vstu); HVO * prghvoPara = NewObj HVO[vstu.Size()]; for (int istu = 0; istu < vstu.Size(); istu++) prghvoPara[istu] = istu + 2; CacheVecProp(1, kflidStText_Paragraphs, prghvoPara, vstu.Size()); ITsStrFactoryPtr qtsf; qtsf.CreateInstance(CLSID_TsStrFactory); int enc = 100; // replace by the right number when we figure out what it is for (istu = 0; istu < vstu.Size(); istu++) { StrUni stuPara = vstu[istu]; ITsStringPtr qtss; CheckHr(qtsf->MakeStringRgch(stuPara.Chars(), stuPara.Length(), enc, &qtss)); CacheStringProp(istu + 2, kflidStTxtPara_Contents, qtss); } ITsPropsBldrPtr qtpb; qtpb.CreateInstance(CLSID_TsPropsBldr); StrUni stuNormal = L"Normal"; CheckHr(qtpb->SetStrPropValue(kspNamedStyle,stuNormal.Bstr())); delete[] prghvoPara; }
/*---------------------------------------------------------------------------------------------- Initialize a style with an empty text properties object. Called from the XML import routines. ----------------------------------------------------------------------------------------------*/ void WpStylesheet::AddEmptyTextProps(HVO hvoStyle) { WpDaPtr wpda = dynamic_cast<WpDa *>(m_qsda.Ptr()); ITsTextPropsPtr qttp; ITsPropsBldrPtr qtpb; qtpb.CreateInstance(CLSID_TsPropsBldr); CheckHr(qtpb->GetTextProps(&qttp)); CheckHr(wpda->CacheUnknown(hvoStyle, kflidStStyle_Rules, qttp)); }
/*---------------------------------------------------------------------------------------------- Initialize an empty document. It has a document object (always ID 1!) and one paragraph containing (implicitly) an empty string. Style is set to Normal Review SharonC(JohnT): what encoding should the empty string have?? ----------------------------------------------------------------------------------------------*/ void WpDa::InitNewEmpty() { HVO hvoPara = 2; CacheVecProp(1, kflidStText_Paragraphs, &hvoPara, 1); ITsStrFactoryPtr qtsf; qtsf.CreateInstance(CLSID_TsStrFactory); ITsStringPtr qtss; int enc = 100; CheckHr(qtsf->MakeStringRgch(L"", 0, enc, &qtss)); CacheStringProp(hvoPara, kflidStTxtPara_Contents, qtss); ITsPropsBldrPtr qtpb; qtpb.CreateInstance(CLSID_TsPropsBldr); StrUni stuNormal = L"Normal"; CheckHr(qtpb->SetStrPropValue(kspNamedStyle, stuNormal.Bstr())); }
/*---------------------------------------------------------------------------------------------- Change all the occurrences of the old styles names to the new names, and delete any obsolete names. ----------------------------------------------------------------------------------------------*/ bool FwDbMergeStyles::ProcessFormatting(ComVector<ITsTextProps> & vqttp, StrUni stuDelete) { bool fAnyChanged = false; for (int ittp = 0; ittp < vqttp.Size(); ittp++) { SmartBstr sbstr; HRESULT hr; CheckHr(hr = vqttp[ittp]->GetStrPropValue(ktptNamedStyle, &sbstr)); if (hr == S_OK && sbstr.Length() > 0) { ITsPropsBldrPtr qtpb = NULL; StrUni stuOld(sbstr.Chars()); StrUni stuNew; if (Delete(stuOld)) { CheckHr(vqttp[ittp]->GetBldr(&qtpb)); if (stuDelete.Length() == 0) { // If the style name to delete is empty, we want to pass null // so that the named style string property is removed. CheckHr(qtpb->SetStrPropValue(ktptNamedStyle, NULL)); } else CheckHr(qtpb->SetStrPropValue(ktptNamedStyle, stuDelete.Bstr())); } else if (Rename(stuOld, stuNew)) { CheckHr(vqttp[ittp]->GetBldr(&qtpb)); CheckHr(qtpb->SetStrPropValue(ktptNamedStyle, stuNew.Bstr())); } if (qtpb) { ITsTextPropsPtr qttpNew; CheckHr(qtpb->GetTextProps(&qttpNew)); vqttp[ittp] = qttpNew; fAnyChanged = true; } } } return fAnyChanged; }
/*---------------------------------------------------------------------------------------------- Create a paragraph style called "Normal". For now just use a minimal (ie, empty) set of text properties. ----------------------------------------------------------------------------------------------*/ void WpStylesheet::AddNormalParaStyle() { WpDaPtr wpda = dynamic_cast<WpDa *>(m_qsda.Ptr()); Assert(wpda); HVO hvoNormal; CheckHr(GetNewStyleHVO(&hvoNormal)); ITsTextPropsPtr qttp; ITsPropsBldrPtr qtpb; qtpb.CreateInstance(CLSID_TsPropsBldr); CheckHr(qtpb->GetTextProps(&qttp)); // Get a non-const version of the "Normal" string: // REVIEW: Should the PutStyle method be made to accept const strings? SmartBstr sbstrName(g_pszwStyleNormal); SmartBstr sbstrUsage(g_pszwStyleNormal); CheckHr(PutStyle(sbstrName, sbstrUsage, hvoNormal, 0, 0, kstParagraph, true, false, qttp)); CheckHr(wpda->CacheObjProp(hvoNormal, kflidStStyle_Next, hvoNormal)); }
/*---------------------------------------------------------------------------------------------- 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) }
/*---------------------------------------------------------------------------------------------- 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) }
/*---------------------------------------------------------------------------------------------- Construct the view constructor. Pass the RecordSpec of the view it is for, which allows it to find its block specs. ENHANCE JohnT: This is a rather low level object to know about the application and its list of views. Should we just pass in the list of block specs? ----------------------------------------------------------------------------------------------*/ CleCustDocVc::CleCustDocVc(UserViewSpec * puvs, AfLpInfo * plpi, CleMainWnd * pcmw) : VwCustDocVc(puvs, plpi, 0, kflidCmPossibilityList_Possibilities) { ITsStrFactoryPtr qtsf; qtsf.CreateInstance(CLSID_TsStrFactory); StrUni stu; stu.Load(kstidSpaces0); CheckHr(qtsf->MakeStringRgch(stu.Chars(), stu.Length(), m_qlpi->GetDbInfo()->UserWs(), &m_qtssMissing)); ITsPropsBldrPtr qtpb; qtpb.CreateInstance(CLSID_TsPropsBldr); // Border thickness below about 1/96 inch, a single pixel on a typical display. CheckHr(qtpb->SetIntPropValues(ktptBorderTop, ktpvMilliPoint, kdzmpInch / 96)); // About a line (say 12 point) of white space above and below the border. CheckHr(qtpb->SetIntPropValues(ktptPadTop, ktpvMilliPoint, 12000)); CheckHr(qtpb->SetIntPropValues(ktptMarginTop, ktpvMilliPoint, 12000)); CheckHr(qtpb->GetTextProps(&m_qttpMain)); CheckHr(qtpb->SetIntPropValues(ktptBorderBottom, ktpvMilliPoint, kdzmpInch / 96)); CheckHr(qtpb->SetIntPropValues(ktptPadBottom, ktpvMilliPoint, 12000)); CheckHr(qtpb->GetTextProps(&m_qttpMainLast)); qtpb.CreateInstance(CLSID_TsPropsBldr); CheckHr(qtpb->SetIntPropValues(ktptMarginTop, ktpvMilliPoint, 12000)); CheckHr(qtpb->GetTextProps(&m_qttpMainFirst)); qtpb.CreateInstance(CLSID_TsPropsBldr); // Border thickness below about 1/96 inch, a single pixel on a typical display. CheckHr(qtpb->SetIntPropValues(ktptBorderBottom, ktpvMilliPoint, kdzmpInch / 96)); CheckHr(qtpb->SetIntPropValues(ktptPadBottom, ktpvMilliPoint, 12000)); CheckHr(qtpb->SetIntPropValues(ktptMarginBottom, ktpvMilliPoint, 12000)); CheckHr(qtpb->GetTextProps(&m_qttpMainFlat)); // And make the one for subentries. qtpb.CreateInstance(CLSID_TsPropsBldr); CheckHr(qtpb->SetIntPropValues(ktptPadTop, ktpvMilliPoint, 12000)); CheckHr(qtpb->SetIntPropValues(ktptBorderTop, ktpvMilliPoint, 0)); CheckHr(qtpb->SetIntPropValues(ktptMarginBottom, ktpvMilliPoint, 0)); // The value below is sort of a default for one level of indentation; it will be // adjusted for lower levels. CheckHr(qtpb->SetIntPropValues(ktptPadLeading, ktpvMilliPoint, kdzmpInch * 3 / 10)); CheckHr(qtpb->GetTextProps(&m_qttpSub)); CheckHr(qtpb->SetIntPropValues(ktptBorderBottom, ktpvMilliPoint, kdzmpInch / 96)); CheckHr(qtpb->SetIntPropValues(ktptPadBottom, ktpvMilliPoint, 12000)); CheckHr(qtpb->GetTextProps(&m_qttpSubLast)); m_qRecVc.Attach(NewObj CleRecVc); m_qcmw.Attach(pcmw); AddRefObj(pcmw); PossListInfoPtr qpli; m_qlpi->LoadPossList(pcmw->GetHvoPssl(), pcmw->AnalysisEnc(), &qpli); m_hvoPssl = qpli->GetPsslId(); }
HRESULT ViewTest2::Run() { // Make a special VwGraphics (#define BASELINE in compiling it turns on special features). // This VwGraphics will not draw (2nd arg false) but will record attempts at drawing into // the baseline. m_psts = NewObj SilTestSite(); m_qst.Attach(m_psts); m_qvg.Attach(NewObj VwGraphics(m_psts, false, true)); m_qst->SetBaselineFile(SmartBstr(L"c:\\fw\\testlog\\log\\VwGraphics").Bstr()); // Todo LukeU(JohnT): make an off-screen bitmap HDC and initialize the VwGraphics to use it. // Here is your off-screen bitmap and memory surface HDC hdcScr, hdcMem; hdcScr = GetDC(NULL); hdcMem = CreateCompatibleDC(hdcScr); HBITMAP hBitmap = CreateCompatibleBitmap(hdcMem, 400, 400); SelectObject(hdcMem, hBitmap); ReleaseDC(NULL, hdcScr); m_qvg->Initialize(hdcMem); // Make a dummy root site for the Root box to talk back to m_qtrs.Attach(NewObj VwTestRootSite); m_qtrs->SetVgObject(m_qvg); Rect rcSrc(0, 0, 96, 96); Rect rcDst(0, 0, 96, 96); m_qtrs->SetSrcRoot(rcSrc); m_qtrs->SetDstRoot(rcDst); // Make our view constructor. m_qtvc.Attach(NewObj TestStVc); // Put some dummy data into a cache. HVO 1 identifies the text as a whole. // Arbitrarily objects 2, 3, and 4 are the three paragraphs of our test data. m_qda.Attach(NewObj VwCacheDa); HVO rghvoPara[3] = {2, 3, 4}; m_qda->CacheVecProp(1, kflidStText_Paragraphs, rghvoPara, 3); ITsStrFactoryPtr qtsf; qtsf.CreateInstance(CLSID_TsStrFactory); ITsStringPtr qtss; int enc = 100; StrUni stuPara0 = L"This is the first paragraph"; StrUni stuPara1 = L"Here is another paragraph, quite silly and trivial but it should " L"help test things"; StrUni stuPara2 = L"I try to keep the text in these quite different so they can't be " L"confused"; CheckHr(qtsf->MakeStringRgch(stuPara0.Chars(), stuPara0.Length(), enc, &qtss)); m_qda->CacheStringProp(rghvoPara[0], kflidStTxtPara_Contents, qtss); CheckHr(qtsf->MakeStringRgch(stuPara1.Chars(), stuPara1.Length(), enc, &qtss)); m_qda->CacheStringProp(rghvoPara[1], kflidStTxtPara_Contents, qtss); CheckHr(qtsf->MakeStringRgch(stuPara2.Chars(), stuPara2.Length(), enc, &qtss)); m_qda->CacheStringProp(rghvoPara[2], kflidStTxtPara_Contents, qtss); ITsPropsBldrPtr qtpb; qtpb.CreateInstance(CLSID_TsPropsBldr); StrUni stuNormal = L"Normal"; CheckHr(qtpb->SetStrPropValue(kspNamedStyle, stuNormal.Bstr())); // Make the root box and initialize it. m_qrootb.CreateInstance(CLSID_VwRootBox); // OK, we have a root box set up. Now we can try some tests on it! TestInit(); TestDataAccess(); TestLayout(350); TestDrawRoot(); TestOverlay(); TestMakeSimpleSel(); TestMakeTextSelection(); TestKeys(); TestMouse(); Testget_Site(); TestLoseFocus(); TestListener(); m_qrootb->Close(); m_qrootb.Clear(); m_qda.Clear(); DeleteDC(hdcMem); DeleteObject(hBitmap); return S_OK; }