/// ------------------------------------------------------------------------------------ /// <summary> /// Set both book and section. Don't make a selection; typically the caller will proceed /// to do that. /// </summary> /// <param name="selHelper">The selection helper.</param> /// <param name="selLimitType">Which end of the selection</param> /// <param name="iBook">The index of the book (in the book filter).</param> /// <param name="iSection">The index of the section (relative to /// <paramref name="iBook"/>), or -1 for a selection that is not in a section (e.g. /// title).</param> /// <remarks>This method should change only the book and section levels of the /// selection, but not any other level.</remarks> /// ------------------------------------------------------------------------------------ public virtual void SetBookAndSection(SelectionHelper selHelper, SelectionHelper.SelLimitType selLimitType, int iBook, int iSection) { if (selHelper == null || iBook < 0) { return; } int nLevels = selHelper.GetNumberOfLevels(selLimitType); if (nLevels == 0) { Debug.Fail("This should not happen!!!"); return; } selHelper.GetLevelInfo(selLimitType)[nLevels - 1].tag = BookTag; selHelper.GetLevelInfo(selLimitType)[nLevels - 1].ihvo = iBook; if (iSection >= 0 && nLevels >= 2) { selHelper.GetLevelInfo(selLimitType)[nLevels - 2].tag = (int)ScrBook.ScrBookTags.kflidSections; selHelper.GetLevelInfo(selLimitType)[nLevels - 2].ihvo = iSection; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Deletes footnotes when there is a range selection. /// </summary> /// <param name="helper"></param> /// ------------------------------------------------------------------------------------ private void DeleteFootnoteRange(SelectionHelper helper) { int nTopLevels = helper.GetNumberOfLevels(SelectionHelper.SelLimitType.Top); int nBottomLevels = helper.GetNumberOfLevels(SelectionHelper.SelLimitType.Bottom); // Get the index of the book containing the first footnote in the selection. // Then get the index of the footnote within that book. int iFirstBook = helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[nTopLevels - 1].ihvo; int iFirstFootnote = helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[nTopLevels - 2].ihvo; // Get the index of the book containing the last footnote in the selection. // Then get the index of the footnote within that book. int iLastBook = helper.GetLevelInfo(SelectionHelper.SelLimitType.Bottom)[nBottomLevels - 1].ihvo; int iLastFootnote = helper.GetLevelInfo(SelectionHelper.SelLimitType.Bottom)[nBottomLevels - 2].ihvo; // Loop through the books containing footnotes in the selection. for (int iBook = iFirstBook; iBook <= iLastBook; iBook++) { IScrBook book = BookFilter.GetBook(iBook); int iBeg = iFirstFootnote; if (iFirstBook != iLastBook && iBook > iFirstBook) { iBeg = 0; } int iEnd = iLastFootnote; if (iFirstBook != iLastBook && iBook < iLastBook) { iEnd = book.FootnotesOS.Count - 1; } // Loop through the footnotes from the selection that are in the // current book. Go in reverse order through the collection. for (int i = iEnd; i >= iBeg; i--) { // TODO: check filter for each HVO IScrFootnote footnote = Cache.ServiceLocator.GetInstance <IScrFootnoteRepository>().GetObject(book.FootnotesOS[i].Hvo); book.FootnotesOS.Remove(footnote); } } }
public void ReadOnlySpaceAfterFootnoteMarker() { // Prepare the test by creating a footnote view FwStyleSheet styleSheet = new FwStyleSheet(); styleSheet.Init(Cache, m_scr.Hvo, ScriptureTags.kflidStyles); using (Form form = new Form()) using (DummyFootnoteView footnoteView = new DummyFootnoteView(Cache)) { footnoteView.StyleSheet = styleSheet; footnoteView.Dock = DockStyle.Fill; footnoteView.Name = "footnoteView"; footnoteView.Visible = true; form.Controls.Add(footnoteView); form.Show(); try { // Select the footnote marker and some characters of the footnote paragraph footnoteView.RootBox.MakeSimpleSel(true, false, false, true); SelectionHelper selHelper = SelectionHelper.GetSelectionInfo(null, footnoteView); selHelper.IchAnchor = 0; selHelper.IchEnd = 5; SelLevInfo[] selLevInfo = new SelLevInfo[3]; Assert.AreEqual(4, selHelper.GetNumberOfLevels(SelectionHelper.SelLimitType.End)); Array.Copy(selHelper.GetLevelInfo(SelectionHelper.SelLimitType.End), 1, selLevInfo, 0, 3); selHelper.SetLevelInfo(SelectionHelper.SelLimitType.End, selLevInfo); selHelper.SetTextPropId(SelectionHelper.SelLimitType.End, StTxtParaTags.kflidContents); selHelper.SetSelection(true); // Now the real test: IVwSelection sel = footnoteView.RootBox.Selection; ITsString tss; sel.GetSelectionString(out tss, string.Empty); Assert.AreEqual("a ", tss.Text.Substring(0, 2)); // make sure the marker and the space are read-only and the paragraph not. ITsTextProps[] vttp; IVwPropertyStore[] vvps; int cttp; SelectionHelper.GetSelectionProps(sel, out vttp, out vvps, out cttp); Assert.IsTrue(cttp >= 3); Assert.IsFalse(SelectionHelper.IsEditable(vttp[0], vvps[0]), "Footnote marker is not read-only"); Assert.IsFalse(SelectionHelper.IsEditable(vttp[1], vvps[1]), "Space after marker is not read-only"); Assert.IsTrue(SelectionHelper.IsEditable(vttp[2], vvps[2]), "Footnote text is read-only"); Assert.IsTrue(SelectionHelper.IsEditable(vttp[3], vvps[3]), "Footnote text is read-only"); } finally { form.Close(); } } }
protected override int GetItemHvo(SelectionHelper sel, SelectionHelper.SelLimitType limit) { if (Rule.StrucDescOS.Count == 0 || sel.GetNumberOfLevels(limit) == 0) { return(0); } SelLevInfo[] levels = sel.GetLevelInfo(limit); return(levels[levels.Length - 1].hvo); }
protected override ICmObject GetItem(SelectionHelper sel, SelectionHelper.SelLimitType limit) { if (Rule.StrucDescOS.Count == 0 || sel.GetNumberOfLevels(limit) == 0) { return(null); } var levels = sel.GetLevelInfo(limit); return(m_cache.ServiceLocator.GetObject(levels[levels.Length - 1].hvo)); }
public void SpaceAfterFootnoteMarker() { IScrBook book = m_scr.ScriptureBooksOS[0]; IScrFootnote footnote = AddFootnote(book, (IStTxtPara)book.TitleOA.ParagraphsOS[0], 0, "This is a footnote"); footnote.FootnoteMarker = Cache.TsStrFactory.MakeString("a", Cache.WritingSystemFactory.GetWsFromStr("en")); // Prepare the test by creating a footnote view FwStyleSheet styleSheet = new FwStyleSheet(); styleSheet.Init(Cache, m_scr.Hvo, ScriptureTags.kflidStyles); using (DummyFootnoteView footnoteView = new DummyFootnoteView(Cache)) { 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, false, false, true); SelectionHelper selHelper = SelectionHelper.GetSelectionInfo(null, footnoteView); selHelper.IchAnchor = 0; selHelper.IchEnd = 5; SelLevInfo[] selLevInfo = new SelLevInfo[3]; Assert.AreEqual(4, selHelper.GetNumberOfLevels(SelectionHelper.SelLimitType.End)); Array.Copy(selHelper.GetLevelInfo(SelectionHelper.SelLimitType.End), 1, selLevInfo, 0, 3); selHelper.SetLevelInfo(SelectionHelper.SelLimitType.End, selLevInfo); selHelper.SetTextPropId(SelectionHelper.SelLimitType.End, StTxtParaTags.kflidContents); selHelper.SetSelection(true); // Now the real test: IVwSelection sel = footnoteView.RootBox.Selection; ITsString tss; sel.GetSelectionString(out tss, string.Empty); Assert.AreEqual("a ", tss.Text.Substring(0, 2)); // make sure the marker and the space are read-only (maybe have to select each run // separately to make this test truly correct) ITsTextProps[] vttp; IVwPropertyStore[] vvps; int cttp; SelectionHelper.GetSelectionProps(sel, out vttp, out vvps, out cttp); Assert.IsTrue(cttp >= 2); Assert.IsFalse(SelectionHelper.IsEditable(vttp[0], vvps[0]), "Footnote marker is not read-only"); Assert.IsFalse(SelectionHelper.IsEditable(vttp[1], vvps[1]), "Space after marker is not read-only"); } }
public void SpaceAfterFootnoteMarker() { // Prepare the test by creating a footnote view FwStyleSheet styleSheet = new FwStyleSheet(); styleSheet.Init(m_fdoCache, m_scr.Hvo, (int)Scripture.ScriptureTags.kflidStyles); using (DummyFootnoteView footnoteView = new DummyFootnoteView(m_fdoCache)) { 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, false, false, true); SelectionHelper selHelper = SelectionHelper.GetSelectionInfo(null, footnoteView); selHelper.IchAnchor = 0; selHelper.IchEnd = 5; SelLevInfo[] selLevInfo = new SelLevInfo[3]; Assert.AreEqual(4, selHelper.GetNumberOfLevels(SelectionHelper.SelLimitType.End)); Array.Copy(selHelper.GetLevelInfo(SelectionHelper.SelLimitType.End), 1, selLevInfo, 0, 3); selHelper.SetLevelInfo(SelectionHelper.SelLimitType.End, selLevInfo); selHelper.SetTextPropId(SelectionHelper.SelLimitType.End, (int)StTxtPara.StTxtParaTags.kflidContents); selHelper.SetSelection(true); // Now the real test: IVwSelection sel = footnoteView.RootBox.Selection; ITsString tss; sel.GetSelectionString(out tss, string.Empty); Assert.AreEqual("a ", tss.Text.Substring(0, 2)); // // make sure the marker and the space are read-only and the paragraph not. // ITsTextProps[] vttp; // IVwPropertyStore[] vvps; // int cttp; // SelectionHelper.GetSelectionProps(sel, out vttp, out vvps, out cttp); // Assert.IsTrue(cttp >= 3); // Assert.IsFalse(SelectionHelper.IsEditable(vttp[0], vvps[0]), // "Footnote marker is not read-only"); // Assert.IsFalse(SelectionHelper.IsEditable(vttp[1], vvps[1]), // "Space after marker is not read-only"); // Assert.IsTrue(SelectionHelper.IsEditable(vttp[2], vvps[2]), // "Footnote text is read-only"); // Assert.IsTrue(SelectionHelper.IsEditable(vttp[3], vvps[3]), // "Footnote text is read-only"); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Set both book and section. Don't make a selection; typically the caller will proceed /// to do that. /// </summary> /// <param name="selHelper">The selection helper.</param> /// <param name="selLimitType">Which end of the selection</param> /// <param name="iBook">The index of the book (in the book filter).</param> /// <param name="iSection">The index of the section (relative to /// <paramref name="iBook"/>), or -1 for a selection that is not in a section (e.g. /// title).</param> /// <remarks>This method should change only the book and section levels of the /// selection, but not any other level.</remarks> /// ------------------------------------------------------------------------------------ public override void SetBookAndSection(SelectionHelper selHelper, SelectionHelper.SelLimitType selLimitType, int iBook, int iSection) { if (selHelper == null) { return; } // we can only deal with one book if (iBook != GetBookIndex(null, selLimitType) || iSection < 0) { return; } int nLevels = selHelper.GetNumberOfLevels(selLimitType); selHelper.GetLevelInfo(selLimitType)[nLevels - 1].tag = ScrBookTags.kflidSections; selHelper.GetLevelInfo(selLimitType)[nLevels - 1].ihvo = iSection; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Go to the next paragraph looking at the specified selection helper. /// </summary> /// <returns>A new selection for the next paragraph, or null if there is no next /// paragraph</returns> /// ------------------------------------------------------------------------------------ private IVwSelection FindNextPara(SelectionHelper helper) { IVwRootBox rootb = helper.RootSite.RootBox; int level = helper.GetNumberOfLevels(SelectionHelper.SelLimitType.Top) - 1; while (level >= 0) { int iBox = helper.Selection.get_BoxIndex(false, level); IVwSelection sel = rootb.MakeSelInBox(helper.Selection, false, level, iBox + 1, true, false, false); if (sel != null) { return(sel); // We found the next paragraph } // Try the next level up level--; } return(null); }
protected override int GetInsertionIndex(ICmObject[] objs, SelectionHelper sel) { if (sel.GetNumberOfLevels(SelectionHelper.SelLimitType.Top) == 0) { int cellId = GetCell(sel, SelectionHelper.SelLimitType.Top); switch (cellId) { case PhMetathesisRuleTags.kidxLeftEnv: return(0); case PhMetathesisRuleTags.kidxLeftSwitch: if (Rule.MiddleIndex != -1) { return(Rule.MiddleIndex); } else if (Rule.RightSwitchIndex != -1) { return(Rule.RightSwitchIndex); } else if (Rule.RightEnvIndex != -1) { return(Rule.RightEnvIndex); } break; case PhMetathesisRuleTags.kidxRightSwitch: if (Rule.RightEnvIndex != -1) { return(Rule.RightEnvIndex); } break; } return(objs.Length); } else { return(base.GetInsertionIndex(objs, sel)); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Perform tests to make sure that Anchor and End of selection are the same /// </summary> /// <param name="selHelper"></param> /// ------------------------------------------------------------------------------------ protected void AssertSameAnchorAndEnd(SelectionHelper selHelper) { Assert.AreEqual(selHelper.IchAnchor, selHelper.IchEnd, "Selection spans multiple characters"); Assert.AreEqual(selHelper.GetIhvoRoot(SelectionHelper.SelLimitType.Anchor), selHelper.GetIhvoRoot(SelectionHelper.SelLimitType.End), "Different root objects for anchor and end"); Assert.AreEqual( selHelper.GetNumberOfPreviousProps(SelectionHelper.SelLimitType.Anchor), selHelper.GetNumberOfPreviousProps(SelectionHelper.SelLimitType.End), "Different number of previous props for anchor and end"); Assert.AreEqual( selHelper.GetAssocPrev(SelectionHelper.SelLimitType.Anchor), selHelper.GetAssocPrev(SelectionHelper.SelLimitType.End), "Different association with previous character"); Assert.AreEqual( selHelper.GetNumberOfLevels(SelectionHelper.SelLimitType.Anchor), selHelper.GetNumberOfLevels(SelectionHelper.SelLimitType.End), "Different number of levels"); Assert.AreEqual( selHelper.GetWritingSystem(SelectionHelper.SelLimitType.Anchor), selHelper.GetWritingSystem(SelectionHelper.SelLimitType.End), "Different writing system"); Assert.IsTrue(m_basicView.IsSelectionVisible(null), "Selection not visible"); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Compare the values of <see cref="SelectionHelper"/> with the expected values /// </summary> /// <param name="type"></param> /// <param name="selectionHelper"></param> /// <param name="ihvoRoot"></param> /// <param name="nPrevProps"></param> /// <param name="ich"></param> /// <param name="nWs"></param> /// <param name="fAssocPrev"></param> /// <param name="nLevels"></param> /// <param name="tag1"></param> /// <param name="cpropPrev1"></param> /// <param name="ihvo1"></param> /// <param name="tag0"></param> /// <param name="cpropPrev0"></param> /// <param name="ihvo0"></param> /// ------------------------------------------------------------------------------------ protected void CheckSelectionHelperValues(SelectionHelper.SelLimitType type, SelectionHelper selectionHelper, int ihvoRoot, int nPrevProps, int ich, int nWs, bool fAssocPrev, int nLevels, int tag1, int cpropPrev1, int ihvo1, int tag0, int cpropPrev0, int ihvo0) { Assert.IsTrue(m_basicView.IsSelectionVisible(null), "Selection not visible"); Assert.AreEqual(ihvoRoot, selectionHelper.GetIhvoRoot(type), "ihvoRoot differs"); Assert.AreEqual(nPrevProps, selectionHelper.GetNumberOfPreviousProps(type), "nPrevProps differs"); Assert.AreEqual(ich, selectionHelper.GetIch(type), "ich differs"); Assert.AreEqual(nWs, selectionHelper.GetWritingSystem(type), "ws differs"); Assert.AreEqual(fAssocPrev, selectionHelper.GetAssocPrev(type), "fAssocPrev differs"); Assert.AreEqual(nLevels, selectionHelper.GetNumberOfLevels(type), "Number of levels differs"); if (nLevels >= 2) { Assert.AreEqual(tag1, selectionHelper.GetLevelInfo(type)[1].tag, "tag (level 1) differs"); Assert.AreEqual(cpropPrev1, selectionHelper.GetLevelInfo(type)[1].cpropPrevious, "cpropPrev (level 1) differs"); Assert.AreEqual(ihvo1, selectionHelper.GetLevelInfo(type)[1].ihvo, "ihvo (level 1) differs"); } Assert.AreEqual(tag0, selectionHelper.GetLevelInfo(type)[0].tag, "tag (level 0) differs"); Assert.AreEqual(cpropPrev0, selectionHelper.GetLevelInfo(type)[0].cpropPrevious, "cpropPrev (level 0) differs"); Assert.AreEqual(ihvo0, selectionHelper.GetLevelInfo(type)[0].ihvo, "ihvo (level 0) differs"); }