OffsetFromTopOfDiv() public method

Gets the number of printer pixels (source/layout units) from the top of the given division's main layout stream to the top of the data represented by the first page element on this page for that stream. This may only be an estimate, particularly if: this page has no elements (at least for the given division) this page is broken there are previous pages that are not fully laid out (or broken)
Public to make testing easier.
public OffsetFromTopOfDiv ( SIL.FieldWorks.Common.PrintLayout.DivisionLayoutMgr div ) : int
div SIL.FieldWorks.Common.PrintLayout.DivisionLayoutMgr The division layout manager.
return int
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
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Layout a page :-)
		/// </summary>
		/// <param name="page">The page to lay out</param>
		/// <returns><c>true</c> if the remainder of this division completely fits on this page;
		/// <c>false</c> if there is additional material from this division to lay out on
		/// subsequent pages.</returns>
		/// ------------------------------------------------------------------------------------
		internal bool LayoutPage(Page page)
		{
			CheckDisposed();
			Debug.Assert(!page.IsDisposed);

			using (new SuspendDrawing(Publication))
			using (new WaitCursor(Publication))
			{
				int offsetFromTopOfDiv = page.OffsetFromTopOfDiv(this);
				int ysStartNextPage;
				int leftMargin = LeftMarginInPrinterPixels(page);

				int dysSpaceUsedOnPage;
				IVwGraphics vg = Publication.PrinterGraphics;
				MainLayoutStream.LayoutPage(vg, AvailableMainStreamColumWidthInPrinterPixels,
					page.FreeSpace.Height, ref offsetFromTopOfDiv, page.Handle,
					m_numberMainStreamColumns, out dysSpaceUsedOnPage, out ysStartNextPage);
				Publication.ReleaseGraphics(vg);

				// It's possible that the layout deleted the page (TE-7839)
				if (page.IsDisposed)
				{
					Debug.WriteLine("Page got deleted in MainLayoutStream.LayoutPage.");
					return true;
				}

				if (dysSpaceUsedOnPage == 0)
				{
					Debug.WriteLine(string.Format("Division '{0}' didn't use any space on page {1}",
						Name, page.PageNumber));
					return true;
				}

				// Layout and add column page elements in main layout stream.
				for (int iColumn = 0; iColumn < m_numberMainStreamColumns; iColumn++)
				{
					int heightThisColumn = MainLayoutStream.ColumnHeight(iColumn);
					int overlapThisColumn = MainLayoutStream.ColumnOverlapWithPrevious(iColumn);
					AddElement(page, dysSpaceUsedOnPage, iColumn + 1, m_numberMainStreamColumns, leftMargin,
						offsetFromTopOfDiv, heightThisColumn, overlapThisColumn);

					offsetFromTopOfDiv += heightThisColumn;
				}

				bool fCompletedDivision = (ysStartNextPage <= 0);
				if (!fCompletedDivision)
				{
					// We need more pages for this division; nothing more on this page
					Page nextPage = Publication.PageAfter(page);
					if (nextPage != null && Publication.Divisions[nextPage.FirstDivOnPage] == this)
					{
						// There is already another page for this division; adjust its start position.
						nextPage.AdjustOffsetFromTopOfDiv(ysStartNextPage);
					}
					else
					{
						// There are no more pages for this division; insert one.
						nextPage = InsertPage(ysStartNextPage, page);
					}
				}
				else
				{
					// Delete any subsequent pages for this same division.
					for (Page nextPage = Publication.PageAfter(page); nextPage != null; )
					{
						// If nextPage belongs to another division, we're all done.
						if (nextPage.FirstDivOnPage < Publication.Divisions.Count &&
							Publication.Divisions[nextPage.FirstDivOnPage] != this)
							break;
						Page delPage = nextPage;
						nextPage = Publication.PageAfter(nextPage);
						Publication.DeletePage(delPage);
					}
				}
				return fCompletedDivision;
			}
		}
Example #3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Ensure that the data corresponding to the location of the given page consists of
		/// real boxes, not lazy ones.
		/// </summary>
		/// <param name="page"></param>
		/// <returns>true if it had to do anything...the caller should recheck the scroll
		/// position and which pages need drawing, and call again.</returns>
		/// ------------------------------------------------------------------------------------
		public bool EnsureRealBoxAt(Page page)
		{
			CheckDisposed();

			bool result = false;
			DivisionLayoutMgr div = m_divisions[page.FirstDivOnPage];
			// ENHANCE (TE-5866): Do this for all divisions on the page.

			IVwGraphics vg = PrinterGraphics;
			try
			{
				int offset = page.OffsetFromTopOfDiv(div);
				Rect rcPage = new Rect(0, offset, PageWidthInPrinterPixels,
					offset + PageHeightInPrinterPixels);
				((IVwGraphicsWin32)vg).SetClipRect(ref rcPage);
				Rect rcTrans = new Rect(0, 0, (int)DpiXPrinter, (int)DpiYPrinter);
				// Make sure we have real data in this section of the root.
				if (div.MainRootBox != null)
				{
					result = div.MainRootBox.PrepareToDraw(vg, rcTrans, rcTrans) !=
						VwPrepDrawResult.kxpdrNormal;
				}
			}
			finally
			{
				ReleaseGraphics(vg);
			}
			return result;
		}