public void TestFwTextBoxSize() { using (var textBox = new FwTextBox()) { textBox.AdjustStringHeight = true; textBox.controlID = null; textBox.Enabled = false; textBox.TabStop = false; textBox.BackColor = System.Drawing.SystemColors.Control; textBox.HasBorder = false; textBox.Location = new System.Drawing.Point(5, 5); textBox.Size = new System.Drawing.Size(100, 30); textBox.Dock = System.Windows.Forms.DockStyle.Fill; textBox.Visible = true; textBox.WordWrap = false; textBox.Tss = TsStringHelper.MakeTSS("Test", m_hvoEnglishWs); Assert.LessOrEqual(textBox.PreferredHeight, textBox.Height, "The simple string should fit within the default height."); Assert.LessOrEqual(textBox.PreferredWidth, textBox.Width, "The simple string should fit within the default width."); textBox.Tss = TsStringHelper.MakeTSS("This is a very long string that should be larger than the default box size in some way or other.", m_hvoEnglishWs); Console.WriteLine("PreferredHeight 2 = {0}", textBox.PreferredHeight); Console.WriteLine("PreferredWidth 2 = {0}", textBox.PreferredWidth); Assert.LessOrEqual(textBox.PreferredHeight, textBox.Height, "The longer string should still fit within the default height (for no wordwrapping)."); Assert.Greater(textBox.PreferredWidth, textBox.Width, "The longer string should not fit within the default width (for no wordwrapping)"); textBox.WordWrap = true; textBox.Tss = TsStringHelper.MakeTSS("This is a very long string that should be even larger than the default box size in some way or other.", m_hvoEnglishWs); Console.WriteLine("PreferredHeight 3 = {0}", textBox.PreferredHeight); Console.WriteLine("PreferredWidth 3 = {0}", textBox.PreferredWidth); Assert.Greater(textBox.PreferredHeight, textBox.Height, "The longest string should not fit within the default height (for wordwrapping)."); Assert.LessOrEqual(textBox.PreferredWidth, textBox.Width, "The longest string should fit with the default width (for wordwrapping)."); } }
public void DeleteFootnoteWithoutORC() { IScrBook book = (IScrBook)m_scr.ScriptureBooksOS[0]; int originalFootnoteCount = book.FootnotesOS.Count; // Insert a new footnote into the collection and view IScrFootnote footnote = Cache.ServiceLocator.GetInstance <IScrFootnoteFactory>().Create(); book.FootnotesOS.Insert(0, footnote); IScrTxtPara para = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle( footnote, ScrStyleNames.CrossRefFootnoteParagraph); para.Contents = TsStringHelper.MakeTSS("My footnote", Cache.DefaultVernWs); m_footnoteView.RefreshDisplay(); MakeFootnoteSelection(0, 0, 0); // verify that a footnote was added to the collection Assert.AreEqual(originalFootnoteCount + 1, book.FootnotesOS.Count); m_footnoteView.DeleteFootnote(); // verify that the footnote was deleted Assert.AreEqual(originalFootnoteCount, book.FootnotesOS.Count); Assert.IsFalse(footnote.IsValidObject); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// <param name="vwenv"></param> /// <param name="hvo"></param> /// <param name="frag"></param> /// ------------------------------------------------------------------------------------ public override void Display(IVwEnv vwenv, int hvo, int frag) { CheckDisposed(); int hvoOuter, tag, ihvo; ITsString tss; switch (frag) { case 1: // A ScrBook; display the title. vwenv.AddObjProp((int)ScrBook.ScrBookTags.kflidTitle, this, 2); break; case 2: // An StText; display the paragraphs. vwenv.GetOuterObject(vwenv.EmbeddingLevel - 1, out hvoOuter, out tag, out ihvo); tss = TsStringHelper.MakeTSS( "Hvo = " + hvoOuter + "; Tag = " + tag + "; Ihvo = " + ihvo, InMemoryFdoCache.s_wsHvos.Fr); vwenv.AddString(tss); vwenv.AddObjVecItems((int)StText.StTextTags.kflidParagraphs, this, 3); break; case 3: // StTxtPara, display details of our outer object vwenv.GetOuterObject(vwenv.EmbeddingLevel - 1, out hvoOuter, out tag, out ihvo); tss = TsStringHelper.MakeTSS( "Hvo = " + hvoOuter + "; Tag = " + tag + "; Ihvo = " + ihvo, InMemoryFdoCache.s_wsHvos.Fr); vwenv.AddString(tss); break; default: throw new ApplicationException("Unexpected frag in DummyCollectorEnvVc"); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// <param name="vwenv"></param> /// <param name="hvo"></param> /// <param name="frag"></param> /// ------------------------------------------------------------------------------------ public override void Display(IVwEnv vwenv, int hvo, int frag) { int frWs = vwenv.DataAccess.WritingSystemFactory.GetWsFromStr("fr"); int hvoOuter, tag, ihvo; ITsString tss; switch (frag) { case 1: // A ScrBook; display the title. vwenv.AddObjProp(ScrBookTags.kflidTitle, this, 2); break; case 2: // An StText; display the paragraphs. vwenv.GetOuterObject(vwenv.EmbeddingLevel - 1, out hvoOuter, out tag, out ihvo); tss = TsStringHelper.MakeTSS( "Hvo = " + hvoOuter + "; Tag = " + tag + "; Ihvo = " + ihvo, frWs); vwenv.AddString(tss); vwenv.AddObjVecItems(StTextTags.kflidParagraphs, this, 3); break; case 3: // StTxtPara, display details of our outer object vwenv.GetOuterObject(vwenv.EmbeddingLevel - 1, out hvoOuter, out tag, out ihvo); tss = TsStringHelper.MakeTSS( "Hvo = " + hvoOuter + "; Tag = " + tag + "; Ihvo = " + ihvo, frWs); vwenv.AddString(tss); break; default: throw new ApplicationException("Unexpected frag in DummyCollectorEnvVc"); } }
public void Add_EmptyObjectCollection_CollectionContainsSingleElement() { using (var listBox = new FwListBox()) { using (var collection = new FwListBox.ObjectCollection(listBox)) { ITsString testString = TsStringHelper.MakeTSS("test", m_hvoEnglishWs); // The Test collection.Add(testString); Assert.AreEqual(1, collection.Count); Assert.IsTrue(collection.Contains(testString)); } } }
public void IsHighlighted_CollectionWithSingleElement_ReturnsTrue() { using (var listBox = new FwListBox()) { using (var innerFwListBox = new InnerFwListBox(listBox)) { ITsString testString1 = TsStringHelper.MakeTSS("test1", m_hvoEnglishWs); listBox.Items.Add(testString1); innerFwListBox.MakeRoot(); listBox.HighlightedIndex = 0; // The Test Assert.AreEqual(true, innerFwListBox.IsHighlighted(0)); } } }
public void Clear_CollectionWithSingleElement_CollectionShouldBeEmpty() { using (var listBox = new FwListBox()) { using (var collection = new FwListBox.ObjectCollection(listBox)) { ITsString testString = TsStringHelper.MakeTSS("test", m_hvoEnglishWs); collection.Add(testString); // The Test collection.Clear(); Assert.AreEqual(0, collection.Count); Assert.IsFalse(collection.Contains(testString)); } } }
public void SetIndex_CollectionWithSingleElement_ValueShouldHaveChanged() { using (var listBox = new FwListBox()) { using (var collection = new FwListBox.ObjectCollection(listBox)) { ITsString testString1 = TsStringHelper.MakeTSS("test1", m_hvoEnglishWs); ITsString testString2 = TsStringHelper.MakeTSS("test2", m_hvoEnglishWs); collection.Add(testString1); // The Test collection[0] = testString2; Assert.AreEqual(1, collection.Count); Assert.IsFalse(collection.Contains(testString1)); Assert.IsTrue(collection.Contains(testString2)); } } }
public void FootnoteTranslationTest() { // get an existing footnote IScrBook book = m_scr.ScriptureBooksOS[1]; // book of James IStFootnote footnote = book.FootnotesOS[0]; StTxtPara para = (StTxtPara)footnote.ParagraphsOS[0]; // add a translation to the footnote ICmTranslation translation = para.GetOrCreateBT(); translation.Translation.AnalysisDefaultWritingSystem.UnderlyingTsString = TsStringHelper.MakeTSS("abcde", m_fdoCache.DefaultAnalWs); FwStyleSheet styleSheet = new FwStyleSheet(); styleSheet.Init(m_fdoCache, m_scr.Hvo, (int)Scripture.ScriptureTags.kflidStyles); // Prepare the test by creating a footnote view using (DummyFootnoteView footnoteView = new DummyFootnoteView(m_fdoCache, true)) { footnoteView.StyleSheet = styleSheet; footnoteView.Visible = false; // We don't actually want to show it, but we need to force the view to create the root // box and lay it out so that various test stuff can happen properly. footnoteView.MakeRoot(); footnoteView.CallLayout(); // Select the footnote marker and some characters of the footnote paragraph footnoteView.RootBox.MakeSimpleSel(true, true, false, true); SelectionHelper selHelper = SelectionHelper.GetSelectionInfo(null, footnoteView); // Now the real test: IVwSelection sel = footnoteView.RootBox.Selection.GrowToWord(); ITsString tss; sel.GetSelectionString(out tss, string.Empty); Assert.AreEqual("abcde", tss.Text); } }
public void FootnoteTranslationTest() { // get an existing footnote IScrBook book = m_scr.ScriptureBooksOS[1]; // book of Exodus IScrFootnote footnote = AddFootnote(book, (IStTxtPara)book.TitleOA.ParagraphsOS[0], 0, "This is a footnote"); IStTxtPara para = (IStTxtPara)footnote.ParagraphsOS[0]; // add a translation to the footnote ICmTranslation translation = para.GetOrCreateBT(); int analWs = Cache.DefaultAnalWs; translation.Translation.set_String(analWs, TsStringHelper.MakeTSS("abcde", analWs)); FwStyleSheet styleSheet = new FwStyleSheet(); styleSheet.Init(Cache, m_scr.Hvo, ScriptureTags.kflidStyles); // Prepare the test by creating a footnote view using (DummyFootnoteView footnoteView = new DummyFootnoteView(Cache, true)) { footnoteView.StyleSheet = styleSheet; footnoteView.Visible = false; // We don't actually want to show it, but we need to force the view to create the root // box and lay it out so that various test stuff can happen properly. footnoteView.MakeRoot(); footnoteView.CallLayout(); // Select the footnote marker and some characters of the footnote paragraph footnoteView.RootBox.MakeSimpleSel(true, true, false, true); // Now the real test: IVwSelection sel = footnoteView.RootBox.Selection.GrowToWord(); ITsString tss; sel.GetSelectionString(out tss, string.Empty); Assert.AreEqual("abcde", tss.Text); } }
public void DeleteFootnoteWithoutORC() { CheckDisposed(); ScrBook book = (ScrBook)m_scr.ScriptureBooksOS[0]; int originalFootnoteCount = book.FootnotesOS.Count; // Insert a new footnote into the collection and view StFootnote footnote = (StFootnote)book.FootnotesOS.InsertAt(new StFootnote(), 0); StTxtPara para = (StTxtPara)footnote.ParagraphsOS.Append(new StTxtPara()); para.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.CrossRefFootnoteParagraph); para.Contents.UnderlyingTsString = TsStringHelper.MakeTSS("My footnote", Cache.DefaultVernWs); m_footnoteView.RefreshDisplay(); MakeFootnoteSelection(0, 0, 0); // verify that a footnote was added to the collection Assert.AreEqual(originalFootnoteCount + 1, book.FootnotesOS.Count); m_footnoteView.DeleteFootnote(); // verify that the footnote was deleted Assert.AreEqual(originalFootnoteCount, book.FootnotesOS.Count); Assert.IsFalse(Cache.IsRealObject(footnote.Hvo, StFootnote.kClassId)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// <param name="vwenv"></param> /// <param name="hvo"></param> /// <param name="frag"></param> /// ------------------------------------------------------------------------------------ public override void Display(IVwEnv vwenv, int hvo, int frag) { if ((m_displayType & DisplayType.kLiteralStringLabels) != 0) { ITsStrFactory factory = TsStrFactoryClass.Create(); vwenv.AddString(factory.MakeString("Label" + m_counter++, m_wsDefault)); } switch (frag) { case 1: // the root; display the subitems, first using non-lazy view, then lazy one. if ((m_displayType & DisplayType.kBookFootnoteDetailsSeparateParas) == DisplayType.kBookFootnoteDetailsSeparateParas) { vwenv.AddObjVecItems(m_flid, this, 10); } if ((m_displayType & DisplayType.kBookFootnoteDetailsSinglePara) == DisplayType.kBookFootnoteDetailsSinglePara) { vwenv.AddObjVecItems(m_flid, this, 11); } else { if ((m_displayType & DisplayType.kNormal) == DisplayType.kNormal) { vwenv.AddObjVecItems(m_flid, this, 3); } if ((m_displayType & DisplayType.kLazy) == DisplayType.kLazy) { vwenv.AddObjVecItems(m_flid, this, 2); } } if ((m_displayType & DisplayType.kBookTitle) == DisplayType.kBookTitle) { vwenv.AddObjProp(ScrBookTags.kflidTitle, this, 3); } if (m_displayType == DisplayType.kOuterObjDetails) { vwenv.AddObjVecItems(m_flid, this, 6); } break; case 2: // An StText, display paragraphs lazily if ((m_displayType & DisplayType.kWithTopMargin) == DisplayType.kWithTopMargin) { vwenv.AddLazyVecItems(StTextTags.kflidParagraphs, this, 4); } vwenv.AddLazyVecItems(StTextTags.kflidParagraphs, this, 5); break; case 3: // An StText, display paragraphs not lazily. if ((m_displayType & DisplayType.kWithTopMargin) == DisplayType.kWithTopMargin) { vwenv.AddObjVecItems(StTextTags.kflidParagraphs, this, 4); } vwenv.AddObjVecItems(StTextTags.kflidParagraphs, this, 5); if ((m_displayType & DisplayType.kDuplicateParagraphs) != 0) { vwenv.AddObjVecItems(StTextTags.kflidParagraphs, this, 5); } break; case 4: // StTxtPara, display contents with top margin if ((m_displayType & DisplayType.kMappedPara) == DisplayType.kMappedPara) { vwenv.OpenMappedPara(); } vwenv.set_IntProperty((int)FwTextPropType.ktptMarginTop, (int)FwTextPropVar.ktpvMilliPoint, kMarginTop); vwenv.AddStringProp(StTxtParaTags.kflidContents, null); vwenv.AddStringProp(StTxtParaTags.kflidContents, null); vwenv.AddStringProp(StTxtParaTags.kflidContents, null); if ((m_displayType & DisplayType.kMappedPara) == DisplayType.kMappedPara) { vwenv.CloseParagraph(); } break; case 5: // StTxtPara, display contents without top margin //vwenv.set_IntProperty((int)FwTextPropType.ktptFontSize, // (int)FwTextPropVar.ktpvMilliPoint, 15000); if ((m_displayType & DisplayType.kMappedPara) == DisplayType.kMappedPara) { vwenv.OpenMappedPara(); } vwenv.AddStringProp(StTxtParaTags.kflidContents, null); vwenv.AddStringProp(StTxtParaTags.kflidContents, null); vwenv.AddStringProp(StTxtParaTags.kflidContents, null); if ((m_displayType & DisplayType.kMappedPara) == DisplayType.kMappedPara) { vwenv.CloseParagraph(); } break; case 6: // StTxtPara, display details of our outer object int hvoOuter, tag, ihvo; vwenv.GetOuterObject(vwenv.EmbeddingLevel - 1, out hvoOuter, out tag, out ihvo); ITsString tss = TsStringHelper.MakeTSS("Hvo = " + hvoOuter + "; Tag = " + tag + "; Ihvo = " + ihvo, m_wsDefault); vwenv.AddString(tss); break; case ScrBookTags.kflidSections: vwenv.AddObjVecItems(ScrBookTags.kflidSections, this, ScrSectionTags.kflidContent); break; case ScrSectionTags.kflidHeading: case ScrSectionTags.kflidContent: if ((m_displayType & DisplayType.kNormal) == DisplayType.kNormal) { vwenv.AddObjProp(frag, this, 3); } if ((m_displayType & DisplayType.kLazy) == DisplayType.kLazy) { vwenv.AddObjProp(frag, this, 2); } break; case 7: // ScrBook vwenv.OpenDiv(); vwenv.AddObjVecItems(ScrBookTags.kflidFootnotes, this, 8); vwenv.CloseDiv(); break; case 8: // StFootnote vwenv.AddObjVecItems(StTextTags.kflidParagraphs, this, 9); break; case 9: // StTxtPara vwenv.AddStringProp(StTxtParaTags.kflidContents, null); break; case 10: // Display a Footnote by displaying its "FootnoteMarker" in a paragraph // by itself, followed by the sequence of paragraphs. vwenv.AddStringProp(StFootnoteTags.kflidFootnoteMarker, null); vwenv.AddObjVecItems(StTextTags.kflidParagraphs, this, 9); break; case 11: // Display a Footnote by displaying its "FootnoteMarker" followed by the // contents of its first paragraph (similar to the way footnotes are displayed in // real life. vwenv.AddObjVecItems(StTextTags.kflidParagraphs, this, 12); break; case 12: // Footnote paragraph with marker vwenv.OpenMappedTaggedPara(); // The footnote marker is not editable. vwenv.set_IntProperty((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable); // add a read-only space after the footnote marker vwenv.set_IntProperty((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable); ITsStrFactory strFactory = TsStrFactoryClass.Create(); vwenv.AddString(strFactory.MakeString(" ", DefaultWs)); vwenv.AddStringProp(StTxtParaTags.kflidContents, null); vwenv.CloseParagraph(); break; default: throw new ApplicationException("Unexpected frag in DummyBasicViewVc"); } }