GetNumberOfLevels() public method

Gets the number of levels needed to traverse the view objects to reach the given limit of the selection.
public GetNumberOfLevels ( SelLimitType type ) : int
type SelLimitType
return int
示例#1
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);
				}
			}
		}
示例#2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Deletes a section heading.
		/// </summary>
		/// <param name="helper">Selection information</param>
		/// <param name="allowHeadingText">if <code>true</code> section head will be deleted
		/// even if heading contains text</param>
		/// <param name="positionAtEnd">if <code>true</code> IP will be at end of paragraph
		/// before top point of current selection</param>
		/// <returns><code>true</code> if deletion was done</returns>
		/// ------------------------------------------------------------------------------------
		private bool DeleteSectionHead(SelectionHelper helper, bool allowHeadingText,
			bool positionAtEnd)
		{
			ILocationTracker tracker = ((ITeView)Control).LocationTracker;
			if (helper.GetNumberOfLevels(SelectionHelper.SelLimitType.Top) !=
				tracker.GetLevelCount((int)ScrSection.ScrSectionTags.kflidContent))
				return false;
			int tag = helper.GetTextPropId(SelectionHelper.SelLimitType.Top);
			if (tag != (int)StTxtPara.StTxtParaTags.kflidContents &&
				tag != SimpleRootSite.kTagUserPrompt)
			{
				// Currently this is the only possible leaf property in draft view;
				// if this changes somehow, we'll probably need to enhance this code.
				Debug.Assert(false);
				return false;
			}
			int hvoBook = tracker.GetBookHvo(helper, SelectionHelper.SelLimitType.Top);
			if (hvoBook < 0)
			{
				Debug.Assert(false);
				return false;
			}
			ScrBook book = new ScrBook(m_cache, hvoBook);

			int iSection = tracker.GetSectionIndexInBook(helper, SelectionHelper.SelLimitType.Top);
			if (iSection < 0)
			{
				// Something changed catastrophically. Book has something in it other than sections.
				Debug.Assert(false);
				return false;
			}
			IScrSection section = book.SectionsOS[iSection];

			if (helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[0].tag !=
				(int)StText.StTextTags.kflidParagraphs)
			{
				// Something changed catastrophically. StText has something in it other than paragraphs!
				Debug.Assert(false);
				return false;
			}
			// For now we just handle the heading.
			if (helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[1].tag !=
				(int)ScrSection.ScrSectionTags.kflidHeading)
			{
				// Add code here if desired to handle bsp/del at boundary of body.
				return false;
			}

			// OK, we're dealing with a change at the boundary of a section heading
			// (in a paragraph of an StText that is the heading of an ScrSection in an ScrBook).
			IStText text = section.HeadingOA;
			int ihvoPara = helper.GetLevelInfo(SelectionHelper.SelLimitType.Top)[0].ihvo;
			IStTxtPara para = (IStTxtPara)(text.ParagraphsOS[ihvoPara]);

			if (!allowHeadingText && para.Contents.Length > 0)
			{
				// The current heading paragraph has something in it!
				// For now we won't try to handle this.
				// (The problem is knowing what to do with the undeleted header text...
				// make it part of the previous section? The previous header? Delete it?)
				return false;
			}
			if (text.ParagraphsOS.Count != 1)
			{
				// Backspace at start or delete at end of non-empty section, and the paragraph is
				// empty. Do nothing.
				return false;

				// Other options:
				// - delete the section? But what do we do with the rest of its heading?
				// - delete the empty paragraph? That's easy...just
				//		text.ParagraphsOS.RemoveAt(ihvoPara);
				// But where do we put the IP afterwards? At the end of the previous body,
				// for bsp, or the start of our own body, for del? Or keep it in the heading?
			}
			// OK, we're in a completely empty section heading.
			// If it's the very first section of the book, we can't join it to the previous
			// section, so do nothing. (May eventually enhance to join the two books...
			// perhaps after asking for confirmation!)
			if (iSection == 0)
				return false;
			// Finally...we know we're going to merge the two sections.
			MergeContentWithPreviousSection(helper, book, section, iSection, positionAtEnd);
			return true;
		}
		protected override int GetInsertionIndex(int[] hvos, SelectionHelper sel)
		{
			if (sel.GetNumberOfLevels(SelectionHelper.SelLimitType.Top) == 0)
			{
				int cellId = GetCell(sel, SelectionHelper.SelLimitType.Top);
				switch (cellId)
				{
					case PhMetathesisRule.kidxLeftEnv:
						return 0;

					case PhMetathesisRule.kidxLeftSwitch:
						if (Rule.MiddleIndex != -1)
							return Rule.MiddleIndex;
						else if (Rule.RightSwitchIndex != -1)
							return Rule.RightSwitchIndex;
						else if (Rule.RightEnvIndex != -1)
							return Rule.RightEnvIndex;
						break;

					case PhMetathesisRule.kidxRightSwitch:
						if (Rule.RightEnvIndex != -1)
							return Rule.RightEnvIndex;
						break;
				}
				return hvos.Length;
			}
			else
			{
				return base.GetInsertionIndex(hvos, sel);
			}
		}
示例#4
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Go to the next paragraph looking at the specified selection helper.
		/// </summary>
		/// <returns>A new selection for the next paragraph, or null if there is no next
		/// paragraph</returns>
		/// ------------------------------------------------------------------------------------
		private IVwSelection FindNextPara(SelectionHelper helper)
		{
			IVwRootBox rootb = helper.RootSite.RootBox;

			int level = helper.GetNumberOfLevels(SelectionHelper.SelLimitType.Top) - 1;
			while (level >= 0)
			{
				int iBox = helper.Selection.get_BoxIndex(false, level);
				IVwSelection sel =  rootb.MakeSelInBox(helper.Selection, false, level,
					iBox + 1, true, false, false);
				if (sel != null)
					return sel; // We found the next paragraph

				// Try the next level up
				level--;
			}

			return null;
		}
		protected override int GetItemHvo(SelectionHelper sel, SelectionHelper.SelLimitType limit)
		{
			if (Rule.StrucDescOS.Count == 0 || sel.GetNumberOfLevels(limit) == 0)
				return 0;

			SelLevInfo[] levels = sel.GetLevelInfo(limit);
			return levels[levels.Length - 1].hvo;
		}
示例#6
0
			/// ------------------------------------------------------------------------------------
			/// <summary>
			/// Set both book and section. Don't make a selection; typically the caller will proceed
			/// to do that.
			/// </summary>
			/// <param name="selHelper">The selection helper.</param>
			/// <param name="selLimitType">Which end of the selection</param>
			/// <param name="iBook">The index of the book (in the book filter).</param>
			/// <param name="iSection">The index of the section (relative to
			/// <paramref name="iBook"/>), or -1 for a selection that is not in a section (e.g.
			/// title).</param>
			/// <remarks>This method should change only the book and section levels of the
			/// selection, but not any other level.</remarks>
			/// ------------------------------------------------------------------------------------
			public override void SetBookAndSection(SelectionHelper selHelper,
				SelectionHelper.SelLimitType selLimitType, int iBook, int iSection)
			{
				if (selHelper == null)
					return;

				// we can only deal with one book
				if (iBook != GetBookIndex(null, selLimitType) || iSection < 0)
					return;

				int nLevels = selHelper.GetNumberOfLevels(selLimitType);
				selHelper.GetLevelInfo(selLimitType)[nLevels - 1].tag =
					(int)ScrBook.ScrBookTags.kflidSections;
				selHelper.GetLevelInfo(selLimitType)[nLevels - 1].ihvo = iSection;
			}
		protected override ICmObject GetItem(SelectionHelper sel, SelectionHelper.SelLimitType limit)
		{
			if (Rule.StrucDescOS.Count == 0 || sel.GetNumberOfLevels(limit) == 0)
				return null;

			var levels = sel.GetLevelInfo(limit);
			return m_cache.ServiceLocator.GetObject(levels[levels.Length - 1].hvo);
		}
示例#8
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Set both book and section. Don't make a selection; typically the caller will proceed
		/// to do that.
		/// </summary>
		/// <param name="selHelper">The selection helper.</param>
		/// <param name="selLimitType">Which end of the selection</param>
		/// <param name="iBook">The index of the book (in the book filter).</param>
		/// <param name="iSection">The index of the section (relative to
		/// <paramref name="iBook"/>), or -1 for a selection that is not in a section (e.g.
		/// title).</param>
		/// <remarks>This method should change only the book and section levels of the
		/// selection, but not any other level.</remarks>
		/// ------------------------------------------------------------------------------------
		public virtual void SetBookAndSection(SelectionHelper selHelper,
			SelectionHelper.SelLimitType selLimitType, int iBook, int iSection)
		{
			if (!Visible)
				return;

			int newHvoBook = m_bookFilter.GetBook(iBook).Hvo;
			ScrBook book = new ScrBook(m_cache, newHvoBook);
			int[] hvoAllSections = book.SectionsOS.HvoArray;
			if (iSection < 0 || iSection >= hvoAllSections.Length)
				return; // We won't be able to find our section (TE-8242)

			foreach (DivisionLayoutMgr div in Divisions)
			{
				if (div.Configurer.MainObjectId != newHvoBook)
					continue; // We don't care about the division if it doesn't use our book

				FocusedStream = div.MainLayoutStream;

				TePrintLayoutConfig configurer = div.Configurer as TePrintLayoutConfig;
				if (configurer == null)
					continue;

				int hvoSection = hvoAllSections[iSection];
				IFilter filter = configurer.SectionFilter.Filter;
				if (!filter.MatchesCriteria(hvoSection))
				{
					// This division doesn't contain the desired section, so we try
					// the following section
					continue;
				}

				// Find the index of the section in the filtered section list,
				// i.e. in the view
				int iSectionInView = -1;
				int iSectionLim = Math.Min(hvoAllSections.Length, iSection + 1);
				for (int iSectionInBook = 0; iSectionInBook < iSectionLim;
					iSectionInBook++)
				{
					if (filter.MatchesCriteria(hvoAllSections[iSectionInBook]))
						iSectionInView++;
				}

				if (iSectionInView < 0)
					continue;

				selHelper.GetLevelInfo(selLimitType)[selHelper.GetNumberOfLevels(selLimitType) - 1].tag =
					GetSectionTag(configurer);
				selHelper.GetLevelInfo(selLimitType)[selHelper.GetNumberOfLevels(selLimitType) - 1].ihvo =
					iSectionInView;

				// We found the division that used the book we care about so lets quit
				return;
			}

			ApplicationException e = new ApplicationException(
				"Can't find division for given book and index");
			e.Data.Add("iBook", iBook);
			e.Data.Add("iSection", iSection);
			e.Data.Add("View name", Name);
			throw e;
		}
示例#9
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Set both book and section. Don't make a selection; typically the caller will proceed
		/// to do that.
		/// </summary>
		/// <param name="selHelper">The selection helper.</param>
		/// <param name="selLimitType">Which end of the selection</param>
		/// <param name="iBook">The index of the book (in the book filter).</param>
		/// <param name="iSection">The index of the section (relative to
		/// <paramref name="iBook"/>), or -1 for a selection that is not in a section (e.g.
		/// title).</param>
		/// <remarks>This method should change only the book and section levels of the
		/// selection, but not any other level.</remarks>
		/// ------------------------------------------------------------------------------------
		public virtual void SetBookAndSection(SelectionHelper selHelper,
			SelectionHelper.SelLimitType selLimitType, int iBook, int iSection)
		{
			if (selHelper == null || iBook < 0)
				return;

			int nLevels = selHelper.GetNumberOfLevels(selLimitType);
			if (nLevels == 0)
			{
				Debug.Fail("This should not happen!!!");
				return;
			}

			selHelper.GetLevelInfo(selLimitType)[nLevels - 1].tag = BookTag;
			selHelper.GetLevelInfo(selLimitType)[nLevels - 1].ihvo = iBook;

			if (iSection >= 0 && nLevels >= 2)
			{
				selHelper.GetLevelInfo(selLimitType)[nLevels - 2].tag = ScrBookTags.kflidSections;
				selHelper.GetLevelInfo(selLimitType)[nLevels - 2].ihvo = iSection;
			}
		}