11ecadb57SMathias Bauer<?xml version="1.0" encoding="UTF-8"?>
21ecadb57SMathias Bauer<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*3e02b54dSAndrew Rist<!--***********************************************************
4*3e02b54dSAndrew Rist *
5*3e02b54dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
6*3e02b54dSAndrew Rist * or more contributor license agreements.  See the NOTICE file
7*3e02b54dSAndrew Rist * distributed with this work for additional information
8*3e02b54dSAndrew Rist * regarding copyright ownership.  The ASF licenses this file
9*3e02b54dSAndrew Rist * to you under the Apache License, Version 2.0 (the
10*3e02b54dSAndrew Rist * "License"); you may not use this file except in compliance
11*3e02b54dSAndrew Rist * with the License.  You may obtain a copy of the License at
12*3e02b54dSAndrew Rist *
13*3e02b54dSAndrew Rist *   http://www.apache.org/licenses/LICENSE-2.0
14*3e02b54dSAndrew Rist *
15*3e02b54dSAndrew Rist * Unless required by applicable law or agreed to in writing,
16*3e02b54dSAndrew Rist * software distributed under the License is distributed on an
17*3e02b54dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18*3e02b54dSAndrew Rist * KIND, either express or implied.  See the License for the
19*3e02b54dSAndrew Rist * specific language governing permissions and limitations
20*3e02b54dSAndrew Rist * under the License.
21*3e02b54dSAndrew Rist *
22*3e02b54dSAndrew Rist ***********************************************************-->
231ecadb57SMathias Bauer<script:module xmlns:script="http://openoffice.org/2000/script" script:name="TOC" script:language="StarBasic">REM  *****  BASIC  *****
241ecadb57SMathias Bauer
251ecadb57SMathias BauerDim oDialog AS Object
261ecadb57SMathias BauerDim document AS Object
271ecadb57SMathias Bauer
281ecadb57SMathias BauerSub Main
291ecadb57SMathias Bauer	document = StarDesktop.CurrentComponent
301ecadb57SMathias Bauer
311ecadb57SMathias Bauer	BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
321ecadb57SMathias Bauer	oDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlgTOC&quot;)
331ecadb57SMathias Bauer	oDialogModel = oDialog.Model
341ecadb57SMathias Bauer
351ecadb57SMathias Bauer	ocbAddTag = oDialog.GetControl(&quot;cbAddTag&quot;)
361ecadb57SMathias Bauer
371ecadb57SMathias Bauer	&apos; Check if bookmarks are allowed here
381ecadb57SMathias Bauer	If IsInList Then
391ecadb57SMathias Bauer		msgbox &quot;No Bookmarks allowed inside a list.&quot;, 48, &quot;D&apos;oh!&quot;
401ecadb57SMathias Bauer		Exit Sub
411ecadb57SMathias Bauer	End If
421ecadb57SMathias Bauer
431ecadb57SMathias Bauer	nBookmarkType = IsInBookmark
441ecadb57SMathias Bauer	If nBookmarkType = 3 Then &apos; inside TOC bookmark
451ecadb57SMathias Bauer		ocbAddTag.State = 0
461ecadb57SMathias Bauer	End If
471ecadb57SMathias Bauer
481ecadb57SMathias Bauer	If oDialog.Execute() = 1 Then
491ecadb57SMathias Bauer		&apos; Insert the bookmark construction
501ecadb57SMathias Bauer		olbTOC = oDialog.GetControl(&quot;lbTOC&quot;)
511ecadb57SMathias Bauer
521ecadb57SMathias Bauer		If nBookmarkType = 0 Then&apos; not in a bookmark, always add parent tags
531ecadb57SMathias Bauer			bmid = CreateID
541ecadb57SMathias Bauer			&apos; now check if we are in a para with text (this wouldn&apos;t be valid)
551ecadb57SMathias Bauer			If Not(ParaIsEmpty) Then
561ecadb57SMathias Bauer				CR
571ecadb57SMathias Bauer			End If
581ecadb57SMathias Bauer			InsertTag(&quot;BOOKMARK_&quot;,&quot;&lt;BOOKMARK branch=&quot;&quot;contents&quot;&quot; id=&quot;&quot;bm_id&quot; + bmid + &quot;&quot;&quot;&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
591ecadb57SMathias Bauer			For i=0 to ubound(olbTOC.Items)
601ecadb57SMathias Bauer				LF
611ecadb57SMathias Bauer				InsertTag(&quot;BOOKMARKVALUE_&quot;,&quot;&lt;BOOKMARKVALUE&gt;&quot;)
621ecadb57SMathias Bauer				InsertField(&quot;BOOKMARKVALUE&quot;,olbTOC.Items(i))
631ecadb57SMathias Bauer				InsertTag(&quot;_BOOKMARKVALUE&quot;,&quot;&lt;/BOOKMARKVALUE&gt;&quot;)
641ecadb57SMathias Bauer			Next i
651ecadb57SMathias Bauer			LF
661ecadb57SMathias Bauer			InsertTagCR(&quot;_BOOKMARK&quot;,&quot;&lt;/BOOKMARK&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
671ecadb57SMathias Bauer
681ecadb57SMathias Bauer		ElseIf nBookmarkType = 3 Then &apos; correct bookmark type
691ecadb57SMathias Bauer			If ocbAddTag.State = 1 Then
701ecadb57SMathias Bauer				bmid = CreateID
711ecadb57SMathias Bauer				&apos; now check if we are in a para with text (this wouldn&apos;t be valid)
721ecadb57SMathias Bauer				If Not(ParaIsEmpty) Then
731ecadb57SMathias Bauer					CR
741ecadb57SMathias Bauer				End If
751ecadb57SMathias Bauer				InsertTag(&quot;BOOKMARK_&quot;,&quot;&lt;BOOKMARK branch=&quot;&quot;contents&quot;&quot; id=&quot;&quot;bm_id&quot; + bmid + &quot;&quot;&quot;&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
761ecadb57SMathias Bauer			End If
771ecadb57SMathias Bauer			For i=0 to ubound(olbTOC.Items)
781ecadb57SMathias Bauer				LF
791ecadb57SMathias Bauer				InsertTag(&quot;BOOKMARKVALUE_&quot;,&quot;&lt;BOOKMARKVALUE&gt;&quot;)
801ecadb57SMathias Bauer				InsertField(&quot;BOOKMARKVALUE&quot;,olbTOC.Items(i))
811ecadb57SMathias Bauer				InsertTag(&quot;_BOOKMARKVALUE&quot;,&quot;&lt;/BOOKMARKVALUE&gt;&quot;)
821ecadb57SMathias Bauer			Next i
831ecadb57SMathias Bauer			If ocbAddTag.State = 1 Then
841ecadb57SMathias Bauer				LF
851ecadb57SMathias Bauer				InsertTagCR(&quot;_BOOKMARK&quot;,&quot;&lt;/BOOKMARK&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
861ecadb57SMathias Bauer			End If
871ecadb57SMathias Bauer		Else	&apos; wrong bookmark type
881ecadb57SMathias Bauer			bmid = CreateID
891ecadb57SMathias Bauer			&apos; now check if we are in a para with text (this wouldn&apos;t be valid)
901ecadb57SMathias Bauer			If Not(ParaIsEmpty) Then
911ecadb57SMathias Bauer				CR
921ecadb57SMathias Bauer			End If
931ecadb57SMathias Bauer			InsertTag(&quot;BOOKMARK_&quot;,&quot;&lt;BOOKMARK branch=&quot;&quot;contents&quot;&quot; id=&quot;&quot;bm_id&quot; + bmid + &quot;&quot;&quot;&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
941ecadb57SMathias Bauer			For i=0 to ubound(olbTOC.Items)
951ecadb57SMathias Bauer				LF
961ecadb57SMathias Bauer				InsertTag(&quot;BOOKMARKVALUE_&quot;,&quot;&lt;BOOKMARKVALUE&gt;&quot;)
971ecadb57SMathias Bauer				InsertField(&quot;BOOKMARKVALUE&quot;,olbTOC.Items(i))
981ecadb57SMathias Bauer				InsertTag(&quot;_BOOKMARKVALUE&quot;,&quot;&lt;/BOOKMARKVALUE&gt;&quot;)
991ecadb57SMathias Bauer			Next i
1001ecadb57SMathias Bauer			LF
1011ecadb57SMathias Bauer			InsertTagCR(&quot;_BOOKMARK&quot;,&quot;&lt;/BOOKMARK&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
1021ecadb57SMathias Bauer		End If
1031ecadb57SMathias Bauer
1041ecadb57SMathias Bauer	End If
1051ecadb57SMathias Bauer	oDialog.dispose
1061ecadb57SMathias Bauer
1071ecadb57SMathias BauerEnd Sub
1081ecadb57SMathias Bauer
1091ecadb57SMathias BauerSub RemoveKeyStroke(Event As Object)
1101ecadb57SMathias Bauer	Select Case Event.KeyCode
1111ecadb57SMathias Bauer		Case com.sun.star.awt.Key.RETURN
1121ecadb57SMathias Bauer			RemoveIndexEntry
1131ecadb57SMathias Bauer		Case com.sun.star.awt.Key.SPACE
1141ecadb57SMathias Bauer			RemoveIndexEntry
1151ecadb57SMathias Bauer	End Select
1161ecadb57SMathias BauerEnd Sub
1171ecadb57SMathias Bauer
1181ecadb57SMathias Bauer
1191ecadb57SMathias BauerSub RemoveTOCEntry
1201ecadb57SMathias Bauer	olbTOC = oDialog.GetControl(&quot;lbTOC&quot;)
1211ecadb57SMathias Bauer	ItemsPos = olbTOC.getSelectedItemsPos
1221ecadb57SMathias Bauer	For i=0 to ubound(ItemsPos)
1231ecadb57SMathias Bauer		olbTOC.removeItems(ItemsPos(i)-i,1)
1241ecadb57SMathias Bauer	Next i
1251ecadb57SMathias BauerEnd Sub
1261ecadb57SMathias Bauer
1271ecadb57SMathias BauerSub KeyPressedRemove(Event As Object)
1281ecadb57SMathias Bauer	Select Case Event.KeyCode
1291ecadb57SMathias Bauer		Case com.sun.star.awt.Key.DELETE
1301ecadb57SMathias Bauer		RemoveTOCEntry
1311ecadb57SMathias Bauer	End Select
1321ecadb57SMathias BauerEnd Sub
1331ecadb57SMathias Bauer
1341ecadb57SMathias BauerSub AddKeyStroke(Event As Object)
1351ecadb57SMathias Bauer	Select Case Event.KeyCode
1361ecadb57SMathias Bauer		Case com.sun.star.awt.Key.RETURN
1371ecadb57SMathias Bauer			AddTOCEntry
1381ecadb57SMathias Bauer		Case com.sun.star.awt.Key.SPACE
1391ecadb57SMathias Bauer			AddTOCEntry
1401ecadb57SMathias Bauer	End Select
1411ecadb57SMathias BauerEnd Sub
1421ecadb57SMathias Bauer
1431ecadb57SMathias BauerSub AddTOCEntry
1441ecadb57SMathias Bauer		oTxtTOC = oDialog.GetControl(&quot;txtTOC&quot;)
1451ecadb57SMathias Bauer		If (oTxtTOC.Text = &quot;&quot;) Then
1461ecadb57SMathias Bauer			msgbox &quot;Enter a TOC entry first.&quot;
1471ecadb57SMathias Bauer		Else
1481ecadb57SMathias Bauer			&apos; Insert the index entry into the list
1491ecadb57SMathias Bauer			olbTOC = oDialog.GetControl(&quot;lbTOC&quot;)
1501ecadb57SMathias Bauer			olbTOC.addItem(oTxtTOC.Text,0)
1511ecadb57SMathias Bauer		End If
1521ecadb57SMathias Bauer
1531ecadb57SMathias BauerEnd Sub
1541ecadb57SMathias Bauer
1551ecadb57SMathias Bauer
156*3e02b54dSAndrew Rist</script:module>
157