blob: d0bb414397890bf1e304db40f8eb50940a2d29ae [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<!--***********************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
***********************************************************-->
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Helpers" script:language="StarBasic">&apos; *** MODULE HELPERS ***
&apos;=======================================================
&apos; Main
&apos;-------------------------------------------------------
&apos; Ensure that necessary library functions are available
&apos;=======================================================
Sub Main
GlobalScope.BasicLibraries.loadLibrary(&quot;Tools&quot;)
End Sub
&apos;=======================================================
&apos; ShowProp
&apos;-------------------------------------------------------
&apos; Displays a dialog that shows the properties and
&apos; the methods of an object. Used for debugging.
&apos;=======================================================
Sub ShowProp(Elem As Object)
dim oDialog As Object
BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
oDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlgObjProp&quot;)
oDialogModel = oDialog.Model
oTxtProp = oDialog.GetControl(&quot;txtProp&quot;)
oTxtProp.Text = Join(Split(Elem.dbg_properties,&quot;;&quot;),chr(13))
oTxtMeth = oDialog.GetControl(&quot;txtMeth&quot;)
oTxtMeth.Text = Join(Split(Elem.dbg_methods,&quot;;&quot;),chr(13))
oTxtInt = oDialog.GetControl(&quot;txtInt&quot;)
oTxtInt.Text = Join(Split(Elem.dbg_supportedInterfaces,&quot;;&quot;),chr(13))
oDialog.Execute()
oDialog.dispose
End Sub
&apos;=======================================================
&apos; AlphaNum
&apos;-------------------------------------------------------
&apos; Removes all invalid characters from a string
&apos;=======================================================
Function AlphaNum(Strg As String)
dim OutStrg As String
dim sValid As String
sValid = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789&quot;
For i=1 to Len(Strg)
If (Instr(sValid,LCase(Mid(Strg,i,1)))) Then
OutStrg = OutStrg + Mid(Strg,i,1)
End If
Next i
AlphaNum = OutStrg
End Function
&apos;=======================================================
&apos; Replace
&apos;-------------------------------------------------------
&apos; Replaces a character with another character in a string
&apos;=======================================================
Function Replace(txt As String, ReplaceFrom As String, ReplaceTo As String)
dim OutStr As String
For i=1 to len(txt)
If LCase(mid(txt,i,1))=ReplaceFrom Then
OutStr = OutStr + ReplaceTo
Else
OutStr = OutStr + mid(txt,i,1)
End If
Next i
Replace = OutStr
End Function
&apos;=======================================================
&apos; ReplaceAll
&apos;-------------------------------------------------------
&apos; Replaces a character with another character in a string
&apos;=======================================================
Function ReplaceAll(txt As String, ReplaceFrom As String, ReplaceTo As String)
dim OutStr As String
For i=1 to len(txt)
bFound = 0
For j=1 to len(ReplaceFrom)
If LCase(mid(txt,i,1))=LCase(mid(ReplaceFrom,j,1)) Then
bFound = 1
OutStr = OutStr + ReplaceTo
j = len(ReplaceFrom)
End If
Next j
If bFound=0 Then
OutStr = OutStr + mid(txt,i,1)
End If
Next i
ReplaceAll = OutStr
End Function
&apos;=======================================================
&apos; CreateID
&apos;-------------------------------------------------------
&apos; Creates a numerical randomized ID
&apos;=======================================================
Function CreateID
sDate = ReplaceAll(Date,&quot;/:. \&quot;,&quot;&quot;)
sTime = ReplaceAll(Time,&quot;/:. \AMP&quot;,&quot;&quot;)
Randomize
CreateID = sDate + sTime + Int(Rnd * 100)
End Function
&apos;=======================================================
&apos; InsertTag
&apos;-------------------------------------------------------
&apos; Inserts an inline tag (element) in the document at the
&apos; current cursor position. It also sets the character
&apos; format to hlp_aux_tag
&apos;=======================================================
Sub InsertTag (Element As String, Content As String)
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dim args(5) as new com.sun.star.beans.PropertyValue
args(0).Name = &quot;Type&quot;
args(0).Value = 8
args(1).Name = &quot;SubType&quot;
args(1).Value = 1
args(2).Name = &quot;Name&quot;
args(2).Value = Element
args(3).Name = &quot;Content&quot;
args(3).Value = Content
args(4).Name = &quot;Format&quot;
args(4).Value = -1
args(5).Name = &quot;Separator&quot;
args(5).Value = &quot; &quot;
SetCharStyle(&quot;hlp_aux_tag&quot;)
dispatcher.executeDispatch(document, &quot;.uno:InsertField&quot;, &quot;&quot;, 0, args())
SetCharStyle(&quot;Default&quot;)
End Sub
&apos;=======================================================
&apos; INSERTTAGCR
&apos;-------------------------------------------------------
&apos; Inserts a tag (element) in the document at the
&apos; current cursor position in its own newly created paragraph.
&apos; It also sets the character format to hlp_aux_tag and
&apos; the paragraph to the specified value (should start with hlp_)
&apos;=======================================================
Sub InsertTagCR (Element As String, Content As String, Style As String)
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dim args(5) as new com.sun.star.beans.PropertyValue
args(0).Name = &quot;Type&quot;
args(0).Value = 8
args(1).Name = &quot;SubType&quot;
args(1).Value = 1
args(2).Name = &quot;Name&quot;
args(2).Value = Element
args(3).Name = &quot;Content&quot;
args(3).Value = Content
args(4).Name = &quot;Format&quot;
args(4).Value = -1
args(5).Name = &quot;Separator&quot;
args(5).Value = &quot; &quot;
CR
goUp(1)
SetParaStyle(Style)
SetCharStyle(&quot;hlp_aux_tag&quot;)
dispatcher.executeDispatch(document, &quot;.uno:InsertField&quot;, &quot;&quot;, 0, args())
SetCharStyle(&quot;Default&quot;)
goDown(1)
End Sub
&apos;=======================================================
&apos; InsertField
&apos;-------------------------------------------------------
&apos; Inserts a field in the document at the
&apos; current cursor position.
&apos;=======================================================
Sub InsertField(Field as String, Content as String)
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dim args(5) as new com.sun.star.beans.PropertyValue
args(0).Name = &quot;Type&quot;
args(0).Value = 8
args(1).Name = &quot;SubType&quot;
args(1).Value = 1
args(2).Name = &quot;Name&quot;
args(2).Value = Field
args(3).Name = &quot;Content&quot;
args(3).Value = Content
args(4).Name = &quot;Format&quot;
args(4).Value = -1
args(5).Name = &quot;Separator&quot;
args(5).Value = &quot; &quot;
dispatcher.executeDispatch(document, &quot;.uno:InsertField&quot;, &quot;&quot;, 0, args())
End Sub
&apos;=======================================================
&apos; GoUp
&apos;-------------------------------------------------------
&apos; Simulates the CursorUp key
&apos;=======================================================
Sub goUp(Count As Integer, Optional bSelect As Boolean)
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dim args(1) as new com.sun.star.beans.PropertyValue
args(0).Name = &quot;Count&quot;
args(0).Value = Count
args(1).Name = &quot;Select&quot;
If IsMissing(bSelect) Then
args(1).Value = false
Else
args(1).Value = bSelect
End If
dispatcher.executeDispatch(document, &quot;.uno:GoUp&quot;, &quot;&quot;, 0, args())
End Sub
&apos;=======================================================
&apos; GoDown
&apos;-------------------------------------------------------
&apos; Simulates the CursorDown key
&apos;=======================================================
Sub goDown(Count As Integer, Optional bSelect As Boolean)
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dim args(1) as new com.sun.star.beans.PropertyValue
args(0).Name = &quot;Count&quot;
args(0).Value = Count
args(1).Name = &quot;Select&quot;
If IsMissing(bSelect) Then
args(1).Value = false
Else
args(1).Value = bSelect
End If
dispatcher.executeDispatch(document, &quot;.uno:GoDown&quot;, &quot;&quot;, 0, args())
End Sub
&apos;=======================================================
&apos; GoRight
&apos;-------------------------------------------------------
&apos; Simulates the CursorRight key
&apos;=======================================================
Sub goRight(Count As Integer, Optional bSelect As Boolean)
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dim args(1) as new com.sun.star.beans.PropertyValue
args(0).Name = &quot;Count&quot;
args(0).Value = Count
args(1).Name = &quot;Select&quot;
If IsMissing(bSelect) Then
args(1).Value = false
Else
args(1).Value = bSelect
End If
dispatcher.executeDispatch(document, &quot;.uno:GoRight&quot;, &quot;&quot;, 0, args())
End Sub
&apos;=======================================================
&apos; GoLeft
&apos;-------------------------------------------------------
&apos; Simulates the CursorLeft key
&apos;=======================================================
Sub goLeft(Count As Integer, optional bSelect As boolean)
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dim args(1) as new com.sun.star.beans.PropertyValue
args(0).Name = &quot;Count&quot;
args(0).Value = Count
args(1).Name = &quot;Select&quot;
If IsMissing(bSelect) Then
args(1).Value = false
Else
args(1).Value = bSelect
End If
dispatcher.executeDispatch(document, &quot;.uno:GoLeft&quot;, &quot;&quot;, 0, args())
End Sub
&apos;=======================================================
&apos; CR
&apos;-------------------------------------------------------
&apos; Inserts a Carriage Return (a new paragraph)
&apos;=======================================================
Sub CR
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
oSel = thiscomponent.getcurrentcontroller.getselection
oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
oCur.gotoEndOfParagraph(0)
thiscomponent.getcurrentcontroller.select(oCur)
dispatcher.executeDispatch(document, &quot;.uno:InsertPara&quot;, &quot;&quot;, 0, Array())
End Sub
&apos;=======================================================
&apos; CR_before
&apos;-------------------------------------------------------
&apos; Inserts a Carriage Return (a new paragraph) before the current para
&apos;=======================================================
Sub CR_before
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
oSel = thiscomponent.getcurrentcontroller.getselection
oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
oCur.gotoStartOfParagraph(0)
thiscomponent.getcurrentcontroller.select(oCur)
dispatcher.executeDispatch(document, &quot;.uno:InsertPara&quot;, &quot;&quot;, 0, Array())
End Sub
&apos;=======================================================
&apos; LF
&apos;-------------------------------------------------------
&apos; Inserts a line feed (manual line break)
&apos;=======================================================
sub LF
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dispatcher.executeDispatch(document, &quot;.uno:InsertLinebreak&quot;, &quot;&quot;, 0, Array())
end sub
&apos;=======================================================
&apos; SetParaStyle
&apos;-------------------------------------------------------
&apos; Sets the para style to the given value
&apos;=======================================================
Sub SetParaStyle(StyleName As String)
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dim args(1) as new com.sun.star.beans.PropertyValue
args(0).Name = &quot;Template&quot;
args(0).Value = StyleName
args(1).Name = &quot;Family&quot;
args(1).Value = 2
dispatcher.executeDispatch(document, &quot;.uno:StyleApply&quot;, &quot;&quot;, 0, args())
end Sub
&apos;=======================================================
&apos; SetCharStyle
&apos;-------------------------------------------------------
&apos; Sets the character style to the given value
&apos;=======================================================
Sub SetCharStyle(StyleName As String)
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dim args(1) as new com.sun.star.beans.PropertyValue
args(0).Name = &quot;Template&quot;
args(0).Value = StyleName
args(1).Name = &quot;Family&quot;
args(1).Value = 1
dispatcher.executeDispatch(document, &quot;.uno:StyleApply&quot;, &quot;&quot;, 0, args())
end Sub
&apos;=======================================================
&apos; InsertNewParaData
&apos;-------------------------------------------------------
&apos; Inserts a new ID for the paragraph
&apos;=======================================================
Sub InsertNewParaData
If not IsHelpFile Then
msgbox(strErr_NoHelpFile)
Exit Sub
End If
oSel = thiscomponent.getcurrentcontroller.getselection
oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
arParaData = GetParaData
sID = arParaData(0)
slocalize = arParaData(1)
sMsg = arParaData(2)
If sMsg &lt;&gt; &quot;&quot; Then
msgbox &quot;Cannot assign paragraph id:&quot;+chr(13)+sMsg,48,&quot;Error&quot;
Exit Sub
End If
If sID &lt;&gt; &quot;&quot; Then
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;
Exit Sub
End If
oCur.gotoStartOfParagraph(0)
If (Left(oCur.ParaStyleName,8) = &quot;hlp_head&quot;) Then
id = &quot;hd_id&quot; + CreateID
thiscomponent.getcurrentcontroller.select(oCur)
MetaData = id
SetCharStyle(&quot;hlp_aux_parachanged&quot;)
InsertField(&quot;ID&quot;,MetaData)
SetCharStyle(&quot;Default&quot;)
Else
id = &quot;par_id&quot; + CreateID
thiscomponent.getcurrentcontroller.select(oCur)
MetaData = id
SetCharStyle(&quot;hlp_aux_parachanged&quot;)
InsertField(&quot;ID&quot;,MetaData)
SetCharStyle(&quot;Default&quot;)
End If
End Sub
&apos;=======================================================
&apos; LoadDialog
&apos;-------------------------------------------------------
&apos; Loads a BASIC dialog
&apos;=======================================================
Function LoadDialog(Libname as String, DialogName as String, Optional oLibContainer)
Dim oLib as Object
Dim oLibDialog as Object
Dim oRuntimeDialog as Object
If IsMissing(oLibContainer ) then
oLibContainer = DialogLibraries
End If
oLibContainer.LoadLibrary(LibName)
oLib = oLibContainer.GetByName(Libname)
oLibDialog = oLib.GetByName(DialogName)
oRuntimeDialog = CreateUnoDialog(oLibDialog)
LoadDialog() = oRuntimeDialog
End Function
&apos;=======================================================
&apos; Surprise
&apos;-------------------------------------------------------
&apos; D&apos;oh
&apos;=======================================================
Sub Surprise
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;
End Sub
&apos;=======================================================
&apos; InsertNote
&apos;-------------------------------------------------------
&apos; Inserts a note (annotation) at the current position
&apos;=======================================================
sub InsertNote(Content As String)
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dim args(2) as new com.sun.star.beans.PropertyValue
args(0).Name = &quot;Text&quot;
args(0).Value = Content
args(1).Name = &quot;Author&quot;
args(1).Value = &quot;Help Tooling - DO NOT EDIT&quot;
args(2).Name = &quot;Date&quot;
args(2).Value = &quot;02/27/2004&quot;
dispatcher.executeDispatch(document, &quot;.uno:InsertAnnotation&quot;, &quot;&quot;, 0, args())
end sub
&apos;=======================================================
&apos; InsertText
&apos;-------------------------------------------------------
&apos; Inserts a string at the current position
&apos;=======================================================
Sub InsertText(strg As String)
oSel = thiscomponent.getcurrentcontroller.getselection
oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
oCur.String = strg
End Sub
&apos;=======================================================
&apos; ParaIsEmpty
&apos;-------------------------------------------------------
&apos; Evaluates if a paragraph is empty.
&apos;=======================================================
Function ParaIsEmpty
oSel = thiscomponent.getcurrentcontroller.getselection
oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
oCur.gotoStartOfParagraph(0)
ParaIsEmpty = oCur.IsEndOfParagraph
End Function
&apos;=======================================================
&apos; IsInBookmark
&apos;-------------------------------------------------------
&apos; Evaluates if the cursor is inside a &lt;bookmark&gt; &lt;/bookmark&gt; element
&apos;=======================================================
Function IsInBookmark
oSel = thiscomponent.getcurrentcontroller.getselection
oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
If ((oCur.ParaStyleName = &quot;hlp_aux_bookmark&quot;) AND (not(oCur.IsEndOfParagraph))) Then
oCur.GotoStartOfParagraph(0)
oCur.GotoEndOfParagraph(1)
sText = Left(oCur.GetString,Instr(oCur.GetString,&quot;&quot;&quot; id=&quot;&quot;&quot;)-1)
sText = Right(sText,Len(sText)-InStr(sText,&quot;&quot;&quot;&quot;))
Select Case Left(sText,3)
Case &quot;ind&quot;
IsInBookmark = 1
Case &quot;hid&quot;
IsInBookmark = 2
Case &quot;con&quot;
IsInBookmark = 3
Case Else
IsInBookmark = 0
End Select
Else
IsInBookmark = 0
End If
End Function
&apos;=======================================================
&apos; IsInTable
&apos;-------------------------------------------------------
&apos; Evaluates if the cursor is in a table
&apos;=======================================================
Function IsInTable
oSel = thiscomponent.getcurrentcontroller.getselection
oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
IsInTable = (VarType(oCur.TextTable) &lt;&gt; 0)
End Function
&apos;=======================================================
&apos; InsertLink
&apos;-------------------------------------------------------
&apos; Inserts a hyperlink at the current position
&apos;=======================================================
Sub InsertLink(sPath As String, sText As String, sName As String)
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dim args(4) as new com.sun.star.beans.PropertyValue
args(0).Name = &quot;Hyperlink.Text&quot;
args(0).Value = sText
args(1).Name = &quot;Hyperlink.URL&quot;
args(1).Value = sPath
args(2).Name = &quot;Hyperlink.Target&quot;
args(2).Value = &quot;&quot;
args(3).Name = &quot;Hyperlink.Name&quot;
args(3).Value = sName
args(4).Name = &quot;Hyperlink.Type&quot;
args(4).Value = 1
dispatcher.executeDispatch(document, &quot;.uno:SetHyperlink&quot;, &quot;&quot;, 0, args())
args(0).Name = &quot;Count&quot;
args(0).Value = 1
args(1).Name = &quot;Select&quot;
args(1).Value = false
dispatcher.executeDispatch(document, &quot;.uno:GoRight&quot;, &quot;&quot;, 0, args())
End Sub
&apos;=======================================================
&apos; AssignMissingIDs
&apos;-------------------------------------------------------
&apos; Assigns IDs to elements that miss them
&apos;=======================================================
Sub AssignMissingIDs
&apos; NOT IMPLEMENTED YET
end sub
&apos;=======================================================
&apos; CreateTable
&apos;-------------------------------------------------------
&apos; Creates a new table
&apos;=======================================================
Sub CreateTable(nRows as Integer, nCols as Integer, sID as String)
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dim args1(3) as new com.sun.star.beans.PropertyValue
args1(0).Name = &quot;TableName&quot;
args1(0).Value = sID
args1(1).Name = &quot;Columns&quot;
args1(1).Value = nCols
args1(2).Name = &quot;Rows&quot;
args1(2).Value = nRows
args1(3).Name = &quot;Flags&quot;
args1(3).Value = 9
dispatcher.executeDispatch(document, &quot;.uno:InsertTable&quot;, &quot;&quot;, 0, args1())
args1(0).Name = &quot;TopBottomMargin.TopMargin&quot;
args1(0).Value = 500
args1(1).Name = &quot;TopBottomMargin.BottomMargin&quot;
args1(1).Value = 0
args1(2).Name = &quot;TopBottomMargin.TopRelMargin&quot;
args1(2).Value = 100
args1(3).Name = &quot;TopBottomMargin.BottomRelMargin&quot;
args1(3).Value = 100
dispatcher.executeDispatch(document, &quot;.uno:TopBottomMargin&quot;, &quot;&quot;, 0, args1())
dispatcher.executeDispatch(document, &quot;.uno:SelectAll&quot;, &quot;&quot;, 0, Array())
SetParaStyle(&quot;hlp_tablecontent&quot;)
GoDown(1)
end Sub
&apos;=======================================================
&apos; IsBlockImage
&apos;-------------------------------------------------------
&apos; Evaluates if the cursor is in a paragraph with
&apos; a block image (image in its own paragraph)
&apos;=======================================================
Function IsBlockImage
oSel = thiscomponent.getcurrentcontroller.getselection
oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
oCur.gotoStartOfParagraph(0)
oCur.gotoEndOfParagraph(1)
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
IsBlockImage = (not(Left(sStr,4)=&quot;IMG&gt;&quot;) AND (Right(sStr,6)=&quot;&lt;/IMG&gt;&quot;))
End Function
&apos;=======================================================
&apos; HasCaption
&apos;-------------------------------------------------------
&apos; Evaluates if the current image has a caption element
&apos;=======================================================
Function HasCaption
oSel = thiscomponent.getcurrentcontroller.getselection
If oSel.ImplementationName = &quot;SwXTextGraphicObject&quot; Then
oCur = oSel(0).getAnchor.getText.createTextCursorByRange(oSel(0).getAnchor)
Else
oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
End If
oCur.gotoStartOfParagraph(0)
oCur.gotoEndOfParagraph(1)
HasCaption = (InStr(oCur.String,&quot;&lt;IMGCAPTION&quot;)&gt;0)
End Function
&apos;=======================================================
&apos; GetImageID
&apos;-------------------------------------------------------
&apos; Returns the ID of an image at the cursor position
&apos;=======================================================
Function GetImageID
oSel = thiscomponent.getcurrentcontroller.getselection
If oSel.ImplementationName = &quot;SwXTextGraphicObject&quot; Then
oCur = oSel(0).getAnchor.getText.createTextCursorByRange(oSel(0).getAnchor)
Else
oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
End If
oCur.gotoStartOfParagraph(0)
oCur.gotoEndOfParagraph(1)
sStr = Right(oCur.String,Len(oCur.String)-(InStr(oCur.String,&quot;IMG ID=&quot;&quot;&quot;)+7))
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
End Function
&apos;=======================================================
&apos; SelAll
&apos;-------------------------------------------------------
&apos; Selects everything
&apos;=======================================================
Sub SelAll
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dispatcher.executeDispatch(document, &quot;.uno:SelectAll&quot;, &quot;&quot;, 0, Array())
End Sub
&apos;=======================================================
&apos; GetParaData
&apos;-------------------------------------------------------
&apos; Returns the Paragraph ID and localization status
&apos;=======================================================
Function GetParaData
arParaData = Array(&quot;&quot;,&quot;&quot;,&quot;&quot;) &apos; ID, localize, #message
oSel = thiscomponent.getcurrentcontroller.getselection
oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
oCur.gotoStartOfParagraph(0)
oCur.gotoEndOfParagraph(1)
sID = &quot;&quot;
Enum = oCur.createEnumeration
Fd = FALSE
TE = Enum.nextElement
TP = TE.createEnumeration
Ct = 0
posID = 0
Do While TP.hasmoreElements
Ct = Ct+1
TPE = TP.nextElement
If TPE.TextPortionType=&quot;TextField&quot; Then
If TPE.TextField.TextFieldMaster.Name=&quot;ID&quot; Then
sID = TPE.TextField.Content
Fd = TRUE
Exit Do
End If
End If
If TPE.String = &quot;&quot; Then
Ct = Ct-1
End If
Loop
If ((Left(oCur.ParaStyleName,8) = &quot;hlp_aux_&quot;) or (Left(oCur.ParaStyleName,4) &lt;&gt; &quot;hlp_&quot;)) Then
arParaData(2)=&quot;Invalid Paragraph Style&quot;
GetParaData = arParaData
Exit Function
End If
If sID = &quot;&quot; Then
GetParaData = arParaData
Exit Function
End If
If Right(sID,7) = &quot;_NOL10N&quot; Then
arParaData(0) = Left(sID,Len(sID)-7)
arParaData(1) = &quot;no&quot;
Else
arParaData(0) = sID
arParaData(1) = &quot;yes&quot;
End If
GetParaData = arParaData
End Function
&apos;=======================================================
&apos; SetsParaData
&apos;-------------------------------------------------------
&apos; Sets the Paragraph ID and localization status
&apos;=======================================================
Sub SetParaData(sID as String, sLocalize as String)
oSel = thiscomponent.getcurrentcontroller.getselection
oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
oCur.gotoStartOfParagraph(0)
oCur.gotoEndOfParagraph(1)
Enum = oCur.createEnumeration
Fd = FALSE
Do While Enum.hasMoreElements
TE = Enum.nextElement
TP = TE.createEnumeration
Ct = 0
posID = 0
Do While TP.hasmoreElements
Ct = Ct+1
TPE = TP.nextElement
If TPE.TextPortionType=&quot;TextField&quot; Then
If TPE.TextField.TextFieldMaster.Name=&quot;ID&quot; Then
posID = Ct
If sLocalize = &quot;no&quot; Then
TPE.TextField.Content = sID+&quot;_NOL10N&quot;
TPE.TextField.IsVisible = TRUE
ElseIf sLocalize = &quot;yes&quot; Then
TPE.TextField.Content = sID
TPE.TextField.IsVisible = TRUE
Else
msgbox &quot;Unknown localization parameter: &quot;+sLocalize,0,&quot;Error&quot;
End If
Fd = TRUE
Exit Do
End If
End If
If TPE.String = &quot;&quot; Then
Ct = Ct-1
End If
Loop
If Fd Then
Exit Do
End If
Loop
oCur.TextField.update
UpdateFields
End Sub
&apos;=======================================================
&apos; IsInList
&apos;-------------------------------------------------------
&apos; Evaluates if the cursor is inside a list (ordered or unordered)
&apos;=======================================================
Function IsInList
oSel = thiscomponent.getcurrentcontroller.getselection
oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
If oCur.NumberingStyleName = &quot;&quot; Then
IsInList = false
ElseIf oCur.NumberingRules.NumberingIsOutline = true Then
IsInList = false
Else
IsInList = true
End If
End Function
&apos;=======================================================
&apos; TagFormatIsCorrect
&apos;-------------------------------------------------------
&apos; Checks for correct paragraph format for tags
&apos;=======================================================
Function TagFormatIsCorrect(sTN As String, sPS As String)
arTag = Array(&quot;BOOKMARK&quot;,&quot;SORT&quot;,&quot;SECTION&quot;,&quot;SWITCH&quot;,&quot;CASE&quot;,&quot;DEFAULT&quot;)
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;)
For n=0 to ubound(arTag)
If (sTN = arTag(n) AND sPS &lt;&gt; arTagFormat(n)) Then
TagFormatIsCorrect = arTagFormat(n)
Exit Function
End If
TagFormatIsCorrect = &quot;&quot;
Next n
End Function
&apos;=======================================================
&apos; GetFilePath
&apos;-------------------------------------------------------
&apos; look for the &quot;text/...&quot; part of the file name and separate it
&apos;=======================================================
Function GetFilePath(fname As String)
i = 1
Do
If (Mid(fname,i,5) = &quot;text/&quot;) Then
Strg = Mid(fname,i,Len(fname)-i+1)
Exit Do
Else
i = i+1
Strg = fname
End If
Loop While (i+5 &lt; Len(fname))
GetFilePath = Strg
End Function
&apos;=======================================================
&apos; OpenGraphics
&apos;-------------------------------------------------------
&apos; Calls the graphic open dialog for inserting an image
&apos;=======================================================
Function OpenGraphics(oDoc As Object)
Dim ListAny(0) as Long
Dim oStoreProperties(0) as New com.sun.star.beans.PropertyValue
GlobalScope.BasicLibraries.loadLibrary(&quot;Tools&quot;)
ListAny(0) = com.sun.star.ui.dialogs.TemplateDescription.FILEOPEN_SIMPLE
&apos; ListAny(0) = com.sun.star.ui.dialogs.TemplateDescription.FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE
oFileDialog = CreateUnoService(&quot;com.sun.star.ui.dialogs.FilePicker&quot;)
oFileDialog.Initialize(ListAny())
sLastImgDir = ReadConfig(&quot;LastImgDir&quot;)
If sLastImgDir &lt;&gt; &quot;&quot; Then
oFileDialog.setDisplayDirectory(sLastImgDir)
End If
oMasterKey = GetRegistryKeyContent(&quot;org.openoffice.TypeDetection.Types/&quot;)
oTypes() = oMasterKey.Types
oFileDialog.AppendFilter(oTypes.GetByName(&quot;gif_Graphics_Interchange&quot;).UIName, &quot;*.gif&quot;)
oFileDialog.AppendFilter(oTypes.GetByName(&quot;png_Portable_Network_Graphic&quot;).UIName, &quot;*.png&quot;)
oFileDialog.SetTitle(&quot;Insert Image&quot;)
iAccept = oFileDialog.Execute()
If iAccept = 1 Then
sPath = oFileDialog.Files(0)
WriteConfig(&quot;LastImgDir&quot;,oFileDialog.getDisplayDirectory)
UIFilterName = oFileDialog.GetCurrentFilter()
OpenGraphics = oFileDialog.Files(0)
Else
OpenGraphics = &quot;&quot;
End If
oFileDialog.Dispose()
End Function
&apos;=======================================================
&apos; WriteConfig
&apos;-------------------------------------------------------
&apos; Reads a parameter value from the config file
&apos;=======================================================
Function ReadConfig(Parm As String)
oPath = createUNOService(&quot;com.sun.star.util.PathSettings&quot;)
filename = oPath.UserConfig+&quot;/helpauthoring.cfg&quot;
iNumber = Freefile
bFound = false
If FileExists(filename) Then
Open filename For Input As iNumber
Do While (not eof(iNumber) AND not(bFound))
Line Input #iNumber, sLine
If InStr(sLine, &quot;=&quot;) &gt; 0 Then
arLine = split(sLine,&quot;=&quot;)
If arLine(0) = Parm Then
sResult = arLine(1)
bFound = true
End If
End If
Loop
Close #iNumber
If bFound Then
ReadConfig = sResult
Else
ReadConfig = &quot;&quot;
End If
Else
ReadConfig = &quot;&quot;
End If
End Function
&apos;=======================================================
&apos; WriteConfig
&apos;-------------------------------------------------------
&apos; Writes a parameter/value pair to the config file
&apos;=======================================================
Function WriteConfig(Parm As String, Value As String)
Dim arLines(0) As String
bFound = false
oPath = createUNOService(&quot;com.sun.star.util.PathSettings&quot;)
filename = oPath.UserConfig+&quot;/helpauthoring.cfg&quot;
iNumber = Freefile
If FileExists(filename) Then
Open filename For Input As iNumber
Do While (not eof(iNumber))
Line Input #iNumber, sLine
If InStr(sLine, &quot;=&quot;) &gt; 0 Then
sDim = ubound(arLines())+1
ReDim Preserve arLines(sDim)
arLines(sDim) = sLine
End If
Loop
Close #iNumber
nLine = 1
Do While (nLine &lt;= ubound(arLines())) and (not bFound)
arLine = split(arLines(nLine),&quot;=&quot;)
If arLine(0) = Parm Then
arLines(nLine) = Parm+&quot;=&quot;+Value
bFound = true
End If
nLine = nLine +1
Loop
nLine = 1
Open filename For Output As iNumber
Do While (nLine &lt;= ubound(arLines()))
Print #iNumber, arLines(nLine)
nLine = nLine + 1
Loop
If (not bFound) Then
Print #iNumber, Parm+&quot;=&quot;+Value
End If
Close #iNumber
Else
Open filename For Output As iNumber
Print #iNumber, Parm+&quot;=&quot;+Value
Close #iNumber
End If
End Function
Function GetRelPath(sPath As String)
sHelpPrefix = ReadConfig(&quot;HelpPrefix&quot;)
If sHelpPrefix = &quot;&quot; Then
sHelpPrefix = SetDocumentRoot
End If
GetRelPath = Right(sPath, Len(sPath)-(InStr(sPath,sHelpPrefix) + Len(sHelpPrefix)-1))
End Function
Function SetDocumentRoot
sHelpPrefix = ReadConfig(&quot;HelpPrefix&quot;)
oFolderDialog = CreateUnoService(&quot;com.sun.star.ui.dialogs.FolderPicker&quot;)
oFolderDialog.SetTitle(&quot;Select Document Root Folder&quot;)
If sHelpPrefix &gt; &quot;&quot; Then
oFolderDialog.setDisplayDirectory(sHelpPrefix)
End If
iAccept = oFolderDialog.Execute()
If iAccept = 1 Then
sHelpPrefix = oFolderDialog.getDirectory + &quot;/&quot;
WriteConfig(&quot;HelpPrefix&quot;,sHelpPrefix)
End If
SetDocumentRoot = sHelpPrefix
End Function
Function MakeAbsPath(sPath As String)
sHelpPrefix = ReadConfig(&quot;HelpPrefix&quot;)
If sHelpPrefix = &quot;&quot; Then
sHelpPrefix = SetDocumentRoot
End If
If Right(sPath,4) &lt;&gt; &quot;.xhp&quot; Then
sPath=sPath+&quot;.xhp&quot;
End If
MakeAbsPath = sHelpPrefix+sPath
End Function
Sub UpdateFields
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dispatcher.executeDispatch(document, &quot;.uno:UpdateFields&quot;, &quot;&quot;, 0, Array())
End Sub
Function IsHelpFile
document = StarDesktop.CurrentComponent
IsHelpFile = (Right(GetFilePath(document.URL),4)=&quot;.xhp&quot;)
End Function
Function GetUserFieldNumber(fn as String)
fnum = -1
For a=0 to document.DocumentInfo.getUserFieldCount - 1
If document.DocumentInfo.getUserFieldName(a) = fn Then
fnum = a
Exit for
End If
Next a
GetUserFieldNumber = fnum
End Function
</script:module>