Exemplo n.º 1
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();
                    }
                }
        }
Exemplo n.º 2
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");
            }
        }
Exemplo n.º 3
0
            public SelectionWrapper(SimpleRootSite rootSite)
            {
                SelectionHelper = new SelectionHelper(rootSite.EditingHelper.CurrentSelection);

                ITsTextProps[]     textProps;
                IVwPropertyStore[] propertyStores;
                int numberOfProps;

                SelectionHelper.GetSelectionProps(SelectionHelper.Selection,
                                                  out textProps, out propertyStores, out numberOfProps);
                if (numberOfProps > 0)
                {
                    m_TextProps = textProps;
                }
            }
Exemplo n.º 4
0
        private static ITsTextProps[] GetSelectionProps(SelectionHelper selectionHelper)
        {
            IVwSelection selection = selectionHelper.Selection;

            ITsTextProps[]     vttp;
            IVwPropertyStore[] vvps;
            int cttp;

            SelectionHelper.GetSelectionProps(selection, out vttp, out vvps, out cttp);

            // ENHANCE: We probably should call a method similar to VwTextSel::CleanPropertiesForTyping
            // to get rid of any unwanted properties.

            return(vttp);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Helper method that returns a TsString with properties read from Selection.
        /// TODO: typing next to verse numbers shouldn't preserve selection.
        /// </summary>
        ITsString CreateTsStringUsingSelectionProps(string text, SelectionHelper selectionHelper)
        {
            IVwSelection selection = selectionHelper.Selection;
            TsStrBldr    bld       = TsStrBldrClass.Create();

            ITsTextProps[]     vttp;
            IVwPropertyStore[] vvps;
            int cttp;

            SelectionHelper.GetSelectionProps(selection, out vttp, out vvps, out cttp);

            // handle the unlikely event of no selection props.
            if (cttp == 0)
            {
                return(TsStringUtils.MakeTss(text, AssociatedSimpleRootSite.WritingSystemFactory.UserWs));
            }

            bld.ReplaceRgch(0, bld.Length, text, text.Length, vttp[0]);
            return(bld.GetString().get_NormalizedForm(FwNormalizationMode.knmNFD));
        }
Exemplo n.º 6
0
        private void GetStyleNames(SimpleRootSite rootsite, IVwSelection sel, ref string paraStyleName,
                                   ref string charStyleName)
        {
            ITsTextProps[]     vttp;
            IVwPropertyStore[] vvps;
            int cttp;

            SelectionHelper.GetSelectionProps(sel, out vttp, out vvps, out cttp);
            bool   fSingleStyle = true;
            string sStyle       = null;

            for (int ittp = 0; ittp < cttp; ++ittp)
            {
                string style = vttp[ittp].Style();
                if (ittp == 0)
                {
                    sStyle = style;
                }
                else if (sStyle != style)
                {
                    fSingleStyle = false;
                }
            }
            if (fSingleStyle && !String.IsNullOrEmpty(sStyle))
            {
                if (ActiveStyleSheet.GetType(sStyle) == (int)StyleType.kstCharacter)
                {
                    if (sel.CanFormatChar)
                    {
                        charStyleName = sStyle;
                    }
                }
                else
                {
                    if (sel.CanFormatPara)
                    {
                        paraStyleName = sStyle;
                    }
                }
            }
            if (paraStyleName == null)
            {
                // Look at the paragraph (if there is one) to get the paragraph style.
                var helper = SelectionHelper.GetSelectionInfo(sel, rootsite);
                var info   = helper.GetLevelInfo(SelectionHelper.SelLimitType.End);
                if (info.Length > 0)
                {
                    var hvo = info[0].hvo;
                    if (hvo != 0)
                    {
                        var cmObjectRepository = m_callbacks.Cache.ServiceLocator.GetInstance <ICmObjectRepository>();
                        if (cmObjectRepository.IsValidObjectId(hvo))                         // perhaps some sort of dummy; we can't get paragraph style.
                        {
                            var cmo = cmObjectRepository.GetObject(hvo);
                            if (cmo is IStPara)
                            {
                                paraStyleName = (cmo as IStPara).StyleName;
                            }
                        }
                    }
                }
            }
        }