/*
 * SDK Pullenti Unitext, version 4.33, fabruary 2026. Copyright (c) 2013-2026, Pullenti. All rights reserved. 
 * Non-Commercial Freeware and Commercial Software. 
 * This class is generated using the converter UniSharping (www.unisharping.ru) from Pullenti C# project. 
 * The latest version of the code is available on the site www.pullenti.ru
 */

using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml;

namespace Pullenti.Unitext
{
    /// <summary>
    /// Информация о страницах и колонтитулах.
    /// </summary>
    public class UnitextPagesection : UnitextItem
    {
        /// <summary>
        /// Ширина страницы (в см)
        /// </summary>
        public double Width;
        /// <summary>
        /// Высота страницы (в см)
        /// </summary>
        public double Height;
        /// <summary>
        /// Левый отступ (в см)
        /// </summary>
        public double Left;
        /// <summary>
        /// Верхний отступ (в см)
        /// </summary>
        public double Top;
        /// <summary>
        /// Правый отступ (в см)
        /// </summary>
        public double Right;
        /// <summary>
        /// Нижний отступ (в см)
        /// </summary>
        public double Bottom;
        /// <summary>
        /// Высота верхнего колонтитула (в см)
        /// </summary>
        public double HeaderHeight;
        /// <summary>
        /// Высота нижнего колонтитула (в см)
        /// </summary>
        public double FooterHeight;
        /// <summary>
        /// Верхние и нижние колонтитулы (могут относиться к разным страницам - см. их тип)
        /// </summary>
        public List<UnitextPagesectionItem> Items = new List<UnitextPagesectionItem>();
        public override UnitextItem Clone()
        {
            UnitextPagesection res = new UnitextPagesection();
            res._cloneFrom(this);
            res.Width = Width;
            res.Height = Height;
            res.Left = Left;
            res.Right = Right;
            res.Top = Top;
            res.Bottom = Bottom;
            res.HeaderHeight = HeaderHeight;
            res.FooterHeight = FooterHeight;
            foreach (UnitextPagesectionItem it in Items) 
            {
                res.Items.Add(it.Clone() as UnitextPagesectionItem);
            }
            foreach (UnitextPagesectionItem it in res.Items) 
            {
                it.Parent = res;
            }
            if (m_StyledFrag != null) 
                res.m_StyledFrag = m_StyledFrag.Clone();
            return res;
        }
        public override string ToString()
        {
            return string.Format("Section {0}: {1}x{2}", Id, Pullenti.Util.MiscHelper.OutDouble(Width), Pullenti.Util.MiscHelper.OutDouble(Height));
        }
        public override void GetXml(XmlWriter xml)
        {
            xml.WriteStartElement("section");
            this._writeXmlAttrs(xml);
            if (Width > 0) 
                xml.WriteAttributeString("width", Pullenti.Util.MiscHelper.OutDouble(Width));
            if (Height > 0) 
                xml.WriteAttributeString("height", Pullenti.Util.MiscHelper.OutDouble(Height));
            if (Left > 0) 
                xml.WriteAttributeString("left", Pullenti.Util.MiscHelper.OutDouble(Left));
            if (Top > 0) 
                xml.WriteAttributeString("top", Pullenti.Util.MiscHelper.OutDouble(Top));
            if (Right > 0) 
                xml.WriteAttributeString("right", Pullenti.Util.MiscHelper.OutDouble(Right));
            if (Bottom > 0) 
                xml.WriteAttributeString("bottom", Pullenti.Util.MiscHelper.OutDouble(Bottom));
            if (HeaderHeight > 0) 
                xml.WriteAttributeString("header", Pullenti.Util.MiscHelper.OutDouble(HeaderHeight));
            if (FooterHeight > 0) 
                xml.WriteAttributeString("footer", Pullenti.Util.MiscHelper.OutDouble(FooterHeight));
            foreach (UnitextPagesectionItem it in Items) 
            {
                it.GetXml(xml);
            }
            xml.WriteEndElement();
        }
        double _parseDouble(string str)
        {
            double d;
            if (Pullenti.Util.MiscHelper.TryParseDouble(str, out d)) 
                return d;
            return 0;
        }
        public override void FromXml(XmlNode xml)
        {
            base.FromXml(xml);
            foreach (XmlAttribute a in xml.Attributes) 
            {
                if (a.LocalName == "width") 
                    Width = this._parseDouble(a.Value);
                else if (a.LocalName == "height") 
                    Height = this._parseDouble(a.Value);
                else if (a.LocalName == "left") 
                    Left = this._parseDouble(a.Value);
                else if (a.LocalName == "top") 
                    Top = this._parseDouble(a.Value);
                else if (a.LocalName == "right") 
                    Right = this._parseDouble(a.Value);
                else if (a.LocalName == "bottom") 
                    Bottom = this._parseDouble(a.Value);
                else if (a.LocalName == "header") 
                    HeaderHeight = this._parseDouble(a.Value);
                else if (a.LocalName == "footer") 
                    FooterHeight = this._parseDouble(a.Value);
            }
            foreach (XmlNode x in xml.ChildNodes) 
            {
                if (x.LocalName == "item") 
                {
                    UnitextPagesectionItem it = new UnitextPagesectionItem();
                    it.Parent = this;
                    it.FromXml(x);
                    Items.Add(it);
                }
            }
        }
        public override void GetAllItems(List<UnitextItem> res, int lev)
        {
            if (res != null) 
                res.Add(this);
            foreach (UnitextPagesectionItem it in Items) 
            {
                it.Parent = this;
                it.GetAllItems(res, lev + 1);
            }
        }
    }
}