1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<!--***********************************************************
4 *
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements.  See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership.  The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License.  You may obtain a copy of the License at
12 *
13 *   http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied.  See the License for the
19 * specific language governing permissions and limitations
20 * under the License.
21 *
22 ***********************************************************-->
23<script:module xmlns:script="http://openoffice.org/2000/script" script:name="TOC" script:language="StarBasic">REM  *****  BASIC  *****
24
25Dim oDialog AS Object
26Dim document AS Object
27
28Sub Main
29	document = StarDesktop.CurrentComponent
30
31	BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
32	oDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlgTOC&quot;)
33	oDialogModel = oDialog.Model
34
35	ocbAddTag = oDialog.GetControl(&quot;cbAddTag&quot;)
36
37	&apos; Check if bookmarks are allowed here
38	If IsInList Then
39		msgbox &quot;No Bookmarks allowed inside a list.&quot;, 48, &quot;D&apos;oh!&quot;
40		Exit Sub
41	End If
42
43	nBookmarkType = IsInBookmark
44	If nBookmarkType = 3 Then &apos; inside TOC bookmark
45		ocbAddTag.State = 0
46	End If
47
48	If oDialog.Execute() = 1 Then
49		&apos; Insert the bookmark construction
50		olbTOC = oDialog.GetControl(&quot;lbTOC&quot;)
51
52		If nBookmarkType = 0 Then&apos; not in a bookmark, always add parent tags
53			bmid = CreateID
54			&apos; now check if we are in a para with text (this wouldn&apos;t be valid)
55			If Not(ParaIsEmpty) Then
56				CR
57			End If
58			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;)
59			For i=0 to ubound(olbTOC.Items)
60				LF
61				InsertTag(&quot;BOOKMARKVALUE_&quot;,&quot;&lt;BOOKMARKVALUE&gt;&quot;)
62				InsertField(&quot;BOOKMARKVALUE&quot;,olbTOC.Items(i))
63				InsertTag(&quot;_BOOKMARKVALUE&quot;,&quot;&lt;/BOOKMARKVALUE&gt;&quot;)
64			Next i
65			LF
66			InsertTagCR(&quot;_BOOKMARK&quot;,&quot;&lt;/BOOKMARK&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
67
68		ElseIf nBookmarkType = 3 Then &apos; correct bookmark type
69			If ocbAddTag.State = 1 Then
70				bmid = CreateID
71				&apos; now check if we are in a para with text (this wouldn&apos;t be valid)
72				If Not(ParaIsEmpty) Then
73					CR
74				End If
75				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;)
76			End If
77			For i=0 to ubound(olbTOC.Items)
78				LF
79				InsertTag(&quot;BOOKMARKVALUE_&quot;,&quot;&lt;BOOKMARKVALUE&gt;&quot;)
80				InsertField(&quot;BOOKMARKVALUE&quot;,olbTOC.Items(i))
81				InsertTag(&quot;_BOOKMARKVALUE&quot;,&quot;&lt;/BOOKMARKVALUE&gt;&quot;)
82			Next i
83			If ocbAddTag.State = 1 Then
84				LF
85				InsertTagCR(&quot;_BOOKMARK&quot;,&quot;&lt;/BOOKMARK&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
86			End If
87		Else	&apos; wrong bookmark type
88			bmid = CreateID
89			&apos; now check if we are in a para with text (this wouldn&apos;t be valid)
90			If Not(ParaIsEmpty) Then
91				CR
92			End If
93			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;)
94			For i=0 to ubound(olbTOC.Items)
95				LF
96				InsertTag(&quot;BOOKMARKVALUE_&quot;,&quot;&lt;BOOKMARKVALUE&gt;&quot;)
97				InsertField(&quot;BOOKMARKVALUE&quot;,olbTOC.Items(i))
98				InsertTag(&quot;_BOOKMARKVALUE&quot;,&quot;&lt;/BOOKMARKVALUE&gt;&quot;)
99			Next i
100			LF
101			InsertTagCR(&quot;_BOOKMARK&quot;,&quot;&lt;/BOOKMARK&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
102		End If
103
104	End If
105	oDialog.dispose
106
107End Sub
108
109Sub RemoveKeyStroke(Event As Object)
110	Select Case Event.KeyCode
111		Case com.sun.star.awt.Key.RETURN
112			RemoveIndexEntry
113		Case com.sun.star.awt.Key.SPACE
114			RemoveIndexEntry
115	End Select
116End Sub
117
118
119Sub RemoveTOCEntry
120	olbTOC = oDialog.GetControl(&quot;lbTOC&quot;)
121	ItemsPos = olbTOC.getSelectedItemsPos
122	For i=0 to ubound(ItemsPos)
123		olbTOC.removeItems(ItemsPos(i)-i,1)
124	Next i
125End Sub
126
127Sub KeyPressedRemove(Event As Object)
128	Select Case Event.KeyCode
129		Case com.sun.star.awt.Key.DELETE
130		RemoveTOCEntry
131	End Select
132End Sub
133
134Sub AddKeyStroke(Event As Object)
135	Select Case Event.KeyCode
136		Case com.sun.star.awt.Key.RETURN
137			AddTOCEntry
138		Case com.sun.star.awt.Key.SPACE
139			AddTOCEntry
140	End Select
141End Sub
142
143Sub AddTOCEntry
144		oTxtTOC = oDialog.GetControl(&quot;txtTOC&quot;)
145		If (oTxtTOC.Text = &quot;&quot;) Then
146			msgbox &quot;Enter a TOC entry first.&quot;
147		Else
148			&apos; Insert the index entry into the list
149			olbTOC = oDialog.GetControl(&quot;lbTOC&quot;)
150			olbTOC.addItem(oTxtTOC.Text,0)
151		End If
152
153End Sub
154
155
156</script:module>
157