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

Const PartialMapWidth As Single = 300
Const PartialMapHeight As Single = 400
Const s_PartialMapCSIMname = "CSIM" ' Partial Map Client Side Image Map name

Option Explicit

Sub Main

    Dim addin As Mm5WebExportAddIn
    Dim webex As WebExport
    Dim aPage As Mm5WebExportLib.Page

    Set addin = WebExportHelper.WebExportAddIn
    Set webex = addin.ActiveWebExport
    Set aPage = webex.ActivePage

    Dim oneTopic As Topic

    Dim template As String
    Dim topicString As String
    Dim bodyString As String
    Dim TheUnit As Long
    Dim imagemapFilename As String
    Dim ImageMapCounter As Long
    Dim CurrentImageMapCount As Variant
    Dim DoExportSubTopicsSection As Boolean
    Dim DoExportPartialMaps As Boolean
    Dim SubLinksStyle As String


    On Error GoTo ReportError

    webex.Trace("Entering BoxPartMap.mmbas",2)

    template = webex.ReadFile("BoxPartMap.htm")

    Set aPage = webex.ActivePage
    Set oneTopic = webex.ActiveTopic

	' Assume nothing will be exported
    ' Export the partial map only if the user has selected it, and if there are any subtopics
    bodyString = ""

	SubLinksStyle = webex.GetParameter("Strings.Show.SubLinks")

    ' Determine if partial map section should be generated
    If (oneTopic.SubTopics(False).Count > 0) And (SubLinksStyle <> "none") Then
        ' Only process the partial map template if the topic is the first topic on a page
        If oneTopic Is aPage.GetTopic(1) Then

			' Determine the style of the links to insert
		    Select Case SubLinksStyle

			   Case "partmapssingle"

					If (webex.Pages.Item(1) Is aPage) And (oneTopic.IsCentralTopic) Then
						' Export first page link only
						 Call CreateImage( oneTopic, webex, topicString, template, bodyString )

	     			End If

			   Case "partmaps"

		                Call CreateImage( oneTopic, webex, topicString, template, bodyString )

			   Case "links"
			   		' Get parameters for HTML template processing
					webex.SetParameter("CustomParameter.PartialMapFileName", "")
	            	webex.SetParameter("CustomParameter.PartialMapWidth", "")
	           		webex.SetParameter("CustomParameter.PartialMapHeight", "")
	            	webex.SetParameter("CustomParameter.PartialMapCSIMname", "")
	            	webex.SetParameter("CustomParameter.PartialMapCSIM", "")

			 	    ' Read our template
		    		topicString = template

				    ' Process all commands and parameters
				    ProcessString webex, topicString

				    ' Our merged string to write back
				    bodyString = topicString

	    	   Case Else
	            	' not the first topic, empty fields
	            	' Get parameters for HTML template processing
					webex.SetParameter("CustomParameter.PartialMapFileName", "")
	            	webex.SetParameter("CustomParameter.PartialMapWidth", "")
	           		webex.SetParameter("CustomParameter.PartialMapHeight", "")
	            	webex.SetParameter("CustomParameter.PartialMapCSIMname", "")
	            	webex.SetParameter("CustomParameter.PartialMapCSIM", "")

		    End Select

	    End If

    End If

    ' Write out the result
    webex.PushString(bodyString)

    webex.Trace("Exiting BoxPartMap.mmbas",2)

    Exit Sub

ReportError:
    ProcessError(webex)
    Exit Sub


End Sub

Sub CreateImage( oneTopic As Topic, webex As WebExport, topicString As String, template As String, bodyString As String)

	Dim theMapGraphic As GraphicExport
	Dim i_1 As Integer ' subtopic counter
	Dim m_Subtopic As Topic ' temporary subtopic
	Dim fullImagemapFilename As String
    Dim baseImagemapFilename As String
	Dim s_PartialMapCSIM As String ' Partial map Client Side Image Map

    Set theMapGraphic = oneTopic.Document.GraphicExport
    theMapGraphic.Reset
    theMapGraphic.AddCustomizedTopic(oneTopic,1)

    ' Set up topics for client size imagemap
    For i_1 = 1 To oneTopic.SubTopics(False).Count
        Dim link As HyperlinkData
        Set m_Subtopic = oneTopic.SubTopics(False).Item(i_1)
        link = TopicHyperlink(webex, m_Subtopic)
        theMapGraphic.AddLink(m_Subtopic, mmLinkTypeTopic, _
            link.Url, link.Label, TargetAttribute(link))
    Next i_1
    baseImagemapFilename = "PartialMaps/" + webex.Pages.FindPage(oneTopic).BaseFilename + ".gif"
    fullImagemapFilename = webex.FullExportFilename(baseImagemapFilename)
    If webex.ShouldWriteFile(fullImagemapFilename) Then
        theMapGraphic.ExportSized(fullImagemapFilename,mmGraphicTypeGif,PartialMapWidth,PartialMapHeight,True,True)
    End If
    s_PartialMapCSIM = theMapGraphic.GetImageMap(s_PartialMapCSIMname)

    ' Get parameters for HTML template processing
    webex.SetParameter("CustomParameter.PartialMapFileName", baseImagemapFilename)
    webex.SetParameter("CustomParameter.PartialMapWidth", PartialMapWidth)
    webex.SetParameter("CustomParameter.PartialMapHeight", PartialMapHeight)
    webex.SetParameter("CustomParameter.PartialMapCSIMname", s_PartialMapCSIMname)
    webex.SetParameter("CustomParameter.PartialMapCSIM", s_PartialMapCSIM)

    ' Read our template
	topicString = template

    ' Process all commands and parameters
    ProcessString webex, topicString

    ' Our merged string to write back
    bodyString = topicString

End Sub
