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