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

'' This sample demoes all built-in list template available in DsWord.
Public Class BuiltInListStyles
    Public Function CreateDocx() As GcWordDocument
        Dim doc = New GcWordDocument()
        Dim pars = doc.Body.Paragraphs

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

        Dim n = 0
        For Each id In [Enum].GetValues(GetType(BuiltInListTemplateId))
            Dim listTemplate = doc.ListTemplates.Add(id, $"listTemplate{n}")
            n += 1
            pars.Add($"List formatted using built-in list template '{listTemplate.Name}':")
            Dim m = 0
            Dim levels = New Stack(Of Integer)
            levels.Push(m)
            For Each i In New Integer() {0, 0, 0, 1, 1, 2, 2, 2, 1}
                If (i > levels.Count) Then
                    levels.Push(m)
                    m = 0
                ElseIf (i < levels.Count) Then
                    m = levels.Pop()
                End If

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

        '' Done
        Return doc
    End Function
End Class