int m_wsUr; // Urdu writing system (used for Foreign style) #endregion #region Test setup /// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { m_inMemoryCache.InitializeWritingSystemEncodings(); // create footnote m_footnote = new StFootnote(); m_book = (ScrBook)m_scrInMemoryCache.AddBookToMockedScripture(1, "Genesis"); m_book.FootnotesOS.Append(m_footnote); m_footnote.FootnoteMarker.Text = "o"; m_footnote.DisplayFootnoteMarker = true; m_footnote.DisplayFootnoteReference = false; // create one empty footnote para StTxtPara para = new StTxtPara(); m_footnote.ParagraphsOS.Append(para); para.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalFootnoteParagraph); m_strFact = TsStrFactoryClass.Create(); m_vernWs = Cache.LangProject.DefaultVernacularWritingSystem; para.Contents.UnderlyingTsString = m_strFact.MakeString(string.Empty, m_vernWs); m_footnotePara = (StTxtPara)m_footnote.ParagraphsOS[0]; m_wsUr = InMemoryFdoCache.s_wsHvos.Ur; // used with 'foreign' character style m_wsDe = InMemoryFdoCache.s_wsHvos.De; // used for back translations m_wsEs = InMemoryFdoCache.s_wsHvos.Es; }
public void GetFootnoteMarkerFromGuid() { StFootnote footnote = new StFootnote(); m_scr.ScriptureBooksOS[0].FootnotesOS.Append(footnote); footnote.FootnoteMarker.Text = "a"; Guid guid = m_fdoCache.GetGuidFromId(footnote.Hvo); // Add the guid property so we can get it out as a string. ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); byte[] objData = MiscUtils.GetObjData(guid, 1); propsBldr.SetStrPropValueRgch(1, objData, objData.Length); // Get the guid property as a string. string sObjData; propsBldr.GetStrPropValue(1, out sObjData); using (StVc vc = new StVc()) { vc.Cache = m_fdoCache; vc.DefaultWs = m_fdoCache.LanguageWritingSystemFactoryAccessor.UserWs; ITsString footnoteMarker = vc.GetStrForGuid(sObjData.Substring(1)); Assert.AreEqual("2", footnoteMarker.Text); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Constructor for the FootnoteInfo structure /// </summary> /// <param name="stFootnote">given footnote</param> /// ------------------------------------------------------------------------------------ public FootnoteInfo(StFootnote stFootnote) { footnote = stFootnote; StPara para = (StPara)footnote.ParagraphsOS[0]; if (para.StyleRules != null) { paraStylename = para.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle); } else { paraStylename = null; Debug.Fail("StyleRules should never be null."); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add a back translation footnote ref ORC in the given translation for the given footnote /// </summary> /// <param name="trans">The given translation, usually a back translation</param> /// <param name="ichPos">The 0-based character offset into the translation string /// at which we will insert the reference ORC</param> /// <param name="ws">writing system of the ORC</param> /// <param name="footnote">The given footnote</param> /// ------------------------------------------------------------------------------------ public void AddFootnoteORCtoTrans(ICmTranslation trans, int ichPos, int ws, StFootnote footnote) { CheckDisposed(); // Insert a footnote reference ORC into the given translation string ITsStrBldr tsStrBldr = trans.Translation.GetAlternative(ws).UnderlyingTsString.GetBldr(); footnote.InsertRefORCIntoTrans(tsStrBldr, ichPos, ws); trans.Translation.SetAlternative(tsStrBldr.GetString(), ws); }
/// ------------------------------------------------------------------------------------ /// <summary> /// A helper method for book merger tests- /// Verifies the contents of the given sub-difference /// for a two-sided subDiff representing a text comparison. This overload does not /// check for the starting and ending references for sub-diffs that are created without /// that information. /// </summary> /// <param name="rootDiff">The root difference.</param> /// <param name="iSubDiff">The sub difference to verify.</param> /// <param name="subDiffType">Type of the sub difference.</param> /// <param name="footnoteCurr">The footnote curr.</param> /// <param name="ichMinCurr">The beginning character offset of the difference in the /// current.</param> /// <param name="ichLimCurr">The ending character offset of the difference in the /// current.</param> /// <param name="footnoteRev">The footnote rev.</param> /// <param name="ichMinRev">The beginning character offset of the difference in the /// revision.</param> /// <param name="ichLimRev">The ending character offset of the difference in the /// current.</param> /// <remarks>char styles are not verified here; test code should just check /// those directly if relevant</remarks> /// ------------------------------------------------------------------------------------ public static void VerifySubDiffFootnote(Difference rootDiff, int iSubDiff, DifferenceType subDiffType, StFootnote footnoteCurr, int ichMinCurr, int ichLimCurr, StFootnote footnoteRev, int ichMinRev, int ichLimRev) { Difference subDiff = rootDiff.SubDiffsForORCs[iSubDiff]; // the Current para stuff Assert.AreEqual((footnoteCurr != null) ? footnoteCurr.ParagraphsOS[0].Hvo : 0, subDiff.HvoCurr); Assert.AreEqual(ichMinCurr, subDiff.IchMinCurr); Assert.AreEqual(ichLimCurr, subDiff.IchLimCurr); // the Revision para stuff Assert.AreEqual((footnoteRev != null) ? footnoteRev.ParagraphsOS[0].Hvo : 0, subDiff.HvoRev); Assert.AreEqual(ichMinRev, subDiff.IchMinRev); Assert.AreEqual(ichLimRev, subDiff.IchLimRev); // section stuff should be null Assert.IsNull(subDiff.HvosSectionsRev); Assert.IsNull(subDiff.HvosSectionsCurr); // subDiffs may not have subDiffs, so far Assert.IsNull(subDiff.SubDiffsForORCs); Assert.IsNull(subDiff.SubDiffsForParas); Assert.AreEqual(subDiffType, subDiff.DiffType); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Constructor for the FootnoteInfo structure /// </summary> /// <param name="stFootnote">given footnote</param> /// <param name="sParaStylename">paragraph style of the footnote</param> /// ------------------------------------------------------------------------------------ public FootnoteInfo(StFootnote stFootnote, string sParaStylename) { footnote = stFootnote; paraStylename = sParaStylename; }
/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected override void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (m_isDisposed) return; if (disposing) { // Dispose managed resources here. } // Dispose unmanaged resources here, whether disposing is true or false. if (m_cpe != null && Marshal.IsComObject(m_cpe)) Marshal.ReleaseComObject(m_cpe); m_cpe = null; m_settings = null; m_SOWrapper = null; m_sSegmentText = null; m_sMarker = null; m_styleProxy = null; m_vernParaStyleProxy = null; m_vernTextProps = null; m_analTextProps = null; m_styleProxies = null; m_notesStyleProxies = null; m_lastPara = null; m_BookTitleParaProxy = null; m_DefaultFootnoteParaProxy = null; m_TsStringFactory = null; m_BTFootnoteStrBldr = null; m_CurrParaPictures = null; m_CurrParaFootnotes = null; m_BTPendingPictures = null; m_CurrBTFootnote = null; m_sBtFootnoteParaStyle = null; m_BtFootnoteStrBldrs = null; m_PendingAnnotations = null; m_BTfootnoteIndex = null; m_sCharStyleEndMarker = null; m_sFootnoteEndMarker = null; m_sCharStyleBeginMarker = null; m_sFootnoteBeginMarker = null; m_scrTranslatorAnnotationDef = null; base.Dispose(disposing); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create a mindless footnote (i.e., it's marker, paragraph style, etc. won't be set). /// </summary> /// <param name="book">Book to insert footnote into</param> /// <param name="para">Paragraph to insert footnote into</param> /// <param name="iFootnotePos">The 0-based index of the new footnote in the collection /// of footnotes owned by the book</param> /// <param name="ichPos">The 0-based character offset into the paragraph</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ protected StFootnote InsertTestFootnote(IScrBook book, IStTxtPara para, int iFootnotePos, int ichPos) { // Create the footnote StFootnote footnote = new StFootnote(); book.FootnotesOS.InsertAt(footnote, iFootnotePos); // Update the paragraph contents to include the footnote marker ITsStrBldr tsStrBldr = para.Contents.UnderlyingTsString.GetBldr(); footnote.InsertOwningORCIntoPara(tsStrBldr, ichPos, 0); // Don't care about ws para.Contents.UnderlyingTsString = tsStrBldr.GetString(); return footnote; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Scrolls the requested footnote to the top of the view /// </summary> /// <param name="footnote">The target footnote</param> /// <param name="fPutInsertionPtAtEnd">if set to <c>true</c> and showing the view, /// the insertion point will be put at the end of the footnote text instead of at the /// beginning, as would be appropriate in the case of a newly inserted footnote that has /// Reference Text. This parameter is ignored if footnote is null.</param> /// ------------------------------------------------------------------------------------ public void ScrollToFootnote(StFootnote footnote, bool fPutInsertionPtAtEnd) { CheckDisposed(); // find book owning this footnote int iBook = m_bookFilter.GetBookIndex(footnote.OwnerHVO); ScrBook book = new ScrBook(Cache, footnote.OwnerHVO); // find index of this footnote int iFootnote = footnote.IndexInOwner; // create selection pointing to this footnote FootnoteEditingHelper.ScrollToFootnote(iBook, iFootnote, (fPutInsertionPtAtEnd ? ((StTxtPara)footnote.ParagraphsOS[0]).Contents.Length: 0)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Process a back translation segment (duh) /// </summary> /// ------------------------------------------------------------------------------------ protected void ProcessBackTransSegment() { if (m_styleProxy.Function == FunctionValues.Chapter) { ProcessStartOfChapter(); return; } if (!m_settings.ImportBackTranslation) { if (m_styleProxy.Function == FunctionValues.Verse) m_currentRef.Verse = SOWrapper.SegmentFirstRef.Verse; return; } if (CurrentBook == null) { // An interleaved BT paragraph is being imported for a book that // doesn't exist. throw new ScriptureUtilsException(SUE_ErrorCode.BackTransMissingVernBook, null, null, ScrReference.NumberToBookCode(m_nBookNumber), null, null, true); } // Any non-end marker ends a character style if (m_context != ContextValues.EndMarker) EndCharStyle(); ITsTextProps ttpBtSeg; bool fThisSegmentEndsAFootnote = false; if (m_importDomain == ImportDomain.Main) { int wsBT = BackTransWS; ttpBtSeg = GetBTProps(wsBT); if (wsBT != m_wsCurrBtPara && (m_styleProxy.Domain != MarkerDomain.Default || m_styleProxy.StyleType == StyleType.kstParagraph)) { // We're about to change which WS is being processed, so end any open character // style and/or footnote. EndCharStyle(); if (m_fInFootnote) { EndFootnote(); fThisSegmentEndsAFootnote = (m_currDomain & MarkerDomain.Footnote) == 0; } m_wsCurrBtPara = wsBT; } else if (m_context == ContextValues.EndMarker) fThisSegmentEndsAFootnote = ProcessBTEndMarker(); else if (m_fInFootnote && (m_currDomain & MarkerDomain.Footnote) != 0 && m_styleProxy.StyleType == StyleType.kstParagraph) { EndFootnote(); fThisSegmentEndsAFootnote = (m_currDomain & MarkerDomain.Footnote) == 0; } } else { ttpBtSeg = GetBTProps(m_wsCurrBtPara); if (m_context == ContextValues.EndMarker) fThisSegmentEndsAFootnote = ProcessBTEndMarker(); } if (m_importDomain == ImportDomain.BackTrans && ProcessingParagraphStart) { if (m_fInFootnote) { EndFootnote(); fThisSegmentEndsAFootnote = (m_currDomain & MarkerDomain.Footnote) == 0; } AddBackTranslations(); } if (!m_fInScriptureText && m_styleProxy.Context == ContextValues.Text && m_styleProxy.Structure == StructureValues.Body) { // If this BT segment is a scripture body segment and we don't already have // a paragraph started, this file must have an implicit paragraph start, // so we initialize the member that holds the para style proxy for the // corresponding vernacular para so we'll have something reasonable to // look for when we go to find the corresponding para. if (m_BTStrBldrs.Count == 0 && m_importDomain == ImportDomain.BackTrans) m_vernParaStyleProxy = m_DefaultScrParaProxy; m_fInScriptureText = true; m_iNextBtPara = 0; } ITsStrBldr strbldr; if (m_BTStrBldrs.ContainsKey(m_wsCurrBtPara)) { // We continue to use the existing BT para builder (for this WS) until the // vernacular paragraph -- and hence any BT paragraph(s) -- get written. // This means that if the BT contains spurious paragraph markers, their // segments will just be appended to the one-and-only BT paragraph (for this // WS) already being built. // TODO: Generate an error annotation. Debug.Assert(m_wsCurrBtPara != 0); strbldr = m_BTStrBldrs[m_wsCurrBtPara]; } else { if (ProcessingParagraphStart) { if (m_importDomain == ImportDomain.Main) { if (m_vernParaStyleProxy == null || m_vernParaStyleProxy.StyleId == null) { // Got an unexpected BT paragraph segment. A BT paragraph came before // any vernacular paragraph in the import stream. int verse = SOWrapper.SegmentFirstRef.Verse; throw new ScriptureUtilsException(SUE_ErrorCode.BackTransMissingVernPara, SOWrapper.CurrentFileName, SOWrapper.CurrentLineNumber, m_sMarker + " " + m_sSegmentText, m_fFoundABook ? CurrentBook.BookId : null, m_foundAChapter ? m_nChapter.ToString() : null, (verse > 0) ? verse.ToString() : null, true); } if (m_vernParaStyleProxy.StyleId != m_styleProxy.StyleId && m_styleProxy.Style.Type != StyleType.kstCharacter) { // Got an unexpected BT paragraph segment. The paragraph style of the BT // paragraph doesn't match the style of the corresponding (i.e., // preceding) vernacular paragraph. int verse = SOWrapper.SegmentFirstRef.Verse; throw new ScriptureUtilsException(SUE_ErrorCode.BackTransStyleMismatch, m_sMarker + " " + m_sSegmentText, string.Format( TeResourceHelper.GetResourceString("kstidBTStyleMismatchDetails"), m_styleProxy.StyleId, m_vernParaStyleProxy.StyleId), m_fFoundABook ? CurrentBook.BookId : null, m_foundAChapter ? m_nChapter.ToString() : null, (verse > 0) ? verse.ToString() : null, true); } } // Non-interleaved BT else { ProcessBtParaStart(); } } strbldr = TsStrBldrClass.Create(); Debug.Assert(m_wsCurrBtPara != 0); m_BTStrBldrs[m_wsCurrBtPara] = strbldr; } if (m_context == ContextValues.Title) { SetBookName(); if (m_fInBookTitle) { // We have another segment to add to the current title AddBookTitleSegment(strbldr, m_vernParaStyleProxy, ttpBtSeg); return; } m_fInBookTitle = true; } AddPendingVerseAndChapterNumsToBackTrans(GetVerseRefAsString(m_wsCurrBtPara), m_wsCurrBtPara, strbldr); if ((m_currDomain & MarkerDomain.Footnote) != 0 && !fThisSegmentEndsAFootnote) { if (m_BTFootnoteStrBldr == null) { if (m_fInFootnote) { // This BT footnote ends the vernacular footnote being built EndFootnote(); } // remember that we are now processing a footnote SetInFootnote(); CheckDataForFootnoteMarker(); m_BTFootnoteStrBldr = TsStrBldrClass.Create(); m_sBtFootnoteParaStyle = (m_styleProxy.StyleType == StyleType.kstCharacter) ? m_DefaultFootnoteParaProxy.StyleId : m_styleProxy.StyleId; if (m_importDomain == ImportDomain.Main) { // If we aren't importing the vernacular... (TE-7445) if (!m_settings.ImportTranslation) { // attempt to find an existing vernacular paragraph that corresponds // to the back translation para. bool append; m_lastPara = FindCorrespondingVernParaForSegment(m_vernParaStyleProxy.Style, m_currentRef, out append); m_CurrParaFootnotes = (m_lastPara != null ? (m_lastPara as StTxtPara).GetFootnotes() : null); } m_CurrBTFootnote = FindCorrespondingFootnote(m_sBtFootnoteParaStyle); if (m_CurrBTFootnote == null) { int verse = SOWrapper.SegmentFirstRef.Verse; throw new ScriptureUtilsException(SUE_ErrorCode.BackTransMissingVernFootnote, SOWrapper.CurrentFileName, SOWrapper.CurrentLineNumber, m_sMarker + " " + m_sSegmentText, m_fFoundABook ? CurrentBook.BookId : null, m_foundAChapter ? m_nChapter.ToString(): null, (verse > 0) ? verse.ToString() : null, true); } } else { m_CurrBTFootnote = null; } } strbldr = m_BTFootnoteStrBldr; if (m_styleProxy.StyleType == StyleType.kstCharacter && m_styleProxy.Context != ContextValues.EndMarker) { SetInCharacterStyle(); } } else if (m_styleProxy.StyleType == StyleType.kstCharacter && m_styleProxy.Function != FunctionValues.Verse) { SetInCharacterStyle(); } // Add a line break between section head segments if we're processing // interleaved back translation section heading segments. if (m_fInSectionHeading && strbldr.Length > 0 && ProcessingParagraphStart && m_importDomain == ImportDomain.Main) { AddTextToPara(kHardLineBreak, ttpBtSeg, strbldr); } AddTextToPara(m_sSegmentText, ttpBtSeg, strbldr); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Deletes the given footnote and recalculates the footnote markers of following /// footnotes. (Note: this does not delete the footnote marker from the text.) /// </summary> /// <param name="footnote"></param> /// ------------------------------------------------------------------------------------ public static void DeleteFootnote(StFootnote footnote) { ScrBook book = new ScrBook(footnote.Cache, footnote.OwnerHVO); book.RemoveFootnote(footnote); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Setup the selection in footnote. /// </summary> /// <param name="footnote">The footnote.</param> /// <param name="book">The book.</param> /// <param name="iBook">The 0-based index of the book.</param> /// <param name="ichStart">The 0-based starting character index.</param> /// <param name="ichEnd">The 0-based ending character index.</param> /// ------------------------------------------------------------------------------------ public void SetupSelectionInFootnote(StFootnote footnote, IScrBook book, int iBook, int ichStart, int ichEnd) { CheckDisposed(); DynamicMock fakeSelHelper = new DynamicMock(typeof(SelectionHelper)); fakeSelHelper.SetupResult("NumberOfLevels", 3); // Setup the anchor SelLevInfo[] topInfo = new SelLevInfo[3]; StTxtPara para = (StTxtPara)footnote.ParagraphsOS[0]; topInfo[0].tag = (int)StText.StTextTags.kflidParagraphs; topInfo[0].ihvo = 0; // only one para per footnote allowed topInfo[0].hvo = para.Hvo; topInfo[1].tag = (int)ScrBook.ScrBookTags.kflidFootnotes; topInfo[1].ihvo = footnote.IndexInOwner; topInfo[1].hvo = footnote.Hvo; topInfo[2].tag = BookFilter.Tag; topInfo[2].ihvo = iBook; topInfo[2].hvo = book.Hvo; // Setup the end SelLevInfo[] bottomInfo = new SelLevInfo[3]; for(int i = 0; i < 3; i++) bottomInfo[i] = topInfo[i]; fakeSelHelper.SetupResult("LevelInfo", topInfo); fakeSelHelper.SetupResult("IchAnchor", ichStart); fakeSelHelper.SetupResult("IchEnd", ichEnd); fakeSelHelper.SetupResultForParams("GetLevelInfo", topInfo, SelectionHelper.SelLimitType.Top); fakeSelHelper.SetupResultForParams("GetLevelInfo", topInfo, SelectionHelper.SelLimitType.Anchor); fakeSelHelper.SetupResultForParams("GetLevelInfo", bottomInfo, SelectionHelper.SelLimitType.Bottom); fakeSelHelper.SetupResultForParams("GetLevelInfo", bottomInfo, SelectionHelper.SelLimitType.End); fakeSelHelper.SetupResultForParams("GetIch", ichStart, SelectionHelper.SelLimitType.Top); fakeSelHelper.SetupResultForParams("GetIch", ichEnd, SelectionHelper.SelLimitType.Bottom); m_viewSelection = (SelectionHelper)fakeSelHelper.MockInstance; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add a mindless footnote (i.e., it's marker, paragraph style, etc. won't be set) /// to a paragraph. /// </summary> /// <param name="footnoteSequence">Sequence of footnotes into which to insert</param> /// <param name="para">the paragraph into which to insert the footnote ORC</param> /// <param name="ichPos">the zero-based character offset at which to insert the footnote /// ORC into the paragraph</param> /// <param name="footnoteText">text for the footnote (no footnote paragraph created if /// null)</param> /// <returns>the new footnote</returns> /// ------------------------------------------------------------------------------------ public StFootnote AddFootnote(FdoOwningSequence<IStFootnote> footnoteSequence, IStTxtPara para, int ichPos, string footnoteText) { CheckDisposed(); // Create the footnote StFootnote footnote = new StFootnote(); footnoteSequence.Append(footnote); // Update the paragraph contents to include the footnote marker ORC ITsStrBldr tsStrBldr = para.Contents.UnderlyingTsString.GetBldr(); footnote.InsertOwningORCIntoPara(tsStrBldr, ichPos, m_fdoCache.DefaultVernWs); para.Contents.UnderlyingTsString = tsStrBldr.GetString(); if (footnoteText != null) { // Create the footnote paragraph with the given footnoteText StTxtParaBldr paraBldr = new StTxtParaBldr(m_fdoCache); paraBldr.ParaProps = StyleUtils.ParaStyleTextProps("Note General Paragraph"); paraBldr.AppendRun(footnoteText, StyleUtils.CharStyleTextProps(null, m_fdoCache.DefaultVernWs)); paraBldr.CreateParagraph(footnote.Hvo); } return footnote; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Show the footnote view. /// </summary> /// <param name="footnote">Footnote to scroll to or null to just display the footnote view</param> /// <param name="fPutInsertionPtAtEnd">if set to <c>true</c> and showing the view, /// the insertion point will be put at the end of the footnote text instead of at the /// beginning, as would be appropriate in the case of a newly inserted footnote that has /// Reference Text. This parameter is ignored if footnote is null.</param> /// ------------------------------------------------------------------------------------ internal override void ShowOrHideFootnoteView(StFootnote footnote, bool fPutInsertionPtAtEnd) { CheckDisposed(); bool fBtActivated = IsBtActivated; if (!FootnoteViewShowing) { base.ShowOrHideFootnoteView(footnote, fPutInsertionPtAtEnd); } else if (footnote != null) { FootnoteView footnoteView = (FootnoteView)GetControl(kFootnoteRow, fBtActivated ? kBackTransColumn : kDraftViewColumn); footnoteView.ScrollToFootnote(footnote, fPutInsertionPtAtEnd); } SetFocus(fBtActivated); }
/// ----------------------------------------------------------------------------------- /// <summary> /// This is the main interesting method of displaying objects and fragments of them. /// Here a text is displayed by displaying its paragraphs; /// and a paragraph is displayed by invoking its style rule, making a paragraph, /// and displaying its contents. /// </summary> /// <param name="vwenv">view environment</param> /// <param name="hvo">id of object to be displayed</param> /// <param name="frag">fragment of data</param> /// ----------------------------------------------------------------------------------- public override void Display(IVwEnv vwenv, int hvo, int frag) { CheckDisposed(); switch(frag) { case (int)StTextFrags.kfrFootnote: { if (HandleEmptyText(vwenv, hvo)) break; vwenv.AddObjVecItems((int)StText.StTextTags.kflidParagraphs, this, (int)StTextFrags.kfrFootnotePara); break; } case (int)StTextFrags.kfrText: { if (HandleEmptyText(vwenv, hvo)) break; if (m_fLazy) { vwenv.AddLazyVecItems((int)StText.StTextTags.kflidParagraphs, this, (int)StTextFrags.kfrPara); } else { vwenv.AddObjVecItems((int)StText.StTextTags.kflidParagraphs, this, (int)StTextFrags.kfrPara); } break; } case (int)StTextFrags.kfrFootnoteMarker: { StFootnote footnote = new StFootnote(Cache, hvo); if (footnote.DisplayFootnoteMarker) DisplayFootnoteMarker(vwenv); break; } case (int)StTextFrags.kfrLabel: { // The label is not editable. vwenv.set_IntProperty((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable); vwenv.AddString(m_tssLabel); break; } case (int)StTextFrags.kfrPara: case (int)StTextFrags.kfrFootnotePara: { InsertParagraphBody(vwenv, hvo, frag, true, ContentType, this); break; } case (int)StTextFrags.kfrTranslation: { vwenv.set_IntProperty((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, Editable ? (int)TptEditable.ktptIsEditable : (int)TptEditable.ktptNotEditable); // Display the translation, or its user prompt if (!InsertTranslationUserPrompt(vwenv, hvo)) { vwenv.AddStringAltMember((int)CmTranslation.CmTranslationTags.kflidTranslation, m_wsDefault, this); } break; } case (int)StTextFrags.kfrSegmentFreeTranslations: // Hvo is a CmBaseAnnotation of one segment of an StTxtPara. if (IsLabelSegment(hvo)) { CmBaseAnnotation segment = (CmBaseAnnotation)CmBaseAnnotation.CreateFromDBObject(Cache, hvo, false); vwenv.AddString(GetBackTransLabelText(segment)); vwenv.AddSimpleRect(ColorUtil.ConvertColorToBGR(this.BackColor), 1200, 0, 0); // a narrow space, font-neutral } else { vwenv.AddObjProp(StTxtPara.SegmentFreeTranslationFlid(Cache), this, (int)StTextFrags.kfrFreeTrans); vwenv.AddString(OneSpaceString); } break; case (int)StTextFrags.kfrFreeTrans: // Hvo is a CmIndirectAnnotation whose Contents are the free/back translation. vwenv.set_IntProperty((int)FwTextPropType.ktptBackColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(SystemColors.Window)); ITsString tssVal = vwenv.DataAccess.get_MultiStringAlt(hvo, (int) CmAnnotation.CmAnnotationTags.kflidComment, BackTranslationWS); if (tssVal.Length == 0 && !SuppressPrompt(hvo, (int)CmAnnotation.CmAnnotationTags.kflidComment)) { vwenv.NoteDependency(new int[] {hvo}, new int[] {(int)CmAnnotation.CmAnnotationTags.kflidComment}, 1); vwenv.AddProp(SimpleRootSite.kTagUserPrompt, this, (int)CmAnnotation.CmAnnotationTags.kflidComment); // Almost invisibly narrow, but the Views code doesn't know it is invisible so it should prevent the prompts collapsing // into the margin. vwenv.AddSimpleRect(ColorUtil.ConvertColorToBGR(this.BackColor), 100, 0, 0); } else { ITsStrBldr bldr = tssVal.GetBldr(); bldr.Replace(0, bldr.Length, "", null); // reduce to empty string in ws. // We want it to change back to the prompt if all is deleted. vwenv.NoteStringValDependency(hvo, (int) CmAnnotation.CmAnnotationTags.kflidComment, BackTranslationWS, bldr.GetString()); vwenv.AddStringAltMember((int)CmAnnotation.CmAnnotationTags.kflidComment, BackTranslationWS, this); // This little separator is useful here, too. Temporarily the comment may be displayed this way even when empty, // and if there is ordinary text following, it is difficult to get an IP displayed in an empty run. vwenv.AddSimpleRect(ColorUtil.ConvertColorToBGR(this.BackColor), 100, 0, 0); } break; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Show (or hide) the footnote view. /// </summary> /// <param name="footnote">Footnote to scroll to or <c>null</c> to just display or hide /// the footnote view. If a footnote is given the footnote view will always be shown. /// </param> /// <param name="fPutInsertionPtAtEnd">if set to <c>true</c> and showing the view, /// the insertion point will be put at the end of the footnote text instead of at the /// beginning, as would be appropriate in the case of a newly inserted footnote that has /// Reference Text. This parameter is ignored if footnote is null.</param> /// ------------------------------------------------------------------------------------ internal override void ShowOrHideFootnoteView(StFootnote footnote, bool fPutInsertionPtAtEnd) { CheckDisposed(); //toggle bool fShow = !m_grid.Rows[kFootnoteRow].Visible || footnote != null; base.ShowOrHideFootnoteView(footnote, fPutInsertionPtAtEnd); if (fShow) { // We don't want to show both draft view rows together with the footnotes m_fBothDraftViewsShowing = (m_grid.Rows[kUpperDraftRow].Visible && m_grid.Rows[kLowerDraftRow].Visible); // Determine which of the draft view to collapse (if both are open) if (m_fBothDraftViewsShowing) { if (FocusedRootSite == GetControl(kUpperDraftRow, kDraftViewColumn)) m_grid.Rows[kLowerDraftRow].Visible = false; else m_grid.Rows[kUpperDraftRow].Visible = false; } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates the ScrFootnote in the given owning ScrBook. /// The caller must take care of inserting the proper ORC and the footnote's paragraph. /// </summary> /// <param name="book">The book that the footnote is being added to</param> /// <param name="iInsertAt">Zero-based index of the position in the book's sequence of /// footnotes where the new footnote is to be inserted</param> /// <param name="sMarker">ref: The marker to use (more or less)</param> /// <param name="cache">The cache.</param> /// <param name="ws">The writing system for the footnote marker.</param> /// <returns>The newly created Footnote object</returns> /// ------------------------------------------------------------------------------------ private static ScrFootnote CreateScrFootnote(IScrBook book, int iInsertAt, ref string sMarker, FdoCache cache, int ws) { // Create StFootnote object and establish it in the database StFootnote foot = new StFootnote(); book.FootnotesOS.InsertAt(foot, iInsertAt); // Construct a ScrFootnote so that its internal variables will get set correctly ScrFootnote footnote = new ScrFootnote(cache, foot.Hvo); // Create a default FootnoteMarker property in the StFootnote with // the correct text properties ITsTextProps markerProps = StyleUtils.CharStyleTextProps(ScrStyleNames.FootnoteMarker, ws); ITsStrBldr tsStrBldrFootnoteMkr = TsStrBldrClass.Create(); // Mark the footnote marker style as being in use. IScripture scr = cache.LangProject.TranslatedScriptureOA; IStStyle markerStyle = scr.FindStyle(ScrStyleNames.FootnoteMarker); markerStyle.InUse = true; if (sMarker == null) sMarker = string.Empty; tsStrBldrFootnoteMkr.Replace(0, 0, sMarker, markerProps); footnote.FootnoteMarker = tsStrBldrFootnoteMkr.GetString(); // Copy current value of default footnote options to the new footnote. footnote.DisplayFootnoteReference = scr.DisplayFootnoteReference; footnote.DisplayFootnoteMarker = scr.DisplayFootnoteMarker; return footnote; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add a back translation footnote in the given translation for the given footnote. /// Inserts a ref ORC in the translation and sets the the BT text in the footnote. /// </summary> /// <param name="trans">The given back translation of an StTxtPara</param> /// <param name="ichPos">The 0-based character offset into the back translation string /// at which we will insert the reference ORC</param> /// <param name="ws">writing system of the BT and ORC</param> /// <param name="footnote">The given footnote</param> /// <param name="footnoteBtText">text for the back translation of the footnote</param> /// <returns>the back translation of the given footnote</returns> /// ------------------------------------------------------------------------------------ public ICmTranslation AddFootnoteORCtoTrans(ICmTranslation trans, int ichPos, int ws, StFootnote footnote, string footnoteBtText) // TODO: rename this method to AddBtFootnote(), so it reads similar to AddFootnote() in tests { CheckDisposed(); AddFootnoteORCtoTrans(trans, ichPos, ws, footnote); // Add the given footnote BT text to the footnote. IStTxtPara para = (IStTxtPara)footnote.ParagraphsOS[0]; ICmTranslation footnoteTrans = para.GetOrCreateBT(); ITsStrBldr tssFootnoteBldr = footnoteTrans.Translation.GetAlternative(ws).UnderlyingTsString.GetBldr(); tssFootnoteBldr.ReplaceRgch(0, 0, footnoteBtText, footnoteBtText.Length, StyleUtils.CharStyleTextProps(null, ws)); footnoteTrans.Translation.SetAlternative(tssFootnoteBldr.GetString(), ws); return footnoteTrans; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates a book with two footnotes. /// </summary> /// <param name="philemon">The book of philemon that will have one paragraph with two /// footnotes.</param> /// <param name="footnote1">first footnote to be inserted at character index 1</param> /// <param name="footnote2">second footnote to be inserted at character index 10</param> /// ------------------------------------------------------------------------------------ private void CreateBookWithTwoFootnotes(out IScrBook philemon, out StFootnote footnote1, out StFootnote footnote2) { philemon = m_scrInMemoryCache.AddBookToMockedScripture(57, "Philemon"); IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(philemon.Hvo); StTxtPara para = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(para, "this is more text", null); footnote1 = m_scrInMemoryCache.AddFootnote(philemon, para, 1); StTxtPara footnotePara = new StTxtPara(); footnote1.ParagraphsOS.Append(footnotePara); footnotePara.Contents.Text = "This is my first footnote"; footnote2 = m_scrInMemoryCache.AddFootnote(philemon, para, 10); footnotePara = new StTxtPara(); footnote2.ParagraphsOS.Append(footnotePara); footnotePara.Contents.Text = "This is my second footnote"; }
public void ApplyParaStyle() { CheckDisposed(); m_footnoteView.EditingHelper.ApplyStyle(ScrStyleNames.NormalFootnoteParagraph); int tag; int hvoSimple; bool fGotIt = m_footnoteView.GetSelectedFootnote(out tag, out hvoSimple); Assert.IsTrue(fGotIt); Assert.AreEqual((int)StText.StTextTags.kflidParagraphs, tag); StFootnote footnote = new StFootnote(Cache, hvoSimple); StTxtPara para = (StTxtPara)footnote.ParagraphsOS[0]; Assert.AreEqual(ScrStyleNames.NormalFootnoteParagraph, para.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Apply style to selection /// </summary> /// ------------------------------------------------------------------------------------ public override void ApplyStyle(string sStyleToApply) { CheckDisposed(); // Make sure that the Chapter Number style is not applied to non-numeric data if (sStyleToApply == ScrStyleNames.ChapterNumber && CurrentSelection != null) { ITsString tssSelected; CurrentSelection.Selection.GetSelectionString(out tssSelected, string.Empty); if (tssSelected.Text != null) { foreach (char ch in tssSelected.Text) { if (!Char.IsDigit(ch)) { MiscUtils.ErrorBeep(); return; } } } } base.ApplyStyle(sStyleToApply); // Update the footnote markers if we changed the style of a footnote if ((sStyleToApply == ScrStyleNames.CrossRefFootnoteParagraph || sStyleToApply == ScrStyleNames.NormalFootnoteParagraph) && ParagraphHvo > 0) { // Save the selection SelectionHelper prevSelection = CurrentSelection; if (m_cache.MarkerIndexCache != null) m_cache.MarkerIndexCache.ClearCache(); StTxtPara para = new StTxtPara(m_cache, ParagraphHvo); Debug.Assert(m_cache.GetClassOfObject(para.OwnerHVO) == StFootnote.kClassId); StFootnote footnote = new StFootnote(m_cache, para.OwnerHVO); ScrBook book = new ScrBook(m_cache, footnote.OwnerHVO); m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, book.Hvo, (int)ScrBook.ScrBookTags.kflidFootnotes, 0, book.FootnotesOS.Count, book.FootnotesOS.Count); // restore the selection prevSelection.SetSelection(true); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets a List of all footnotes "owned" by this paragraph. /// </summary> /// ------------------------------------------------------------------------------------ public List<FootnoteInfo> GetFootnotes() { ITsString contents = Contents.UnderlyingTsString; List<FootnoteInfo> footnotes = new List<FootnoteInfo>(); for (int iRun = 0; iRun < contents.RunCount; iRun++) { Guid guidOfObj = StringUtils.GetGuidFromRun(contents, iRun, FwObjDataTypes.kodtOwnNameGuidHot); if (guidOfObj != Guid.Empty) { try { int hvo = m_cache.GetIdFromGuid(guidOfObj); if (hvo > 0) { StFootnote footnote = new StFootnote(m_cache, hvo); footnotes.Add(new FootnoteInfo(footnote)); } } catch { } } } return footnotes; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Finalize the BT of the footnote, if any. /// </summary> /// ------------------------------------------------------------------------------------ protected void EndBTFootnote() { Debug.Assert(m_fInFootnote); Debug.Assert(m_BTFootnoteStrBldr != null); ITsStrBldr strbldr = m_BTStrBldrs[m_wsCurrBtPara]; // No need to assert, since the dictionary will // throw an exception if the key is not present. //Debug.Assert(strbldr != null); TrimTrailingSpace(m_BTFootnoteStrBldr); // If the last character in the paragraph is a separator, then insert the footnote // marker before it. (see TE-2431) int ichMarker = strbldr.Length; if (ichMarker > 0) { string s = strbldr.GetChars(ichMarker - 1, ichMarker); if (UnicodeCharProps.get_IsSeparator(s[0])) ichMarker--; } if (m_CurrBTFootnote != null) { // Don't support importing multi-para footnotes StTxtPara para = (StTxtPara)m_CurrBTFootnote.ParagraphsOS[0]; ICmTranslation transl = para.GetOrCreateBT(); transl.Translation.GetAlternative(m_wsCurrBtPara).UnderlyingTsString = (m_BTFootnoteStrBldr.Length == 0) ? m_TsStringFactory.MakeString(string.Empty, m_wsCurrBtPara) : m_BTFootnoteStrBldr.GetString(); m_CurrBTFootnote.InsertRefORCIntoTrans(strbldr, ichMarker, m_wsCurrBtPara); m_CurrBTFootnote = null; } else { m_BtFootnoteStrBldrs.Add(new BtFootnoteBldrInfo(m_wsCurrBtPara, m_BTFootnoteStrBldr, m_sBtFootnoteParaStyle, ichMarker, m_currentRef)); } m_fInFootnote = false; m_BTFootnoteStrBldr = null; //m_BtFootnoteStrBldrs.Clear(); //m_currDomain = MarkerDomain.Default; // TODO: Do like EndFootnote if ((m_styleProxy.Domain & MarkerDomain.Footnote) == 0) m_currDomain &= ~MarkerDomain.Footnote; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the displayed text for a footnote. /// </summary> /// <param name="iBook">Index of the book the footnote is in</param> /// <param name="iFootnote">Index of the footnote</param> /// <param name="footnote">The footnote object</param> /// <returns>The TsString representing the text of the footnote, including any displayed /// marker, reference, etc.</returns> /// ------------------------------------------------------------------------------------ public ITsString GetDisplayedTextForFootnote(int iBook, int iFootnote, StFootnote footnote) { SelectionHelper helper = new SelectionHelper(); // Create selection in footnote marker SelLevInfo[] anchorLevInfo = new SelLevInfo[4]; anchorLevInfo[3].tag = BookFilter.Tag; anchorLevInfo[3].ihvo = iBook; anchorLevInfo[2].tag = (int)ScrBook.ScrBookTags.kflidFootnotes; anchorLevInfo[2].ihvo = iFootnote; anchorLevInfo[1].tag = (int)StText.StTextTags.kflidParagraphs; anchorLevInfo[1].ihvo = 0; anchorLevInfo[0].tag = -1; anchorLevInfo[0].ihvo = 0; helper.SetLevelInfo(SelectionHelper.SelLimitType.Anchor, anchorLevInfo); helper.SetTextPropId(SelectionHelper.SelLimitType.Anchor, (int)VwSpecialAttrTags.ktagGapInAttrs); helper.IchAnchor = 0; SelLevInfo[] endLevInfo = new SelLevInfo[3]; endLevInfo[2].tag = BookFilter.Tag; endLevInfo[2].ihvo = iBook; endLevInfo[1].tag = (int)ScrBook.ScrBookTags.kflidFootnotes; endLevInfo[1].ihvo = iFootnote; endLevInfo[0].tag = (int)StText.StTextTags.kflidParagraphs; endLevInfo[0].ihvo = 0; helper.SetLevelInfo(SelectionHelper.SelLimitType.End, endLevInfo); helper.SetTextPropId(SelectionHelper.SelLimitType.End, (int)StTxtPara.StTxtParaTags.kflidContents); string footnoteText = ((StTxtPara)footnote.ParagraphsOS[0]).Contents.Text; helper.IchEnd = footnoteText.Length; helper.SetSelection(this, true, true); IVwSelection sel = RootBox.Selection; ITsString tss; sel.GetSelectionString(out tss, string.Empty); return tss; }
/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected virtual void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (m_isDisposed) return; if (disposing) { // Dispose managed resources here. if (m_ParaBldr != null) m_ParaBldr.Dispose(); } // Dispose unmanaged resources here, whether disposing is true or false. m_ParaBldr = null; m_cache = null; m_styleSheet = null; m_scr = null; m_undoManager = null; m_importCallbacks = null; m_ScrSectionHeadParaProxy = null; m_DefaultIntroSectionHeadParaProxy = null; m_DefaultScrParaProxy = null; m_DefaultIntroParaProxy = null; m_BTStrBldrs = null; m_SavedParaBldr = null; m_CurrFootnote = null; m_ttpChapterNumber = null; m_sPrevBook = null; m_scrBook = null; m_currSection = null; m_isDisposed = true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create a footnote reference marker (ref orc) /// </summary> /// <param name="footnote">given footnote</param> /// <param name="para">paragraph owning the translation to insert footnote marker into</param> /// <param name="ws">given writing system for the back translation</param> /// <param name="ichPos">The 0-based character offset into the translation</param> /// ------------------------------------------------------------------------------------ protected void InsertTestBtFootnote(StFootnote footnote, StTxtPara para, int ws, int ichPos) { ICmTranslation trans = para.GetOrCreateBT(); ITsStrBldr bldr = trans.Translation.GetAlternative(ws).UnderlyingTsString.GetBldr(); footnote.InsertRefORCIntoTrans(bldr, ichPos, ws); trans.Translation.SetAlternative(bldr.GetString(), ws); }
/// ------------------------------------------------------------------------------------ /// <summary> /// A helper method for book merger tests- /// Verifies the contents of the given difference /// for a one-sided subDiff representing a footnote in the Revision. /// </summary> /// ------------------------------------------------------------------------------------ public static void VerifySubDiffFootnoteRev(Difference rootDiff, int iSubDiff, StFootnote footnoteRev) { Difference subDiff = rootDiff.SubDiffsForORCs[iSubDiff]; // verify the basics Assert.AreEqual(0, subDiff.RefStart); Assert.AreEqual(0, subDiff.RefEnd); Assert.AreEqual(DifferenceType.NoDifference, subDiff.DiffType); // the Current para stuff Assert.AreEqual(0, subDiff.HvoCurr); Assert.AreEqual(0, subDiff.IchMinCurr); Assert.AreEqual(0, subDiff.IchLimCurr); // the Revision para stuff Assert.AreEqual(((StTxtPara)footnoteRev.ParagraphsOS[0]).Hvo, subDiff.HvoRev); Assert.AreEqual(0, subDiff.IchMinRev); Assert.AreEqual(((StTxtPara)footnoteRev.ParagraphsOS[0]).Contents.Length, subDiff.IchLimRev); // style names should be null Assert.IsNull(subDiff.StyleNameCurr); Assert.IsNull(subDiff.StyleNameRev); // section stuff should be null Assert.IsNull(subDiff.HvosSectionsRev); Assert.IsNull(subDiff.HvosSectionsCurr); // subDiffs may not have subDiffs, so far Assert.IsNull(subDiff.SubDiffsForORCs); //check the root difference for consistency with this subDiff Assert.IsTrue(rootDiff.DiffType == DifferenceType.TextDifference || rootDiff.DiffType == DifferenceType.FootnoteMissingInCurrent); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Scrolls a footnote paragraph into view. /// </summary> /// <param name="diff">The sub-diff, which contains the id of the paragraph in the /// footnote which is to be scrolled into view. Or null if no footnote is specified.</param> /// ------------------------------------------------------------------------------------ public void ScrollToFootnotePara(Difference diff) { CheckDisposed(); // TODO: TE-4610 temporary? ignore scrolling when no footnote in this diff //Debug.Assert(diff != null); if (diff == null) return; // Get the paragraph which contains the difference. StTxtPara para = new StTxtPara(Cache, diff.HvoCurr != 0 ? diff.HvoCurr : diff.HvoRev); // Get the footnote which contains the paragraph. StFootnote footnote = new StFootnote(Cache, para.OwnerHVO); // Find the index of the paragraph. int iPara = para.IndexInOwner; if (iPara < 0) return; // Find index of the footnote. int iFootnote = footnote.IndexInOwner; if (iFootnote < 0) return; // Create selection pointing to this footnote. SelectionHelper selHelper = new SelectionHelper(); selHelper.AssocPrev = false; selHelper.NumberOfLevels = 2; selHelper.LevelInfo[0].tag = (int)StText.StTextTags.kflidParagraphs; selHelper.LevelInfo[0].ihvo = iPara; selHelper.LevelInfo[1].tag = (int)ScrBook.ScrBookTags.kflidFootnotes; selHelper.LevelInfo[1].ihvo = iFootnote; // note: We don't care about seting the ich stuff for this temporary selection. // (The view constructor takes care of highlighting the proper ich range.) // Our mission here is only to scroll to the paragraph. selHelper.IchAnchor = 0; selHelper.IchEnd = 0; // Set the selection. selHelper.SetSelection(this, true, true); ScrollSelectionIntoView(null, VwScrollSelOpts.kssoNearTop); }
/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected override void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (IsDisposed) return; if (disposing) { // Dispose managed resources here. } // Dispose unmanaged resources here, whether disposing is true or false. m_footnote = null;; m_book = null; if (m_strFact != null) Marshal.ReleaseComObject(m_strFact); m_strFact = null;; base.Dispose(disposing); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Starts recalculation of footnotes for a book at the given footnote. /// </summary> /// <param name="footnote">footnote to where recalculation starts</param> /// ------------------------------------------------------------------------------------ public static void RecalculateFootnoteMarkers(StFootnote footnote) { int index = footnote.IndexInOwner; Debug.Assert(index >= 0); RecalculateFootnoteMarkers(new ScrBook(footnote.Cache, footnote.OwnerHVO), index); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Compares the given footnote with the values in m_footnote. /// </summary> /// <param name="footnote">The footnote to compare</param> /// ------------------------------------------------------------------------------------ private void CompareFootnote(StFootnote footnote) { Assert.AreEqual(m_footnote.DisplayFootnoteMarker, footnote.DisplayFootnoteMarker, "Display footnote marker values did not match"); Assert.AreEqual(m_footnote.DisplayFootnoteReference, footnote.DisplayFootnoteReference, "Display footnote reference values did not match"); Assert.AreEqual(m_footnote.FootnoteMarker.Text, footnote.FootnoteMarker.Text); Assert.AreEqual(m_footnote.ParagraphsOS.Count, footnote.ParagraphsOS.Count, "Footnote paragraph count did not match"); string diff = string.Empty; for (int i = 0; i < m_footnote.ParagraphsOS.Count; i++) { StTxtPara expectedPara = (StTxtPara)m_footnote.ParagraphsOS[i]; StTxtPara actualPara = (StTxtPara)footnote.ParagraphsOS[i]; bool result = TsTextPropsHelper.PropsAreEqual(expectedPara.StyleRules, actualPara.StyleRules, out diff); Assert.IsTrue(result, "paragraph " + i + " stylerules differed in: " + diff); result = TsStringHelper.TsStringsAreEqual(expectedPara.Contents.UnderlyingTsString, actualPara.Contents.UnderlyingTsString, out diff); Assert.IsTrue(result, "paragraph " + i + " differed in: " + diff); CompareFootnoteTrans((CmTranslation)expectedPara.GetBT(), (CmTranslation)actualPara.GetBT(), actualPara.Hvo); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates a new StFootnote owned by the given book created from the given string /// representation (Created from GetTextRepresentation()) /// </summary> /// <param name="owner">The object that owns the sequence of footnotes into which the /// new footnote is to be inserted</param> /// <param name="flid">The field id of the property in which the footnotes are owned /// </param> /// <param name="sTextRepOfFootnote">The given string representation of a footnote /// </param> /// <param name="footnoteIndex">0-based index where the footnote will be inserted</param> /// <param name="footnoteMarkerStyleName">style name for footnote markers</param> /// <returns>An StFootnote with the properties set to the properties in the /// given string representation</returns> /// ------------------------------------------------------------------------------------ public static StFootnote CreateFromStringRep(CmObject owner, int flid, string sTextRepOfFootnote, int footnoteIndex, string footnoteMarkerStyleName) { StFootnote createdFootnote = new StFootnote(owner, flid, footnoteIndex); // create an XML reader to read in the string representation System.IO.StringReader reader = new System.IO.StringReader(sTextRepOfFootnote); XmlDocument doc = new XmlDocument(); try { doc.Load(reader); } catch (XmlException) { throw new ArgumentException("Unrecognized XML format for footnote."); } XmlNodeList tagList = doc.SelectNodes("FN"); foreach (XmlNode bla in tagList[0].ChildNodes) { // Footnote marker if (bla.Name == "M") { ITsPropsBldr propBlr = TsPropsBldrClass.Create(); propBlr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, footnoteMarkerStyleName); ITsStrBldr tss = TsStrBldrClass.Create(); tss.Replace(0, 0, bla.InnerText, propBlr.GetTextProps()); createdFootnote.FootnoteMarker.UnderlyingTsString = tss.GetString(); } // Display footnote marker else if (bla.Name == "ShowMarker") { createdFootnote.DisplayFootnoteMarker = true; } // display footnote scripture reference else if (bla.Name == "ShowReference") { createdFootnote.DisplayFootnoteReference = true; } // start of a paragraph else if (bla.Name == "P") { StTxtPara newPara = new StTxtPara(); createdFootnote.ParagraphsOS.Append(newPara); ITsIncStrBldr paraBldr = TsIncStrBldrClass.Create(); CmTranslation trans = null; //ITsStrBldr paraBldr = TsStrBldrClass.Create(); foreach (XmlNode paraTextNode in bla.ChildNodes) { if (paraTextNode.Name == "PS") { // paragraph style ITsPropsBldr propBldr = TsPropsBldrClass.Create(); if (!String.IsNullOrEmpty(paraTextNode.InnerText)) { propBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, paraTextNode.InnerText); } else { Debug.Fail("Attempting to create a footnote paragraph with no paragraph style specified!"); } newPara.StyleRules = propBldr.GetTextProps(); } else if (paraTextNode.Name == "RUN") { CreateRunFromStringRep(owner, paraBldr, paraTextNode); paraBldr.Append(paraTextNode.InnerText); } else if (paraTextNode.Name == "TRANS") { if (trans == null) { trans = (CmTranslation)newPara.GetOrCreateBT(); } // Determine which writing system where the string run(s) will be added. string iculocale = paraTextNode.Attributes.GetNamedItem("WS").Value; if (iculocale == null || iculocale == string.Empty) { throw new ArgumentException( "Unknown ICU locale encountered: " + iculocale); } int transWS = owner.Cache.LanguageEncodings.GetWsFromIcuLocale(iculocale); Debug.Assert(transWS != 0, "Unable to find ws from ICU Locale"); // Build a TsString from the run(s) description. ITsIncStrBldr strBldr = TsIncStrBldrClass.Create(); foreach (XmlNode transTextNode in paraTextNode.ChildNodes) { if (transTextNode.Name != "RUN") { throw new ArgumentException("Unexpected translation element '" + transTextNode.Name + "' encountered for ws '" + iculocale + "'"); } CreateRunFromStringRep(owner, strBldr, transTextNode); strBldr.Append(transTextNode.InnerText); } trans.Translation.SetAlternative(strBldr.GetString(), transWS); } } newPara.Contents.UnderlyingTsString = paraBldr.GetString(); } } owner.Cache.PropChanged(null, PropChangeType.kpctNotifyAll, owner.Hvo, flid, footnoteIndex, 1, 0); return(createdFootnote); }