Beispiel #1
0
        /// ------------------------------------------------------------------------------------
        /// <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;
            }
        }
Beispiel #2
0
        protected override int GetCell(SelectionHelper sel, SelectionHelper.SelLimitType limit)
        {
            if (sel == null)
            {
                return(-1);
            }

            int tag = sel.GetTextPropId(limit);

            if (tag == AffixRuleFormulaVc.ktagLeftEmpty ||
                tag == AffixRuleFormulaVc.ktagRightEmpty ||
                tag == MoAffixProcessTags.kflidOutput)
            {
                return(tag);
            }

            foreach (SelLevInfo level in sel.GetLevelInfo(limit))
            {
                if (level.tag == MoAffixProcessTags.kflidOutput)
                {
                    return(level.tag);
                }
                if (level.tag == MoAffixProcessTags.kflidInput)
                {
                    return(level.hvo);
                }
            }

            return(-1);
        }
        public void FindNextMissingBtFootnoteMarker_BtSectionHeadToContent()
        {
            IScrSection section = m_exodus.SectionsOS[1];

            ITsStrFactory strfact     = TsStrFactoryClass.Create();
            IStTxtPara    contentPara = section.ContentOA[0];
            ITsStrBldr    strBldr     = contentPara.Contents.GetBldr();
            IStFootnote   foot        = m_exodus.InsertFootnoteAt(0, strBldr, 7);

            contentPara.Contents = strBldr.GetString();
            IScrTxtPara footPara = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle(
                foot, ScrStyleNames.NormalFootnoteParagraph);

            footPara.Contents = strfact.MakeString("This is footnote text for footnote", Cache.DefaultVernWs);

            m_draftView.TeEditingHelper.SelectRangeOfChars(0, 0, ScrSectionTags.kflidHeading,
                                                           0, 1, 0, 0, true, true, false, VwScrollSelOpts.kssoDefault);

            m_draftView.CallNextMissingBtFootnoteMarker();

            SelectionHelper helper = m_draftView.EditingHelper.CurrentSelection;

            Assert.IsFalse(helper.IsRange);
            Assert.AreEqual(1, helper.GetLevelInfo(SelectionHelper.SelLimitType.Anchor)[0].ihvo, "IP should be in first non-label segment.");
            Assert.AreEqual(0, helper.IchAnchor, "IP should be at start of segment.");
            Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex);
            Assert.AreEqual(1, m_draftView.TeEditingHelper.SectionIndex);
            Assert.AreEqual(0, m_draftView.ParagraphIndex);
            Assert.AreEqual(ScrSectionTags.kflidContent,
                            m_draftView.EditingHelper.CurrentSelection.LevelInfo[2].tag);
            Assert.IsTrue(m_draftView.TeEditingHelper.IsBackTranslation);
        }
        /// ------------------------------------------------------------------------------------
        /// <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);
                }
            }
        }
Beispiel #5
0
        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);
        }
Beispiel #7
0
            /// ------------------------------------------------------------------------------------
            /// <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;
            }
        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));
        }
Beispiel #9
0
        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");
            }
        }
Beispiel #10
0
        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");
            }
        }
        private ComplexConcPatternNode GetNode(SelectionHelper sel, SelectionHelper.SelLimitType limit)
        {
            if (sel == null || m_patternModel.Root.IsLeaf)
            {
                return(null);
            }

            SelLevInfo[] levels = sel.GetLevelInfo(limit);
            if (levels.Length == 0)
            {
                return(null);
            }

            SelLevInfo level = levels.First(l => l.tag == ComplexConcPatternSda.ktagChildren);

            return(m_patternModel.GetNode(level.hvo));
        }
        public void FindNextMissingBtFootnoteMarker_BtSectionHeadToFootnoteInSecondParaAfterSkippingOne()
        {
            IScrSection section = m_exodus.SectionsOS[1];

            ITsStrFactory strfact     = TsStrFactoryClass.Create();
            IStTxtPara    contentPara = section.ContentOA[0];
            ITsStrBldr    strBldr     = contentPara.Contents.GetBldr();
            IStFootnote   foot        = m_exodus.InsertFootnoteAt(0, strBldr, 7);

            contentPara.Contents = strBldr.GetString();
            IScrTxtPara footPara = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle(
                foot, ScrStyleNames.NormalFootnoteParagraph);

            footPara.Contents = strfact.MakeString("This is footnote text for footnote 1", Cache.DefaultVernWs);

            IMultiString trans = contentPara.SegmentsOS[1].FreeTranslation;
            ITsStrBldr   bldr  = trans.get_String(Cache.DefaultAnalWs).GetBldr();

            TsStringUtils.InsertOrcIntoPara(foot.Guid, FwObjDataTypes.kodtNameGuidHot, bldr, 0, 0, Cache.DefaultAnalWs);
            trans.set_String(Cache.DefaultAnalWs, bldr.GetString());

            contentPara          = section.ContentOA[1];
            strBldr              = contentPara.Contents.GetBldr();
            foot                 = m_exodus.InsertFootnoteAt(0, strBldr, 6);
            contentPara.Contents = strBldr.GetString();
            footPara             = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle(
                foot, ScrStyleNames.NormalFootnoteParagraph);
            footPara.Contents = strfact.MakeString("This is footnote text for footnote 2", Cache.DefaultVernWs);

            m_draftView.TeEditingHelper.SelectRangeOfChars(0, 0, ScrSectionTags.kflidHeading,
                                                           0, 1, 0, 0, true, true, false, VwScrollSelOpts.kssoDefault);

            m_draftView.CallNextMissingBtFootnoteMarker();

            SelectionHelper helper = m_draftView.EditingHelper.CurrentSelection;

            Assert.AreEqual(1, helper.GetLevelInfo(SelectionHelper.SelLimitType.Anchor)[0].ihvo, "IP should be in first non-label segment.");
            Assert.AreEqual(0, helper.IchAnchor, "IP should be at start of segment.");
            Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex);
            Assert.AreEqual(1, m_draftView.TeEditingHelper.SectionIndex);
            Assert.AreEqual(1, m_draftView.ParagraphIndex);
            Assert.AreEqual(ScrSectionTags.kflidContent, m_draftView.EditingHelper.CurrentSelection.LevelInfo[2].tag);
            Assert.IsTrue(m_draftView.TeEditingHelper.IsBackTranslation);
        }
Beispiel #13
0
        protected override ICmObject GetCmObject(SelectionHelper sel, SelectionHelper.SelLimitType limit)
        {
            if (sel == null)
            {
                return(null);
            }

            foreach (SelLevInfo level in sel.GetLevelInfo(limit))
            {
                if (level.tag == MoAffixProcessTags.kflidInput ||
                    level.tag == PhSequenceContextTags.kflidMembers ||
                    level.tag == MoAffixProcessTags.kflidOutput)
                {
                    return(m_cache.ServiceLocator.GetObject(level.hvo));
                }
            }

            return(null);
        }
        protected override int GetCell(SelectionHelper sel, SelectionHelper.SelLimitType limit)
        {
            if (sel == null)
            {
                return(-1);
            }

            foreach (SelLevInfo level in sel.GetLevelInfo(limit))
            {
                if (IsCellFlid(level.tag))
                {
                    return(level.tag);
                }
            }

            if (IsCellFlid(sel.GetTextPropId(limit)))
            {
                return(sel.GetTextPropId(limit));
            }
            return(-1);
        }
        protected override int GetItemHvo(SelectionHelper sel, SelectionHelper.SelLimitType limit)
        {
            if (sel == null)
            {
                return(0);
            }

            int cellId = GetCell(sel);

            if (cellId < 0)
            {
                return(0);
            }

            foreach (SelLevInfo level in sel.GetLevelInfo(limit))
            {
                if (IsCellFlid(level.tag) || level.tag == (int)PhSequenceContext.PhSequenceContextTags.kflidMembers)
                {
                    return(level.hvo);
                }
            }

            return(0);
        }
        protected override ICmObject GetCmObject(SelectionHelper sel, SelectionHelper.SelLimitType limit)
        {
            if (sel == null)
            {
                return(null);
            }

            int cellId = GetCell(sel);

            if (cellId < 0)
            {
                return(null);
            }

            foreach (SelLevInfo level in sel.GetLevelInfo(limit))
            {
                if (IsCellFlid(level.tag) || level.tag == PhSequenceContextTags.kflidMembers)
                {
                    return(m_cache.ServiceLocator.GetObject(level.hvo));
                }
            }

            return(null);
        }
Beispiel #17
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// This is called by a view when the views code is about to delete a paragraph. We
        /// need to save the back translations by moving them to whatever paragraph the deleted
        /// one is merging with.
        /// </summary>
        /// <param name="selHelper">The selection helper</param>
        /// <param name="hvoObject">Paragraph to be deleted</param>
        /// <param name="hvoOwner">StText that owns the para</param>
        /// <param name="tag">flid in which para is owned</param>
        /// <param name="ihvo">index of paragraph in text</param>
        /// <param name="fMergeNext"><c>true</c> if this paragraph is merging with the
        /// following paragraph.</param>
        /// ------------------------------------------------------------------------------------
        public virtual void AboutToDelete(SelectionHelper selHelper, int hvoObject,
                                          int hvoOwner, int tag, int ihvo, bool fMergeNext)
        {
            CheckDisposed();

            if (tag != (int)StText.StTextTags.kflidParagraphs)
            {
                return;
            }

            StTxtPara paraToDelete = new StTxtPara(m_cache, hvoObject);

            // If the paragraph that is being deleted is empty, then do not attempt to save a back
            // translation for it.
            if (paraToDelete.Contents.Text == null)
            {
                return;
            }

            // ihvoTop is either the paragraph before the IP or the first paragraph in a range selection
            int ihvoTop           = ihvo - 1;
            int hvoOwnerSurviving = hvoOwner;

            // Figure out what is being deleted and what is staying.
            // NOTE: it is possible that the selection is no longer valid. This is ok for our purposes here,
            // since all information we access here is already retrieved and stored in member variables of
            // SelectionHelper.
            if (selHelper.IsRange)
            {
                int          paraLev      = selHelper.GetLevelForTag(tag, SelectionHelper.SelLimitType.Top);
                SelLevInfo[] rgSelLevInfo = selHelper.GetLevelInfo(SelectionHelper.SelLimitType.Top);
                ihvoTop = rgSelLevInfo[paraLev].ihvo;
                if (paraLev + 1 < rgSelLevInfo.Length)
                {
                    hvoOwnerSurviving = rgSelLevInfo[paraLev + 1].hvo;
                }
                int ihvoBottom = selHelper.GetLevelInfoForTag(tag, SelectionHelper.SelLimitType.Bottom).ihvo;

                // Pretty sure that if we get here top will NEVER equal bottom.
                Debug.Assert(ihvoTop != ihvoBottom || hvoOwnerSurviving != hvoOwner);
                if (hvoOwnerSurviving == hvoOwner)
                {
                    if (ihvoTop == ihvoBottom)
                    {
                        return;
                    }

                    int ichEnd = selHelper.GetIch(SelectionHelper.SelLimitType.Bottom);
                    // No need to merge because entire paragraph (with its contents) is going away.
                    if (ihvo == ihvoBottom && ichEnd == paraToDelete.Contents.Length)
                    {
                        return;
                    }
                    // No need to merge because entire paragraph (with its contents) is going away.
                    if (ihvo > ihvoTop && ihvo < ihvoBottom)
                    {
                        return;
                    }
                }
            }

            // Determine the surviving paragraph.
            StText    text = new StText(m_cache, hvoOwnerSurviving);
            StTxtPara paraSurviving;

            if (fMergeNext)
            {
                // when merging with next and there are no more paragraphs, then the BT can be discarded.
                if (text.ParagraphsOS.Count < ihvo + 1)
                {
                    return;
                }
                // The surviving paragraph will be the one following the one that is deleted
                paraSurviving = (StTxtPara)text.ParagraphsOS[ihvo + 1];
            }
            else
            {
                // If we are deleting the first paragraph in the surviving text, the BT should
                // also be deleted, so we're done.
                if (ihvo == 0 && hvoOwnerSurviving == hvoOwner)
                {
                    return;
                }
                // The surviving paragraph will be the top one in the selection
                paraSurviving = (StTxtPara)text.ParagraphsOS[ihvoTop];
            }

            ITsStrBldr bldr;
            ILgWritingSystemFactory wsf;
            List <int> writingSystems = GetWsList(out wsf);

            foreach (ICmTranslation transToDelete in paraToDelete.TranslationsOC)
            {
                // Find or create surviving translation of the same type.
                ICmTranslation transSurviving = paraSurviving.GetOrCreateTrans(transToDelete.TypeRA);

                // Merge back translations of the surviving and paragraph to be deleted for each writing system
                foreach (int ws in writingSystems)
                {
                    TsStringAccessor tssAccToDelete = transToDelete.Translation.GetAlternative(ws);
                    if (tssAccToDelete.Text != null)
                    {
                        TsStringAccessor tssAccSurviving = transSurviving.Translation.GetAlternative(ws);
                        bldr = tssAccSurviving.UnderlyingTsString.GetBldr();

                        // If the surviving paragraph ends with white space of the paragraph to delete
                        // begins with white space, add white space.
                        string textSurviving = bldr.Text;
                        ILgCharacterPropertyEngine charPropEng = m_cache.UnicodeCharProps;
                        if (textSurviving != null &&
                            !charPropEng.get_IsSeparator(textSurviving[textSurviving.Length - 1]) &&
                            !charPropEng.get_IsSeparator(tssAccToDelete.Text[0]))
                        {
                            bldr.ReplaceRgch(textSurviving.Length, textSurviving.Length, " ", 1, null);
                        }

                        int cch = bldr.Length;
                        bldr.ReplaceTsString(cch, cch, tssAccToDelete.UnderlyingTsString);
                        tssAccSurviving.UnderlyingTsString = bldr.GetString();
                    }
                }
            }
        }
Beispiel #18
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Setups the specifed SelectionHelper for the specified paragraph and StText.
        /// </summary>
        /// <param name="helper">The SelectionHelper.</param>
        /// <param name="text">The StText.</param>
        /// <param name="para">The para.</param>
        /// <param name="limit">The limit.</param>
        /// <param name="view">The view</param>
        /// ------------------------------------------------------------------------------------
        private void SetupSelectionFor(SelectionHelper helper, StText text, StTxtPara para,
                                       SelectionHelper.SelLimitType limit, FwRootSite view)
        {
            Debug.Assert((view is DraftView && ((DraftView)view).TeEditingHelper != null) ||
                         (view is FootnoteView && ((FootnoteView)view).EditingHelper != null));
            if (view is DraftView)
            {
                DraftView draftView = (DraftView)view;

                if ((text.OwningFlid == (int)ScrSection.ScrSectionTags.kflidContent ||
                     text.OwningFlid == (int)ScrSection.ScrSectionTags.kflidHeading))
                {
                    // text belongs to section heading or contents
                    ScrSection section = new ScrSection(m_fdoCache, text.OwnerHVO);
                    Debug.Assert(section.OwningFlid == (int)ScrBook.ScrBookTags.kflidSections);

                    helper.SetNumberOfLevels(limit, 4);
                    SelLevInfo[] info = helper.GetLevelInfo(limit);
                    info[0].ihvo = para.IndexInOwner;
                    info[0].tag  = (int)StText.StTextTags.kflidParagraphs;
                    info[1].ihvo = text.IndexInOwner;
                    info[1].tag  = text.OwningFlid;
                    info[2].ihvo = section.IndexInBook;
                    info[2].tag  = (int)ScrBook.ScrBookTags.kflidSections;
                    info[3].ihvo = draftView.TeEditingHelper.BookFilter.GetBookIndex(section.OwnerHVO);
                    info[3].tag  = draftView.TeEditingHelper.BookFilter.Tag;
                    helper.SetLevelInfo(SelectionHelper.SelLimitType.End, info);
                }
                else
                {
                    // text belongs to a book title
                    Debug.Assert(text.OwningFlid == (int)ScrBook.ScrBookTags.kflidTitle);
                    ScrBook book = new ScrBook(m_fdoCache, text.OwnerHVO);

                    helper.SetNumberOfLevels(limit, 3);
                    SelLevInfo[] info = helper.GetLevelInfo(limit);
                    info[0].ihvo = para.IndexInOwner;
                    info[0].tag  = (int)StText.StTextTags.kflidParagraphs;
                    info[1].ihvo = text.IndexInOwner;
                    info[1].tag  = text.OwningFlid;
                    info[2].ihvo = draftView.TeEditingHelper.BookFilter.GetBookIndex(book.Hvo);
                    info[2].tag  = draftView.TeEditingHelper.BookFilter.Tag;
                    helper.SetLevelInfo(SelectionHelper.SelLimitType.End, info);
                }
            }
            else if (view is FootnoteView && text.OwningFlid == (int)ScrBook.ScrBookTags.kflidFootnotes)
            {
                // text belongs to a footnote
                FootnoteView footnoteView = (FootnoteView)view;
                StFootnote   footnote     = new StFootnote(m_fdoCache, para.OwnerHVO);
                ScrBook      book         = new ScrBook(m_fdoCache, text.OwnerHVO);

                helper.SetNumberOfLevels(limit, 3);
                SelLevInfo[] info = helper.GetLevelInfo(limit);
                info[0].hvo  = text.Hvo;
                info[0].tag  = (int)StText.StTextTags.kflidParagraphs;
                info[1].hvo  = footnote.Hvo;
                info[1].ihvo = footnote.IndexInOwner;
                info[1].tag  = (int)ScrBook.ScrBookTags.kflidFootnotes;
                info[2].hvo  = book.Hvo;
                info[2].ihvo = footnoteView.BookFilter.GetBookIndex(book.Hvo);
                info[2].tag  = footnoteView.BookFilter.Tag;
                info[0].ich  = info[1].ich = info[2].ich = -1;
                helper.SetLevelInfo(SelectionHelper.SelLimitType.End, info);
            }
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Sets up the specifed SelectionHelper for the specified paragraph and StText.
        /// </summary>
        /// <param name="helper">The SelectionHelper.</param>
        /// <param name="text">The StText.</param>
        /// <param name="para">The para.</param>
        /// <param name="limit">The limit.</param>
        /// <param name="view">The view</param>
        /// ------------------------------------------------------------------------------------
        private void SetupSelectionFor(SelectionHelper helper, IStText text, IStTxtPara para,
                                       SelectionHelper.SelLimitType limit, FwRootSite view)
        {
            Debug.Assert((view is DraftView && ((DraftView)view).TeEditingHelper != null) ||
                         (view is FootnoteView && ((FootnoteView)view).EditingHelper != null));

            helper.SetTextPropId(limit, StTxtParaTags.kflidContents);

            if (view is DraftView)
            {
                DraftView draftView = (DraftView)view;

                if ((text.OwningFlid == ScrSectionTags.kflidContent ||
                     text.OwningFlid == ScrSectionTags.kflidHeading))
                {
                    // text belongs to section heading or contents
                    IScrSection section = (IScrSection)text.Owner;
                    Debug.Assert(section.OwningFlid == ScrBookTags.kflidSections);

                    helper.SetNumberOfLevels(limit, 4);
                    SelLevInfo[] info = helper.GetLevelInfo(limit);
                    info[0].ihvo = para.IndexInOwner;
                    info[0].tag  = StTextTags.kflidParagraphs;
                    info[1].ihvo = 0;
                    info[1].tag  = text.OwningFlid;
                    info[2].ihvo = section.IndexInOwner;
                    info[2].tag  = ScrBookTags.kflidSections;
                    info[3].ihvo = draftView.TeEditingHelper.BookFilter.GetBookIndex((IScrBook)section.Owner);
                    info[3].tag  = draftView.TeEditingHelper.BookFilter.Tag;
                }
                else
                {
                    // text belongs to a book title
                    Debug.Assert(text.OwningFlid == ScrBookTags.kflidTitle);
                    IScrBook book = (IScrBook)text.Owner;

                    helper.SetNumberOfLevels(limit, 3);
                    SelLevInfo[] info = helper.GetLevelInfo(limit);
                    info[0].ihvo = para.IndexInOwner;
                    info[0].tag  = StTextTags.kflidParagraphs;
                    info[1].ihvo = 0;
                    info[1].tag  = text.OwningFlid;
                    info[2].ihvo = draftView.TeEditingHelper.BookFilter.GetBookIndex(book);
                    info[2].tag  = draftView.TeEditingHelper.BookFilter.Tag;
                }
            }
            else if (view is FootnoteView && text.OwningFlid == ScrBookTags.kflidFootnotes)
            {
                // text belongs to a footnote
                FootnoteView footnoteView = (FootnoteView)view;
                IStFootnote  footnote     = (IStFootnote)para.Owner;
                IScrBook     book         = (IScrBook)text.Owner;

                helper.SetNumberOfLevels(limit, 3);
                SelLevInfo[] info = helper.GetLevelInfo(limit);
                info[0].hvo  = text.Hvo;
                info[0].tag  = StTextTags.kflidParagraphs;
                info[1].hvo  = footnote.Hvo;
                info[1].ihvo = footnote.IndexInOwner;
                info[1].tag  = ScrBookTags.kflidFootnotes;
                info[2].hvo  = book.Hvo;
                info[2].ihvo = footnoteView.BookFilter.GetBookIndex(book);
                info[2].tag  = footnoteView.BookFilter.Tag;
                info[0].ich  = info[1].ich = info[2].ich = -1;
            }
        }
		/// ------------------------------------------------------------------------------------
		/// <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");
		}