Exemplo n.º 1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Write all the paragraphs in the given footnote.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void ExportFootnote(ScrFootnote scrFootnote)
		{
			m_fInFootnote = true;
			// TE allows only one paragraph in a footnote!
			Debug.Assert(scrFootnote.ParagraphsOS.Count < 2);
			foreach (IStTxtPara para in scrFootnote.ParagraphsOS)
				ExportParagraph(para, null, false);
			m_fInFootnote = false;
		}
Exemplo n.º 2
0
		// this code was added back when we were trying to display some special UI for editing
		// verse numbers, rather than allowing normal editing.
		///// ------------------------------------------------------------------------------------
		///// <summary>
		///// Changes the mouse cursor if we are over a verse number
		///// </summary>
		///// <param name="sel">The selection</param>
		///// <returns>True if we set a cursor, false otherwise</returns>
		///// ------------------------------------------------------------------------------------
		//protected override bool SetCustomCursor(IVwSelection sel)
		//{
		//    if (Callbacks.EditedRootBox == null)
		//        return false;
		//    SelectionHelper helper = SelectionHelper.Create(sel, Callbacks.EditedRootBox.Site);
		//    if (helper == null || helper.SelProps == null)
		//        return false;
		//    string styleName =
		//        helper.SelProps.GetStrPropValue((int)FwTextPropType.ktptNamedStyle);
		//    if (styleName == ScrStyleNames.VerseNumber)
		//    {
		//        Control.Cursor = Cursors.Arrow;
		//        return true;
		//    }
		//    return false;
		//}

		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// This method is used to get a notification when an owning object-replacement character
		/// (ORC) is deleted. ORCs are used to mark locations in the text of things like pictures
		/// or footnotes. In the case of footnotes, when an owning footnote ORC is deleted, we
		/// need to find the corresponding footnote and delete it.
		/// </summary>
		/// <param name="guid">The GUID of the footnote being deleted.</param>
		/// ------------------------------------------------------------------------------------
		public override void ObjDeleted(ref Guid guid)
		{
			CheckDisposed();

			if (PreventObjDeletions)
				return;

			// This is a check to avoid fallout from a time when we incorrectly imported BT
			// footnote ORCs as owning.
			if (IsBackTranslation)
				return;

			int footnoteHvo = m_cache.GetIdFromGuid(guid);
			if (footnoteHvo == 0)
				return;

			int clsid = m_cache.GetClassOfObject(footnoteHvo);
			if (clsid == 0)
				return;

			// Delete the footnote.
			if (clsid == StFootnote.kClassId)
			{
				using (new WaitCursor(Control))
				{
					ScrFootnote footnote = new ScrFootnote(m_cache, footnoteHvo);
					int paraHvo = footnote.ContainingParagraphHvo;
					// If there's no (vernacular) paragraph with an ORC that references this footnote,
					// there can't be a translation either.
					if (paraHvo > 0)
					{
						StTxtPara para = new StTxtPara(m_cache, paraHvo);
						para.DeleteAnyBtMarkersForFootnote(guid);
					}
					ScrFootnote.DeleteFootnote(footnote);
				}
			}
		}
Exemplo n.º 3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Delete all footnotes between firstFootnoteToDelete and lastFootnoteToDelete. Clean
		/// up BT ORCs for the paragraphs specified.
		/// </summary>
		/// <param name="book">Book that contains the sections to delete</param>
		/// <param name="firstFootnoteToDelete">First footnote that will be deleted
		/// (might be null).</param>
		/// <param name="lastFootnoteToDelete">Last footnote that will be deleted
		/// (might be null).</param>
		/// <param name="hvoFirstPara">First (possibly partial) paragraph being deleted that
		/// might contain ORCs for the first footnotes. Any footnotes being deleted whose ORCs
		/// are in this paragraph will have their corresponding BT ORCs removed as well.
		/// If zero, we don't bother to remove any corresponding BT ORCs in the first para.</param>
		/// <param name="hvoLastPara">Last (possibly partial) paragraph being deleted that
		/// might contain ORCs for the last footnotes. Any footnotes being deleted whose ORCs
		/// are in this paragraph will have their corresponding BT ORCs removed as well.
		/// If zero, we don't bother to remove any corresponding BT ORCs in the last para.</param>
		/// ------------------------------------------------------------------------------------
		private void DeleteFootnotes(IScrBook book, ScrFootnote firstFootnoteToDelete,
			ScrFootnote lastFootnoteToDelete, int hvoFirstPara, int hvoLastPara)
		{
			Debug.Assert((firstFootnoteToDelete == null && lastFootnoteToDelete == null)
				|| (firstFootnoteToDelete != null && lastFootnoteToDelete != null));

			if (firstFootnoteToDelete != null)
			{
				bool fDeleteFootnote = false;
				int[] hvos = book.FootnotesOS.HvoArray;
				for (int i = hvos.Length - 1; i >= 0; i--)
				{
					if (hvos[i] == lastFootnoteToDelete.Hvo)
						fDeleteFootnote = true; // we are now in the range of footnotes to delete

					if (fDeleteFootnote)
					{
						// This code fixes TE-4882.
						ScrFootnote footnote = new ScrFootnote(m_cache, hvos[i]);
						int hvoPara = footnote.ContainingParagraphHvo;
						Debug.Assert(hvoPara > 0);
						if ((hvoPara == hvoFirstPara || hvoPara == hvoLastPara) && hvoPara > 0)
						{
							StTxtPara para = new StTxtPara(m_cache, hvoPara);
							para.DeleteAnyBtMarkersForFootnote(footnote.Guid);
						}
						m_cache.DeleteObject(hvos[i]);
					}

					if (hvos[i] == firstFootnoteToDelete.Hvo)
						break;
				}
			}
		}
Exemplo n.º 4
0
		public void GetMarkerForCrossRef_Scripture_AutoNumbered()
		{
			CheckDisposed();

			ScrFootnote footnote = new ScrFootnote(Cache, m_genesis.FootnotesOS.HvoArray[0]);
			StTxtPara para = new StTxtPara();
			footnote.ParagraphsOS.Append(para);
			para.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.CrossRefFootnoteParagraph);

			footnote = new ScrFootnote(Cache, m_genesis.FootnotesOS.HvoArray[1]);
			para = new StTxtPara();
			footnote.ParagraphsOS.Append(para);
			para.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.CrossRefFootnoteParagraph);

			footnote = new ScrFootnote(Cache, m_genesis.FootnotesOS.HvoArray[2]);
			para = new StTxtPara();
			footnote.ParagraphsOS.Append(para);
			para.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.CrossRefFootnoteParagraph);

			ITsString expectedMarker = MakeMarker("c");
			m_scr.CrossRefMarkerType = FootnoteMarkerTypes.AutoFootnoteMarker;
			m_scr.FootnoteMarkerType = FootnoteMarkerTypes.NoFootnoteMarker;  // Just to make sure it's not using this by mistake
			AssertEx.AreTsStringsEqual(expectedMarker, footnote.FootnoteMarker);
		}
Exemplo n.º 5
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Deletes a footnote
		/// </summary>
		/// <param name="args"></param>
		/// <returns><c>true</c> if we handle this</returns>
		/// ------------------------------------------------------------------------------------
		protected bool OnDeleteFootnote(object args)
		{
			if (DataUpdateMonitor.IsUpdateInProgress(DataAccess))
				return true; //discard this event

			if (!ValidFootnoteSelection)
				return true;

			string undo;
			string redo;
			TeResourceHelper.MakeUndoRedoLabels("kstidUndoDelFootnote", out undo, out redo);
			using (new UndoTaskHelper(this, undo, redo, false))
			using (new DataUpdateMonitor(this, RootBox.DataAccess, this, "DeleteFootnote"))
			{
				SelectionHelper helper = SelectionHelper.Create(this);
				int fnLevel = helper.GetLevelForTag((int)ScrBook.ScrBookTags.kflidFootnotes);

				if (helper.Selection.IsRange)
					DeleteFootnoteRange(helper);
				else
				{
					// There's no range selection, so delete only one footnote
					ScrFootnote footnote = new ScrFootnote(m_fdoCache, helper.LevelInfo[fnLevel].hvo);
					ScrFootnote.DeleteFootnoteAndMarker(footnote);
				}

				if (RootBox.Height <= 0)
					DraftView.Focus();
				else
				{
					int iBook = helper.LevelInfo[fnLevel + 1].ihvo;
					ScrBook book = m_bookFilter.GetBook(iBook);
					int iFootnote = helper.LevelInfo[fnLevel].ihvo;

					// If the last footnote in the book was deleted find a footnote to move to
					if (iFootnote >= book.FootnotesOS.Count)
						FindNearestFootnote(ref iBook, ref iFootnote);

					FootnoteEditingHelper.ScrollToFootnote(iBook, iFootnote, 0);
				}
			}

			return true;
		}
Exemplo n.º 6
0
		public void DeleteFootnoteFromContextMenuRangeSelection()
		{
			CheckDisposed();

			SelectionHelper selHelper = new SelectionHelper();
			selHelper.AssocPrev = true;
			selHelper.NumberOfLevels = 3;

			SelLevInfo[] anchorLevInfo = new SelLevInfo[3];
			anchorLevInfo[2].tag = m_footnoteView.BookFilter.Tag;
			anchorLevInfo[2].ihvo = 1;
			anchorLevInfo[1].tag = (int)ScrBook.ScrBookTags.kflidFootnotes;
			anchorLevInfo[1].ihvo = 2;
			anchorLevInfo[0].tag = (int)StText.StTextTags.kflidParagraphs;
			anchorLevInfo[0].ihvo = 0;
			selHelper.SetLevelInfo(SelectionHelper.SelLimitType.Anchor, anchorLevInfo);
			selHelper.IchAnchor = 1;

			SelLevInfo[] endLevInfo = new SelLevInfo[3];
			endLevInfo[2].tag = m_footnoteView.BookFilter.Tag;
			endLevInfo[2].ihvo = 1;
			endLevInfo[1].tag = (int)ScrBook.ScrBookTags.kflidFootnotes;
			endLevInfo[1].ihvo = 6;
			endLevInfo[0].tag = (int)StText.StTextTags.kflidParagraphs;
			endLevInfo[0].ihvo = 0;
			selHelper.SetLevelInfo(SelectionHelper.SelLimitType.End, endLevInfo);
			selHelper.IchEnd = 7;

			// Now that all the preparation to set the selection is done, set it.
			selHelper.SetSelection(m_footnoteView, true, true);
			Application.DoEvents();

			// First get the footnotes we're deleting.
			ScrFootnote[] footnotes = new ScrFootnote[5];
			Guid[] guidFootnotes = new Guid[5];
			int[] hvoParas = new int[5];
			for (int i = 0; i < 5; i++)
			{
				footnotes[i] = new ScrFootnote(Cache, m_Jude.FootnotesOS.HvoArray[i + 2]);
				guidFootnotes[i] = Cache.GetGuidFromId(footnotes[i].Hvo);
				hvoParas[i] = footnotes[i].ContainingParagraphHvo;
			}

			m_footnoteView.DeleteFootnote();

			foreach (ScrFootnote footnote in footnotes)
				Assert.IsFalse(Cache.IsRealObject(footnote.Hvo, StFootnote.kClassId));

			// now make sure that we don't find the footnote markers
			for (int i = 0; i < 5; i++)
			{
				VerifyRemovedFootnoteMarker(hvoParas[i], guidFootnotes[i]);
				VerifyRemovedFootnoteMarker(hvoParas[i], guidFootnotes[i], InMemoryFdoCache.s_wsHvos.En);
				VerifyRemovedFootnoteMarker(hvoParas[i], guidFootnotes[i], InMemoryFdoCache.s_wsHvos.De);
			}
		}
Exemplo n.º 7
0
		public void GetRefForFootnote_IntroPara()
		{
			CheckDisposed();

			ScrFootnote footnote = new ScrFootnote(Cache, m_genesis.FootnotesOS.HvoArray[0]);
			StTxtPara para = new StTxtPara();
			footnote.ParagraphsOS.Append(para);
			para.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalFootnoteParagraph);
			m_scr.DisplayFootnoteReference = true;
			Assert.AreEqual("", footnote.RefAsString, "Intro footnotes don't have Scripture references.");
		}
Exemplo n.º 8
0
		public void DeleteFootnote()
		{
			CheckDisposed();

			IScrBook book;
			InsertTestFootnote(20, out book);
			InsertTestFootnote(60, out book);
			InsertTestFootnote(100, out book);

			// First get the guid for the footnote we're deleting.
			IScrSection section = book.SectionsOS[0];
			IStTxtPara para = (IStTxtPara)section.ContentOA.ParagraphsOS[0];
			ITsString tssOrig = para.Contents.UnderlyingTsString;
			ITsTextProps props = para.Contents.UnderlyingTsString.get_Properties(1);
			string sGuid = props.GetStrPropValue((int)FwTextPropType.ktptObjData);

			// Send the objData string without the first character because the first character
			// is the object replacement character and the rest of the string is the GUID.
			Guid guid = MiscUtils.GetGuidFromObjData(sGuid.Substring(1));

			// Verify the footnote object is in the DB.
			ICmObject obj = CmObject.CreateFromDBObject(Cache, Cache.GetIdFromGuid(guid));
			Assert.IsTrue(obj is StFootnote, "Oops! Footnote isn't in the DB so it cannot be deleted.");

			// Delete text including the first footnote from the first para in Exodus.
			m_draftView.SelectRangeOfChars(0, 0, 0, 2, 20);
			m_draftView.OnKeyDown(new KeyEventArgs(Keys.Delete));

			// Now verify the footnote object has been removed from the DB.
			Assert.AreEqual(0, Cache.GetIdFromGuid(guid), "Footnote was not deleted from DB.");

			// Verify that all footnote markers have been updated
			string expectedMarker = "a";
			foreach (int hvo in book.FootnotesOS.HvoArray)
			{
				ScrFootnote footnote = new ScrFootnote(Cache, hvo);
				Assert.AreEqual(expectedMarker, footnote.FootnoteMarker.Text);
				expectedMarker = new string((char) (expectedMarker[0] + 1), 1);
			}

			// Verify the expected paragraph contents (removing characters 2 to 20).
			ITsStrBldr tssBldr = tssOrig.GetBldr();
			tssBldr.ReplaceRgch(2, 20, "", 0, null);
			ITsString tssExpected = tssBldr.GetString();
			Assert.AreEqual(tssExpected.Text, para.Contents.UnderlyingTsString.Text);
		}
Exemplo n.º 9
0
		public void InsertFootnote_AfterEmptyParaWithChapterNumberStyle()
		{
			CheckDisposed();

			IScrBook book;
			ScrFootnote footnote0 = InsertTestFootnote(0, out book);
			ScrFootnote footnote1 = InsertTestFootnote(3, out book);
			ScrFootnote scrFootnote1 = new ScrFootnote(Cache, footnote1.Hvo);
			ScrFootnote.DeleteFootnoteAndMarker(scrFootnote1);

			int iSection = book.SectionsOS.Count - 1;
			IScrSection section = book.SectionsOS[iSection];
			IStTxtPara emptyChapterPara = new StTxtPara();
			section.ContentOA.ParagraphsOS.InsertAt(emptyChapterPara, 0);
			ITsStrBldr bldr = emptyChapterPara.Contents.UnderlyingTsString.GetBldr();
			ITsTextProps ttpChapterNumber = TsPropsFactoryClass.Create().MakeProps(
				ScrStyleNames.ChapterNumber, Cache.DefaultVernWs, 0);
			bldr.SetProperties(0, 0, ttpChapterNumber);
			emptyChapterPara.Contents.UnderlyingTsString = bldr.GetString();

			Assert.AreEqual(1, book.FootnotesOS.Count);

			// Insert a footnote later in the section.
			m_draftView.SetInsertionPoint(0, iSection, 1, 3, false);
			SelectionHelper helper = SelectionHelper.Create(m_draftView);

			m_scr.DisplayFootnoteReference = true; // Why is this line here?

			ScrFootnote footnote2 = m_draftView.InsertFootnote(helper);


			// Verify the footnote is added to the book.
			Assert.AreEqual(footnote2.Hvo, book.FootnotesOS.HvoArray[1]);

			// Verify the footnotes were given the proper marker.
			Assert.AreEqual("b", footnote2.FootnoteMarker.Text);
		}
Exemplo n.º 10
0
		public void DeleteFootnoteInRangeSelectionAcrossMultipleBooks()
		{
			SetupSelectionForRangeAcrossBooks();
			IScripture scr = m_cache.LangProject.TranslatedScriptureOA;

			ScrFootnote[] footnotes = new ScrFootnote[4];
			Guid[] guidFootnotes = new Guid[4];
			int[] hvoParas = new int[4];

			// First get the footnotes we're deleting from JAMES.
			IScrBook book = (IScrBook)scr.ScriptureBooksOS[1];
			footnotes[0] = new ScrFootnote(m_cache, book.FootnotesOS.HvoArray[31]);
			footnotes[1] = new ScrFootnote(m_cache, book.FootnotesOS.HvoArray[32]);

			// First get the footnotes we're deleting from JUDE.
			book = (IScrBook)scr.ScriptureBooksOS[2];
			footnotes[2] = new ScrFootnote(m_cache, book.FootnotesOS.HvoArray[0]);
			footnotes[3] = new ScrFootnote(m_cache, book.FootnotesOS.HvoArray[1]);

			for (int i = 0; i < 4; i++)
			{
				guidFootnotes[i] = m_cache.GetGuidFromId(footnotes[i].Hvo);
				hvoParas[i] = footnotes[i].ContainingParagraphHvo;
			}

			m_footnoteView.DeleteFootnote();

			foreach (IStFootnote footnote in footnotes)
				Assert.IsFalse(m_cache.IsRealObject(footnote.Hvo, StFootnote.kClassId));

			// now make sure that we don't find the footnote markers
			for (int i = 0; i < 4; i++)
			{
				Assert.IsFalse(IsFootnoteMarkerInText(hvoParas[i], guidFootnotes[i]),
					"Footnote marker didn't get deleted from text");
			}
		}
Exemplo n.º 11
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get the start and end reference of the specified position <paramref name="ivPos"/>
		/// in the paragraph. Section reference could be used, if available, to fill in missing
		/// information, but (at least for now) we will not search back into previous sections.
		/// </summary>
		/// <param name="wsBT">HVO of the writing system of the BT to search, or -1 to search
		/// the vernacular.</param>
		/// <param name="ivPos">Character offset in the paragraph.</param>
		/// <param name="fAssocPrev">Consider this position to be associated with any preceding
		/// text in the paragraph (in the case where ichPos is at a chapter boundary).</param>
		/// <param name="refStart">[out] Start reference</param>
		/// <param name="refEnd">[out] End reference</param>
		/// <remarks><p><paramref name="refStart"/> and <paramref name="refEnd"/> are only
		/// different if we have bridged verse numbers.</p>
		/// <p>May return incomplete or invalid reference if, for example, the section
		/// object does not have a valid start reference.</p>
		/// <p>If ivPos LT zero, we will not search this para, but look only in previous
		/// paragraphs</p></remarks>
		/// ------------------------------------------------------------------------------------
		public void GetBCVRefAtPosition(int wsBT, int ivPos, bool fAssocPrev,
			out BCVRef refStart, out BCVRef refEnd)
		{
			refStart = new BCVRef();
			refEnd = new BCVRef();

			// Might be trying to get the BCVRef in a footnote
			int ownerOwnFlid = m_cache.GetOwningFlidOfObject(OwnerHVO);
			if (ownerOwnFlid == (int)ScrBook.ScrBookTags.kflidFootnotes)
			{
				ScrFootnote footnote = new ScrFootnote(m_cache, OwnerHVO);
				refStart = footnote.StartRef;
				refEnd = footnote.StartRef;
				return;
			}

			BCVRef refStartT = new BCVRef();
			BCVRef refEndT = new BCVRef();
			ChapterVerseFound found = ChapterVerseFound.None;
			bool fGotVerse = false;
			ScrTxtPara para = this; // curent paragraph being examined for reference
			int chvoParas = 0; // count of paragraphs in the section
			int ihvoPara = 0; // index of the paragraph within the section

			BCVRef sectRefStart;
			BCVRef sectRefEnd;
			GetSectionStartAndEndRefs(out sectRefStart, out sectRefEnd);

			while (true)
			{
				if (para == this)
				{
					found = para.GetBCVRefAtPosWithinPara(wsBT, ivPos, fAssocPrev, out refStartT,
						out refEndT);
				}
				else
					found = para.GetBCVRefAtEndOfPara(out refStartT, out refEndT);

				// if we found a verse, remember it
				if (!fGotVerse && ((found & ChapterVerseFound.Verse) != 0))
				{
					refStart.Verse = refStartT.Verse;
					refEnd.Verse = refEndT.Verse;
					fGotVerse = true;
				}

				// if we found a chapter, process it
				if ((found & ChapterVerseFound.Chapter) != 0)
				{
					if (sectRefStart != null && !sectRefStart.IsEmpty)
						refStart.Book = refEnd.Book = sectRefStart.Book; //may not exist

					refStart.Chapter = refEnd.Chapter = refStartT.Chapter;

					// GetBCVwithinPara always returns a verse if it finds a chapter number
					// so we have already built the full reference
					Debug.Assert(fGotVerse);
					return;
				}

				// We got to the beginning of the paragraph being edited and still haven't
				// found a decent reference for our edited text, so keep looking back to
				// get it from a previous paragraph.

				// First time thru, figure out which paragraph we are in
				if (chvoParas == 0)
				{
					// REVIEW (EberhardB): does this work if not all paragraphs are
					// loaded in the cache?
					chvoParas = m_cache.GetVectorSize(OwnerHVO,
						(int)StText.StTextTags.kflidParagraphs);
					// Go forward through vector of paragraphs to find the one being parsed
					for (ihvoPara = 0; ihvoPara < chvoParas; ihvoPara++)
					{
						int hvoPara = m_cache.GetVectorItem(OwnerHVO,
							(int)StText.StTextTags.kflidParagraphs,	ihvoPara);
						if (hvoPara == Hvo)
							break; // found our current para
					}
				}

				// Move to the previous paragraph
				ihvoPara--;

				if (ihvoPara < 0)
				{
					// We are at the beginning of the section. We can't look back any further.
					// ENHANCE TomB: If we search all the way through to the beginning of the
					// section and never get a valid reference, this section begins in the
					// middle of a verse or chapter (unlikely in the case of a verse, but
					// quite likely in the case of a chapter). OR (most likely) this edit
					// happened at the very beginning of the section, and when we start
					// parsing, the first thing we'll get is a decent reference.
					// REVIEW: we're using the section reference, but since they don't get
					// updated, a change (like removing a chapter) in a previous section
					// could mess up this section.
					if (fGotVerse)
					{
						// Use the verse we got previously (already set), along with the
						// first chapter for the section and the book, if available.
						if (sectRefStart != 0)
						{
							refStart.Chapter = refEnd.Chapter = sectRefStart.Chapter;
							refStart.Book = refEnd.Book = sectRefStart.Book;
						}
					}
					else
					{
						// REVIEW:
						// For now, we're just using the first verse for the section, but this
						// could be wrong if the section begins in the middle of a verse bridge
						// or misleading if the section just doesn't yet have verse numbers
						// marked.
						if (sectRefStart != 0)
						{
							refStart = new BCVRef(sectRefStart);
							refEnd = new BCVRef(sectRefStart);
						}

						// If we are looking for a negative position in the first para of a section
						// the needed result is not precisely defined yet,
						// but this is where you could set it
//						if (para == this && ivPos < 0)
//							refStart.Verse = refEnd.Verse = ????;
					}
					return;
				}

				// Set up for the previous paragraph in this section, and we'll try again
				int hvoNewPara = m_cache.GetVectorItem(OwnerHVO,
					(int)StText.StTextTags.kflidParagraphs, ihvoPara);
				// use a special constructor since we already know the section refs
				para = new ScrTxtPara(m_cache, hvoNewPara, false, false);
			}
		}
Exemplo n.º 12
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get full reference (BCV-CV) of the given StText. Returns an empty string if we can't find a book name
		/// with the given 'ws'.
		/// </summary>
		/// <param name="stText"></param>
		/// <param name="ws"></param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		public ITsString BookChapterVerseBridgeAsTss(StText stText, int ws)
		{
			ITsString tssTitle = null;
			Debug.Assert(Scripture.IsResponsibleFor(stText), "given StText should belong to scripture.");
			int owningFlid = stText.OwningFlid;
			if (owningFlid == (int)ScrBook.ScrBookTags.kflidFootnotes)
			{
				ScrFootnote footnote = new ScrFootnote(Cache, stText.Hvo);
				string footnoteRefStr = ContainingRefAsString(footnote);
				ScrBook book = footnote.Owner as ScrBook;
				ITsString tssBook = book.Name.GetAlternativeTss(ws);
				if (tssBook.Length > 0)
				{
					ITsStrBldr bldr = tssBook.GetBldr();
					int cch = bldr.Length;
					bldr.Replace(cch, cch, " " + footnoteRefStr, null);
					tssTitle = bldr.GetString();
				}
			}
			else if (owningFlid == (int)ScrSection.ScrSectionTags.kflidContent ||
				owningFlid == (int)ScrSection.ScrSectionTags.kflidHeading)
			{
				ScrSection section = stText.Owner as ScrSection;

				ITsString tssBookChapterVerseBridge = this.BookChapterVerseBridgeAsTss(section, ws);
				tssTitle = tssBookChapterVerseBridge;
			}
			else if (owningFlid == (int)FDO.Scripture.ScrBook.ScrBookTags.kflidTitle)
			{
				ScrBook book = stText.Owner as ScrBook;
				ITsString tssBookName = book.Name.GetAlternativeTss(ws);
				if (tssBookName.Length > 0)
				{
					ITsStrBldr bldr = tssBookName.GetBldr();
					int cch = bldr.Length;
					bldr.Replace(cch, cch, String.Format(" ({0})",
						ResourceHelper.GetResourceString("kstidScriptureTitle")), null);
					tssTitle = bldr.GetString();
				}
			}
			else
			{
				// throw.
			}
			if (tssTitle == null)
			{
				// return an empty string.
				ITsStrFactory isf = TsStrFactoryClass.Create();
				tssTitle = isf.MakeString("", ws);
			}
			return tssTitle;
		}
Exemplo n.º 13
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get the Chapter Verse Reference representation for a footnote (ie. sectionCV-CV Footnote(footnoteCV))
		/// Or Title representation (ie. Title Footnote(OwnOrd))
		/// </summary>
		/// <param name="footnote"></param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		public string ContainingRefAsString(ScrFootnote footnote)
		{
			footnote.IgnoreDisplaySettings = true; // so we can access GetReference.
			string parentContext = "";
			string footnoteRef = "";
			int hvoContainingObj;
			if (footnote.TryGetContainingSectionHvo(out hvoContainingObj))
			{
				ScrSection section = new ScrSection(Cache, hvoContainingObj);
				parentContext = ChapterVerseBridgeAsString(section);
				footnoteRef = footnote.GetReference(m_cache.DefaultUserWs).Trim();
			}
			else if (footnote.TryGetContainingTitle(out hvoContainingObj))
			{
				parentContext = ResourceHelper.GetResourceString("kstidScriptureTitle");
				footnoteRef = footnote.OwnOrd.ToString();
			}
			return String.Format("{0} {1}({2})", parentContext,
				ResourceHelper.GetResourceString("kstidScriptureFootnote"), footnoteRef);
		}
Exemplo n.º 14
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Get the string that should be displayed in place of an object character associated
		/// with the specified GUID.
		/// </summary>
		/// <param name="bstrGuid"></param>
		/// <returns></returns>
		/// -----------------------------------------------------------------------------------
		public override ITsString GetStrForGuid(string bstrGuid)
		{
			CheckDisposed();

			Debug.Assert(Cache != null);
			Debug.Assert(bstrGuid.Length == 8);

			Guid guid = MiscUtils.GetGuidFromObjData(bstrGuid);

			int hvoObj = Cache.GetIdFromGuid(guid);

			if (hvoObj != 0)
			{
				if (Cache.GetClassOfObject(hvoObj) == StFootnote.kclsidStFootnote)
				{
					ScrFootnote footnote = new ScrFootnote(Cache, hvoObj);
					ITsStrBldr bldr = footnote.MakeFootnoteMarker(DefaultWs);
					if (bldr.Length == 0 && Options.ShowMarkerlessIconsSetting)
					{
						// Use the restore window icon character from Marlett as the
						// footnote marker.
						ITsPropsBldr propsBldr = bldr.get_Properties(0).GetBldr();
						propsBldr.SetStrPropValue((int) FwTextPropType.ktptFontFamily,
							"Marlett");
						if (PrintLayout) // don't display markerless icon in print layout view
							bldr.Replace(0, 0, string.Empty, propsBldr.GetTextProps());
						else
							bldr.Replace(0, 0, "\u0032", propsBldr.GetTextProps());
					}
					else if (bldr.Length > 0)
					{
						// This is to prevent the word-wrap from wrapping at the beginning of
						// a footnote marker.
						// REVIEW (TimS): \uFEFF is deprecated as a non-break character in Unicode now. Should
						//                use \u2060 but no fonts/renderers seem to have it defined. Should
						//                maybe change this eventually.
						string directionIndicator = (RightToLeft) ? "\u200F" : "\u200E";
						bldr.Replace(0, 0, directionIndicator + "\uFEFF" + directionIndicator, null);
					}

					bldr.SetIntPropValues(0, bldr.Length,
						(int)FwTextPropType.ktptEditable,
						(int)FwTextPropVar.ktpvEnum,
						(int)TptEditable.ktptNotEditable);

					return bldr.GetString();
				}
			}

			// If the GUID was not found then return a missing object string
			ITsStrFactory tsf = TsStrFactoryClass.Create();
			return tsf.MakeString("<missing object>", Cache.DefaultUserWs);
		}
Exemplo n.º 15
0
		/// ------------------------------------------------------------------------------------
		/// <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;
		}
Exemplo n.º 16
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// <param name="hvoBook">The hvo of the book containing the footnotes</param>
		/// <param name="ivMin">The index in the vector of the change</param>
		/// <param name="cvIns">the number of footnotes inserted</param>
		/// <param name="cvDel">the number of footnotes deleted</param>
		/// ------------------------------------------------------------------------------------
		protected override void DoEffectsOfPropChange(int hvoBook, int ivMin, int cvIns, int cvDel)
		{
			bool fNeedToRecalculate = true;
			ScrBook book = new ScrBook(m_cache, hvoBook);
			if (cvIns > 0)
			{
				// if we inserted, we only need to recalculate the markers if the inserted footnote
				// offset the auto-lettering.
				Debug.Assert(ivMin < book.FootnotesOS.Count);
				ScrFootnote footnoteIns = new ScrFootnote(m_cache, book.FootnotesOS.HvoArray[ivMin]);
				fNeedToRecalculate = (footnoteIns.FootnoteType == FootnoteMarkerTypes.AutoFootnoteMarker);
			}
			if (fNeedToRecalculate)
				ScrFootnote.RecalculateFootnoteMarkers(book, ivMin);
		}
Exemplo n.º 17
0
		public void DeleteFootnoteFromContextMenuIPSelection()
		{
			CheckDisposed();

			MakeFootnoteSelection(1, 1, 1);

			// First get the footnote we're deleting.
			ScrFootnote footnote = new ScrFootnote(Cache, m_Jude.FootnotesOS.HvoArray[1]);
			Guid guidFootnote = Cache.GetGuidFromId(footnote.Hvo);

			// Find the paragraph that this footnote is in
			int hvoPara = footnote.ContainingParagraphHvo;

			m_footnoteView.DeleteFootnote();

			Assert.IsFalse(Cache.IsRealObject(footnote.Hvo, StFootnote.kClassId));

			// Now make sure that we don't find the footnote marker in the vern or either BT of
			// the para that used to contain it.
			VerifyRemovedFootnoteMarker(hvoPara, guidFootnote);
			VerifyRemovedFootnoteMarker(hvoPara, guidFootnote, InMemoryFdoCache.s_wsHvos.En);
			VerifyRemovedFootnoteMarker(hvoPara, guidFootnote, InMemoryFdoCache.s_wsHvos.De);
		}
Exemplo n.º 18
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Write the first paragraph in the given footnote.  (TE allows only 1 paragraph in
		/// footnotes!)
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void ExportFootnote(ScrFootnote foot)
		{
			IStTxtPara para = foot.ParagraphsOS[0] as IStTxtPara;
			string sStyle = para.StyleName;
			if (String.IsNullOrEmpty(sStyle))
				sStyle = "scrFootnote";
			else
				sStyle = m_xhtml.GetValidCssClassName(sStyle);
			ITsStrBldr bldr = foot.MakeFootnoteMarker(m_cache.DefaultVernWs);
			string sFootnoteMarker = bldr.Text;
			ITsString tssPara = para.Contents.UnderlyingTsString;
			m_writer.WriteLine("<span class=\"{0}\" id=\"{1}\" title=\"{2}\">",
				sStyle, "F" + foot.Guid.ToString().ToUpperInvariant(), sFootnoteMarker);
			m_xhtml.MapCssToLang(sStyle, LanguageCode(StringUtils.GetWsAtOffset(tssPara, 0)));
			WriteTsStringAsXml(tssPara, 4);
			m_writer.WriteLine("</span>");
			// The following class is inserted by the XSLT processing.
			m_xhtml.MapCssToLang("scrFootnoteMarker", LanguageCode(m_cache.DefaultVernWs));
		}
Exemplo n.º 19
0
		public void GetRefForCrossRef_Scripture_DontDisplay()
		{
			CheckDisposed();

			ScrFootnote footnote = new ScrFootnote(Cache, m_genesis.FootnotesOS.HvoArray[1]);
			StTxtPara para = new StTxtPara();
			footnote.ParagraphsOS.Append(para);
			para.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.CrossRefFootnoteParagraph);
			m_scr.DisplayFootnoteReference = true; // Just to make sure it's not using this by mistake
			m_scr.CrossRefsCombinedWithFootnotes = false;
			m_scr.DisplayCrossRefReference = false;
			Assert.AreEqual(string.Empty, footnote.RefAsString);
		}
Exemplo n.º 20
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Display the footnote marker.
		/// </summary>
		/// <param name="vwenv">View environment</param>
		/// <param name="footnote">The footnote.</param>
		/// ------------------------------------------------------------------------------------
		private void DisplayFootnoteMarker(IVwEnv vwenv, ScrFootnote footnote)
		{
			vwenv.NoteDependency(new int[] { footnote.Hvo },
				new int[] { (int)StFootnote.StFootnoteTags.kflidFootnoteMarker }, 1);
			// The footnote marker is not editable.
			vwenv.set_IntProperty((int)FwTextPropType.ktptEditable,
				(int)FwTextPropVar.ktpvEnum,
				(int)TptEditable.ktptNotEditable);

			ITsStrBldr strBldr = footnote.MakeFootnoteMarker(DefaultWs);
			strBldr.Replace(strBldr.Length, strBldr.Length, " ", null);
			vwenv.AddString(strBldr.GetString());
		}
Exemplo n.º 21
0
		public void FootnoteRefVerseBridge()
		{
			CheckDisposed();

			ScrFootnote footnote = new ScrFootnote(Cache, m_genesis.FootnotesOS.HvoArray[2]);
			StTxtPara footnotePara = new StTxtPara();
			footnote.ParagraphsOS.Append(footnotePara);
			footnotePara.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalFootnoteParagraph);
			m_scr.DisplayFootnoteReference = true;

			// Add a new verse bridge
			IScrSection section = m_genesis.SectionsOS[1];
			StTxtPara para = (StTxtPara) section.ContentOA.ParagraphsOS[1];
			ITsStrBldr bldr = para.Contents.UnderlyingTsString.GetBldr();
			bldr.Replace(1, 1, "-9", StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber,
				Cache.DefaultVernWs));
			para.Contents.UnderlyingTsString = bldr.GetString();

			// Give property change event related to verse insert.
			Cache.PropChanged(null, PropChangeType.kpctNotifyAll,
				para.Hvo, StTxtPara.ktagVerseNumbers, 0, 1, 1); // char positions and counts are ignored

			// Verify that reference for footnote is now correct
			Assert.AreEqual("1:5-9 ", footnote.RefAsString);
		}
Exemplo n.º 22
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// This is the main interesting method of displaying objects and fragments of them.
		/// Scripture Footnotes are displayed by displaying each footnote's reference and text.
		/// The text is displayed using the standard view constructor for StText.
		/// </summary>
		/// <param name="vwenv"></param>
		/// <param name="hvo"></param>
		/// <param name="frag"></param>
		/// ------------------------------------------------------------------------------------
		public override void Display(IVwEnv vwenv, int hvo, int frag)
		{
			CheckDisposed();

			switch (frag)
			{
				case (int)FootnoteFrags.kfrScripture:
				{
					vwenv.NoteDependency(new int[] { m_cache.LangProject.TranslatedScriptureOAHvo },
						new int[] { (int)Scripture.ScriptureTags.kflidScriptureBooks }, 1);
					vwenv.AddLazyVecItems(BooksTag, this, (int)FootnoteFrags.kfrBook);
					break;
				}
				case (int)FootnoteFrags.kfrRootInPageSeq:
				{
					int tag = DummyVirtualHandler.InstallDummyHandler(m_cache.VwCacheDaAccessor,
						"Scripture", "FootnotesOnPage",
						(int)CellarModuleDefns.kcptReferenceSequence).Tag;
					// Get the list of footnotes to display
					int[] hvos = m_cache.GetVectorProperty(hvo, tag, true);
					if (hvos.Length > 0)
					{
						int ownerHvo = m_cache.GetOwnerOfObject(hvos[0]);
						// The ownerHvo should be the HVO of the book
						vwenv.NoteDependency(new int[] { ownerHvo },
							new int[] { (int)ScrBook.ScrBookTags.kflidFootnotes }, 1);
					}
					vwenv.AddObjVec(tag, this, (int)FootnoteFrags.kfrAllFootnotesWithinPagePara);
					break;
				}
				case (int)FootnoteFrags.kfrFootnoteWithinPagePara:
				{
					// Note a dependency on the footnote options so that the footnote will
					// be refreshed when these are changed.
					int[] depHvos = { hvo };
					int[] depTags = { StFootnote.ktagFootnoteOptions };
					vwenv.NoteDependency(depHvos, depTags, 1);

					// Insert the marker and reference
					vwenv.AddObj(hvo, this, (int)StTextFrags.kfrFootnoteMarker);
					vwenv.AddObj(hvo,  this,(int)StTextFrags.kfrFootnoteReference);

					// Insert (we hope only one) paragraph contents.
					vwenv.AddObjVecItems((int)StText.StTextTags.kflidParagraphs, this,
						(int)FootnoteFrags.kfrFootnoteParaWithinPagePara);
					break;
				}
				case (int) FootnoteFrags.kfrFootnoteParaWithinPagePara:
				{
					if (!InsertParaContentsUserPrompt(vwenv, hvo))
					{
						// Display the text paragraph contents, or its user prompt.
						vwenv.AddStringProp((int)StTxtPara.StTxtParaTags.kflidContents, null);
					}
					break;
				}
				case (int)FootnoteFrags.kfrBook:
				{
					vwenv.OpenDiv();
					vwenv.AddObjVecItems((int)ScrBook.ScrBookTags.kflidFootnotes, this,
						(int)StTextFrags.kfrFootnote);
					vwenv.CloseDiv();
					break;
				}
				case (int)StTextFrags.kfrFootnoteMarker:
				{
					ScrFootnote footnote = new ScrFootnote(Cache, hvo);
					if (footnote.DisplayFootnoteMarker)
						DisplayFootnoteMarker(vwenv, footnote);
					break;
				}
				case (int)StTextFrags.kfrFootnoteReference:
				{
					ITsStrFactory tsStrFactory = TsStrFactoryClass.Create();
					ITsPropsFactory tpf = TsPropsFactoryClass.Create();
					ITsTextProps ttp = tpf.MakeProps(ScrStyleNames.FootnoteTargetRef, m_wsDefault, 0);

					ScrFootnote footnote = new ScrFootnote(m_cache, hvo);
					string footnoteRef = footnote.GetReference(m_wsDefault);
					ITsString tssRef = tsStrFactory.MakeStringWithPropsRgch(footnoteRef,
						footnoteRef.Length, ttp);
					vwenv.set_IntProperty((int)FwTextPropType.ktptEditable,
						(int)FwTextPropVar.ktpvEnum,
						(int)TptEditable.ktptNotEditable);
					vwenv.AddString(tssRef);
					break;
				}
				default:
					base.Display(vwenv, hvo, frag);
					break;
			}
		}
Exemplo n.º 23
0
		public void GetMarkerForCrossRef_Scripture_LiteralSymbol()
		{
			CheckDisposed();

			ScrFootnote footnote = new ScrFootnote(Cache, m_genesis.FootnotesOS.HvoArray[1]);
			StTxtPara para = new StTxtPara();
			footnote.ParagraphsOS.Append(para);
			para.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.CrossRefFootnoteParagraph);
			ITsStrFactory factory = TsStrFactoryClass.Create();
			m_scr.CrossRefMarkerType = FootnoteMarkerTypes.SymbolicFootnoteMarker;
			m_scr.CrossRefMarkerSymbol = "$";
			m_scr.FootnoteMarkerType = FootnoteMarkerTypes.AutoFootnoteMarker; // Just to make sure it's not using this by mistake
			AssertEx.AreTsStringsEqual(MakeMarker("$"), footnote.FootnoteMarker);
		}
Exemplo n.º 24
0
		public void AboutToDelete_CorrectFootnoteOwner()
		{
			CheckDisposed();

			IScrBook philemon = m_scrInMemoryCache.AddBookToMockedScripture(57, "Philemon");
			IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(philemon.Hvo);
			section.VerseRefStart = section.VerseRefEnd = 57001001;
			StTxtPara para1 = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(para1, "this is some text", null);
			StTxtPara para2 = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(para2, "this is some more text", null);
			StFootnote fn = m_scrInMemoryCache.AddFootnote(philemon, para2, 12);
			// force the footnote cache to be built now if it wasn't earlier.
			philemon = new ScrBook(m_scrInMemoryCache.Cache, philemon.Hvo);
			ScrFootnote footnote = new ScrFootnote(m_scrInMemoryCache.Cache, fn.Hvo);
			Assert.AreEqual(para2.Hvo, footnote.ContainingParagraphHvo, "Footnote containing paragraph not setup correctly");

			// check the normal case - fMergeNext is false
			m_editingHelper.SetupSelectionInPara(para2, 1, section, 0, philemon, 0, 0, false);
			m_editingHelper.AboutToDelete(m_editingHelper.CurrentSelection, para2.Hvo, para2.OwnerHVO,
				(int)StText.StTextTags.kflidParagraphs, 1, false);
			Assert.AreEqual(para1.Hvo, footnote.ContainingParagraphHvo, "Footnote containing paragraph not updated on paragraph merge - fMergeNext = false");

			// check the special case for an empty paragraph - fMergeNext is true
			m_editingHelper.SetupSelectionInPara(para1, 0, section, 0, philemon, 0, 0, false);
			m_editingHelper.AboutToDelete(m_editingHelper.CurrentSelection, para1.Hvo, para1.OwnerHVO,
				(int)StText.StTextTags.kflidParagraphs, 0, true);
			Assert.AreEqual(para2.Hvo, footnote.ContainingParagraphHvo, "Footnote containing paragraph not updated on paragraph merge - fMergeNext = true");
		}
Exemplo n.º 25
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Deletes footnotes when there is a range selection.
		/// </summary>
		/// <param name="helper"></param>
		/// ------------------------------------------------------------------------------------
		private void DeleteFootnoteRange(SelectionHelper helper)
		{
			int nTopLevels = helper.GetNumberOfLevels(SelectionHelper.SelLimitType.Top);
			int nBottomLevels = helper.GetNumberOfLevels(SelectionHelper.SelLimitType.Bottom);

			// Get the index of the book containing the first footnote in the selection.
			// Then get the index of the footnote within that book.
			int iFirstBook =
				helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[nTopLevels-1].ihvo;
			int iFirstFootnote =
				helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[nTopLevels-2].ihvo;

			// Get the index of the book containing the last footnote in the selection.
			// Then get the index of the footnote within that book.
			int iLastBook =
				helper.GetLevelInfo(SelectionHelper.SelLimitType.Bottom)[nBottomLevels-1].ihvo;
			int iLastFootnote =
				helper.GetLevelInfo(SelectionHelper.SelLimitType.Bottom)[nBottomLevels-2].ihvo;

			// Loop through the books containing footnotes in the selection.
			for (int iBook = iFirstBook; iBook <= iLastBook; iBook++)
			{
				ScrBook book = BookFilter.GetBook(iBook);

				int iBeg = iFirstFootnote;
				if (iFirstBook != iLastBook && iBook > iFirstBook)
					iBeg = 0;

				int iEnd = iLastFootnote;
				if (iFirstBook != iLastBook && iBook < iLastBook)
					iEnd = book.FootnotesOS.Count - 1;

				// Loop through the footnotes from the selection that are in the
				// current book. Go in reverse order through the collection.
				for (int i = iEnd; i >= iBeg; i--)
				{
					// TODO: check filter for each HVO
					ScrFootnote footnote = new ScrFootnote(m_fdoCache, book.FootnotesOS[i].Hvo);
					ScrFootnote.DeleteFootnoteAndMarker(footnote);
				}
			}
		}
Exemplo n.º 26
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Deletes a footnote along with its marker in the text. This also recalculates the
		/// footnote markers of following footnotes.
		/// </summary>
		/// <param name="footnote"></param>
		/// ------------------------------------------------------------------------------------
		public static void DeleteFootnoteAndMarker(ScrFootnote footnote)
		{
			// Paragraph changes are not monitored by cache - refresh cache for book before
			// doing deletion
			IScrBook book = new ScrBook(footnote.Cache, footnote.OwnerHVO);
			// REVIEW: Probably not needed now??? ((ScrBook)book).RefreshFootnoteRefs();

			// Get paragraph containing footnote and search for run having footnote ref.
			int hvoPara = footnote.ContainingParagraphHvo;
			if (hvoPara != 0)
			{
				StTxtPara para = new StTxtPara(footnote.Cache, hvoPara);
				para.DeleteAnyBtMarkersForFootnote(footnote.Guid);
				ITsString tssContent = para.Contents.UnderlyingTsString;
				TsRunInfo runInfo = new TsRunInfo();
				int i;
				for (i = 0; i < tssContent.RunCount; i++)
				{
					ITsTextProps textProps = tssContent.FetchRunInfo(i, out runInfo);
					string strGuid =
						textProps.GetStrPropValue((int)FwTextPropType.ktptObjData);
					if (strGuid != null)
					{
						Guid guid = MiscUtils.GetGuidFromObjData(strGuid.Substring(1));
						if (footnote.Guid == guid)
							break;
					}
				}
				System.Diagnostics.Debug.Assert(i < tssContent.RunCount, "Footnote marker not found in text");

				// Remove footnote ref from paragraph - then delete the footnote
				ITsStrBldr bldr = tssContent.GetBldr();
				bldr.Replace(runInfo.ichMin, runInfo.ichLim, string.Empty, null);
				para.Contents.UnderlyingTsString = bldr.GetString();
			}
			DeleteFootnote(footnote);
		}
Exemplo n.º 27
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Delete all footnotes between firstFootnoteToDelete and lastFootnoteToDelete.
		/// </summary>
		/// <remarks>Use this version of DeleteFootnotes() when there is no need to clean up
		/// ORCs in corresponding BTs, such as when the deletion being performed is deleting
		/// only entire paragraphs.</remarks>
		/// <param name="book">Book that contains the sections to delete</param>
		/// <param name="firstFootnoteToDelete">First footnote that will be deleted
		/// (might be null).</param>
		/// <param name="lastFootnoteToDelete">Last footnote that will be deleted
		/// (might be null).</param>
		/// ------------------------------------------------------------------------------------
		private void DeleteFootnotes(IScrBook book, ScrFootnote firstFootnoteToDelete,
			ScrFootnote lastFootnoteToDelete)
		{
			DeleteFootnotes(book, firstFootnoteToDelete, lastFootnoteToDelete, 0, 0);
		}
Exemplo n.º 28
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Recalculates footnote markers for all footnotes in book starting at the given
		/// footnote index.
		/// </summary>
		/// <param name="book"></param>
		/// <param name="iStartAt"></param>
		/// ------------------------------------------------------------------------------------
		public static void RecalculateFootnoteMarkers(IScrBook book, int iStartAt)
		{
			FdoCache cache = book.Cache;
			IScripture scr = cache.LangProject.TranslatedScriptureOA;
			// Paragraph changes are not monitored by cache - refresh cache for book before
			// doing recalculation
			((ScrBook)book).RefreshFootnoteRefs();

			if (cache.MarkerIndexCache == null)
				cache.MarkerIndexCache = new FootnoteMarkerIndexCache(cache);

			int hvoPrevPara = 0;
			ScrFootnote footnote = null;
			FdoOwningSequence<IStFootnote> footnotes = book.FootnotesOS;
			for (int i = iStartAt; i < footnotes.Count; i++)
			{
				footnote = new ScrFootnote(cache, footnotes.HvoArray[i]);
				bool refreshFootnote =
					cache.MarkerIndexCache.GetDirtyFlagForFootnote(footnote.Hvo);

				if (refreshFootnote && footnote != null)
				{
					cache.MarkerIndexCache.ClearDirtyFlagForFootnote(footnote.Hvo);
					cache.PropChanged(null, PropChangeType.kpctNotifyAll,
						footnote.Hvo, (int)StFootnote.StFootnoteTags.kflidFootnoteMarker, 0, 1, 1);

					// Give a notification to the paragraph when all markers have been
					// updated so that it will display the updated footnote markers.
					if (footnote.HasORCInVernacular)
					{
						int hvoPara = footnote.ContainingParagraphHvo;
						if (hvoPara != hvoPrevPara && hvoPrevPara != 0)
						{
							using (new IgnorePropChanged(cache, PropChangedHandling.SuppressChangeWatcher))
							{
								cache.PropChanged(null, PropChangeType.kpctNotifyAll,
									hvoPrevPara, (int)StTxtPara.StTxtParaTags.kflidContents,
									0, 1, 1);
							}
						}
						hvoPrevPara = hvoPara;
					}
				}
			}
			// Give a notification for the last paragraph so that it will display
			// the updated footnote markers.
			if (hvoPrevPara != 0)
			{
				using (new IgnorePropChanged(cache, PropChangedHandling.SuppressChangeWatcher))
				{
					cache.PropChanged(null, PropChangeType.kpctNotifyAll,
						hvoPrevPara, (int)StTxtPara.StTxtParaTags.kflidContents, 0, 1, 1);
				}
			}
		}
Exemplo n.º 29
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Adds the overrides to highlight a footnote diff.
		/// </summary>
		/// <param name="hvo">The hvo of the footnote paragraph.</param>
		/// ------------------------------------------------------------------------------------
		private void AddOverridesToHighlightFootnoteDiff(int hvo)
		{
			Difference diff = FindSubDiffForFootnote(hvo);
			if (diff == null)
				return;

			StTxtPara para = new StTxtPara(Cache, hvo);

			// Get the footnote which contains the paragraph.
			int ownerHvo = para.OwnerHVO;
			Debug.Assert(m_cache.GetClassOfObject(ownerHvo) == StFootnote.kClassId);
			if (m_cache.GetClassOfObject(ownerHvo) != StFootnote.kClassId)
				return; //don't override the props for this para; continue on gracefully
			ScrFootnote footnote = new ScrFootnote(Cache, ownerHvo);

			// Only add offset to first paragraph in footnote (should only be one para)
			int offset = 0;
			if (footnote.ParagraphsOS[0].Hvo == hvo)
			{
				int refLength = footnote.GetReference(m_wsDefault).Length;
				int markerLength = footnote.FootnoteMarker.Length;
				//add one for the space in between (added in StVc)
				offset = refLength + markerLength + 1;
			}

			const uint knNinch = 0x80000000;


			// Now add appropriate properties.
			// Need to add override properties for each run in the
			// range to be highlighted.
			int ichOverrideMin = diff.GetIchMin(m_fRev);
			ITsString tss = para.Contents.UnderlyingTsString;
			TsRunInfo runInfo;
			int ichOverrideLim;
			int prevLim = 0;
			do
			{
				tss.FetchRunInfoAt(ichOverrideMin, out runInfo);
				ichOverrideLim = Math.Min(diff.GetIchLim(m_fRev), runInfo.ichLim);
				// Prevent infinite loop in case of bad data in difference
				if (ichOverrideLim == prevLim)
					break;
				prevLim = ichOverrideLim;
				DispPropOverride prop = new DispPropOverride();
				prop.chrp.clrBack = DiffViewVc.kHighlightColor;
				prop.chrp.clrFore = knNinch;
				prop.chrp.clrUnder = knNinch;
				prop.chrp.dympOffset = -1;
				prop.chrp.ssv = -1;
				prop.chrp.unt = -1;
				prop.chrp.ttvBold = -1;
				prop.chrp.ttvItalic = -1;
				prop.chrp.dympHeight = -1;
				prop.chrp.szFaceName = null;
				prop.chrp.szFontVar = null;
				prop.ichMin = ichOverrideMin + offset;
				prop.ichLim = ichOverrideLim + offset;
				m_DispPropOverrides.Add(prop);
				ichOverrideMin = ichOverrideLim;
			}
			while (ichOverrideLim < diff.GetIchLim(m_fRev));
		}
Exemplo n.º 30
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Loads the footnotes.
		/// </summary>
		/// <param name="footnoteHvo">The footnote hvo.</param>
		/// ------------------------------------------------------------------------------------
		private void LoadFootnotes(int footnoteHvo)
		{
			Debug.Assert(m_cache.GetClassOfObject(footnoteHvo) == StFootnote.kClassId);
			StFootnote foot = new StFootnote(m_cache, footnoteHvo);
			IScrBook book = new ScrBook(m_cache, foot.OwnerHVO);
			int footnoteCount = GetBookFootnoteCount(book.Hvo);
			FdoOwningSequence<IStFootnote> footnotes = book.FootnotesOS;

			// If the information we want is already in the cache, then do nothing
			if (footnotes.Count == footnoteCount && m_htFootnoteIndex.ContainsKey(footnoteHvo))
				return;

			ScrFootnote footnote = null;
			int index = 0;
			for (int i = 0; i < footnotes.Count; i++)
			{
				footnote = new ScrFootnote(m_cache, footnotes.HvoArray[i]);
				if (footnote.FootnoteType == FootnoteMarkerTypes.AutoFootnoteMarker)
				{
					int oldIndex = GetFootnoteIndex(footnote.Hvo);
					if (oldIndex != index)
						m_htFootnoteIndex[footnote.Hvo] = new FootnoteIndexCacheInfo(index, true);
					index++;
				}
			}
			m_htBookFootnoteCount[book.Hvo] = footnotes.Count;
		}