/// <summary>
        /// Removes the last item from this region and checks
        /// to make sure that the item removed matches the povided item
        /// </summary>
        /// <param name="ensureitem"></param>
        public void AssertRemoveLastItem(PDFLayoutItem ensureitem)
        {
            PDFLayoutItem removed = this.RemoveLastItem();

            if (removed != ensureitem)
            {
                throw new ArgumentOutOfRangeException("ensureItem");
            }
        }
        /// <summary>
        /// Internal method that changes the parent of this item - cannot be null
        /// </summary>
        /// <param name="item"></param>
        internal void SetParent(PDFLayoutItem item)
        {
            if (null == item)
            {
                throw new ArgumentNullException("item");
            }

            this.Parent = item;
        }
Exemple #3
0
        protected virtual IPDFResourceContainer GetParentResourceRegister()
        {
            PDFLayoutItem parent = this.Parent;

            while (null != parent && !(parent is IPDFResourceContainer))
            {
                parent = parent.Parent;
            }
            return(parent as IPDFResourceContainer);
        }
        internal protected PDFLayoutBlock GetParentBlock()
        {
            PDFLayoutItem parent = this.Parent;

            while (null != parent && !(parent is PDFLayoutBlock))
            {
                parent = parent.Parent;
            }
            return(parent as PDFLayoutBlock);
        }
 /// <summary>
 /// Removes the latout item from this regions contents if it exists. Returns true if it was removed, otherwise false
 /// </summary>
 /// <param name="ensureItem"></param>
 /// <returns></returns>
 public bool RemoveItem(PDFLayoutItem ensureItem)
 {
     if (null != ensureItem)
     {
         return(this.Contents.Remove(ensureItem));
     }
     else
     {
         return(false);
     }
 }
        /// <summary>
        /// Increases the size of this region by the size of the layout item
        /// </summary>
        /// <param name="item"></param>
        public void AddToSize(PDFLayoutItem item)
        {
            PDFUnit h = item.Height;
            PDFUnit w = item.Width;

            //Update the size
            PDFSize sz = this.UsedSize;

            sz.Height    += h;
            sz.Width      = PDFUnit.Max(sz.Width, w);
            this.UsedSize = sz;
        }
        /// <summary>
        /// Checks that the last item in this region is closed
        /// </summary>
        protected virtual void AssertLastItemIsClosed()
        {
            if (null == _contents || _contents.Count == 0)
            {
                return;
            }
            PDFLayoutItem last = _contents[_contents.Count - 1];

            if (!last.IsClosed)
            {
                throw new InvalidOperationException(Errors.LayoutContainerHasExistingOpenItem);
            }
        }
        /// <summary>
        /// Closes the currently open line or block
        /// </summary>
        /// <returns>true if the line was closed.</returns>
        public void CloseCurrentItem()
        {
            //Current line will throw an exeception if this region is closed.
            PDFLayoutItem last = this.CurrentItem;

            if (null != last && !last.IsClosed)
            {
                //We have a line so lets try to close it.
                last.Close();

                //AddToSize(last);
            }
        }
        /// <summary>
        /// Gets the index of the page this item is positioned on
        /// </summary>
        /// <returns></returns>
        protected int GetPageIndex()
        {
            PDFLayoutItem item = this;

            while (null != item)
            {
                if (item is PDFLayoutPage)
                {
                    return((item as PDFLayoutPage).PageIndex);
                }
                else
                {
                    item = item.Parent;
                }
            }
            return(NULL_PAGEINDEX);
        }
        /// <summary>
        /// Removes and returns the last item in this region. If this region doesn't have any contents, then returns null.
        /// </summary>
        /// <returns>The last item removed</returns>
        public PDFLayoutItem RemoveLastItem()
        {
            //this.AssertIsOpen();

            if (this._contents == null || _contents.Count == 0)
            {
                return(null);
            }

            int           last    = this.Contents.Count - 1;
            PDFLayoutItem removed = this.Contents[last];

            if (removed is PDFLayoutLine)
            {
                ((PDFLayoutLine)removed).LineIndex = -1;
            }
            this.Contents.RemoveAt(last);
            return(removed);
        }
        //
        // methods
        //

        #region public PDFLayoutBlock LastOpenBlock()

        /// <summary>
        /// Returns the last block in this region that is open.
        /// Returns null if this region does not contain any blocks, or the last block is closed.
        /// </summary>
        /// <returns></returns>
        public PDFLayoutBlock LastOpenBlock()
        {
            if (null != this.Contents && this.Contents.Count > 0)
            {
                PDFLayoutItem item = this.Contents[this.Contents.Count - 1];
                if (item is PDFLayoutBlock)
                {
                    PDFLayoutBlock block = item as PDFLayoutBlock;
                    if (block.IsClosed == false)
                    {
                        return(block.LastOpenBlock());
                    }
                }
                else
                {
                    //the last item is not a block, so any previous blocks must be closed.
                }
            }
            return(null);
        }
        /// <summary>
        /// Gets the index of the column this item is positioned on
        /// </summary>
        /// <returns></returns>
        protected int GetColumnIndex()
        {
            PDFLayoutItem item = this;

            while (null != item)
            {
                if (item is PDFLayoutRegion)
                {
                    return((item as PDFLayoutRegion).ColumnIndex);
                }
                else if (item is PDFLayoutBlock)
                {
                    return((item as PDFLayoutBlock).CurrentRegion.ColumnIndex);
                }
                else
                {
                    item = item.Parent;
                }
            }
            return(NULL_COLUMNINDEX);
        }
        //
        // ctor(s)
        //

        #region protected PDFLayoutItem(PDFLayoutItem parent)

        /// <summary>
        /// Creates a new PDFLayout item
        /// </summary>
        /// <param name="parent"></param>
        protected PDFLayoutItem(PDFLayoutItem parent, IPDFComponent owner)
        {
            this.Owner    = owner;
            this.Parent   = parent;
            this.IsClosed = false;
        }
        //
        // .ctor(s)
        //

        #region protected PDFLayoutContainerItem(PDFLayoutItem parent, IPDFComponent owner, IPDFLayoutEngine engine, PDFStyle full)

        /// <summary>
        /// Creates a new PDFLayoutContainerItem with the specified parent, owner and style
        /// </summary>
        /// <param name="parent">The parent container of this item</param>
        /// <param name="owner">The component owner of this item</param>
        /// <param name="full">The style applied to this item based on it's container owner</param>
        protected PDFLayoutContainerItem(PDFLayoutItem parent, IPDFComponent owner, IPDFLayoutEngine engine, Style full)
            : base(parent, owner)
        {
            this.FullStyle = full;
            this.Engine    = engine;
        }