Пример #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();
                    }
                }
        }
Пример #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");
            }
        }
Пример #3
0
        /// <summary>
        /// If we are in ReadOnlySelect mode, intercept the click, and select the appropriate row
        /// without installing a normal selection.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseUp(MouseEventArgs e)
        {
            //If XmlBrouseView did not receive a mouse down event then we do not want to
            //do anything on the mouseUp because the mouseUp would have come from clicking
            //somewhere else. LT-8939
            if (!m_fMouseUpEnabled)
            {
                return;
            }

            try
            {
                if (m_selectedIndex == -1)
                {
                    return;                     // Can't do much in an empty list, so quit.
                }
                m_fHandlingMouseUp = true;
#pragma warning disable 219
                int oldSelectedIndex = m_selectedIndex;
#pragma warning restore 219

                // Note all the stuff we might want to know about what was clicked that we will
                // use later. We want to get this now before anything changes, because there can
                // be scrolling effects from converting dummy objects to real.
                IVwSelection vwsel            = MakeSelectionAt(e);
                int          newSelectedIndex = GetRowIndexFromSelection(vwsel, true);
                // If we're changing records, we need to do some tricks to keep the selection in the place
                // clicked and the focus here. Save the information we will need.
                SelectionHelper clickSel = null;
                if (newSelectedIndex != SelectedIndex && vwsel != null && SelectionHelper.IsEditable(vwsel))
                {
                    clickSel = SelectionHelper.Create(vwsel, this);
                }
                ITsString tssWord      = null;    // word clicked for click copy
                ITsString tssSource    = null;    // whole source string of clicked cell for click copy
                int       hvoNewSelRow = 0;       // hvo of new selected row (only for click copy)
                int       ichStart     = 0;       // of tssWord in tssSource
                if (ClickCopy != null && e.Button == MouseButtons.Left && newSelectedIndex >= 0)
                {
                    if (vwsel != null && vwsel.SelType == VwSelType.kstText)
                    {
                        int icol = vwsel.get_BoxIndex(false, 3);
                        if (icol != Vc.OverrideAllowEditColumn + 1)
                        {
                            IVwSelection vwSelWord = vwsel.GrowToWord();
                            // GrowToWord() can return a null -- see LT-9163 and LT-9349.
                            if (vwSelWord != null)
                            {
                                vwSelWord.GetSelectionString(out tssWord, " ");
                                tssWord      = StripTrailingNewLine(tssWord);
                                hvoNewSelRow = m_sda.get_VecItem(m_hvoRoot, m_fakeFlid,
                                                                 newSelectedIndex);
                                int  hvoObj, tag, ws;
                                bool fAssocPrev;
                                vwSelWord.TextSelInfo(false, out tssSource, out ichStart, out fAssocPrev, out hvoObj,
                                                      out tag, out ws);
                            }
                        }
                    }
                }

                // We need to manually change the index for ReadOnly views.
                // SimpleRootSite delegates RightMouseClickEvent to our RecordBrowseView parent,
                // which also makes the selection for us..
                if (ReadOnlySelect && e.Button != MouseButtons.Right)
                {
                    if (this.m_xbvvc.HasSelectColumn && e.X < m_xbvvc.SelectColumnWidth)
                    {
                        base.OnMouseUp(e);                         // allows check box to operate.
                    }
                }
                else
                {
                    // If we leave this set, the base method call's side effects like updating the WS combo
                    // don't happen.
                    m_fHandlingMouseUp = false;
                    base.OnMouseUp(e);                     // normal behavior.
                    m_fHandlingMouseUp = true;
                }
                SetSelectedIndex(newSelectedIndex);
                if (tssWord != null)
                {
                    // We're doing click copies; generate an event.
                    // Do this AFTER other actions which may change the current line.
                    ClickCopy(this, new ClickCopyEventArgs(tssWord, hvoNewSelRow, tssSource, ichStart));
                }
                if (clickSel != null)
                {
                    IVwSelection finalSel = null;
                    // There seem to be some cases where the selection helper can't restore the selection.
                    // One that came up in FWR-3666 was clicking on a check box.
                    // If we can't re-establish an editiable selection just let the default behavior continue.
                    try
                    {
                        finalSel = clickSel.MakeRangeSelection(RootBox, false);
                    }
                    catch (Exception)
                    {
                    }
                    if (finalSel != null && SelectionHelper.IsEditable(finalSel))
                    {
                        finalSel.Install();
                        FocusMe();
                    }
                }
            }
            finally
            {
                m_fHandlingMouseUp = false;
                m_fMouseUpEnabled  = false;
            }
        }
Пример #4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Get a list of suggested corrections if the selection is a spelling or similar error.
        /// Returns null if there is no problem at the selection location.
        /// Note that it may also return an empty list; this has a distinct meaning, namely,
        /// that there IS a problem, but we have no useful suggestions for what to change it to.
        /// nonSpellingError is set true when the error is not simply a mis-spelled word in a
        /// single writing system; currently this should disable or hide the commands to add
        /// the word to the dictionary or change multiple occurrences.
        /// The input arguments indicate where the user clicked and allow us to find the
        /// text he might be trying to correct. The other output arguments indicate which WS
        /// (wasAlt -- 0 for simple string) of which property (tag) of which object (hvoObj)
        /// is affected by the change, the ws of the mis-spelled word, and the corresponding
        /// spelling engine. Much of this information is already known to the
        /// SpellCorrectMenuItems returned, but some clients use it in creating other menu options.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public ICollection <SpellCorrectMenuItem> GetSuggestions(Point mousePos,
                                                                 SimpleRootSite rootsite, out int hvoObj, out int tag, out int wsAlt, out int wsText,
                                                                 out string word, out ISpellEngine dict, out bool nonSpellingError)
        {
            hvoObj           = tag = wsAlt = wsText = 0;   // make compiler happy for early returns
            word             = null;
            dict             = null;
            nonSpellingError = true;

            IVwRootBox rootb = rootsite != null ? rootsite.RootBox : null;

            if (rootb == null)
            {
                return(null);
            }

            // Get a selection at the indicated point.
            IVwSelection sel = rootsite.GetSelectionAtPoint(mousePos, false);

            // Get the selected word and verify that it is a single run within a single
            // editable string.
            if (sel != null)
            {
                sel = sel.GrowToWord();
            }
            if (sel == null || !sel.IsRange || sel.SelType != VwSelType.kstText || !SelectionHelper.IsEditable(sel))
            {
                return(null);
            }
            ITsString tss;
            bool      fAssocPrev;
            int       ichAnchor;

            sel.TextSelInfo(false, out tss, out ichAnchor, out fAssocPrev, out hvoObj, out tag, out wsAlt);
            int ichEnd, hvoObjE, tagE, wsE;

            sel.TextSelInfo(true, out tss, out ichEnd, out fAssocPrev, out hvoObjE, out tagE, out wsE);
            if (hvoObj != hvoObjE || tag != tagE || wsAlt != wsE)
            {
                return(null);
            }

            int ichMin = Math.Min(ichEnd, ichAnchor);
            int ichLim = Math.Max(ichEnd, ichAnchor);

            ILgWritingSystemFactory wsf = rootsite.RootBox.DataAccess.WritingSystemFactory;

            // May need to enlarge the word beyond what GrowToWord does, if there is adjacent wordforming material.
            int ichMinAdjust = AdjustWordBoundary(wsf, tss, false, ichMin, 0) + 1;             // further expanded start of word.
            int ichLimAdjust = AdjustWordBoundary(wsf, tss, true, ichLim - 1, tss.Length);     // further expanded lim of word.
            // From the ends we can strip stuff with different spell-checking properties.
            IVwStylesheet styles     = rootsite.RootBox.Stylesheet;
            int           spellProps = SpellCheckProps(tss, ichMin, styles);

            while (ichMinAdjust < ichMin && SpellCheckProps(tss, ichMinAdjust, styles) != spellProps)
            {
                ichMinAdjust++;
            }
            while (ichLimAdjust > ichLim && SpellCheckProps(tss, ichLimAdjust - 1, styles) != spellProps)
            {
                ichLimAdjust--;
            }
            ichMin = ichMinAdjust;
            ichLim = ichLimAdjust;

            // Now we have the specific range we will check. Get the actual string.
            ITsStrBldr bldr = tss.GetBldr();

            if (ichLim < bldr.Length)
            {
                bldr.ReplaceTsString(ichLim, bldr.Length, null);
            }
            if (ichMin > 0)
            {
                bldr.ReplaceTsString(0, ichMin, null);
            }
            ITsString tssWord = bldr.GetString();

            // See whether we need the special blue underline, which is used mainly for adjacent words in different writing systems.
            List <int> wss = TsStringUtils.GetWritingSystems(tssWord);

            if (wss.Count > 1)
            {
                return(MakeWssSuggestions(tssWord, wss, rootb, hvoObj, tag, wsAlt, ichMin, ichLim));
            }
            ITsString keepOrcs;             // holds any ORCs we found in the original word that we need to keep rather than reporting.
            IList <SpellCorrectMenuItem> result = MakeEmbeddedNscSuggestion(ref tssWord, styles, rootb,
                                                                            hvoObj, tag, wsAlt, ichMin, ichLim, out keepOrcs);

            if (result.Count > 0)
            {
                return(result);
            }

            // Determine whether it is a spelling problem.
            wsText = TsStringUtils.GetWsOfRun(tssWord, 0);
            dict   = SpellingHelper.GetSpellChecker(wsText, wsf);
            if (dict == null)
            {
                return(null);
            }
            word = tssWord.get_NormalizedForm(FwNormalizationMode.knmNFC).Text;
            if (word == null)
            {
                return(null);                // don't think this can happen, but...
            }
            if (dict.Check(word))
            {
                return(null);                // not mis-spelled.
            }
            // Get suggestions. Make sure to return an empty collection rather than null, even if no suggestions,
            // to indicate an error.
            ICollection <string> suggestions = dict.Suggest(word);

            foreach (string suggest in suggestions)
            {
                ITsString replacement = TsStringUtils.MakeString(suggest, wsText);
                if (keepOrcs != null)
                {
                    ITsStrBldr bldrRep = keepOrcs.GetBldr();
                    bldrRep.ReplaceTsString(0, 0, replacement);
                    replacement = bldrRep.GetString();
                }
                result.Add(new SpellCorrectMenuItem(rootb, hvoObj, tag, wsAlt, ichMin, ichLim, suggest,
                                                    replacement));
            }
            nonSpellingError = false;             // it IS a spelling problem.
            return(result);
        }