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="IND" script:language="StarBasic">REM  *****  BASIC  *****
24
25Dim oDialog AS Object
26Dim document AS Object
27
28Sub Main
29
30	If not IsHelpFile Then
31		msgbox(strErr_NoHelpFile)
32		Exit Sub
33	End If
34
35	document = StarDesktop.CurrentComponent
36
37	BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
38	oDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlgIND&quot;)
39	ocbAddTag = oDialog.GetControl(&quot;cbAddTag&quot;)
40
41	&apos; Check if bookmarks are allowed here
42	If IsInList Then
43		msgbox &quot;No Bookmarks allowed inside a list.&quot;, 48, &quot;D&apos;oh!&quot;
44		Exit Sub
45	End If
46
47
48	nBookmarkType = IsInBookmark
49	If nBookmarkType = 1 Then &apos; inside INDEX bookmark
50		ocbAddTag.State = 0
51	End If
52
53	oDialogModel = oDialog.Model
54
55	If oDialog.Execute() = 1 Then
56		&apos; Insert the bookmark construction
57		olbIND = oDialog.GetControl(&quot;lbIND&quot;)
58
59		If nBookmarkType = 0 Then&apos; not in a bookmark, always add parent tags
60			bmid = CreateID
61			&apos; now check if we are in a para with text (this wouldn&apos;t be valid)
62			If Not(ParaIsEmpty) Then
63				CR
64			End If
65			InsertTag(&quot;BOOKMARK_&quot;,&quot;&lt;BOOKMARK branch=&quot;&quot;index&quot;&quot; id=&quot;&quot;bm_id&quot; + bmid + &quot;&quot;&quot;&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
66
67			For i=0 to ubound(olbIND.Items)
68				LF
69				InsertTag(&quot;BOOKMARKVALUE_&quot;,&quot;&lt;BOOKMARKVALUE&gt;&quot;)
70				InsertField(&quot;BOOKMARKVALUE&quot;,olbIND.Items(i))
71				InsertTag(&quot;_BOOKMARKVALUE&quot;,&quot;&lt;/BOOKMARKVALUE&gt;&quot;)
72			Next i
73			LF
74			InsertTagCR(&quot;_BOOKMARK&quot;,&quot;&lt;/BOOKMARK&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
75
76		ElseIf nBookmarkType = 1 Then &apos; in a correct bookmark type
77			If ocbAddTag.State = 1 Then
78				If Not(ParaIsEmpty) Then
79					CR
80				End If
81				InsertTag(&quot;BOOKMARK_&quot;,&quot;&lt;BOOKMARK branch=&quot;&quot;index&quot;&quot; id=&quot;&quot;bm_id&quot; + bmid + &quot;&quot;&quot;&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
82				For i=0 to ubound(olbIND.Items)
83					LF
84					InsertTag(&quot;BOOKMARKVALUE_&quot;,&quot;&lt;BOOKMARKVALUE&gt;&quot;)
85					InsertField(&quot;BOOKMARKVALUE&quot;,olbIND.Items(i))
86					InsertTag(&quot;_BOOKMARKVALUE&quot;,&quot;&lt;/BOOKMARKVALUE&gt;&quot;)
87				Next i
88				If ocbAddTag.State = 1 Then
89					LF
90					InsertTagCR(&quot;_BOOKMARK&quot;,&quot;&lt;/BOOKMARK&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
91				End If
92			Else
93				For i=0 to ubound(olbIND.Items)
94					LF
95					InsertTag(&quot;BOOKMARKVALUE_&quot;,&quot;&lt;BOOKMARKVALUE&gt;&quot;)
96					InsertField(&quot;BOOKMARKVALUE&quot;,olbIND.Items(i))
97					InsertTag(&quot;_BOOKMARKVALUE&quot;,&quot;&lt;/BOOKMARKVALUE&gt;&quot;)
98				Next i
99			End If
100		Else	&apos; in a wrong bookmark type
101			If Not(ParaIsEmpty) Then
102				CR
103			End If
104			InsertTag(&quot;BOOKMARK_&quot;,&quot;&lt;BOOKMARK branch=&quot;&quot;index&quot;&quot; id=&quot;&quot;bm_id&quot; + bmid + &quot;&quot;&quot;&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
105			For i=0 to ubound(olbIND.Items)
106				LF
107				InsertTag(&quot;BOOKMARKVALUE_&quot;,&quot;&lt;BOOKMARKVALUE&gt;&quot;)
108				InsertField(&quot;BOOKMARKVALUE&quot;,olbIND.Items(i))
109				InsertTag(&quot;_BOOKMARKVALUE&quot;,&quot;&lt;/BOOKMARKVALUE&gt;&quot;)
110			Next i
111			LF
112			InsertTagCR(&quot;_BOOKMARK&quot;,&quot;&lt;/BOOKMARK&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
113		End If
114	End If
115
116	oDialog.dispose
117
118End Sub
119
120Sub AddKeyStroke(Event As Object)
121	Select Case Event.KeyCode
122		Case com.sun.star.awt.Key.RETURN
123			AddIndexEntry
124		Case com.sun.star.awt.Key.SPACE
125			AddIndexEntry
126	End Select
127End Sub
128
129Sub AddIndexEntry
130
131		oTxtLevel1 = oDialog.GetControl(&quot;txtLevel1&quot;)
132		oTxtLevel2 = oDialog.GetControl(&quot;txtLevel2&quot;)
133
134		If oTxtLevel2.Text &lt;&gt; &quot;&quot; Then
135			IndexEntry = oTxtLevel1.Text + &quot;;&quot; + oTxtLevel2.Text
136		Else
137			IndexEntry = oTxtLevel1.Text
138		End If
139
140		If ((oTxtLevel1.Text = &quot;&quot;) OR (IndexEntry = &quot;&lt;Level 1&gt;;&lt;Level 2&gt;&quot;)) Then
141			msgbox &quot;Enter an index entry first.&quot;
142		Else
143			&apos; Insert the index entry into the list
144			olbIND = oDialog.GetControl(&quot;lbIND&quot;)
145			olbIND.addItem(IndexEntry,0)
146		End If
147
148End Sub
149
150Sub RemoveKeyStroke(Event As Object)
151	Select Case Event.KeyCode
152		Case com.sun.star.awt.Key.RETURN
153			RemoveIndexEntry
154		Case com.sun.star.awt.Key.SPACE
155			RemoveIndexEntry
156	End Select
157End Sub
158
159
160Sub RemoveIndexEntry
161	olbIND = oDialog.GetControl(&quot;lbIND&quot;)
162	ItemsPos = olbIND.getSelectedItemsPos
163	For i=0 to ubound(ItemsPos)
164		olbIND.removeItems(ItemsPos(i)-i,1)
165	Next i
166End Sub
167
168Sub KeyPressedAdd(Event As Object)
169	Select Case Event.KeyCode
170		Case com.sun.star.awt.Key.INSERT
171			AddIndexEntry
172	End Select
173End Sub
174
175Sub KeyPressedRemove(Event As Object)
176	Select Case Event.KeyCode
177		Case com.sun.star.awt.Key.DELETE
178		RemoveIndexEntry
179	End Select
180End Sub
181</script:module>
182