Example #1
0
        /// update some or generate all cssbox
        /// </summary>
        /// <param name="parentElement"></param>
        /// <param name="fullmode">update all nodes (true) or somenode (false)</param>
        internal void UpdateChildBoxes(HtmlElement parentElement, bool fullmode)
        {
            //recursive ***
            //first just generate into primary pricipal box
            //layout process  will correct it later

            switch (parentElement.ChildrenCount)
            {
            case 0: { } break;

            case 1:
            {
                CssBox hostBox = HtmlElement.InternalGetPrincipalBox(parentElement);
                //only one child -- easy
                DomNode child  = parentElement.GetChildNode(0);
                int     newBox = 0;
                switch (child.NodeType)
                {
                case HtmlNodeType.TextNode:
                {
                    HtmlTextNode singleTextNode = (HtmlTextNode)child;
                    RunListHelper.AddRunList(hostBox, parentElement.Spec, singleTextNode);
                }
                break;

                case HtmlNodeType.ShortElement:
                case HtmlNodeType.OpenElement:
                {
                    HtmlElement childElement = (HtmlElement)child;
                    var         spec         = childElement.Spec;
                    if (spec.CssDisplay == CssDisplay.None)
                    {
                        return;
                    }

                    newBox++;
                    //--------------------------------------------------
                    if (fullmode)
                    {
                        CssBox newbox = CreateBox(hostBox, childElement, fullmode);
                        childElement.SetPrincipalBox(newbox);
                    }
                    else
                    {
                        CssBox existing = HtmlElement.InternalGetPrincipalBox(childElement);
                        if (existing == null)
                        {
                            CssBox box = CreateBox(hostBox, childElement, fullmode);
                            childElement.SetPrincipalBox(box);
                        }
                        else
                        {
                            //just insert
                            hostBox.AppendChild(existing);
                            if (!childElement.SkipPrincipalBoxEvalulation)
                            {
                                existing.Clear();
                                UpdateChildBoxes(childElement, fullmode);
                                childElement.SkipPrincipalBoxEvalulation = true;
                            }
                        }
                    }
                }
                break;
                }
            }
            break;

            default:
            {
                CssBox        hostBox    = HtmlElement.InternalGetPrincipalBox(parentElement);
                CssWhiteSpace ws         = parentElement.Spec.WhiteSpace;
                int           childCount = parentElement.ChildrenCount;
                int           newBox     = 0;
                for (int i = 0; i < childCount; ++i)
                {
                    var childNode = parentElement.GetChildNode(i);
                    switch (childNode.NodeType)
                    {
                    case HtmlNodeType.TextNode:
                    {
                        HtmlTextNode textNode = (HtmlTextNode)childNode;
                        switch (ws)
                        {
                        case CssWhiteSpace.Pre:
                        case CssWhiteSpace.PreWrap:
                        {
                            RunListHelper.AddRunList(
                                CssBox.AddNewAnonInline(hostBox),
                                parentElement.Spec, textNode);
                        }
                        break;

                        case CssWhiteSpace.PreLine:
                        {
                            if (newBox == 0 && textNode.IsWhiteSpace)
                            {
                                continue;                        //skip
                            }

                            RunListHelper.AddRunList(
                                CssBox.AddNewAnonInline(hostBox),
                                parentElement.Spec, textNode);
                        }
                        break;

                        default:
                        {
                            if (textNode.IsWhiteSpace)
                            {
                                continue;                        //skip
                            }
                            RunListHelper.AddRunList(
                                CssBox.AddNewAnonInline(hostBox),
                                parentElement.Spec, textNode);
                        }
                        break;
                        }

                        newBox++;
                    }
                    break;

                    case HtmlNodeType.ShortElement:
                    case HtmlNodeType.OpenElement:
                    {
                        HtmlElement childElement = (HtmlElement)childNode;
                        var         spec         = childElement.Spec;
                        if (spec.CssDisplay == CssDisplay.None)
                        {
                            continue;
                        }

                        if (fullmode)
                        {
                            CssBox box = CreateBox(hostBox, childElement, fullmode);
                        }
                        else
                        {
                            CssBox existingCssBox = HtmlElement.InternalGetPrincipalBox(childElement);
                            if (existingCssBox == null)
                            {
                                CssBox box = CreateBox(hostBox, childElement, fullmode);
                            }
                            else
                            {
                                //just insert
                                hostBox.AppendChild(existingCssBox);
                                if (!childElement.SkipPrincipalBoxEvalulation)
                                {
                                    existingCssBox.Clear();
                                    UpdateChildBoxes(childElement, fullmode);
                                    childElement.SkipPrincipalBoxEvalulation = true;
                                }
                            }
                        }
                        newBox++;
                    }
                    break;

                    default:
                    {
                    }
                    break;
                    }
                }
            }
            break;
            }
            //----------------------------------
            //summary formatting context
            //that will be used on layout process
            //----------------------------------
        }
        public static CssBox CreateListItemBox(CssBox parent, HtmlElement childElement)
        {
            var spec   = childElement.Spec;
            var newBox = new CssBoxListItem(spec, parent.RootGfx);

            newBox.SetController(childElement);
            parent.AppendChild(newBox);
            if (spec.ListStyleType != CssListStyleType.None)
            {
                //create sub item collection
                var itemBulletBox = new CssBox(spec.GetAnonVersion(), parent.RootGfx);
                newBox.BulletBox = itemBulletBox;
                CssBox.UnsafeSetParent(itemBulletBox, newBox);
                CssBox.ChangeDisplayType(itemBulletBox, CssDisplay.Inline);
                //---------------------------------------------------------------
                //set content of bullet
                char[] text_content = null;
                switch (spec.ListStyleType)
                {
                case CssListStyleType.Disc:
                {
                    text_content = discItem;
                }
                break;

                case CssListStyleType.Circle:
                {
                    text_content = circleItem;
                }
                break;

                case CssListStyleType.Square:
                {
                    text_content = squareItem;
                }
                break;

                case CssListStyleType.Decimal:
                {
                    text_content = (GetIndexForList(newBox, childElement).ToString(CultureInfo.InvariantCulture) + ".").ToCharArray();
                }
                break;

                case CssListStyleType.DecimalLeadingZero:
                {
                    text_content = (GetIndexForList(newBox, childElement).ToString("00", CultureInfo.InvariantCulture) + ".").ToCharArray();
                }
                break;

                default:
                {
                    text_content = (BulletNumberFormatter.ConvertToAlphaNumber(GetIndexForList(newBox, childElement), spec.ListStyleType) + ".").ToCharArray();
                }
                break;
                }
                //---------------------------------------------------------------
                CssBox.UnsafeSetTextBuffer(itemBulletBox, text_content);
                List <CssRun> runlist = new List <CssRun>();
                bool          hasSomeCharacter;
                splitter.ParseWordContent(text_content, spec, itemBulletBox.IsBlock, runlist, out hasSomeCharacter);
                RunListHelper.AddRunList(itemBulletBox, spec, runlist, text_content, false);
            }
            return(newBox);
        }