/// ------------------------------------------------------------------------------------ /// <summary> /// Performs the delegated action if the given selection is for a footnote anchor icon. /// ENHANCE: This code currently assumes that any iconic representation of an ORC is /// for a footnote anchor. When we support showing picture anchors (or anything else) /// iconically, this will have to be changed to account for that. /// </summary> /// ------------------------------------------------------------------------------------ protected static void HandleFootnoteAnchorIconSelected(IVwSelection sel, FootnoteAnchorFoundDelegate action) { if (sel == null) throw new ArgumentNullException("sel"); if (action == null) throw new ArgumentNullException("action"); if (sel.SelType == VwSelType.kstPicture) { // See if this is a ORC-replacement picture, in which case we treat it // as a clickable object rather than a picture. int ichAnchor = sel.get_ParagraphOffset(false); int ichEnd = sel.get_ParagraphOffset(true); if (ichAnchor >= 0 && ichAnchor < ichEnd) { SelectionHelper selHelperOrc = SelectionHelper.Create(sel, sel.RootBox.Site); SelLevInfo info; bool found = false; switch (selHelperOrc.TextPropId) { case StTxtParaTags.kflidContents: found = selHelperOrc.GetLevelInfoForTag(StTextTags.kflidParagraphs, out info); break; case CmTranslationTags.kflidTranslation: found = (selHelperOrc.GetLevelInfoForTag(-1, out info) && selHelperOrc.Ws > 0); break; case SegmentTags.kflidFreeTranslation: if (selHelperOrc.GetLevelInfoForTag(StTxtParaTags.kflidSegments, out info) && selHelperOrc.Ws > 0) { // adjust anchor offset to be a segment offset - need to subtract off the beginning offset // for the segment. SelectionHelper selHelperStartOfSeg = new SelectionHelper(selHelperOrc); selHelperStartOfSeg.IchAnchor = selHelperStartOfSeg.IchEnd = 0; IVwSelection selSegStart = selHelperStartOfSeg.SetSelection(selHelperOrc.RootSite, false, false); ichAnchor -= selSegStart.get_ParagraphOffset(false); found = true; } break; default: // Ignore everything else because it doesn't have footnotes. return; } if (found) action(info.hvo, selHelperOrc.TextPropId, selHelperOrc.Ws, ichAnchor); } } }