'#Reference {A3B5C45B-F842-44fc-A5E5-50CED69BA86E}#2.0#0#C:\Program Files\Mindjet\MindManager 6\Mm5WebExport.dll#Mm5webexport 2.0 Type Library
'#Uses "TOCHandler.cls"
'#Uses "GlobalUtilities.mmbas"
'#Uses "GlobalParameterNames.mmbas"
'#Uses "GlobalTypes.mmbas"

Dim CurrentBranchLevel As Long
Dim LevelCounter As Long
Dim TheOutlineNumber As String
Dim MainTopicCounter As Long
Dim LastLevel As Long

Dim s As Long
Dim CurrentOutlineNumber As String
Dim NumberOfLevelsToJumpDown As Long

Option Explicit

Sub Main

Dim m_Addin As Mm5WebExportAddIn
Dim m_Webex As WebExport
Dim m_Page As Mm5WebExportLib.Page
Dim m_Topic As Topic
Dim s_BodyString As String

	Set m_Addin = WebExportHelper.WebExportAddIn
	Set m_Webex = m_Addin.ActiveWebExport

	On Error GoTo ReportError

	m_Webex.Trace("Entering OneCntOutItem.mmbas",2)

	' Get the central topic object
	Set m_Page = m_Webex.ActivePage
	Set m_Topic = m_Page.GetTopic(1).Document.CentralTopic ' find central topic
	m_Webex.ActiveTopic = m_Topic ' generate WebExport.CurrentTopic.Text parameter

	m_Webex.Trace("Single_Contents_OutlineItem.mmbas - Starting recursive call",1)

	' Recursive map traversal
	' Outline level counter initialization
	LastLevel = 0
	MainTopicCounter = 0
	Call MapTraversal(m_Topic, s_BodyString, m_Webex)

	' Store our result
	m_Webex.PushString(s_BodyString)

	m_Webex.Trace("Exiting OneCntOutItem.mmbas",2)

	Exit Sub

ReportError:
	ProcessError(m_Webex)

End Sub

Function MapTraversal(ByVal oneTopic As Topic, ByRef bodyString As String, ByRef webex As WebExport)

   Dim oneTOCHandler As TOCHandler
   Dim nextTopic As Topic
   Dim TopicCount As Integer
   Dim LocalTemplate As String
   Dim LocalTopicString As String
   Dim k As Long
   Dim l As Long
   Dim TheTOCNumber As String
   Dim TopicText As String
   Dim TopicLink As HyperlinkData

   Set oneTOCHandler = New TOCHandler

		' Keep track of "recurse level"
		LevelCounter = LevelCounter + 1

        TopicCount = oneTopic.SubTopics(False).Count

          For k = 1 To TopicCount

            Set nextTopic = oneTopic.SubTopics(False).Item(k)

                 TheTOCNumber = oneTOCHandler.GetOutlineNumberForTopic(nextTopic, _
                 	webex.GetParameter("Strings.Show.NumberToLevel"))

                 TopicLink = TopicHyperlink(webex, nextTopic)

                 webex.SetParameter("CustomParameter.TopicHyperlink", TopicLink.Url)
                 webex.SetParameter("CustomParameter.TopicText", VerifyTopicText(webex, nextTopic))
                 webex.SetParameter("CustomParameter.TopicTarget", TargetAttribute(TopicLink))

                 ' Enforce maximum "TOC level"
                 webex.SetParameter("CustomParameter.TOCOutlineNumberToWrite", TheTOCNumber)

                 ' Enforce maximum "indentation levels"
                 If LevelCounter > 5 Then
                     webex.SetParameter("CustomParameter.TOCOutlineLevel", "x")
                    Else
                     webex.SetParameter("CustomParameter.TOCOutlineLevel", LevelCounter)
                 End If

	         LocalTemplate = webex.ReadFile("OneCntOutItem.htm")
	         LocalTopicString = LocalTemplate

	         ' Process our template and replace parameters, then store new bodystring
	         ProcessString webex, LocalTopicString
	         bodyString = bodyString + LocalTopicString

	       ' Recursive call
           If webex.GetParameter(TdNavigationDepth) > LevelCounter Then
	       		Call MapTraversal(nextTopic, bodyString, webex)
		   End If

        Next k

  ' Close open levels as we exit recursive loop
  'bodyString = bodyString + "</div>" + vbCrLf

' Keep track of recurse level
LevelCounter = LevelCounter - 1

End Function

