/// <summary> /// Look up the selected wordform in the dictionary and display its lexical entry. /// </summary> /// <param name="argument"></param> public bool OnLexiconLookup(object argument) { CheckDisposed(); IVwSelection wordsel = SelectionBeginningGrowToWord(m_rootb.Selection); if (wordsel == null) { return(false); } ITsString tss; int ichMin, ichLim, hvo, tag, ws; bool fAssocPrev; wordsel.TextSelInfo(false, out tss, out ichMin, out fAssocPrev, out hvo, out tag, out ws); wordsel.TextSelInfo(true, out tss, out ichLim, out fAssocPrev, out hvo, out tag, out ws); if (ichLim > 0) { // TODO (TimS): need to provide help to the dialog (last 2 params) LexEntryUi.DisplayOrCreateEntry(m_fdoCache, hvo, tag, ws, ichMin, ichLim, this, m_mediator, FwApp.App, "UserHelpFile"); } // LexEntryUi leui = LexEntryUi.FindEntryForWordform(m_fdoCache, hvo, tag, ichMin, ichLim); // if (leui == null) // { // MessageBox.Show(this, "Sorry...could not find a matching entry in the lexicon"); // return false; // } // leui.ShowSummaryDialog(this); return(true); }
public void InsertVerseNumber_AtTitle() { CheckDisposed(); IVwRootBox rootBox = m_draftView.RootBox; rootBox.MakeSimpleSel(true, true, false, true); IVwSelection sel = m_draftView.TeEditingHelper.CurrentSelection.Selection; int tag; int hvoSel; m_draftView.TeEditingHelper.GetSelectedScrElement(out tag, out hvoSel); Assert.AreEqual((int)ScrBook.ScrBookTags.kflidTitle, tag, "First para in view was not a Title"); ITsString tss; int ich; bool fAssocPrev; int hvoObj; int enc; sel.TextSelInfo(true, out tss, out ich, out fAssocPrev, out hvoObj, out tag, out enc); string str = tss.Text; m_draftView.InsertVerseNumber(); // may destroy or move selection? Make another one to be sure. rootBox.MakeSimpleSel(true, true, false, true); sel = m_draftView.TeEditingHelper.CurrentSelection.Selection; sel.TextSelInfo(true, out tss, out ich, out fAssocPrev, out hvoObj, out tag, out enc); string str2 = tss.Text; Assert.AreEqual(str, str2, "Should not have inserted verse num into title para"); }
public void FindInDictionary(IOleDbEncap ode, IFwMetaDataCache mdc, IVwOleDbDa oleDbAccess, IVwSelection sel) { using (FdoCache cache = new FdoCache(ode, mdc, oleDbAccess)) { if (sel == null) { return; } IVwSelection sel2 = sel.EndPoint(false); if (sel2 == null) { return; } IVwSelection sel3 = sel2.GrowToWord(); if (sel3 == null) { return; } ITsString tss; int ichMin, ichLim, hvo, tag, ws; bool fAssocPrev; sel3.TextSelInfo(false, out tss, out ichMin, out fAssocPrev, out hvo, out tag, out ws); sel3.TextSelInfo(true, out tss, out ichLim, out fAssocPrev, out hvo, out tag, out ws); // TODO (TimS): need to supply help information (last 2 params) LexEntryUi.DisplayOrCreateEntry(cache, hvo, tag, ws, ichMin, ichLim, null, null, null, string.Empty); return; } }
public void GotoVerse_VerseInBridge() { IScrSection section = AddSectionToMockedBook(m_exodus); AddParaToMockedText(section.HeadingOA, ScrStyleNames.SectionHead); IStTxtPara para = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph); AddRunToMockedPara(para, "1", ScrStyleNames.ChapterNumber); AddRunToMockedPara(para, "1", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse text", null); AddRunToMockedPara(para, "3-5", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse text", null); AddRunToMockedPara(para, "6-8", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse text", null); AddRunToMockedPara(para, "9-10", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse text", null); m_draftView.RootBox.Reconstruct(); // update the view // Set the selection to the start of the section m_draftView.TeEditingHelper.SetInsertionPoint(0, 0, 0, 0, false); // Attempt to go to Exodus 1:3 (start of bridge) Assert.IsTrue(m_draftView.TeEditingHelper.GotoVerse(new ScrReference(2, 1, 3, m_scr.Versification))); // Make sure selection is at the end of the 3-5 bridge IVwSelection vwsel = m_draftView.RootBox.Selection; int ich, hvo, textTag, enc; bool fAssocPrev; ITsString tss2; vwsel.TextSelInfo(false, out tss2, out ich, out fAssocPrev, out hvo, out textTag, out enc); Assert.AreEqual(StTxtParaTags.kflidContents, textTag); Assert.AreEqual("3-5", tss2.Text.Substring(ich - 3, 3)); Assert.IsFalse(fAssocPrev); // Attempt to go to Exodus 1:7 (middle of bridge) Assert.IsTrue(m_draftView.TeEditingHelper.GotoVerse(new ScrReference(2, 1, 7, m_scr.Versification))); // Make sure selection is at the end of the 6-8 bridge vwsel = m_draftView.RootBox.Selection; vwsel.TextSelInfo(false, out tss2, out ich, out fAssocPrev, out hvo, out textTag, out enc); Assert.AreEqual(StTxtParaTags.kflidContents, textTag); Assert.AreEqual("6-8", tss2.Text.Substring(ich - 3, 3)); Assert.IsFalse(fAssocPrev); // Attempt to go to Exodus 1:10 (end of bridge) Assert.IsTrue(m_draftView.TeEditingHelper.GotoVerse(new ScrReference(2, 1, 10, m_scr.Versification))); // Make sure selection is at the end of the 9-10 bridge vwsel = m_draftView.RootBox.Selection; vwsel.TextSelInfo(false, out tss2, out ich, out fAssocPrev, out hvo, out textTag, out enc); Assert.AreEqual(StTxtParaTags.kflidContents, textTag); Assert.AreEqual("9-10", tss2.Text.Substring(ich - 4, 4)); Assert.IsFalse(fAssocPrev); }
internal bool SafeToDoMacro(IVwSelection sel, out ICmObject obj, out int flid, out int ws, out int start, out int length) { start = flid = ws = length = 0; // defaults so we can return early. obj = null; if (sel == null || !(sel.SelType == VwSelType.kstText)) { return(false); } ITsString dummy; int hvoA, hvoE, flidE, ichA, ichE, wsE; bool fAssocPrev; sel.TextSelInfo(false, out dummy, out ichA, out fAssocPrev, out hvoA, out flid, out ws); sel.TextSelInfo(true, out dummy, out ichE, out fAssocPrev, out hvoE, out flidE, out wsE); // for safety require selection to be in a single property. if (hvoA != hvoE || flid != flidE || ws != wsE) { return(false); } var cache = (FdoCache)m_mediator.PropertyTable.GetValue("cache"); obj = cache.ServiceLocator.ObjectRepository.GetObject(hvoA); start = Math.Min(ichA, ichE); length = Math.Max(ichA, ichE) - start; return(true); }
protected bool CheckForValidDelete(IVwSelection sel, out int cvsli, out int hvoObj) { hvoObj = 0; if (sel == null) { cvsli = 0; // satisfy compiler. return(false); // nothing selected, give up. } cvsli = sel.CLevels(false); // CLevels includes the string property itself, but AllTextSelInfo doesn't need it. cvsli--; if (cvsli == 0) { // No object in selection, so quit. return(false); } ITsString tss; int ichAnchor; bool fAssocPrev; int tag; int ws; int ichEnd; int hvoObjEnd; sel.TextSelInfo(false, out tss, out ichAnchor, out fAssocPrev, out hvoObj, out tag, out ws); sel.TextSelInfo(true, out tss, out ichEnd, out fAssocPrev, out hvoObjEnd, out tag, out ws); return(hvoObj == hvoObjEnd); }
/// <summary> /// Return annotation Hvo of the closest word-segment to the beginning of the current selection. /// </summary> /// <returns></returns> public int AnnotationHvoClosestToSelection() { CheckDisposed(); IVwSelection sel = SelectionBeginningGrowToWord(m_rootb.Selection); // find segment related to current selection if (sel == null) { return(0); } ITsString tss; int ichMin, ichLim, hvoStTxtPara, tag, ws; bool fAssocPrev; sel.TextSelInfo(false, out tss, out ichMin, out fAssocPrev, out hvoStTxtPara, out tag, out ws); sel.TextSelInfo(true, out tss, out ichLim, out fAssocPrev, out hvoStTxtPara, out tag, out ws); bool fExactMatch; int hvoAnnotation = FindTwficHvoForStTxtPara(hvoStTxtPara, ichMin, ichLim, out fExactMatch); m_lastFoundAnnotationHvo = hvoAnnotation; return(hvoAnnotation); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Assuming the selection can be expanded to a word and a corresponding LexEntry can /// be found, show the related words dialog with the words related to the selected one. /// </summary> /// <param name="cache">The cache.</param> /// <param name="sel">The sel.</param> /// <param name="owner">The owner.</param> /// <param name="mediator"></param> /// <param name="propertyTable"></param> /// <param name="helpProvider"></param> /// <param name="helpFileKey"></param> /// ------------------------------------------------------------------------------------ public static void DisplayRelatedEntries(LcmCache cache, IVwSelection sel, IWin32Window owner, Mediator mediator, PropertyTable propertyTable, IHelpTopicProvider helpProvider, string helpFileKey) { if (sel == null) { return; } IVwSelection sel2 = sel.EndPoint(false); if (sel2 == null) { return; } IVwSelection sel3 = sel2.GrowToWord(); if (sel3 == null) { return; } ITsString tss; int ichMin, ichLim, hvo, tag, ws; bool fAssocPrev; sel3.TextSelInfo(false, out tss, out ichMin, out fAssocPrev, out hvo, out tag, out ws); sel3.TextSelInfo(true, out tss, out ichLim, out fAssocPrev, out hvo, out tag, out ws); if (tss.Text == null) { return; } ITsString tssWf = tss.GetSubstring(ichMin, ichLim); using (LexEntryUi leui = FindEntryForWordform(cache, tssWf)) { // This doesn't work as well (unless we do a commit) because it may not see current typing. //LexEntryUi leui = LexEntryUi.FindEntryForWordform(cache, hvo, tag, ichMin, ichLim); if (leui == null) { if (tssWf != null && tssWf.Length > 0) { RelatedWords.ShowNotInDictMessage(owner); } return; } int hvoEntry = leui.Object.Hvo; int[] domains; int[] lexrels; IVwCacheDa cdaTemp; if (!RelatedWords.LoadDomainAndRelationInfo(cache, hvoEntry, out domains, out lexrels, out cdaTemp, owner)) { return; } IVwStylesheet styleSheet = GetStyleSheet(cache, propertyTable); using (RelatedWords rw = new RelatedWords(cache, sel3, hvoEntry, domains, lexrels, cdaTemp, styleSheet, mediator, false)) { rw.ShowDialog(owner); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Do remaining initialization once we (might) have a selection. /// </summary> /// ------------------------------------------------------------------------------------ void Init() { if (m_sel == null) { return; } if (m_sel.SelType == VwSelType.kstPicture) { // TextSelInfo doesn't work; but we can get a good approximation of much of the // information like this. // Out variables for AllTextSelInfo. int ihvoRoot; int tagTextProp; int cpropPrevious; int ichAnchor; int ichEnd; int ws; bool fAssocPrev; int ihvoEnd; ITsTextProps ttpBogus; // Main array of information retrieved from sel that made combo. SelLevInfo[] rgvsli; // Analysis can now be zero (e.g., displaying alternate case form for non-existent WfiWordform) // and I don't believe it's a problem for the code below (JohnT). // if (sandbox.Analysis == 0) // { // // We aren't fully initialized yet, so don't do anything. // return null; // } try { int cvsli = m_sel.CLevels(false) - 1; rgvsli = SelLevInfo.AllTextSelInfo(m_sel, cvsli, out ihvoRoot, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd, out ws, out fAssocPrev, out ihvoEnd, out ttpBogus); } catch (Exception) { // If anything goes wrong just give up. return; } m_ichA = ichAnchor; m_ichE = ichEnd; if (rgvsli.Length > 0) { m_hvoObjA = m_hvoObjE = rgvsli[0].hvo; } m_tagA = m_tagE = tagTextProp; } else { m_sel.TextSelInfo(true, out m_tssE, out m_ichE, out m_fAssocPrev, out m_hvoObjE, out m_tagE, out m_wsE); m_sel.TextSelInfo(false, out m_tssA, out m_ichA, out m_fAssocPrev, out m_hvoObjA, out m_tagA, out m_wsA); } m_fIsRange = m_sel.IsRange; m_selType = m_sel.SelType; }
public void GotoVerse_MultipleHitsDontFindFirst() { IScrSection section = AddSectionToMockedBook(m_exodus); AddParaToMockedText(section.HeadingOA, ScrStyleNames.SectionHead); IStTxtPara para = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph); AddRunToMockedPara(para, "1", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse text", null); AddRunToMockedPara(para, "2", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse text", null); AddRunToMockedPara(para, "3", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse text", null); AddRunToMockedPara(para, "4", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse text", null); AddRunToMockedPara(para, "5", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse text", null); AddRunToMockedPara(para, "1", ScrStyleNames.VerseNumber); int secondVerseOnePos = para.Contents.Length; AddRunToMockedPara(para, "verse text", null); AddRunToMockedPara(para, "6", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse text", null); m_draftView.RootBox.Reconstruct(); // update the view // Set the selection to the start of the section m_draftView.TeEditingHelper.SetInsertionPoint(0, 0, 0, 0, false); // Attempt to go to the first instance of Exodus 1:1 (should exist) Assert.IsTrue(m_draftView.TeEditingHelper.GotoVerse(new ScrReference(2, 1, 1, m_scr.Versification))); // Make sure selection is immediately following the second verse 1 IVwSelection vwsel = m_draftView.RootBox.Selection; int ich, hvo, textTag, enc; bool fAssocPrev; ITsString tss2; vwsel.TextSelInfo(false, out tss2, out ich, out fAssocPrev, out hvo, out textTag, out enc); Assert.AreEqual(StTxtParaTags.kflidContents, textTag); Assert.AreEqual("1", tss2.Text.Substring(ich - 1, 1)); Assert.AreEqual(secondVerseOnePos, ich); Assert.IsFalse(fAssocPrev); // Attempt to go to the second instance of Exodus 1:1 (should exist) Assert.IsTrue(m_draftView.TeEditingHelper.GotoVerse(new ScrReference(2, 1, 1, m_scr.Versification))); // Make sure selection is immediately following the first verse 1 vwsel = m_draftView.RootBox.Selection; vwsel.TextSelInfo(false, out tss2, out ich, out fAssocPrev, out hvo, out textTag, out enc); Assert.AreEqual(StTxtParaTags.kflidContents, textTag); Assert.AreEqual("1", tss2.Text.Substring(ich - 1, 1)); Assert.AreEqual(1, ich); Assert.IsFalse(fAssocPrev); }
protected VwDelProbResponse DeleteObjectFromVector(IVwSelection sel, int cvsli, int hvoObj) { int hvoObjEnd = hvoObj; int ichAnchor; int ichEnd; bool fAssocPrev; int ws; int ihvoRoot; int tagTextProp; int cpropPrevious; int ihvoEnd; ITsTextProps ttp; SelLevInfo[] rgvsli = SelLevInfo.AllTextSelInfo(sel, cvsli, out ihvoRoot, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd, out ws, out fAssocPrev, out ihvoEnd, out ttp); IVwSelection vwselWhole = null; Debug.Assert(m_rootb != null); // Create a selection that covers the entire target object. If it differs from // the new selection, we'll install it (which will recurse back to this method). vwselWhole = m_rootb.MakeTextSelInObj(ihvoRoot, cvsli, rgvsli, 0, null, false, false, false, true, false); if (vwselWhole != null) { ITsString tssWhole; int ichAnchorWhole; int ichEndWhole; int hvoObjWhole; int hvoObjEndWhole; bool fAssocPrevWhole; int tagWhole; int wsWhole; vwselWhole.TextSelInfo(false, out tssWhole, out ichAnchorWhole, out fAssocPrevWhole, out hvoObjWhole, out tagWhole, out wsWhole); vwselWhole.TextSelInfo(true, out tssWhole, out ichEndWhole, out fAssocPrevWhole, out hvoObjEndWhole, out tagWhole, out wsWhole); if (hvoObj == hvoObjWhole && hvoObjEnd == hvoObjEndWhole && ichAnchor == ichAnchorWhole && ichEnd == ichEndWhole) { // We've selected the whole string for it, so remove the object from the // vector. int[] hvosOld = m_fdoCache.GetVectorProperty(m_rootObj.Hvo, m_rootFlid, false); UpdateTimeStampsIfNeeded(hvosOld); for (int i = 0; i < hvosOld.Length; ++i) { if (hvosOld[i] == hvoObj) { RemoveObjectFromList(hvosOld, i); break; } } } } return(VwDelProbResponse.kdprDone); }
/// <summary> /// Guess where we can break words. /// </summary> /// <param name="argument"></param> public void OnGuessWordBreaks(object argument) { CheckDisposed(); IVwSelection sel = RootBox.Selection; ITsString tss; int ichMin, hvoStart, ichLim, hvoEnd, tag, ws; bool fAssocPrev; sel.TextSelInfo(false, out tss, out ichMin, out fAssocPrev, out hvoStart, out tag, out ws); sel.TextSelInfo(true, out tss, out ichLim, out fAssocPrev, out hvoEnd, out tag, out ws); if (sel.EndBeforeAnchor) { Swap(ref ichMin, ref ichLim); Swap(ref hvoStart, ref hvoEnd); } WordBreakGuesser guesser = new WordBreakGuesser(m_fdoCache, hvoStart); if (hvoStart == hvoEnd) { if (ichMin == ichLim) { ichMin = 0; ichLim = -1; // do the whole paragraph for an IP. } guesser.Guess(ichMin, ichLim, hvoStart); } else { guesser.Guess(ichMin, -1, hvoStart); bool fProcessing = false; ISilDataAccess sda = m_fdoCache.MainCacheAccessor; int hvoStText = m_hvoRoot; int cpara = sda.get_VecSize(hvoStText, StTextTags.kflidParagraphs); for (int i = 0; i < cpara; i++) { int hvoPara = sda.get_VecItem(hvoStText, StTextTags.kflidParagraphs, i); if (hvoPara == hvoStart) { fProcessing = true; } else if (hvoPara == hvoEnd) { break; } else if (fProcessing) { guesser.Guess(0, -1, hvoPara); } } guesser.Guess(0, ichLim, hvoEnd); } TurnOnShowInvisibleSpaces(); }
protected void DeleteObjectFromVector(IVwSelection sel, int cvsli, int hvoObj, string undoText, string redoText) { int hvoObjEnd = hvoObj; int ichAnchor; int ichEnd; bool fAssocPrev; int ws; int ihvoRoot; int tagTextProp; int cpropPrevious; int ihvoEnd; ITsTextProps ttp; SelLevInfo[] rgvsli = SelLevInfo.AllTextSelInfo(sel, cvsli, out ihvoRoot, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd, out ws, out fAssocPrev, out ihvoEnd, out ttp); Debug.Assert(m_rootb != null); // Create a selection that covers the entire target object. If it differs from // the new selection, we'll install it (which will recurse back to this method). IVwSelection vwselWhole = m_rootb.MakeTextSelInObj(ihvoRoot, cvsli, rgvsli, 0, null, false, false, false, true, false); if (vwselWhole != null) { ITsString tssWhole; int ichAnchorWhole; int ichEndWhole; int hvoObjWhole; int hvoObjEndWhole; bool fAssocPrevWhole; int tagWhole; int wsWhole; vwselWhole.TextSelInfo(false, out tssWhole, out ichAnchorWhole, out fAssocPrevWhole, out hvoObjWhole, out tagWhole, out wsWhole); vwselWhole.TextSelInfo(true, out tssWhole, out ichEndWhole, out fAssocPrevWhole, out hvoObjEndWhole, out tagWhole, out wsWhole); if (hvoObj == hvoObjWhole && hvoObjEnd == hvoObjEndWhole && ichAnchor == ichAnchorWhole && ichEnd == ichEndWhole) { // We've selected the whole string for it, so remove the object from the // vector. var hvosOld = ((ISilDataAccessManaged)m_cache.DomainDataByFlid).VecProp(m_rootObj.Hvo, m_rootFlid); UpdateTimeStampsIfNeeded(hvosOld); for (int i = 0; i < hvosOld.Length; ++i) { if (hvosOld[i] == hvoObj) { RemoveObjectFromList(hvosOld, i, undoText, redoText); break; } } } } }
protected override void HandleSelectionChange(IVwRootBox rootb, IVwSelection vwselNew) { CheckDisposed(); if (m_handlingSelectionChanged) { return; } m_handlingSelectionChanged = true; try { m_selectedSenseHvo = 0; if (vwselNew == null) { return; } base.HandleSelectionChange(rootb, vwselNew); // Get the Id of the selected snes, and store it. int cvsli = vwselNew.CLevels(false); // CLevels includes the string property itself, but AllTextSelInfo doesn't need it. cvsli--; if (cvsli == 0) { // No objects in selection: don't allow a selection. m_rootb.DestroySelection(); // Enhance: invoke launcher's selection dialog. return; } ITsString tss; int ichAnchor; int ichEnd; bool fAssocPrev; int hvoObj; int hvoObjEnd; int tag; int ws; vwselNew.TextSelInfo(false, out tss, out ichAnchor, out fAssocPrev, out hvoObj, out tag, out ws); vwselNew.TextSelInfo(true, out tss, out ichEnd, out fAssocPrev, out hvoObjEnd, out tag, out ws); if (hvoObj != hvoObjEnd) { return; } m_selectedSenseHvo = hvoObj; } finally { m_handlingSelectionChanged = false; } }
/// <summary> /// Determine whether the current selection is at a place suitable for type-ahead. If not, answer 0. /// (In this case the values of hvoParent and ihvo should not be relied on.) /// If so, indicate the object whose property may be set by type-ahead (hvoParent), the object /// in the relevant property that is selected (return result), and its index within the property /// (0 if atomic). /// </summary> /// <param name="rootb"></param> /// <param name="sel"></param> /// <param name="hvoParent"></param> /// <param name="ihvo"></param> /// <returns></returns> private int SelectedObject(IVwRootBox rootb, IVwSelection sel, out int hvoParent, out int ihvo) { hvoParent = 0; ihvo = 0; if (rootb == null) // If we don't have a root box, can't do anything interesting. { return(0); } if (sel == null) // nothing interesting to do without a selection, either. { return(0); } ITsString tssA, tssE; int ichA, ichE, hvoObjA, hvoObjE, tagA, tagE, ws; bool fAssocPrev; // Enhance JohnT: what we're really trying to do here is confirm that the selection is // all in one string property. We could readily have a method in the selection interface to tell us that. sel.TextSelInfo(false, out tssA, out ichA, out fAssocPrev, out hvoObjA, out tagA, out ws); if (tagA != m_taTagName && tagA != m_snTagName) { return(0); // selection not anchored in any sort of type-ahead name property. } sel.TextSelInfo(true, out tssE, out ichE, out fAssocPrev, out hvoObjE, out tagE, out ws); int cch = tssA.Length; // To do our type-ahead trick, both ends of the seleciton must be in the same string property. // Also, we want the selection to extend to the end of the name. // Enhance JohnT: if we do a popup window, it may not matter whether the selection extends // to the end; just show items that match. if (tagE != tagA || hvoObjE != hvoObjA || cch != tssE.Length || Math.Max(ichA, ichE) != cch) { return(0); // not going to attempt type-ahead behavior } int clev = sel.CLevels(false); if (clev < 2) { return(0); // can't be our property. } int tagParent, cpropPrevious; IVwPropertyStore vps; sel.PropInfo(false, 1, out hvoParent, out tagParent, out ihvo, out cpropPrevious, out vps); if (tagParent != m_virtualTagObj) { return(0); // not our virtual property! } return(hvoObjA); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Performs a bunch of verifications in a draft view after a scripture book has been /// inserted. /// </summary> /// <param name="sTitle">Book main title expected in the draft view.</param> /// <param name="book">The ScrBook inserted in the draft view. The test assumes this /// is canonically the first book in the view.</param> /// ------------------------------------------------------------------------------------ private void VerifyInsertedBookInDraftView(string sTitle, IScrBook book) { bool fAssocPrev; int ich, hvoObj, tag, enc; ITsString tss; SelectionHelper selHelper = SelectionHelper.Create(m_mainWnd.TheDraftView); // Make sure that IP has been given appropriate properties for typing regular // vernacular text (not continuing to enter text using "Chapter Number" style). Assert.AreEqual(4, selHelper.NumberOfLevels); // This better be the first book in the view. Assert.AreEqual(0, selHelper.LevelInfo[3].ihvo); // Since this book was just inserted, we should be in the first section. Assert.AreEqual(0, selHelper.LevelInfo[2].ihvo); // The InsertBook command should leave our insertion point in the Content of // this section (as opposed to the section Heading). Assert.AreEqual((int)ScrSection.ScrSectionTags.kflidContent, selHelper.LevelInfo[1].tag); // We should be in the first paragraph of that section's content. Assert.AreEqual(0, selHelper.LevelInfo[0].ihvo); // We should have a simple IP, not a range selection IVwSelection sel = selHelper.Selection; Assert.IsFalse(sel.IsRange); Assert.AreEqual(1, selHelper.IchAnchor, "IP should follow chapter number"); // If the user starts typing, they should be entering regular vernacular text Assert.AreEqual(StyleUtils.CharStyleTextProps(null, m_wsVern), selHelper.SelProps); // Put cursor in the book title. If TestLangProj ever contains a book before sTitle // (i.e., canonically), then this will no longer be the first book in the view. m_mainWnd.TheDraftView.TeEditingHelper.GoToFirstBook(); sel = m_mainWnd.TheDraftView.RootBox.Selection; sel.TextSelInfo(true, out tss, out ich, out fAssocPrev, out hvoObj, out tag, out enc); Assert.IsNull(tss.Text, "book title has a title"); // Put the cursor in the empty section heading and verify stuff about the section // heading. m_mainWnd.TheDraftView.TeEditingHelper.GoToFirstSection(); sel = m_mainWnd.TheDraftView.RootBox.Selection; sel.TextSelInfo(true, out tss, out ich, out fAssocPrev, out hvoObj, out tag, out enc); AssertEx.RunIsCorrect(tss, 0, null, null, m_wsVern); // Make sure the chapter number is set m_mainWnd.TheDraftView.SetInsertionPoint(0, 0, 0, 0, true); sel = m_mainWnd.TheDraftView.RootBox.Selection; sel.TextSelInfo(true, out tss, out ich, out fAssocPrev, out hvoObj, out tag, out enc); AssertEx.RunIsCorrect(tss, 0, "1", ScrStyleNames.ChapterNumber, m_wsVern); }
public void GotoVerse_VerseOneAfterChapterNum() { IScrSection section = AddSectionToMockedBook(m_exodus); AddParaToMockedText(section.HeadingOA, ScrStyleNames.SectionHead); IStTxtPara para1 = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph); AddRunToMockedPara(para1, "1", ScrStyleNames.ChapterNumber); AddRunToMockedPara(para1, "1", ScrStyleNames.VerseNumber); AddRunToMockedPara(para1, "verse one", null); AddRunToMockedPara(para1, "2", ScrStyleNames.VerseNumber); AddRunToMockedPara(para1, "verse two", null); AddRunToMockedPara(para1, "3", ScrStyleNames.VerseNumber); AddRunToMockedPara(para1, "verse three", null); m_draftView.RootBox.Reconstruct(); // update the view // Set the selection to the start of the section m_draftView.TeEditingHelper.SetInsertionPoint(0, 0, 0, 0, false); // Attempt to go to Exodus 1:1 Assert.IsTrue(m_draftView.TeEditingHelper.GotoVerse(new ScrReference(2, 1, 1, m_scr.Versification))); // Make sure selection is at the first verse IVwSelection vwsel = m_draftView.RootBox.Selection; int ich, hvo, textTag, enc; bool fAssocPrev; ITsString tss2; vwsel.TextSelInfo(false, out tss2, out ich, out fAssocPrev, out hvo, out textTag, out enc); Assert.AreEqual(StTxtParaTags.kflidContents, textTag); Assert.AreEqual("verse one", tss2.Text.Substring(ich, 9)); Assert.IsFalse(fAssocPrev); }
public void GotoVerse_VerseMissingInMiddle() { IScrSection section = AddSectionToMockedBook(m_exodus); AddParaToMockedText(section.HeadingOA, ScrStyleNames.SectionHead); IStTxtPara para = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph); AddRunToMockedPara(para, "8", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse eight", null); AddRunToMockedPara(para, "10", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse ten", null); m_draftView.RootBox.Reconstruct(); // update the view // Set the selection to the start of the section m_draftView.TeEditingHelper.SetInsertionPoint(0, 0, 0, 0, false); // Attempt to go to Exodus 1:9 (should not exist) Assert.IsTrue(m_draftView.TeEditingHelper.GotoVerse(new ScrReference(2, 1, 9, m_scr.Versification))); // Make sure selection is between verse number 8 and its verse text. IVwSelection vwsel = m_draftView.RootBox.Selection; int ich, hvo, textTag, enc; bool fAssocPrev; ITsString tss2; vwsel.TextSelInfo(false, out tss2, out ich, out fAssocPrev, out hvo, out textTag, out enc); Assert.AreEqual(StTxtParaTags.kflidContents, textTag); Assert.AreEqual("8", tss2.Text.Substring(ich - 1, 1)); Assert.AreEqual("verse eight", tss2.Text.Substring(ich, 11)); Assert.IsFalse(fAssocPrev); }
public void GotoVerse_VerseMissingAtStart() { IScrSection section = AddSectionToMockedBook(m_exodus); AddParaToMockedText(section.HeadingOA, ScrStyleNames.SectionHead); IStTxtPara para = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph); AddRunToMockedPara(para, "7", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse seven", null); AddRunToMockedPara(para, "8", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse eight", null); m_draftView.RootBox.Reconstruct(); // update the view // Set the selection to right after the 7 at the start of the section m_draftView.TeEditingHelper.SetInsertionPoint(0, 0, 0, 1, false); // Attempt to go to Exodus 1:6 (should not exist) Assert.IsTrue(m_draftView.TeEditingHelper.GotoVerse(new ScrReference(2, 1, 6, m_scr.Versification))); // Make sure selection is immediately preceding the 7 that marks the beginning // of verse 7. IVwSelection vwsel = m_draftView.RootBox.Selection; int ich, hvo, textTag, enc; bool fAssocPrev; ITsString tss2; vwsel.TextSelInfo(false, out tss2, out ich, out fAssocPrev, out hvo, out textTag, out enc); Assert.AreEqual(StTxtParaTags.kflidContents, textTag); Assert.AreEqual("7verse seven", tss2.Text.Substring(ich, 12)); Assert.IsFalse(fAssocPrev); }
private void GetWordLimitsOfSelection(out int ichMin, out int ichLim, out int hvo, out int tag, out int ws, out ITsString tss) { ichMin = ichLim = hvo = tag = ws = 0; tss = null; IVwSelection wordsel = SelectionBeginningGrowToWord(RootSite.RootBox.Selection); if (wordsel == null) { return; } bool fAssocPrev; wordsel.TextSelInfo(false, out tss, out ichMin, out fAssocPrev, out hvo, out tag, out ws); wordsel.TextSelInfo(true, out tss, out ichLim, out fAssocPrev, out hvo, out tag, out ws); }
private bool GetSelectedWordPos(IVwSelection sel, out int hvo, out int tag, out int ws, out int ichMin, out int ichLim) { IVwSelection wordsel = SelectionBeginningGrowToWord(sel); if (wordsel == null) { hvo = tag = ws = 0; ichMin = ichLim = -1; return(false); } ITsString tss; bool fAssocPrev; wordsel.TextSelInfo(false, out tss, out ichMin, out fAssocPrev, out hvo, out tag, out ws); wordsel.TextSelInfo(true, out tss, out ichLim, out fAssocPrev, out hvo, out tag, out ws); return(ichLim > 0); }
public void EnterKey_InBtSectionHead() { CheckDisposed(); IScrBook book = m_scrInMemoryCache.AddBookToMockedScripture(2, "Exodus"); m_scrInMemoryCache.AddTitleToMockedBook(book.Hvo, "Exodus"); m_btDraftView.BookFilter.Insert(0, book.Hvo); IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(book.Hvo); StTxtPara headPara = m_scrInMemoryCache.AddSectionHeadParaToSection( section.Hvo, "The first section", ScrStyleNames.SectionHead); // Construct a parent paragraph StTxtPara parentPara = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(parentPara, "1", ScrStyleNames.ChapterNumber); m_scrInMemoryCache.AddRunToMockedPara(parentPara, "1", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(parentPara, "uno ", null); section.AdjustReferences(); // Construct the initial back translation. int wsBt = m_inMemoryCache.Cache.DefaultAnalWs; ICmTranslation headingTrans = m_inMemoryCache.AddBtToMockedParagraph(headPara, wsBt); m_inMemoryCache.AddRunToMockedTrans(headingTrans, wsBt, "BT heading", ScrStyleNames.Header); ICmTranslation paraTrans = m_inMemoryCache.AddBtToMockedParagraph(parentPara, wsBt); m_inMemoryCache.AddRunToMockedTrans(paraTrans, wsBt, "one", null); // Set the following style for section head. IStStyle styleHead = m_scr.FindStyle(ScrStyleNames.SectionHead); IStStyle stylePara = m_scr.FindStyle(ScrStyleNames.NormalParagraph); styleHead.NextRA = stylePara; // Set IP at the end of the section head. int sectionHeadLength = headingTrans.Translation.GetAlternativeTss(wsBt).Length; m_btDraftView.TeEditingHelper.SetInsertionPoint( (int)ScrSection.ScrSectionTags.kflidHeading, 0, 0, 0, sectionHeadLength, false); m_btDraftView.OnKeyPress(new KeyPressEventArgs('\r')); // Verify that the selection has moved to the start of the BT of the section Content. IVwSelection vwsel = m_btDraftView.RootBox.Selection; int ich, hvo, textTag, enc; bool fAssocPrev; ITsString tss; vwsel.TextSelInfo(false, out tss, out ich, out fAssocPrev, out hvo, out textTag, out enc); Assert.AreEqual((int)CmTranslation.CmTranslationTags.kflidTranslation, textTag); Assert.AreEqual(paraTrans.Hvo, hvo, "Current paragraph should be content following section head."); Assert.AreEqual(0, ich); // selection is at start of paragraph }
/// <summary> /// Adjusts the selection. /// </summary> /// <param name="sel">The selection.</param> private void AdjustSelection(SelectionHelper sel) { IVwSelection anchorSel; int curHvo, curIch, curTag; // anchor IP if (!GetSelectionInfo(sel, SelectionHelper.SelLimitType.Anchor, out anchorSel, out curHvo, out curIch, out curTag)) { return; } IVwSelection endSel; int curEndHvo, curEndIch, curEndTag; // end IP if (!GetSelectionInfo(sel, SelectionHelper.SelLimitType.End, out endSel, out curEndHvo, out curEndIch, out curEndTag)) { return; } // create range selection IVwSelection vwSel = RootBox.MakeRangeSelection(anchorSel, endSel, false); if (vwSel != null) { ITsString tss; int ws; bool prev; // only install the adjusted selection if it is different then the current selection int wholeHvo, wholeIch, wholeTag, wholeEndHvo, wholeEndIch, wholeEndTag; vwSel.TextSelInfo(false, out tss, out wholeIch, out prev, out wholeHvo, out wholeTag, out ws); vwSel.TextSelInfo(true, out tss, out wholeEndIch, out prev, out wholeEndHvo, out wholeEndTag, out ws); if (wholeHvo != curHvo || wholeEndHvo != curEndHvo || wholeIch != curIch || wholeEndIch != curEndIch || wholeTag != curTag || wholeEndTag != curEndTag) { vwSel.Install(); } } }
public void GotoVerse_BetweenSections() { // section1: 1, 3 // section2: 21, 20, 22 // ip at beginning of section1 // goto verse 4 IScrSection section = AddSectionToMockedBook(m_exodus); AddParaToMockedText(section.HeadingOA, ScrStyleNames.SectionHead); IStTxtPara para1 = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph); AddRunToMockedPara(para1, "1", ScrStyleNames.ChapterNumber); AddRunToMockedPara(para1, "1", ScrStyleNames.VerseNumber); AddRunToMockedPara(para1, "verse one", null); AddRunToMockedPara(para1, "3", ScrStyleNames.VerseNumber); AddRunToMockedPara(para1, "verse three", null); section = AddSectionToMockedBook(m_exodus); AddParaToMockedText(section.HeadingOA, ScrStyleNames.SectionHead); IStTxtPara para2 = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph); AddRunToMockedPara(para2, "21", ScrStyleNames.VerseNumber); AddRunToMockedPara(para2, "verse twenty-one", null); AddRunToMockedPara(para2, "20", ScrStyleNames.VerseNumber); AddRunToMockedPara(para2, "verse twenty", null); AddRunToMockedPara(para2, "22", ScrStyleNames.VerseNumber); AddRunToMockedPara(para2, "verse twenty-two", null); m_draftView.RootBox.Reconstruct(); // update the view // Set the selection to the start of the section m_draftView.TeEditingHelper.SetInsertionPoint(0, 0, 0, 0, false); // Attempt to go to Exodus 1:4 (should not exist) Assert.IsTrue(m_draftView.TeEditingHelper.GotoVerse(new ScrReference(2, 1, 4, m_scr.Versification))); // Make sure selection is between verse number 3 and it's verse text. IVwSelection vwsel = m_draftView.RootBox.Selection; int ich, hvo, textTag, enc; bool fAssocPrev; ITsString tss2; vwsel.TextSelInfo(false, out tss2, out ich, out fAssocPrev, out hvo, out textTag, out enc); Assert.AreEqual(StTxtParaTags.kflidContents, textTag); Assert.AreEqual("3", tss2.Text.Substring(ich - 1, 1)); Assert.AreEqual("verse three", tss2.Text.Substring(ich, 11)); Assert.IsFalse(fAssocPrev); }
private LexEntryUi GetSelWord() { IVwSelection sel = m_view.RootBox.Selection; if (sel == null) { return(null); } IVwSelection sel2 = sel.EndPoint(false); if (sel2 == null) { return(null); } IVwSelection sel3 = sel2.GrowToWord(); if (sel3 == null) { return(null); } ITsString tss; int ichMin, ichLim, hvo, tag, ws; bool fAssocPrev; sel3.TextSelInfo(false, out tss, out ichMin, out fAssocPrev, out hvo, out tag, out ws); sel3.TextSelInfo(true, out tss, out ichLim, out fAssocPrev, out hvo, out tag, out ws); ITsString tssWf = (m_cdaTemp as ISilDataAccess).get_StringProp(hvo, tag); if (tssWf == null || tssWf.Length == 0) { return(null); } // Ignore what part of it is selected...we want the entry whose whole citation form // the selection is part of. //string wf = tssWf.Text.Substring(ichMin, ichLim - ichMin); return(LexEntryUi.FindEntryForWordform(m_cache, tssWf)); }
public void EnterKey_InBtSectionTitle() { CheckDisposed(); IScrBook book = m_scrInMemoryCache.AddBookToMockedScripture(2, "Exodus"); StText title = m_scrInMemoryCache.AddTitleToMockedBook(book.Hvo, "Exodus"); m_btDraftView.BookFilter.Insert(0, book.Hvo); IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(book.Hvo); StTxtPara headPara = m_scrInMemoryCache.AddSectionHeadParaToSection( section.Hvo, "The first section", ScrStyleNames.SectionHead); // Construct a parent paragraph StTxtPara parentPara = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(parentPara, "1", ScrStyleNames.ChapterNumber); m_scrInMemoryCache.AddRunToMockedPara(parentPara, "1", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(parentPara, "uno ", null); section.AdjustReferences(); // Construct the initial back translation. int wsBt = m_inMemoryCache.Cache.DefaultAnalWs; ICmTranslation titleTrans = m_inMemoryCache.AddBtToMockedParagraph((StTxtPara)title.ParagraphsOS[0], wsBt); m_inMemoryCache.AddRunToMockedTrans(titleTrans, wsBt, "Exodo", ScrStyleNames.MainBookTitle); ICmTranslation headingTrans = m_inMemoryCache.AddBtToMockedParagraph(headPara, wsBt); m_inMemoryCache.AddRunToMockedTrans(headingTrans, wsBt, "BT heading", ScrStyleNames.Header); ICmTranslation paraTrans = m_inMemoryCache.AddBtToMockedParagraph(parentPara, wsBt); m_inMemoryCache.AddRunToMockedTrans(paraTrans, wsBt, "one", null); // Set IP at the start of the title. m_btDraftView.Refresh(); m_btDraftView.RootBox.MakeSimpleSel(true, false, false, true); m_btDraftView.OnKeyPress(new KeyPressEventArgs('\r')); // Verify that the selection has moved to the start of the BT of the section Head. IVwSelection vwsel = m_btDraftView.RootBox.Selection; int ich, hvo, textTag, enc; bool fAssocPrev; ITsString tss; vwsel.TextSelInfo(false, out tss, out ich, out fAssocPrev, out hvo, out textTag, out enc); Assert.AreEqual((int)CmTranslation.CmTranslationTags.kflidTranslation, textTag); Assert.AreEqual(headingTrans.Hvo, hvo, "Current paragraph should first section head."); Assert.AreEqual(0, ich); // selection is at start of paragraph }
protected override bool DoContextMenu(IVwSelection sel, Point pt, Rectangle rcSrcRoot, Rectangle rcDstRoot) { int hvo, tag, ihvo, cpropPrevious; IVwPropertyStore propStore; sel.PropInfo(false, 0, out hvo, out tag, out ihvo, out cpropPrevious, out propStore); string nodePath = null; if (propStore != null) { nodePath = propStore.get_StringProperty((int)FwTextPropType.ktptBulNumTxtBef); } if (string.IsNullOrEmpty(nodePath)) { if (sel.SelType == VwSelType.kstPicture) { return(true); } // may be a literal string, where we can get it from the string itself. ITsString tss; int ich, ws; bool fAssocPrev; sel.TextSelInfo(false, out tss, out ich, out fAssocPrev, out hvo, out tag, out ws); nodePath = tss.get_Properties(0).GetStrPropValue((int)FwTextPropType.ktptBulNumTxtBef); } if (m_configObjectName == null) { m_configObjectName = XmlUtils.GetLocalizedAttributeValue( Mediator.StringTbl, m_xnSpec, "configureObjectName", null); } string label; if (string.IsNullOrEmpty(nodePath)) { label = String.Format(xWorksStrings.ksConfigure, m_configObjectName); } else { label = String.Format(xWorksStrings.ksConfigureIn, nodePath.Split(':')[3], m_configObjectName); } m_contextMenu = new ContextMenuStrip(); var item = new ToolStripMenuItem(label); m_contextMenu.Items.Add(item); item.Click += RunConfigureDialogAt; item.Tag = nodePath; m_contextMenu.Show(this, pt); m_contextMenu.Closed += m_contextMenu_Closed; return(true); }
/// <summary> /// Selects a range of text based on the specified writing system. /// </summary> /// <param name="ws">The writing system.</param> /// <param name="start">The position of the first character in the current text selection within the text box.</param> /// <param name="length">The number of characters to select.</param> /// <remarks> /// If you want to set the start position to the first character in the control's text, set the <i>start</i> parameter to 0. /// You can use this method to select a substring of text, such as when searching through the text of the control and replacing information. /// <b>Note:</b> You can programmatically move the caret within the text box by setting the <i>start</i> parameter to the position within /// the text box where you want the caret to move to and set the <i>length</i> parameter to a value of zero (0). /// The text box must have focus in order for the caret to be moved. /// </remarks> /// <exception cref="ArgumentException"> /// The value assigned to either the <i>start</i> parameter or the <i>length</i> parameter is less than zero. /// </exception> public void Select(int ws, int start, int length) { CheckDisposed(); if (start < 0) { throw new ArgumentException("Starting position is less than zero.", "start"); } if (length < 0) { throw new ArgumentException("Length is less than zero.", "length"); } IVwSelection sel = m_innerControl.RootBox.Selection; if (sel != null) { // See if the desired thing is already selected. If so do nothing. This can prevent stack overflow! ITsString tssDummy; int ichAnchor, ichEnd, hvo, tag, wsDummy; bool fAssocPrev; sel.TextSelInfo(true, out tssDummy, out ichEnd, out fAssocPrev, out hvo, out tag, out wsDummy); sel.TextSelInfo(false, out tssDummy, out ichAnchor, out fAssocPrev, out hvo, out tag, out wsDummy); if (Math.Min(ichAnchor, ichEnd) == start && Math.Max(ichAnchor, ichEnd) == start + length) { return; } } try { m_innerControl.RootBox.MakeTextSelection(0, 0, null, InnerLabeledMultiStringControl.kflid, 0, start, start + length, ws, false, -1, null, true); } catch { } }
/// <summary> /// Get the string representation of the current selection in the environment list, /// plus the selection object and some of its internal information. /// </summary> /// <param name="tss"></param> /// <param name="vwsel"></param> /// <param name="hvoDummyObj"></param> /// <param name="ichAnchor"></param> /// <param name="ichEnd"></param> /// <returns>false if selection spans two or more objects, true otherwise</returns> internal bool GetSelectedStringRep(out ITsString tss, out IVwSelection vwsel, out int hvoDummyObj, out int ichAnchor, out int ichEnd) { CheckDisposed(); tss = null; vwsel = null; hvoDummyObj = 0; ichAnchor = 0; ichEnd = 0; try { ITsString tss2; bool fAssocPrev; int hvoObjEnd; int tag1; int tag2; int ws1; int ws2; vwsel = m_rootb.Selection; vwsel.TextSelInfo(false, out tss, out ichAnchor, out fAssocPrev, out hvoDummyObj, out tag1, out ws1); vwsel.TextSelInfo(true, out tss2, out ichEnd, out fAssocPrev, out hvoObjEnd, out tag2, out ws2); if (hvoDummyObj != hvoObjEnd) { return(false); } } catch { vwsel = null; tss = null; return(true); } return(true); }
public void InsertFootnote() { CheckDisposed(); FdoCache cache = m_firstMainWnd.Cache; // Set the IP to the second section in the first book at the 10th character in // the first paragraph m_firstDraftView.SetInsertionPoint(0, 1, 0, 10, false); ScrBook book = (ScrBook)cache.LangProject.TranslatedScriptureOA.ScriptureBooksOS[0]; int nFootnotes = book.FootnotesOS.Count; m_firstMainWnd.CallInsertFootnote(); Assert.AreEqual(nFootnotes + 1, book.FootnotesOS.Count); // Test footnote string expectedMarker = new String((char)((int)'a' + nFootnotes), 1); StFootnote footnote = (StFootnote)book.FootnotesOS[nFootnotes]; Assert.AreEqual(expectedMarker, footnote.FootnoteMarker.Text, "Wrong footnote marker in footnote"); ITsString tsString = footnote.FootnoteMarker.UnderlyingTsString; ITsTextProps ttp = tsString.get_PropertiesAt(0); string styleName = ttp.GetStrPropValue((int)FwTextPropType.ktptNamedStyle); Assert.AreEqual(ScrStyleNames.FootnoteMarker, styleName, "Wrong style for footnote marker in footnote"); // Test footnote marker in text IVwSelection sel = m_firstDraftView.RootBox.Selection; ITsString tss; int ich, hvoObj, tag, enc; bool fAssocPrev; sel.TextSelInfo(true, out tss, out ich, out fAssocPrev, out hvoObj, out tag, out enc); string strPara = tss.Text; Assert.AreEqual(StringUtils.kchObject, strPara[ich]); ttp = tss.get_PropertiesAt(ich); int nDummy; int wsActual = ttp.GetIntPropValues((int)FwTextPropType.ktptWs, out nDummy); Assert.AreEqual(cache.LangProject.DefaultVernacularWritingSystem, wsActual, "Wrong writing system for footnote marker in text"); string objData = ttp.GetStrPropValue((int)FwTextPropType.ktptObjData); Assert.AreEqual((char)(int)FwObjDataTypes.kodtOwnNameGuidHot, objData[0]); }
internal bool SafeToDoMacro(IVwSelection sel, out ICmObject obj, out int flid, out int ws, out int start, out int length) { start = flid = ws = length = 0; // defaults so we can return early. obj = null; if (sel == null || !(sel.SelType == VwSelType.kstText)) return false; ITsString dummy; int hvoA, hvoE, flidE, ichA, ichE, wsE; bool fAssocPrev; sel.TextSelInfo(false, out dummy, out ichA, out fAssocPrev, out hvoA, out flid, out ws); sel.TextSelInfo(true, out dummy, out ichE, out fAssocPrev, out hvoE, out flidE, out wsE); // for safety require selection to be in a single property. if (hvoA != hvoE || flid != flidE || ws != wsE) return false; var cache = (FdoCache) m_mediator.PropertyTable.GetValue("cache"); obj = cache.ServiceLocator.ObjectRepository.GetObject(hvoA); start = Math.Min(ichA, ichE); length = Math.Max(ichA, ichE) - start; return true; }
/// <summary> /// This is a demonstration of one way to handle special tricks as the user types. /// This is an oversimplified way of forcing numbers to be treated as verse numbers... /// for example, it will cause '5000' in the 'feeding of the 5000' to be treated as a verse number. /// </summary> /// <param name="vwselNew"></param> protected override void HandleSelectionChange(IVwSelection vwselNew) { base.HandleSelectionChange (vwselNew); if (vwselNew == null) return; // Not sure whether this happens, but best to be sure. int ichSel, hvoObj, tag, ws; bool fAssocPrev; ITsString tss; vwselNew.TextSelInfo(false, out tss, out ichSel, out fAssocPrev, out hvoObj, out tag, out ws); string text = tss.get_Text(); if (text == null) return; // empty string. ITsStrBldr tsb = null; for (int ich = 0; ich < text.Length; ++ich) { if (Char.IsDigit(text[ich])) { ITsTextProps ttp = tss.get_PropertiesAt(ich); string styleName = ttp.GetStrPropValue((int)FwKernelLib.FwTextPropType.ktptNamedStyle); if (styleName != "verseNumber") { // We'll change just this one character. We could make this more efficient for dealing with // long strings of digits, but it's unlikely we'll ever have to deal with more than one. if (tsb == null) tsb = tss.GetBldr(); tsb.SetStrPropValue(ich, ich + 1, (int)FwKernelLib.FwTextPropType.ktptNamedStyle, "verseNumber"); } } } if (tsb != null) { ISilDataAccess sda = m_rootb.get_DataAccess(); // In this sample the only string is a multistring. If in doubt, we could test for ws == 0 to // see whether it is a simple string. sda.SetMultiStringAlt(hvoObj, tag, ws, tsb.GetString()); sda.PropChanged(null, (int)FwViews.PropChangeType.kpctNotifyAll, hvoObj, tag, 0, tss.get_Length(), tss.get_Length()); } }
/// <summary> /// Determine whether the current selection is at a place suitable for type-ahead. If not, answer 0. /// (In this case the values of hvoParent and ihvo should not be relied on.) /// If so, indicate the object whose property may be set by type-ahead (hvoParent), the object /// in the relevant property that is selected (return result), and its index within the property /// (0 if atomic). /// </summary> /// <param name="rootb"></param> /// <param name="sel"></param> /// <param name="hvoParent"></param> /// <param name="ihvo"></param> /// <returns></returns> private int SelectedObject(IVwRootBox rootb, IVwSelection sel, out int hvoParent, out int ihvo) { hvoParent = 0; ihvo = 0; if (rootb == null) // If we don't have a root box, can't do anything interesting. return 0; if (sel == null) // nothing interesting to do without a selection, either. return 0; ITsString tssA, tssE; int ichA, ichE, hvoObjA, hvoObjE, tagA, tagE, ws; bool fAssocPrev; // Enhance JohnT: what we're really trying to do here is confirm that the selection is // all in one string property. We could readily have a method in the selection interface to tell us that. sel.TextSelInfo(false, out tssA, out ichA, out fAssocPrev, out hvoObjA, out tagA, out ws); if (tagA != m_taTagName && tagA != m_snTagName) return 0; // selection not anchored in any sort of type-ahead name property. sel.TextSelInfo(true, out tssE, out ichE, out fAssocPrev, out hvoObjE, out tagE, out ws); int cch = tssA.Length; // To do our type-ahead trick, both ends of the seleciton must be in the same string property. // Also, we want the selection to extend to the end of the name. // Enhance JohnT: if we do a popup window, it may not matter whether the selection extends // to the end; just show items that match. if (tagE != tagA || hvoObjE != hvoObjA || cch != tssE.Length || Math.Max(ichA, ichE) != cch) return 0; // not going to attempt type-ahead behavior int clev = sel.CLevels(false); if (clev < 2) return 0; // can't be our property. int tagParent, cpropPrevious; IVwPropertyStore vps; sel.PropInfo(false, 1, out hvoParent, out tagParent, out ihvo, out cpropPrevious, out vps); if (tagParent != m_virtualTagObj) return 0; // not our virtual property! return hvoObjA; }
/// ------------------------------------------------------------------------------------ /// <summary> /// If selection is a simple IP, check current run or runs on either side (if between /// runs). If run(s) is/are a verse number run, return true. /// </summary> /// <param name="vwsel">selection to check</param> /// <returns>True if IP is in or next to a verse number run</returns> /// ------------------------------------------------------------------------------------ private bool SelIPInVerseNumber(IVwSelection vwsel) { if (vwsel.IsRange) return false; ITsString tss; int ich, hvo, tag, ws, ichMin, ichLim; bool fAssocPrev; vwsel.TextSelInfo(true, out tss, out ich, out fAssocPrev, out hvo, out tag, out ws); return InReference(tss, ich, false, out ichMin, out ichLim); }
public override void SelectionChanged(IVwRootBox rootb, IVwSelection vwselNew) { CheckDisposed(); if (vwselNew == null) return; bool hasFoc = Focused; base.SelectionChanged(rootb, vwselNew); ITsString tss; int ichAnchor; bool fAssocPrev; int hvoObj; int tag; int ws; // NB: This will be 0 after each call, since the string does // not have alternatives. Ws would be the WS of an alternative, // if there were any. vwselNew.TextSelInfo(false, out tss, out ichAnchor, out fAssocPrev, out hvoObj, out tag, out ws); int ichEnd; int hvoObjEnd; vwselNew.TextSelInfo(true, out tss, out ichEnd, out fAssocPrev, out hvoObjEnd, out tag, out ws); if (hvoObjEnd != hvoObj) { CheckHeight(); return; } if (m_hvoOldSelection > 0 && hvoObj != m_hvoOldSelection) { // Try to validate previously selected string rep. if (m_silCache.get_StringProp(m_hvoOldSelection, kEnvStringRep).Length==0) { // Remove it from the dummy cache, since its length is 0. int limit = m_silCache.get_VecSize(m_rootObj.Hvo, kMainObjEnvironments); for (int i = 0; i < limit; ++i) { if (m_hvoOldSelection == m_silCache.get_VecItem(m_rootObj.Hvo, kMainObjEnvironments, i)) { RemoveFromDummyCache(i); break; } } } else // Validate previously selected string rep. { ValidateStringRep(m_hvoOldSelection); } } if (hvoObj != kDummyPhoneEnvID) { m_hvoOldSelection = hvoObj; CheckHeight(); return; } if (tss.Length == 0) { CheckHeight(); return; } // Create a new object, and recreate a new empty object. Make this part of the Undo // Task with the character we typed. m_silCache.GetActionHandler().ContinueUndoTask(); int count = m_silCache.get_VecSize(m_rootObj.Hvo, kMainObjEnvironments); int hvoNew = InsertNewEnv(count - 1); m_silCache.SetString(hvoNew, kEnvStringRep, tss); m_silCache.SetString(kDummyPhoneEnvID, kEnvStringRep, DummyString); m_silCache.EndUndoTask(); // Refresh m_silCache.PropChanged(null, (int)PropChangeType.kpctNotifyAll, m_rootObj.Hvo, kMainObjEnvironments, count - 1, 2, 1); // Reset selection. SelLevInfo[] rgvsli = new SelLevInfo[1]; rgvsli[0].cpropPrevious = 0; rgvsli[0].tag = kMainObjEnvironments; rgvsli[0].ihvo = count - 1; m_rootb.MakeTextSelection(0, rgvsli.Length, rgvsli, tag, 0, ichAnchor, ichEnd, ws, fAssocPrev, -1, null, true); m_hvoOldSelection = hvoNew; CheckHeight(); }
public override void SelectionChanged(IVwRootBox rootb, IVwSelection vwselNew) { CheckDisposed(); if (m_handlingSelectionChanged) return; m_handlingSelectionChanged = true; try { m_selectedSenseHvo = 0; if (vwselNew == null) return; base.SelectionChanged(rootb, vwselNew); // Get the Id of the selected snes, and store it. int cvsli = vwselNew.CLevels(false); // CLevels includes the string property itself, but AllTextSelInfo doesn't need it. cvsli--; if (cvsli == 0) { // No objects in selection: don't allow a selection. m_rootb.DestroySelection(); // Enhance: invoke launcher's selection dialog. return; } ITsString tss; int ichAnchor; int ichEnd; bool fAssocPrev; int hvoObj; int hvoObjEnd; int tag; int ws; vwselNew.TextSelInfo(false, out tss, out ichAnchor, out fAssocPrev, out hvoObj, out tag, out ws); vwselNew.TextSelInfo(true, out tss, out ichEnd, out fAssocPrev, out hvoObjEnd, out tag, out ws); if (hvoObj != hvoObjEnd) return; m_selectedSenseHvo = hvoObj; } finally { m_handlingSelectionChanged = false; } }
protected override bool DoContextMenu(IVwSelection sel, Point pt, Rectangle rcSrcRoot, Rectangle rcDstRoot) { int hvo, tag, ihvo, cpropPrevious; IVwPropertyStore propStore; sel.PropInfo(false, 0, out hvo, out tag, out ihvo, out cpropPrevious, out propStore); string nodePath = null; if (propStore != null) { nodePath = propStore.get_StringProperty((int) FwTextPropType.ktptBulNumTxtBef); } if (string.IsNullOrEmpty(nodePath)) { if (sel.SelType == VwSelType.kstPicture) return true; // may be a literal string, where we can get it from the string itself. ITsString tss; int ich, ws; bool fAssocPrev; sel.TextSelInfo(false, out tss, out ich, out fAssocPrev, out hvo, out tag, out ws); nodePath = tss.get_Properties(0).GetStrPropValue((int) FwTextPropType.ktptBulNumTxtBef); } if (m_configObjectName == null) m_configObjectName = XmlUtils.GetLocalizedAttributeValue( Mediator.StringTbl, m_xnSpec, "configureObjectName", null); string label; if (string.IsNullOrEmpty(nodePath)) label = String.Format(xWorksStrings.ksConfigure, m_configObjectName); else label = String.Format(xWorksStrings.ksConfigureIn, nodePath.Split(':')[3], m_configObjectName); m_contextMenu = new ContextMenuStrip(); var item = new ToolStripMenuItem(label); m_contextMenu.Items.Add(item); item.Click += RunConfigureDialogAt; item.Tag = nodePath; m_contextMenu.Show(this, pt); m_contextMenu.Closed += m_contextMenu_Closed; return true; }
/// <summary> /// Handle a problem deleting some selection in the sandbox. So far, the only cases we /// handle are backspace and delete merging morphemes. /// Enhance JohnT: could also handle deleting a range that merges morphemes. /// </summary> /// <param name="sel"></param> /// <param name="dpt"></param> /// <returns></returns> public override VwDelProbResponse OnProblemDeletion(IVwSelection sel, VwDelProbType dpt) { CheckDisposed(); ITsString tss = null; bool fAssocPrev = false; int ichSel = -1; int hvoObj = 0; int tag = 0; int ws; sel.TextSelInfo(false, out tss, out ichSel, out fAssocPrev, out hvoObj, out tag, out ws); if (!m_editMonitor.IsPropMorphBreak(hvoObj, tag, ws)) return VwDelProbResponse.kdprFail; switch (dpt) { case VwDelProbType.kdptBsAtStartPara: case VwDelProbType.kdptBsReadOnly: return m_editMonitor.HandleBackspace() ? VwDelProbResponse.kdprDone : VwDelProbResponse.kdprFail; case VwDelProbType.kdptDelAtEndPara: case VwDelProbType.kdptDelReadOnly: return m_editMonitor.HandleDelete() ? VwDelProbResponse.kdprDone : VwDelProbResponse.kdprFail; default: return VwDelProbResponse.kdprFail; } }
protected bool CheckForValidDelete(IVwSelection sel, out int cvsli, out int hvoObj) { hvoObj = 0; if (sel == null) { cvsli = 0; // satisfy compiler. return false; // nothing selected, give up. } cvsli = sel.CLevels(false); // CLevels includes the string property itself, but AllTextSelInfo doesn't need it. cvsli--; if (cvsli == 0) { // No object in selection, so quit. return false; } ITsString tss; int ichAnchor; bool fAssocPrev; int tag; int ws; int ichEnd; int hvoObjEnd; sel.TextSelInfo(false, out tss, out ichAnchor, out fAssocPrev, out hvoObj, out tag, out ws); sel.TextSelInfo(true, out tss, out ichEnd, out fAssocPrev, out hvoObjEnd, out tag, out ws); return (hvoObj == hvoObjEnd); }
public override void SelectionChanged(IVwRootBox rootb, IVwSelection vwselNew) { CheckDisposed(); if (vwselNew == null) return; base.SelectionChanged(rootb, vwselNew); ITsString tss; int ichAnchor; bool fAssocPrev; int hvoObj; int tag; int ws; vwselNew.TextSelInfo(false, out tss, out ichAnchor, out fAssocPrev, out hvoObj, out tag, out ws); int ichEnd; int hvoObjEnd; vwselNew.TextSelInfo(true, out tss, out ichEnd, out fAssocPrev, out hvoObjEnd, out tag, out ws); if (hvoObjEnd != hvoObj) { // Can't do much with a multi-object selection. CheckHeight(); return; } // The next level out in the view should be the entry in the index. int hvoIndex, ihvoEntry, cpropPrevious, tagEntry; IVwPropertyStore vps; vwselNew.PropInfo(false, 1, out hvoIndex, out tagEntry, out ihvoEntry, out cpropPrevious, out vps); // And the next one is the relevant index. int hvoSense, tagIndex, ihvoIndex; vwselNew.PropInfo(false, 2, out hvoSense, out tagIndex, out ihvoIndex, out cpropPrevious, out vps); int count = m_silCache.get_VecSize(hvoIndex, kFlidEntries); int lastEntryHvo = m_silCache.get_VecItem(hvoIndex, kFlidEntries, count - 1); //string oldForm = m_silCache.get_UnicodeProp(m_hvoOldSelection, (int)ReversalIndexEntry.ReversalIndexEntryTags.kflidForm); string oldForm = null; int wsIndex = m_silCache.get_IntProp(hvoIndex, (int)ReversalIndex.ReversalIndexTags.kflidWritingSystem); ITsString tssEntry = m_silCache.get_MultiStringAlt(m_hvoOldSelection, (int)ReversalIndexEntry.ReversalIndexEntryTags.kflidReversalForm, wsIndex); if (tssEntry != null) oldForm = tssEntry.Text; if (m_hvoOldSelection != 0 && hvoObj != m_hvoOldSelection && (oldForm == null || oldForm.Length == 0)) { // Remove the old string from the dummy cache, since its length is 0. for (int i = 0; i < count; ++i) { if (m_hvoOldSelection == m_silCache.get_VecItem(hvoIndex, kFlidEntries, i)) { RemoveFromDummyCache(hvoIndex, i); break; } } } // If it's not the last index in the list, we can just go on editing it. if (hvoObj != lastEntryHvo) { m_hvoOldSelection = hvoObj; CheckHeight(); return; } // Even if it's the last object, if it's empty we don't need to do anything. if (tss.Length == 0) { CheckHeight(); return; } // Create a new object, and recreate a new empty object. count = m_silCache.get_VecSize(hvoIndex, kFlidEntries); // Assign a new dummy ID. m_dummyId--; // Insert it at the end of the list. m_vwCache.CacheReplace(hvoIndex, kFlidEntries, count, count, new int[] {m_dummyId}, 1); Cache.EnableUndo = false; // Things have changed in a way we can't Undo. // Set its 'form' to be an empty string in the appropriate writing system. ITsTextProps props = tss.get_PropertiesAt(0); int nVar; ws = props.GetIntPropValues((int)FwTextPropType.ktptWs, out nVar); //m_vwCache.CacheUnicodeProp(m_dummyId, (int)ReversalIndexEntry.ReversalIndexEntryTags.kflidForm, String.Empty, 0); //m_vwCache.CacheIntProp(m_dummyId, (int)ReversalIndexEntry.ReversalIndexEntryTags.kflidWritingSystem, ws); ITsString tssEmpty = m_tsf.MakeString("", ws); m_vwCache.CacheStringAlt(m_dummyId, (int)ReversalIndexEntry.ReversalIndexEntryTags.kflidReversalForm, ws, tssEmpty); // Refresh m_silCache.PropChanged(null, (int)PropChangeType.kpctNotifyAll, hvoIndex, kFlidEntries, count, 1, 0); // Reset selection. SelLevInfo[] rgvsli = new SelLevInfo[2]; rgvsli[0].cpropPrevious = 0; rgvsli[0].tag = kFlidEntries; rgvsli[0].ihvo = count - 1; rgvsli[1].cpropPrevious = 0; rgvsli[1].tag = kFlidIndices; rgvsli[1].ihvo = ihvoIndex; try { m_rootb.MakeTextSelection(0, rgvsli.Length, rgvsli, tag, 0, ichAnchor, ichEnd, ws, fAssocPrev, -1, null, true); } catch (Exception e) { Debug.WriteLine(e.ToString()); throw; } m_hvoOldSelection = hvoObj; CheckHeight(); }
public override void SelectionChanged(IVwRootBox prootb, IVwSelection vwselNew) { CheckDisposed(); ITsString tssTyped; int ich, hvo, tag, ws; bool fAssocPrev; vwselNew.TextSelInfo(false, out tssTyped, out ich, out fAssocPrev, out hvo, out tag, out ws); base.SelectionChanged(prootb, vwselNew); if (tssTyped.Length != 0) { // user typed something in the dummy slice! Make a real object. // Save information required for RestoreSelection. MakeRealObject may well dispose this. System.Windows.Forms.Application.Idle += new EventHandler(Application_Idle); } }
/// <summary> /// Answer true if the indicated selection is within a single freeform annotation we can delete. /// </summary> /// <param name="sel"></param> /// <returns></returns> private bool CanDeleteFF(IVwSelection sel, out int hvoAnnotation) { hvoAnnotation = 0; if (sel == null) return false; ITsString tss; int ichEnd, hvoEnd, tagEnd, wsEnd; bool fAssocPrev; sel.TextSelInfo(true, out tss, out ichEnd, out fAssocPrev, out hvoEnd, out tagEnd, out wsEnd); int ichAnchor, hvoAnchor, tagAnchor, wsAnchor; sel.TextSelInfo(false, out tss, out ichAnchor, out fAssocPrev, out hvoAnchor, out tagAnchor, out wsAnchor); if (hvoEnd != hvoAnchor || tagEnd != tagAnchor || wsEnd != wsAnchor) return false; // must be a one-property selection if (tagAnchor != (int)CmAnnotation.CmAnnotationTags.kflidComment) return false; // must be a selection in a freeform annotation. hvoAnnotation = hvoAnchor; return true; }
protected override void HandleSelectionChange(IVwRootBox rootb, IVwSelection vwselNew) { CheckDisposed(); if (vwselNew == null) return; int cvsli = vwselNew.CLevels(false); // CLevels includes the string property itself, but AllTextSelInfo doesn't need it. cvsli--; if (cvsli == 0) { // No objects in selection: don't allow a selection. m_rootb.DestroySelection(); // Enhance: invoke launcher's selection dialog. return; } ITsString tss; int ichAnchor; int ichEnd; bool fAssocPrev; int hvoObj; int hvoObjEnd; int tag; int ws; vwselNew.TextSelInfo(false, out tss, out ichAnchor, out fAssocPrev, out hvoObj, out tag, out ws); vwselNew.TextSelInfo(true, out tss, out ichEnd, out fAssocPrev, out hvoObjEnd, out tag, out ws); if (hvoObj != hvoObjEnd) return; int ihvoRoot; int tagTextProp; int cpropPrevious; int ihvoEnd; ITsTextProps ttp; SelLevInfo[] rgvsli = SelLevInfo.AllTextSelInfo(vwselNew, cvsli, out ihvoRoot, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd, out ws, out fAssocPrev, out ihvoEnd, out ttp); Debug.Assert(m_rootb != null); // Create a selection that covers the entire target object. If it differs from // the new selection, we'll install it (which will recurse back to this method). IVwSelection vwselWhole = m_rootb.MakeTextSelInObj(ihvoRoot, cvsli, rgvsli, 0, null, false, false, false, true, false); if (vwselWhole != null) { ITsString tssWhole; int ichAnchorWhole; int ichEndWhole; int hvoObjWhole; int hvoObjEndWhole; bool fAssocPrevWhole; int tagWhole; int wsWhole; vwselWhole.TextSelInfo(false, out tssWhole, out ichAnchorWhole, out fAssocPrevWhole, out hvoObjWhole, out tagWhole, out wsWhole); vwselWhole.TextSelInfo(true, out tssWhole, out ichEndWhole, out fAssocPrevWhole, out hvoObjEndWhole, out tagWhole, out wsWhole); if (hvoObj == hvoObjWhole && hvoObjEnd == hvoObjEndWhole && (ichAnchor != ichAnchorWhole || ichEnd != ichEndWhole)) { // Install it this time! m_rootb.MakeTextSelInObj(ihvoRoot, cvsli, rgvsli, 0, null, false, false, false, true, true); } } }
/// <summary> /// Given a selection (typically from a click), determine the object that should be the target for jumping to, /// and return the property that was clicked (which in the case of a right-click may generate a spelling menu instead). /// </summary> /// <param name="sel"></param> /// <param name="hvoReal"></param> /// <returns></returns> private int GetInfoForJumpToTool(IVwSelection sel, out int hvoReal) { int ws; int tagRightClickTextProp; bool fAssocPrev; ITsString tss; int ichAnchorDum; int hvoRightClickObject = 0; sel.TextSelInfo(false, out tss, out ichAnchorDum, out fAssocPrev, out hvoRightClickObject, out tagRightClickTextProp, out ws); switch (tagRightClickTextProp) { case ktagSbMorphPrefix: case ktagSbMorphPostfix: m_hvoRightClickMorph = hvoRightClickObject; // Pretend we clicked on the morph form. (See LT-7590.) hvoRightClickObject = Caches.DataAccess.get_ObjectProp(hvoRightClickObject, ktagSbMorphForm); break; case ktagSbNamedObjName: if (sel.CLevels(false) < 2) break; int hvoOuterObj, tagOuter, ihvoOuter, cpropPreviousOuter; IVwPropertyStore vpsDummy; sel.PropInfo(false, 1, out hvoOuterObj, out tagOuter, out ihvoOuter, out cpropPreviousOuter, out vpsDummy); if (tagOuter == ktagSbMorphGloss || tagOuter == ktagSbMorphPos || tagOuter == ktagSbMorphForm || tagOuter == ktagSbMorphEntry) { m_hvoRightClickMorph = hvoOuterObj; } break; default: m_hvoRightClickMorph = 0; break; } hvoReal = m_caches.RealHvo(hvoRightClickObject); return tagRightClickTextProp; }
// Handles a change in the view selection. protected override void HandleSelectionChange(IVwSelection vwselNew) { base.HandleSelectionChange(vwselNew); // Figure what property is selected and display combo only if relevant. SIL.FieldWorks.Common.COMInterfaces.ITsString tss; int ich, tag, enc; bool fAssocPrev; vwselNew.TextSelInfo(true, out tss, out ich, out fAssocPrev, out hvoObjSelected, out tag, out enc); string str = tss.get_Text(); if (tag == ktagWord_Type) { // Display combo at selection SIL.FieldWorks.Common.COMInterfaces.Rect loc; vwselNew.GetParaLocation(out loc); typeComboBox.Location = new System.Drawing.Point(loc.left, loc.top); // 60 is an arbitrary minimum size to make the current contents visible. // Enhance JohnT: figure the width needed by the widest string, add width of arrow, use that // as minimum typeComboBox.Size = new System.Drawing.Size(Math.Max(loc.right - loc.left, 60), loc.bottom - loc.top); typeComboBox.Text = str; // This also makes it visible. this.Controls.Add(typeComboBox); } else { // Hide combo if visible. // Enhance JohnT: possibly also remove on loss of focus? if (this.Controls.Contains(typeComboBox)) { this.Controls.Remove(typeComboBox); } } // Todo JohnT: make something interesting happen when a selection is made. }
/// <summary> /// Get the string representation of the current selection in the environment list, /// plus the selection object and some of its internal information. /// </summary> /// <param name="tss"></param> /// <param name="vwsel"></param> /// <param name="hvoDummyObj"></param> /// <param name="ichAnchor"></param> /// <param name="ichEnd"></param> /// <returns>false if selection spans two or more objects, true otherwise</returns> internal bool GetSelectedStringRep(out ITsString tss, out IVwSelection vwsel, out int hvoDummyObj, out int ichAnchor, out int ichEnd) { CheckDisposed(); tss = null; vwsel = null; hvoDummyObj = 0; ichAnchor = 0; ichEnd = 0; try { ITsString tss2; bool fAssocPrev; int hvoObjEnd; int tag1; int tag2; int ws1; int ws2; vwsel = m_rootb.Selection; vwsel.TextSelInfo(false, out tss, out ichAnchor, out fAssocPrev, out hvoDummyObj, out tag1, out ws1); vwsel.TextSelInfo(true, out tss2, out ichEnd, out fAssocPrev, out hvoObjEnd, out tag2, out ws2); if (hvoDummyObj != hvoObjEnd) return false; } catch { vwsel = null; tss = null; return true; } return true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets ORCs in the selection, if any. /// </summary> /// <param name="sel">The selection of found text.</param> /// <returns>ORCs, if any, in the selected text</returns> /// ------------------------------------------------------------------------------------ private ITsString GetORCsFromTss(IVwSelection sel) { //// Get the paragraph containing the selection and the offset into it. ITsString tssPara; bool fAssocPrev; int hvo, ichStart, ichEnd, tag, ws; sel.TextSelInfo(false, out tssPara, out ichStart, out fAssocPrev, out hvo, out tag, out ws); sel.TextSelInfo(true, out tssPara, out ichEnd, out fAssocPrev, out hvo, out tag, out ws); // The selection string does not contain ORC characters (for footnotes, just // a non-breaking space followed by the footnote marker), so we need to get an ITsString // from the paragraph where the selection is. ITsString tssSelWithORCs = tssPara.GetSubstring(ichStart, ichEnd); return StringUtils.GetOwnedORCs(tssSelWithORCs); }
protected override void HandleSelectionChange(IVwRootBox rootb, IVwSelection vwselNew) { CheckDisposed(); if (vwselNew == null) return; // Get the string value for the old selection before it possibly changes due to a delete. ITsString tssOldSel = null; if (m_hvoOldSelection < 0) tssOldSel = m_sda.get_StringProp(m_hvoOldSelection, kEnvStringRep); base.HandleSelectionChange(rootb, vwselNew); ITsString tss; int ichAnchor; bool fAssocPrev; int hvoObj; int tag; int ws; // NB: This will be 0 after each call, since the string does // not have alternatives. Ws would be the WS of an alternative, // if there were any. vwselNew.TextSelInfo(false, out tss, out ichAnchor, out fAssocPrev, out hvoObj, out tag, out ws); // start of string info int ichEnd; int hvoObjEnd; vwselNew.TextSelInfo(true, out tss, out ichEnd, out fAssocPrev, out hvoObjEnd, out tag, out ws); // end of string info if (hvoObjEnd != hvoObj) { // owner of the end of the string in not the same as at the beginning - is this possible? CheckHeight(); return; } if (m_hvoOldSelection < 0 && (hvoObj != m_hvoOldSelection || (tssOldSel != null && tssOldSel.Length > 0))) { // the new selection is owned by a different object (left the selection) or the old one is not empty // Try to validate previously selected string rep. ITsString tssOld = m_sda.get_StringProp(m_hvoOldSelection, kEnvStringRep); if (tssOld == null || tssOld.Length == 0) { // deleted or erased // Remove it from the dummy cache, since its length is 0. int limit = m_sda.get_VecSize(m_rootObj.Hvo, kMainObjEnvironments); for (int i = 0; i < limit; ++i) { if (m_hvoOldSelection == m_sda.get_VecItem(m_rootObj.Hvo, kMainObjEnvironments, i)) { RemoveFromDummyCache(i); break; } } } else if (hvoObj != m_hvoOldSelection) { // Left the selection, so validate previously selected string rep. ValidateStringRep(m_hvoOldSelection); } } if (hvoObj != kDummyPhoneEnvID) { // this is a "real" env, not the place holder for the next one // normal editing of the current env exits here m_hvoOldSelection = hvoObj; CheckHeight(); return; } // if this is NOT the first pass for the original PropChanged // and the ts string is empty (tss.Text == null) then quit if (m_rootb.IsPropChangedInProgress && tss.Length == 0) { CheckHeight(); return; } // This point is only passed when the empty env pattern becomes "real" // or when this is the original PropChanged pass and the string is null. // This happens when // 1) a characher is typed in the empty env. (was empty but not now) // 2) a non-empty env is left by right-arrowing or clicking passed the separator bar. // Before this, the empty env is a placeholder for the next env. // After it is made real by giving it an hvo for the sda and selection mechanisms, // it must not pass this point again. // Create a new object, and recreate a new empty object. int count = m_sda.get_VecSize(m_rootObj.Hvo, kMainObjEnvironments); int hvoNew = InsertNewEnv(count - 1); m_sda.SetString(hvoNew, kEnvStringRep, tss); // set the last env to the pattern m_sda.SetString(kDummyPhoneEnvID, kEnvStringRep, DummyString); // set a new empty env // Refresh to create a new view box for the DummyString? (doesn't seem to work) m_rootb.PropChanged(m_rootObj.Hvo, kMainObjEnvironments, count - 1, 2, 1); // Set selection after the just added character or on the right side of the separator bar. SelLevInfo[] rgvsli = new SelLevInfo[1]; rgvsli[0].cpropPrevious = 0; rgvsli[0].tag = kMainObjEnvironments; rgvsli[0].ihvo = count - 1; m_rootb.MakeTextSelection(0, rgvsli.Length, rgvsli, tag, 0, ichAnchor, ichEnd, ws, fAssocPrev, -1, null, true); m_hvoOldSelection = hvoNew; CheckHeight(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Determines whether the given TsString can be pasted in the context of the target /// selection. An old DN-style embedded picture can only be pasted into paragraph /// contents. /// </summary> /// <param name="vwselTargetLocation">selection to be replaced by paste operation</param> /// <param name="tss">The TsString from the clipboard</param> /// <returns><c>true</c> if the given string does not contain any embedded strings or if /// the target location is a paragraph contents field.</returns> /// ------------------------------------------------------------------------------------ protected override bool ValidToReplaceSelWithTss(IVwSelection vwselTargetLocation, ITsString tss) { // REVIEW (EberhardB): Do we still support DN-style embedded pictures? //+ Begin fix for Raid bug 897B // Check for an embedded picture. int crun = tss.RunCount; bool fHasPicture = false; ITsTextProps ttp; for (int irun = 0; irun < crun; ++irun) { ttp = tss.get_Properties(irun); string str = ttp.GetStrPropValue((int)FwTextStringProp.kstpObjData); if (str != null) { char chType = str[0]; if (chType == (int)FwObjDataTypes.kodtPictOddHot || chType == (int)FwObjDataTypes.kodtPictEvenHot) { fHasPicture = true; break; } } } if (fHasPicture) { // Vars to call TextSelInfo and find out whether it is a structured // text field. ITsString tssDummy; int ich; bool fAssocPrev; int hvoObj; int tag; int wsTmp; vwselTargetLocation.TextSelInfo(false, out tssDummy, out ich, out fAssocPrev, out hvoObj, out tag, out wsTmp); if (tag != StTxtParaTags.kflidContents) { // TODO (EberhardB): This seems to be Notebook specific! MessageBox.Show(ResourceHelper.GetResourceString("kstidPicsMultiPara")); return false; } } //- End fix for Raid bug 897B return base.ValidToReplaceSelWithTss(vwselTargetLocation, tss); }
/// <summary> /// Answer true if the indicated selection is within a single note we can delete. Also obtain /// the object and property. /// </summary> private bool GetTagAndObjForOnePropSelection(IVwSelection sel, out int hvoObj, out int tagAnchor) { hvoObj = tagAnchor = 0; if (sel == null) return false; ITsString tss; int ichEnd, hvoEnd, tagEnd, wsEnd; bool fAssocPrev; sel.TextSelInfo(true, out tss, out ichEnd, out fAssocPrev, out hvoEnd, out tagEnd, out wsEnd); int ichAnchor, hvoAnchor, wsAnchor; sel.TextSelInfo(false, out tss, out ichAnchor, out fAssocPrev, out hvoAnchor, out tagAnchor, out wsAnchor); if (hvoEnd != hvoAnchor || tagEnd != tagAnchor || wsEnd != wsAnchor) return false; // must be a one-property selection hvoObj = hvoAnchor; return true; }
protected override void HandleSelectionChange(IVwRootBox prootb, IVwSelection vwselNew) { CheckDisposed(); ITsString tssTyped; int ich, hvo, tag, ws; bool fAssocPrev; vwselNew.TextSelInfo(false, out tssTyped, out ich, out fAssocPrev, out hvo, out tag, out ws); base.HandleSelectionChange(prootb, vwselNew); if (tssTyped.Length != 0) { // user typed something in the dummy slice! Make a real object. // Save information required for RestoreSelection. MakeRealObject may well dispose this. m_mediator.IdleQueue.Add(IdleQueuePriority.High, SwitchToRealOnIdle); } }