BuiltInListStyles.cs
//
// This code is part of Document Solutions for Word demos.
// Copyright (c) MESCIUS inc. All rights reserved.
//
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using GrapeCity.Documents.Word;
using GrapeCity.Documents.Imaging;

namespace DsWordWeb.Demos
{
    // This sample demoes all built-in list template available in DsWord.
    public class BuiltInListStyles
    {
        public GcWordDocument CreateDocx()
        {
            var doc = new GcWordDocument();
            var pars = doc.Body.Paragraphs;

            pars.Add("Demo of All Built-in List Templates", doc.Styles[BuiltInStyleId.Title]);

            int n = 0;
            foreach (BuiltInListTemplateId id in Enum.GetValues(typeof(BuiltInListTemplateId)))
            {
                var listTemplate = doc.ListTemplates.Add(id, $"listTemplate{n++}");
                pars.Add($"List formatted using built-in list template '{listTemplate.Name}':");
                int m = 0;
                Stack<int> levels = new Stack<int>(new int[] { m });
                foreach (var i in new int[]{ 0, 0, 0, 1, 1, 2, 2, 2, 1 })
                {
                    if (i > levels.Count)
                    {
                        levels.Push(m);
                        m = 0;
                    }
                    else if (i < levels.Count)
                        m = levels.Pop();

                    var p = pars.Add($"List item {m++} on level {levels.Count}.", doc.Styles[BuiltInStyleId.ListParagraph]);
                    p.ListFormat.Template = listTemplate;
                    p.ListFormat.LevelNumber = i;
                }
            }

            // Done:
            return doc;
        }
    }
}