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="Helpers" script:language="StarBasic">&apos; *** MODULE HELPERS ***
24
25&apos;=======================================================
26&apos; Main
27&apos;-------------------------------------------------------
28&apos; Ensure that necessary library functions are available
29&apos;=======================================================
30Sub Main
31	GlobalScope.BasicLibraries.loadLibrary(&quot;Tools&quot;)
32End Sub
33
34&apos;=======================================================
35&apos; ShowProp
36&apos;-------------------------------------------------------
37&apos; Displays a dialog that shows the properties and
38&apos; the methods of an object. Used for debugging.
39&apos;=======================================================
40Sub ShowProp(Elem As Object)
41	dim oDialog As Object
42
43	BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
44	oDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlgObjProp&quot;)
45	oDialogModel = oDialog.Model
46
47	oTxtProp = oDialog.GetControl(&quot;txtProp&quot;)
48	oTxtProp.Text = Join(Split(Elem.dbg_properties,&quot;;&quot;),chr(13))
49
50	oTxtMeth = oDialog.GetControl(&quot;txtMeth&quot;)
51	oTxtMeth.Text = Join(Split(Elem.dbg_methods,&quot;;&quot;),chr(13))
52
53	oTxtInt = oDialog.GetControl(&quot;txtInt&quot;)
54	oTxtInt.Text = Join(Split(Elem.dbg_supportedInterfaces,&quot;;&quot;),chr(13))
55
56	oDialog.Execute()
57	oDialog.dispose
58End Sub
59
60&apos;=======================================================
61&apos; AlphaNum
62&apos;-------------------------------------------------------
63&apos; Removes all invalid characters from a string
64&apos;=======================================================
65Function AlphaNum(Strg As String)
66	dim OutStrg As String
67	dim sValid As String
68
69	sValid = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789&quot;
70
71	For i=1 to Len(Strg)
72		If (Instr(sValid,LCase(Mid(Strg,i,1)))) Then
73			OutStrg = OutStrg + Mid(Strg,i,1)
74		End If
75	Next i
76	AlphaNum = OutStrg
77End Function
78
79&apos;=======================================================
80&apos; Replace
81&apos;-------------------------------------------------------
82&apos; Replaces a character with another character in a string
83&apos;=======================================================
84Function Replace(txt As String, ReplaceFrom As String, ReplaceTo As String)
85	dim OutStr As String
86	For i=1 to len(txt)
87		If LCase(mid(txt,i,1))=ReplaceFrom Then
88			OutStr = OutStr + ReplaceTo
89		Else
90			OutStr = OutStr + mid(txt,i,1)
91		End If
92	Next i
93	Replace = OutStr
94End Function
95
96
97&apos;=======================================================
98&apos; ReplaceAll
99&apos;-------------------------------------------------------
100&apos; Replaces a character with another character in a string
101&apos;=======================================================
102Function ReplaceAll(txt As String, ReplaceFrom As String, ReplaceTo As String)
103	dim OutStr As String
104	For i=1 to len(txt)
105	    bFound = 0
106		For j=1 to len(ReplaceFrom)
107			If LCase(mid(txt,i,1))=LCase(mid(ReplaceFrom,j,1)) Then
108				bFound = 1
109				OutStr = OutStr + ReplaceTo
110				j = len(ReplaceFrom)
111			End If
112		Next j
113		If bFound=0 Then
114			OutStr = OutStr + mid(txt,i,1)
115		End If
116	Next i
117	ReplaceAll = OutStr
118End Function
119
120
121
122&apos;=======================================================
123&apos; CreateID
124&apos;-------------------------------------------------------
125&apos; Creates a numerical randomized ID
126&apos;=======================================================
127Function CreateID
128	sDate = ReplaceAll(Date,&quot;/:. \&quot;,&quot;&quot;)
129    sTime = ReplaceAll(Time,&quot;/:. \AMP&quot;,&quot;&quot;)
130	Randomize
131	CreateID = sDate + sTime + Int(Rnd * 100)
132End Function
133
134&apos;=======================================================
135&apos; InsertTag
136&apos;-------------------------------------------------------
137&apos; Inserts an inline tag (element) in the document at the
138&apos; current cursor position. It also sets the character
139&apos; format to hlp_aux_tag
140&apos;=======================================================
141Sub InsertTag (Element As String, Content As String)
142	dim document   as object
143	dim dispatcher as object
144
145	document   = ThisComponent.CurrentController.Frame
146	dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
147
148	dim args(5) as new com.sun.star.beans.PropertyValue
149	args(0).Name = &quot;Type&quot;
150	args(0).Value = 8
151	args(1).Name = &quot;SubType&quot;
152	args(1).Value = 1
153	args(2).Name = &quot;Name&quot;
154	args(2).Value = Element
155	args(3).Name = &quot;Content&quot;
156	args(3).Value = Content
157	args(4).Name = &quot;Format&quot;
158	args(4).Value = -1
159	args(5).Name = &quot;Separator&quot;
160	args(5).Value = &quot; &quot;
161	SetCharStyle(&quot;hlp_aux_tag&quot;)
162	dispatcher.executeDispatch(document, &quot;.uno:InsertField&quot;, &quot;&quot;, 0, args())
163	SetCharStyle(&quot;Default&quot;)
164End Sub
165
166&apos;=======================================================
167&apos; INSERTTAGCR
168&apos;-------------------------------------------------------
169&apos; Inserts a tag (element) in the document at the
170&apos; current cursor position in its own newly created paragraph.
171&apos; It also sets the character format to hlp_aux_tag and
172&apos; the paragraph to the specified value (should start with hlp_)
173&apos;=======================================================
174Sub InsertTagCR (Element As String, Content As String, Style As String)
175	dim document   as object
176	dim dispatcher as object
177
178	document   = ThisComponent.CurrentController.Frame
179	dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
180
181	dim args(5) as new com.sun.star.beans.PropertyValue
182	args(0).Name = &quot;Type&quot;
183	args(0).Value = 8
184	args(1).Name = &quot;SubType&quot;
185	args(1).Value = 1
186	args(2).Name = &quot;Name&quot;
187	args(2).Value = Element
188	args(3).Name = &quot;Content&quot;
189	args(3).Value = Content
190	args(4).Name = &quot;Format&quot;
191	args(4).Value = -1
192	args(5).Name = &quot;Separator&quot;
193	args(5).Value = &quot; &quot;
194
195	CR
196	goUp(1)
197	SetParaStyle(Style)
198	SetCharStyle(&quot;hlp_aux_tag&quot;)
199	dispatcher.executeDispatch(document, &quot;.uno:InsertField&quot;, &quot;&quot;, 0, args())
200	SetCharStyle(&quot;Default&quot;)
201	goDown(1)
202End Sub
203
204&apos;=======================================================
205&apos; InsertField
206&apos;-------------------------------------------------------
207&apos; Inserts a field in the document at the
208&apos; current cursor position.
209&apos;=======================================================
210Sub InsertField(Field as String, Content as String)
211	dim document   as object
212	dim dispatcher as object
213
214	document   = ThisComponent.CurrentController.Frame
215	dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
216
217	dim args(5) as new com.sun.star.beans.PropertyValue
218	args(0).Name = &quot;Type&quot;
219	args(0).Value = 8
220	args(1).Name = &quot;SubType&quot;
221	args(1).Value = 1
222	args(2).Name = &quot;Name&quot;
223	args(2).Value = Field
224	args(3).Name = &quot;Content&quot;
225	args(3).Value = Content
226	args(4).Name = &quot;Format&quot;
227	args(4).Value = -1
228	args(5).Name = &quot;Separator&quot;
229	args(5).Value = &quot; &quot;
230
231	dispatcher.executeDispatch(document, &quot;.uno:InsertField&quot;, &quot;&quot;, 0, args())
232End Sub
233
234&apos;=======================================================
235&apos; GoUp
236&apos;-------------------------------------------------------
237&apos; Simulates the CursorUp key
238&apos;=======================================================
239Sub goUp(Count As Integer, Optional bSelect As Boolean)
240	dim document   as object
241	dim dispatcher as object
242
243	document   = ThisComponent.CurrentController.Frame
244	dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
245
246	dim args(1) as new com.sun.star.beans.PropertyValue
247	args(0).Name = &quot;Count&quot;
248	args(0).Value = Count
249	args(1).Name = &quot;Select&quot;
250	If IsMissing(bSelect) Then
251		args(1).Value = false
252	Else
253		args(1).Value = bSelect
254	End If
255
256	dispatcher.executeDispatch(document, &quot;.uno:GoUp&quot;, &quot;&quot;, 0, args())
257End Sub
258
259&apos;=======================================================
260&apos; GoDown
261&apos;-------------------------------------------------------
262&apos; Simulates the CursorDown key
263&apos;=======================================================
264Sub goDown(Count As Integer, Optional bSelect As Boolean)
265	dim document   as object
266	dim dispatcher as object
267
268	document   = ThisComponent.CurrentController.Frame
269	dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
270
271	dim args(1) as new com.sun.star.beans.PropertyValue
272	args(0).Name = &quot;Count&quot;
273	args(0).Value = Count
274	args(1).Name = &quot;Select&quot;
275	If IsMissing(bSelect) Then
276		args(1).Value = false
277	Else
278		args(1).Value = bSelect
279	End If
280
281	dispatcher.executeDispatch(document, &quot;.uno:GoDown&quot;, &quot;&quot;, 0, args())
282End Sub
283
284
285&apos;=======================================================
286&apos; GoRight
287&apos;-------------------------------------------------------
288&apos; Simulates the CursorRight key
289&apos;=======================================================
290Sub goRight(Count As Integer, Optional bSelect As Boolean)
291	dim document   as object
292	dim dispatcher as object
293
294	document   = ThisComponent.CurrentController.Frame
295	dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
296
297	dim args(1) as new com.sun.star.beans.PropertyValue
298	args(0).Name = &quot;Count&quot;
299	args(0).Value = Count
300	args(1).Name = &quot;Select&quot;
301	If IsMissing(bSelect) Then
302		args(1).Value = false
303	Else
304		args(1).Value = bSelect
305	End If
306
307	dispatcher.executeDispatch(document, &quot;.uno:GoRight&quot;, &quot;&quot;, 0, args())
308End Sub
309
310&apos;=======================================================
311&apos; GoLeft
312&apos;-------------------------------------------------------
313&apos; Simulates the CursorLeft key
314&apos;=======================================================
315Sub goLeft(Count As Integer, optional bSelect As boolean)
316	dim document   as object
317	dim dispatcher as object
318
319	document   = ThisComponent.CurrentController.Frame
320	dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
321
322	dim args(1) as new com.sun.star.beans.PropertyValue
323	args(0).Name = &quot;Count&quot;
324	args(0).Value = Count
325	args(1).Name = &quot;Select&quot;
326	If IsMissing(bSelect) Then
327		args(1).Value = false
328	Else
329		args(1).Value = bSelect
330	End If
331
332	dispatcher.executeDispatch(document, &quot;.uno:GoLeft&quot;, &quot;&quot;, 0, args())
333End Sub
334
335&apos;=======================================================
336&apos; CR
337&apos;-------------------------------------------------------
338&apos; Inserts a Carriage Return (a new paragraph)
339&apos;=======================================================
340Sub CR
341	dim document   as object
342	dim dispatcher as object
343
344	document   = ThisComponent.CurrentController.Frame
345	dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
346
347	oSel = thiscomponent.getcurrentcontroller.getselection
348	oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
349	oCur.gotoEndOfParagraph(0)
350	thiscomponent.getcurrentcontroller.select(oCur)
351
352	dispatcher.executeDispatch(document, &quot;.uno:InsertPara&quot;, &quot;&quot;, 0, Array())
353End Sub
354
355&apos;=======================================================
356&apos; CR_before
357&apos;-------------------------------------------------------
358&apos; Inserts a Carriage Return (a new paragraph) before the current para
359&apos;=======================================================
360Sub CR_before
361	dim document   as object
362	dim dispatcher as object
363
364	document   = ThisComponent.CurrentController.Frame
365	dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
366
367	oSel = thiscomponent.getcurrentcontroller.getselection
368	oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
369	oCur.gotoStartOfParagraph(0)
370	thiscomponent.getcurrentcontroller.select(oCur)
371
372	dispatcher.executeDispatch(document, &quot;.uno:InsertPara&quot;, &quot;&quot;, 0, Array())
373End Sub
374
375&apos;=======================================================
376&apos; LF
377&apos;-------------------------------------------------------
378&apos; Inserts a line feed (manual line break)
379&apos;=======================================================
380sub LF
381	dim document   as object
382	dim dispatcher as object
383	document   = ThisComponent.CurrentController.Frame
384	dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
385
386	dispatcher.executeDispatch(document, &quot;.uno:InsertLinebreak&quot;, &quot;&quot;, 0, Array())
387end sub
388
389&apos;=======================================================
390&apos; SetParaStyle
391&apos;-------------------------------------------------------
392&apos; Sets the para style to the given value
393&apos;=======================================================
394Sub SetParaStyle(StyleName As String)
395	dim document   as object
396	dim dispatcher as object
397
398	document   = ThisComponent.CurrentController.Frame
399	dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
400
401	dim args(1) as new com.sun.star.beans.PropertyValue
402	args(0).Name = &quot;Template&quot;
403	args(0).Value = StyleName
404	args(1).Name = &quot;Family&quot;
405	args(1).Value = 2
406
407	dispatcher.executeDispatch(document, &quot;.uno:StyleApply&quot;, &quot;&quot;, 0, args())
408end Sub
409
410&apos;=======================================================
411&apos; SetCharStyle
412&apos;-------------------------------------------------------
413&apos; Sets the character style to the given value
414&apos;=======================================================
415Sub SetCharStyle(StyleName As String)
416	dim document   as object
417	dim dispatcher as object
418
419	document   = ThisComponent.CurrentController.Frame
420	dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
421
422	dim args(1) as new com.sun.star.beans.PropertyValue
423	args(0).Name = &quot;Template&quot;
424	args(0).Value = StyleName
425	args(1).Name = &quot;Family&quot;
426	args(1).Value = 1
427
428	dispatcher.executeDispatch(document, &quot;.uno:StyleApply&quot;, &quot;&quot;, 0, args())
429end Sub
430
431&apos;=======================================================
432&apos; InsertNewParaData
433&apos;-------------------------------------------------------
434&apos; Inserts a new ID for the paragraph
435&apos;=======================================================
436Sub InsertNewParaData
437
438		If not IsHelpFile Then
439		msgbox(strErr_NoHelpFile)
440		Exit Sub
441	End If
442
443	oSel = thiscomponent.getcurrentcontroller.getselection
444	oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
445
446	arParaData = GetParaData
447	sID = arParaData(0)
448	slocalize = arParaData(1)
449	sMsg = arParaData(2)
450
451	If sMsg &lt;&gt; &quot;&quot; Then
452		msgbox &quot;Cannot assign paragraph id:&quot;+chr(13)+sMsg,48,&quot;Error&quot;
453		Exit Sub
454	End If
455
456	If sID &lt;&gt; &quot;&quot; Then
457		msgbox &quot;Paragraph already has an ID.&quot;+chr(13)+&quot;If you want to assign a new ID delete the existing one first.&quot;,48,&quot;Error&quot;
458		Exit Sub
459	End If
460
461	oCur.gotoStartOfParagraph(0)
462
463	If (Left(oCur.ParaStyleName,8) = &quot;hlp_head&quot;) Then
464		id = &quot;hd_id&quot; + CreateID
465		thiscomponent.getcurrentcontroller.select(oCur)
466		MetaData = id
467		SetCharStyle(&quot;hlp_aux_parachanged&quot;)
468		InsertField(&quot;ID&quot;,MetaData)
469		SetCharStyle(&quot;Default&quot;)
470	Else
471		id = &quot;par_id&quot; + CreateID
472		thiscomponent.getcurrentcontroller.select(oCur)
473		MetaData = id
474		SetCharStyle(&quot;hlp_aux_parachanged&quot;)
475		InsertField(&quot;ID&quot;,MetaData)
476		SetCharStyle(&quot;Default&quot;)
477	End If
478
479
480End Sub
481
482&apos;=======================================================
483&apos; LoadDialog
484&apos;-------------------------------------------------------
485&apos; Loads a BASIC dialog
486&apos;=======================================================
487Function LoadDialog(Libname as String, DialogName as String, Optional oLibContainer)
488	Dim oLib as Object
489	Dim oLibDialog as Object
490	Dim oRuntimeDialog as Object
491
492	If IsMissing(oLibContainer ) then
493		oLibContainer = DialogLibraries
494	End If
495
496	oLibContainer.LoadLibrary(LibName)
497	oLib = oLibContainer.GetByName(Libname)
498	oLibDialog = oLib.GetByName(DialogName)
499	oRuntimeDialog = CreateUnoDialog(oLibDialog)
500	LoadDialog() = oRuntimeDialog
501End Function
502
503&apos;=======================================================
504&apos; Surprise
505&apos;-------------------------------------------------------
506&apos; D&apos;oh
507&apos;=======================================================
508Sub Surprise
509	msgbox &quot;This function is unsupported.&quot;+chr(13)+&quot;If you know how to implement this -- go ahead!&quot;,0,&quot;D&apos;oh!&quot;
510End Sub
511
512&apos;=======================================================
513&apos; InsertNote
514&apos;-------------------------------------------------------
515&apos; Inserts a note (annotation) at the current position
516&apos;=======================================================
517sub InsertNote(Content As String)
518	dim document   as object
519	dim dispatcher as object
520
521	document   = ThisComponent.CurrentController.Frame
522	dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
523
524	dim args(2) as new com.sun.star.beans.PropertyValue
525	args(0).Name = &quot;Text&quot;
526	args(0).Value = Content
527	args(1).Name = &quot;Author&quot;
528	args(1).Value = &quot;Help Tooling - DO NOT EDIT&quot;
529	args(2).Name = &quot;Date&quot;
530	args(2).Value = &quot;02/27/2004&quot;
531
532	dispatcher.executeDispatch(document, &quot;.uno:InsertAnnotation&quot;, &quot;&quot;, 0, args())
533end sub
534
535&apos;=======================================================
536&apos; InsertText
537&apos;-------------------------------------------------------
538&apos; Inserts a string at the current position
539&apos;=======================================================
540Sub InsertText(strg As String)
541	oSel = thiscomponent.getcurrentcontroller.getselection
542	oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
543	oCur.String = strg
544End Sub
545
546&apos;=======================================================
547&apos; ParaIsEmpty
548&apos;-------------------------------------------------------
549&apos; Evaluates if a paragraph is empty.
550&apos;=======================================================
551Function ParaIsEmpty
552	oSel = thiscomponent.getcurrentcontroller.getselection
553	oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
554	oCur.gotoStartOfParagraph(0)
555	ParaIsEmpty = oCur.IsEndOfParagraph
556End Function
557
558&apos;=======================================================
559&apos; IsInBookmark
560&apos;-------------------------------------------------------
561&apos; Evaluates if the cursor is inside a &lt;bookmark&gt; &lt;/bookmark&gt; element
562&apos;=======================================================
563Function IsInBookmark
564	oSel = thiscomponent.getcurrentcontroller.getselection
565	oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
566
567	If ((oCur.ParaStyleName = &quot;hlp_aux_bookmark&quot;) AND (not(oCur.IsEndOfParagraph))) Then
568		oCur.GotoStartOfParagraph(0)
569		oCur.GotoEndOfParagraph(1)
570		sText = Left(oCur.GetString,Instr(oCur.GetString,&quot;&quot;&quot; id=&quot;&quot;&quot;)-1)
571		sText = Right(sText,Len(sText)-InStr(sText,&quot;&quot;&quot;&quot;))
572		Select Case Left(sText,3)
573			Case &quot;ind&quot;
574				IsInBookmark = 1
575			Case &quot;hid&quot;
576				IsInBookmark = 2
577			Case &quot;con&quot;
578				IsInBookmark = 3
579			Case Else
580				IsInBookmark = 0
581		End Select
582	Else
583		IsInBookmark = 0
584	End If
585End Function
586
587&apos;=======================================================
588&apos; IsInTable
589&apos;-------------------------------------------------------
590&apos; Evaluates if the cursor is in a table
591&apos;=======================================================
592Function IsInTable
593	oSel = thiscomponent.getcurrentcontroller.getselection
594	oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
595
596	IsInTable = (VarType(oCur.TextTable) &lt;&gt; 0)
597End Function
598
599&apos;=======================================================
600&apos; InsertLink
601&apos;-------------------------------------------------------
602&apos; Inserts a hyperlink at the current position
603&apos;=======================================================
604Sub InsertLink(sPath As String, sText As String, sName As String)
605	dim document   as object
606	dim dispatcher as object
607
608	document   = ThisComponent.CurrentController.Frame
609	dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
610
611	dim args(4) as new com.sun.star.beans.PropertyValue
612	args(0).Name = &quot;Hyperlink.Text&quot;
613	args(0).Value = sText
614	args(1).Name = &quot;Hyperlink.URL&quot;
615	args(1).Value = sPath
616	args(2).Name = &quot;Hyperlink.Target&quot;
617	args(2).Value = &quot;&quot;
618	args(3).Name = &quot;Hyperlink.Name&quot;
619	args(3).Value = sName
620	args(4).Name = &quot;Hyperlink.Type&quot;
621	args(4).Value = 1
622
623	dispatcher.executeDispatch(document, &quot;.uno:SetHyperlink&quot;, &quot;&quot;, 0, args())
624	args(0).Name = &quot;Count&quot;
625	args(0).Value = 1
626	args(1).Name = &quot;Select&quot;
627	args(1).Value = false
628
629	dispatcher.executeDispatch(document, &quot;.uno:GoRight&quot;, &quot;&quot;, 0, args())
630
631End Sub
632
633&apos;=======================================================
634&apos; AssignMissingIDs
635&apos;-------------------------------------------------------
636&apos; Assigns IDs to elements that miss them
637&apos;=======================================================
638Sub AssignMissingIDs
639&apos; NOT IMPLEMENTED YET
640end sub
641
642&apos;=======================================================
643&apos; CreateTable
644&apos;-------------------------------------------------------
645&apos; Creates a new table
646&apos;=======================================================
647Sub CreateTable(nRows as Integer, nCols as Integer, sID as String)
648	dim document   as object
649	dim dispatcher as object
650
651	document   = ThisComponent.CurrentController.Frame
652	dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
653
654	dim args1(3) as new com.sun.star.beans.PropertyValue
655	args1(0).Name = &quot;TableName&quot;
656	args1(0).Value = sID
657	args1(1).Name = &quot;Columns&quot;
658	args1(1).Value = nCols
659	args1(2).Name = &quot;Rows&quot;
660	args1(2).Value = nRows
661	args1(3).Name = &quot;Flags&quot;
662	args1(3).Value = 9
663
664	dispatcher.executeDispatch(document, &quot;.uno:InsertTable&quot;, &quot;&quot;, 0, args1())
665
666	args1(0).Name = &quot;TopBottomMargin.TopMargin&quot;
667	args1(0).Value = 500
668	args1(1).Name = &quot;TopBottomMargin.BottomMargin&quot;
669	args1(1).Value = 0
670	args1(2).Name = &quot;TopBottomMargin.TopRelMargin&quot;
671	args1(2).Value = 100
672	args1(3).Name = &quot;TopBottomMargin.BottomRelMargin&quot;
673	args1(3).Value = 100
674
675	dispatcher.executeDispatch(document, &quot;.uno:TopBottomMargin&quot;, &quot;&quot;, 0, args1())
676	dispatcher.executeDispatch(document, &quot;.uno:SelectAll&quot;, &quot;&quot;, 0, Array())
677	SetParaStyle(&quot;hlp_tablecontent&quot;)
678	GoDown(1)
679end Sub
680
681&apos;=======================================================
682&apos; IsBlockImage
683&apos;-------------------------------------------------------
684&apos; Evaluates if the cursor is in a paragraph with
685&apos; a block image (image in its own paragraph)
686&apos;=======================================================
687Function IsBlockImage
688	oSel = thiscomponent.getcurrentcontroller.getselection
689	oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
690	oCur.gotoStartOfParagraph(0)
691	oCur.gotoEndOfParagraph(1)
692	sStr = Right(oCur.String,Len(oCur.String)-InStr(oCur.String,&quot; &quot;))  &apos;string must start with &lt;IMG and end with IMG with no &lt;IMG in between
693	IsBlockImage = (not(Left(sStr,4)=&quot;IMG&gt;&quot;) AND (Right(sStr,6)=&quot;&lt;/IMG&gt;&quot;))
694End Function
695
696&apos;=======================================================
697&apos; HasCaption
698&apos;-------------------------------------------------------
699&apos; Evaluates if the current image has a caption element
700&apos;=======================================================
701Function HasCaption
702	oSel = thiscomponent.getcurrentcontroller.getselection
703	If oSel.ImplementationName = &quot;SwXTextGraphicObject&quot; Then
704		oCur = oSel(0).getAnchor.getText.createTextCursorByRange(oSel(0).getAnchor)
705	Else
706		oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
707	End If
708	oCur.gotoStartOfParagraph(0)
709	oCur.gotoEndOfParagraph(1)
710	HasCaption = (InStr(oCur.String,&quot;&lt;IMGCAPTION&quot;)&gt;0)
711End Function
712
713&apos;=======================================================
714&apos; GetImageID
715&apos;-------------------------------------------------------
716&apos; Returns the ID of an image at the cursor position
717&apos;=======================================================
718Function GetImageID
719	oSel = thiscomponent.getcurrentcontroller.getselection
720	If oSel.ImplementationName = &quot;SwXTextGraphicObject&quot; Then
721		oCur = oSel(0).getAnchor.getText.createTextCursorByRange(oSel(0).getAnchor)
722	Else
723		oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
724	End If
725	oCur.gotoStartOfParagraph(0)
726	oCur.gotoEndOfParagraph(1)
727	sStr = Right(oCur.String,Len(oCur.String)-(InStr(oCur.String,&quot;IMG ID=&quot;&quot;&quot;)+7))
728	GetImageID = Left(sStr,InStr(sStr,&quot;&quot;&quot;&gt;&quot;)+1)  &apos;string must start with &lt;IMG and end with IMG with no &lt;IMG in between
729End Function
730
731&apos;=======================================================
732&apos; SelAll
733&apos;-------------------------------------------------------
734&apos; Selects everything
735&apos;=======================================================
736Sub SelAll
737	dim document   as object
738	dim dispatcher as object
739
740	document   = ThisComponent.CurrentController.Frame
741	dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
742
743	dispatcher.executeDispatch(document, &quot;.uno:SelectAll&quot;, &quot;&quot;, 0, Array())
744End Sub
745
746&apos;=======================================================
747&apos; GetParaData
748&apos;-------------------------------------------------------
749&apos; Returns the Paragraph ID and localization status
750&apos;=======================================================
751Function GetParaData
752	arParaData = Array(&quot;&quot;,&quot;&quot;,&quot;&quot;) &apos; ID, localize, #message
753
754	oSel = thiscomponent.getcurrentcontroller.getselection
755	oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
756	oCur.gotoStartOfParagraph(0)
757	oCur.gotoEndOfParagraph(1)
758	sID = &quot;&quot;
759	Enum = oCur.createEnumeration
760	Fd = FALSE
761
762
763	TE = Enum.nextElement
764
765	TP = TE.createEnumeration
766	Ct = 0
767	posID = 0
768
769	Do While TP.hasmoreElements
770		Ct = Ct+1
771		TPE = TP.nextElement
772		If TPE.TextPortionType=&quot;TextField&quot; Then
773			If TPE.TextField.TextFieldMaster.Name=&quot;ID&quot; Then
774				sID = TPE.TextField.Content
775				Fd = TRUE
776				Exit Do
777			End If
778		End If
779		If TPE.String = &quot;&quot; Then
780			Ct = Ct-1
781		End If
782	Loop
783
784	If ((Left(oCur.ParaStyleName,8) = &quot;hlp_aux_&quot;) or (Left(oCur.ParaStyleName,4) &lt;&gt; &quot;hlp_&quot;)) Then
785		arParaData(2)=&quot;Invalid Paragraph Style&quot;
786		GetParaData = arParaData
787		Exit Function
788	End If
789
790	If sID = &quot;&quot; Then
791		GetParaData = arParaData
792		Exit Function
793	End If
794
795	If Right(sID,7) = &quot;_NOL10N&quot; Then
796		arParaData(0) = Left(sID,Len(sID)-7)
797		arParaData(1) = &quot;no&quot;
798	Else
799		arParaData(0) = sID
800		arParaData(1) = &quot;yes&quot;
801	End If
802
803	GetParaData = arParaData
804End Function
805
806&apos;=======================================================
807&apos; SetsParaData
808&apos;-------------------------------------------------------
809&apos; Sets the Paragraph ID and localization status
810&apos;=======================================================
811
812Sub SetParaData(sID as String, sLocalize as String)
813
814	oSel = thiscomponent.getcurrentcontroller.getselection
815	oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
816	oCur.gotoStartOfParagraph(0)
817	oCur.gotoEndOfParagraph(1)
818	Enum = oCur.createEnumeration
819	Fd = FALSE
820
821
822	Do While Enum.hasMoreElements
823		TE = Enum.nextElement
824
825		TP = TE.createEnumeration
826		Ct = 0
827		posID = 0
828
829		Do While TP.hasmoreElements
830			Ct = Ct+1
831			TPE = TP.nextElement
832			If TPE.TextPortionType=&quot;TextField&quot; Then
833				If TPE.TextField.TextFieldMaster.Name=&quot;ID&quot; Then
834					posID = Ct
835					If sLocalize = &quot;no&quot; Then
836						TPE.TextField.Content = sID+&quot;_NOL10N&quot;
837						TPE.TextField.IsVisible = TRUE
838					ElseIf sLocalize = &quot;yes&quot; Then
839						TPE.TextField.Content = sID
840						TPE.TextField.IsVisible = TRUE
841					Else
842						msgbox &quot;Unknown localization parameter: &quot;+sLocalize,0,&quot;Error&quot;
843					End If
844					Fd = TRUE
845					Exit Do
846				End If
847			End If
848			If TPE.String = &quot;&quot; Then
849				Ct = Ct-1
850			End If
851		Loop
852		If Fd Then
853			Exit Do
854		End If
855	Loop
856
857	oCur.TextField.update
858	UpdateFields
859
860End Sub
861
862
863&apos;=======================================================
864&apos; IsInList
865&apos;-------------------------------------------------------
866&apos; Evaluates if the cursor is inside a list (ordered or unordered)
867&apos;=======================================================
868Function IsInList
869	oSel = thiscomponent.getcurrentcontroller.getselection
870	oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
871	If oCur.NumberingStyleName = &quot;&quot;  Then
872		IsInList = false
873	ElseIf oCur.NumberingRules.NumberingIsOutline = true Then
874		IsInList = false
875	Else
876		IsInList = true
877	End If
878End Function
879
880&apos;=======================================================
881&apos; TagFormatIsCorrect
882&apos;-------------------------------------------------------
883&apos; Checks for correct paragraph format for tags
884&apos;=======================================================
885Function TagFormatIsCorrect(sTN As String, sPS As String)
886
887	arTag = Array(&quot;BOOKMARK&quot;,&quot;SORT&quot;,&quot;SECTION&quot;,&quot;SWITCH&quot;,&quot;CASE&quot;,&quot;DEFAULT&quot;)
888	arTagFormat = Array(&quot;hlp_aux_bookmark&quot;,&quot;hlp_aux_sort&quot;,&quot;hlp_aux_section&quot;,&quot;hlp_aux_switch&quot;,&quot;hlp_aux_switch&quot;,&quot;hlp_aux_switch&quot;)
889
890	For n=0 to ubound(arTag)
891		If (sTN = arTag(n) AND sPS &lt;&gt; arTagFormat(n)) Then
892			TagFormatIsCorrect = arTagFormat(n)
893			Exit Function
894		End If
895		TagFormatIsCorrect = &quot;&quot;
896	Next n
897
898End Function
899
900&apos;=======================================================
901&apos; GetFilePath
902&apos;-------------------------------------------------------
903&apos; look for the &quot;text/...&quot; part of the file name and separate it
904&apos;=======================================================
905Function GetFilePath(fname As String)
906
907	i = 1
908	Do
909		If (Mid(fname,i,5) = &quot;text/&quot;) Then
910			Strg = Mid(fname,i,Len(fname)-i+1)
911			Exit Do
912		Else
913			i = i+1
914			Strg = fname
915		End If
916	Loop While (i+5 &lt; Len(fname))
917	GetFilePath = Strg
918End Function
919
920&apos;=======================================================
921&apos; OpenGraphics
922&apos;-------------------------------------------------------
923&apos; Calls the graphic open dialog for inserting an image
924&apos;=======================================================
925Function OpenGraphics(oDoc As Object)
926Dim ListAny(0) as Long
927Dim oStoreProperties(0) as New com.sun.star.beans.PropertyValue
928	GlobalScope.BasicLibraries.loadLibrary(&quot;Tools&quot;)
929	ListAny(0) = com.sun.star.ui.dialogs.TemplateDescription.FILEOPEN_SIMPLE
930&apos;	ListAny(0) = com.sun.star.ui.dialogs.TemplateDescription.FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE
931	oFileDialog = CreateUnoService(&quot;com.sun.star.ui.dialogs.FilePicker&quot;)
932	oFileDialog.Initialize(ListAny())
933
934	sLastImgDir = ReadConfig(&quot;LastImgDir&quot;)
935	If sLastImgDir &lt;&gt; &quot;&quot; Then
936		oFileDialog.setDisplayDirectory(sLastImgDir)
937	End If
938
939	oMasterKey = GetRegistryKeyContent(&quot;org.openoffice.TypeDetection.Types/&quot;)
940	oTypes() = oMasterKey.Types
941
942	oFileDialog.AppendFilter(oTypes.GetByName(&quot;gif_Graphics_Interchange&quot;).UIName, &quot;*.gif&quot;)
943	oFileDialog.AppendFilter(oTypes.GetByName(&quot;png_Portable_Network_Graphic&quot;).UIName, &quot;*.png&quot;)
944
945	oFileDialog.SetTitle(&quot;Insert Image&quot;)
946	iAccept = oFileDialog.Execute()
947	If iAccept = 1 Then
948		sPath = oFileDialog.Files(0)
949		WriteConfig(&quot;LastImgDir&quot;,oFileDialog.getDisplayDirectory)
950		UIFilterName = oFileDialog.GetCurrentFilter()
951		OpenGraphics = oFileDialog.Files(0)
952	Else
953		OpenGraphics = &quot;&quot;
954	End If
955	oFileDialog.Dispose()
956End Function
957
958&apos;=======================================================
959&apos; WriteConfig
960&apos;-------------------------------------------------------
961&apos; Reads a parameter value from the config file
962&apos;=======================================================
963Function ReadConfig(Parm As String)
964	oPath = createUNOService(&quot;com.sun.star.util.PathSettings&quot;)
965	filename = oPath.UserConfig+&quot;/helpauthoring.cfg&quot;
966	iNumber = Freefile
967	bFound = false
968	If FileExists(filename) Then
969		Open filename For Input As iNumber
970		Do While (not eof(iNumber) AND not(bFound))
971			Line Input #iNumber, sLine
972			If InStr(sLine, &quot;=&quot;) &gt; 0 Then
973				arLine = split(sLine,&quot;=&quot;)
974				If arLine(0) = Parm Then
975					sResult = arLine(1)
976					bFound = true
977				End If
978			End If
979		Loop
980		Close #iNumber
981		If bFound Then
982			ReadConfig = sResult
983		Else
984			ReadConfig = &quot;&quot;
985		End If
986	Else
987		ReadConfig = &quot;&quot;
988	End If
989End Function
990
991
992&apos;=======================================================
993&apos; WriteConfig
994&apos;-------------------------------------------------------
995&apos; Writes a parameter/value pair to the config file
996&apos;=======================================================
997Function WriteConfig(Parm As String, Value As String)
998	Dim arLines(0) As String
999	bFound = false
1000	oPath = createUNOService(&quot;com.sun.star.util.PathSettings&quot;)
1001	filename = oPath.UserConfig+&quot;/helpauthoring.cfg&quot;
1002	iNumber = Freefile
1003	If FileExists(filename) Then
1004
1005		Open filename For Input As iNumber
1006		Do While (not eof(iNumber))
1007			Line Input #iNumber, sLine
1008			If InStr(sLine, &quot;=&quot;) &gt; 0 Then
1009				sDim = ubound(arLines())+1
1010				ReDim Preserve arLines(sDim)
1011				arLines(sDim) = sLine
1012			End If
1013		Loop
1014		Close #iNumber
1015
1016		nLine = 1
1017		Do While (nLine &lt;= ubound(arLines())) and (not bFound)
1018			arLine = split(arLines(nLine),&quot;=&quot;)
1019			If arLine(0) = Parm Then
1020				arLines(nLine) = Parm+&quot;=&quot;+Value
1021				bFound = true
1022			End If
1023			nLine = nLine +1
1024		Loop
1025
1026		nLine = 1
1027		Open filename For Output As iNumber
1028		Do While (nLine &lt;= ubound(arLines()))
1029			Print #iNumber, arLines(nLine)
1030			nLine = nLine + 1
1031		Loop
1032		If (not bFound) Then
1033			Print #iNumber, Parm+&quot;=&quot;+Value
1034		End If
1035		Close #iNumber
1036
1037	Else
1038		Open filename For Output As iNumber
1039		Print #iNumber, Parm+&quot;=&quot;+Value
1040		Close #iNumber
1041	End If
1042End Function
1043
1044Function GetRelPath(sPath As String)
1045	sHelpPrefix = ReadConfig(&quot;HelpPrefix&quot;)
1046	If sHelpPrefix = &quot;&quot; Then
1047		sHelpPrefix = SetDocumentRoot
1048	End If
1049	GetRelPath = Right(sPath, Len(sPath)-(InStr(sPath,sHelpPrefix) + Len(sHelpPrefix)-1))
1050End Function
1051
1052Function SetDocumentRoot
1053	sHelpPrefix = ReadConfig(&quot;HelpPrefix&quot;)
1054	oFolderDialog = CreateUnoService(&quot;com.sun.star.ui.dialogs.FolderPicker&quot;)
1055	oFolderDialog.SetTitle(&quot;Select Document Root Folder&quot;)
1056	If sHelpPrefix &gt; &quot;&quot; Then
1057		oFolderDialog.setDisplayDirectory(sHelpPrefix)
1058	End If
1059	iAccept = oFolderDialog.Execute()
1060
1061	If iAccept = 1 Then
1062		sHelpPrefix = oFolderDialog.getDirectory + &quot;/&quot;
1063		WriteConfig(&quot;HelpPrefix&quot;,sHelpPrefix)
1064	End If
1065
1066	SetDocumentRoot = sHelpPrefix
1067End Function
1068
1069Function MakeAbsPath(sPath As String)
1070
1071	sHelpPrefix = ReadConfig(&quot;HelpPrefix&quot;)
1072	If sHelpPrefix = &quot;&quot; Then
1073		sHelpPrefix = SetDocumentRoot
1074	End If
1075
1076	If Right(sPath,4) &lt;&gt; &quot;.xhp&quot; Then
1077		sPath=sPath+&quot;.xhp&quot;
1078	End If
1079	MakeAbsPath = sHelpPrefix+sPath
1080End Function
1081
1082
1083Sub UpdateFields
1084	dim document   as object
1085	dim dispatcher as object
1086	document   = ThisComponent.CurrentController.Frame
1087	dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
1088
1089	dispatcher.executeDispatch(document, &quot;.uno:UpdateFields&quot;, &quot;&quot;, 0, Array())
1090End Sub
1091
1092Function IsHelpFile
1093	document = StarDesktop.CurrentComponent
1094	IsHelpFile = (Right(GetFilePath(document.URL),4)=&quot;.xhp&quot;)
1095End Function
1096
1097Function GetUserFieldNumber(fn as String)
1098	fnum = -1
1099	For a=0 to document.DocumentInfo.getUserFieldCount - 1
1100		If document.DocumentInfo.getUserFieldName(a) = fn Then
1101			fnum = a
1102			Exit for
1103		End If
1104	Next a
1105	GetUserFieldNumber = fnum
1106End Function
1107</script:module>
1108