GetFirstElementForStream() public method

Retrieves the page element that corresponds to the given stream. If multiple elements correspond to this stream, it gets the one with the smallest offset in the division (i.e., the one which corresponds to the highest place in the total document).
public GetFirstElementForStream ( IVwLayoutStream stream ) : SIL.FieldWorks.Common.PrintLayout.PageElement
stream IVwLayoutStream The stream
return SIL.FieldWorks.Common.PrintLayout.PageElement
Example #1
0
		/// -------------------------------------------------------------------------------------
		/// <summary>
		/// Inserts additonal pages if needed at dydPosition to approximately match the new
		/// estimated height when a lazy box has been expanded.
		/// </summary>
		/// <param name="changedSizePage">The last page whose top doesn't move (i.e., the one the
		/// lazy box is actually on). We may need to insert pages just after this.</param>
		/// <param name="strm">The IVwLayoutStream interface of the rootbox that is the main
		/// stream on at least some of the pages of this publication (i.e., this publication
		/// should be the IVwRootsite of the given rootbox).</param>
		/// <param name="dydSize">The amount the rootbox grew, in printer pixels. This is
		/// guaranteed to be positive.</param>
		/// <param name="dydPosition">The top of the lazy box which was (partially) expanded,
		/// split, etc (in printer pixels). Or the position of the top of the real box that got
		/// relazified.
		/// </param>
		/// <returns>true if there are not enough pages for the AutoScrollPosition to increase as
		/// much as required.</returns>
		/// -------------------------------------------------------------------------------------
		private bool InsertAdditionalPages(Page changedSizePage, IVwLayoutStream strm,
			int dydSize, int dydPosition)
		{
			Debug.Assert(changedSizePage != null);
			Debug.Assert(dydSize > 0);

			Page nextPage = PageAfter(changedSizePage);
			int heightOfChangedPage; // Current height, to next page or estimated end of doc.
			int iDiv = DivisionIndexForMainStream(strm);
			DivisionLayoutMgr divMgr = Divisions[iDiv];

			if (nextPage == null)
			{
				heightOfChangedPage = dydSize;
				// An empty page may have nothing from the main stream - can happen when project is
				// empty or filter excludes all content
				PageElement pe = changedSizePage.GetFirstElementForStream(strm);
				if (pe != null)
					heightOfChangedPage -= pe.OffsetToTopPageBoundary;
			}
			else
			{
				heightOfChangedPage = nextPage.OffsetFromTopOfDiv(divMgr) -
					changedSizePage.OffsetFromTopOfDiv(divMgr);
			}

			int desiredPageHeight = divMgr.AvailablePageHeightInPrinterPixels;
			// This computes the number of pages to add, if any, so that
			// if the tops of the pages are more than a page and a half apart we
			// insert enough pages so no page is more than an ideal page and a half long.
			// Subtracting half the desired page height accounts both for rounding and
			// the fact that one page (rather than zero) is the desired page height.
			int numberOfPagesToAdd = (heightOfChangedPage - desiredPageHeight / 2) /
				desiredPageHeight;
			// Pathologically, it might be possible for that calculation to produce
			// a negative number, if this page has shrunk to less than a half page from
			// previous lazy box expansions.
			if (numberOfPagesToAdd < 0)
				numberOfPagesToAdd = 0;
			Page pageToInsertAfter = changedSizePage;
			for (int i = 0; i < numberOfPagesToAdd; i++)
			{
				// Insert a new page.
				pageToInsertAfter = InsertPage(iDiv,
					pageToInsertAfter.OffsetFromTopOfDiv(divMgr) + desiredPageHeight,
					pageToInsertAfter);
			}
			// If we're increasing the autoscroll position, do it AFTER we possibly adjust
			// the autoscroll range, otherwise, the increased value might be greater than
			// the old range and get truncated.
			// Remember: Microsoft's idea of how to set AutoScrollPosition is brain-dead. We read
			// it as negative and have to set it as positive.
			int dydPosScreen = (int)(dydPosition * DpiYScreen / DpiYPrinter);
			if (-AutoScrollPosition.Y > dydPosScreen)
			{
				int dydDesiredAutoScrollY = (int)(AutoScrollPosition.Y - (dydSize * DpiYScreen /
					DpiYPrinter)); // larger negative
				AutoScrollPosition = new Point(
					-AutoScrollPosition.X, -dydDesiredAutoScrollY);
				// Something messy happened if we can't achieve that position (presumably
				// it is out of range, we didn't add enough pages).
				return (AutoScrollPosition.Y != dydDesiredAutoScrollY);
			}
			return false; // We get here only if we didn't have to adjust scroll position at all.
		}
Example #2
-12
//		/// ------------------------------------------------------------------------------------
//		/// <summary>
//		/// Determine the gap between the columns.
//		/// </summary>
//		/// <param name="numberColumns">The total number of columns.</param>
//		/// <returns>
//		/// If the element spans the whole width of the page, the column gap is 0.
//		/// Otherwise, it is ColumnGapWidthInPrinterPixels;
//		/// </returns>
//		/// ------------------------------------------------------------------------------------
//		private int ColumnGap(int numberColumns)
//		{
//			return (numberColumns > 1) ? ColumnGapWidthInPrinterPixels : 0;
//		}

		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Adds or adjusts the page element. Note that this is used ONLY for dependent objects,
		/// it arranges them from the bottom up. These elements don't overlap, so no overlap is
		/// passed.
		/// </summary>
		/// <param name="page">The page.</param>
		/// <param name="ysTopOfPrevElement">The top of the previous element.</param>
		/// <param name="ysStreamHeight">Height of the stream.</param>
		/// <param name="stream">The stream.</param>
		/// <param name="pagePosition">The page position.</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		private int AddOrAdjustPageElement(Page page, int ysTopOfPrevElement, int ysStreamHeight,
			IVwLayoutStream stream, int pagePosition)
		{
			Debug.Assert(!page.IsDisposed);

			if (ysStreamHeight <= 0)
				return ysTopOfPrevElement;

			int ysTopOfThisElement = ysTopOfPrevElement - ysStreamHeight;
			Rectangle rectLocationOnPage = new Rectangle(LeftMarginInPrinterPixels(page),
				ysTopOfThisElement,
				AvailablePageWidthInPrinterPixels,
				ysStreamHeight);

			PageElement element = page.GetFirstElementForStream(stream);
			if (element == null)
			{
				// Create page element
				page.AddPageElement(this, stream, false, rectLocationOnPage,
					pagePosition, false, 1, 1, 0,
					ysStreamHeight, 0, MainStreamIsRightToLeft, false);
			}
			else
			{
				// Increase size of page element
				if (element.LocationOnPage.Height != ysStreamHeight)
				{
					// Increase size of/move location
					page.AdjustPageElement(element, rectLocationOnPage, false);
				}
			}
			return ysTopOfThisElement;
		}