blob: e0c57eb9bf7610e28ba304aaad7e30b5649e51ad [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="Find" script:language="StarBasic">&apos; *** MODULE FIND ***
Dim oDialog AS Object
Dim document AS Object
Dim Found(0) As Object
Dim nPos As Integer
&apos;=======================================================
&apos; Main
&apos;-------------------------------------------------------
&apos; Calls the Find routine to search in fields
&apos;=======================================================
Sub Main
If not IsHelpFile Then
msgbox(strErr_NoHelpFile)
Exit Sub
End If
BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
oDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlgFind&quot;)
oDoc = StarDesktop.CurrentComponent
Enum = oDoc.Text.createEnumeration
LastSearchTerm = ReadConfig(&quot;SearchTerm&quot;)
If LastSearchTerm &lt;&gt; &quot;&quot; Then
oTxtFind = oDialog.GetControl(&quot;txtFind&quot;)
oTxtFind.Text = LastSearchTerm
End If
If oDialog.execute() = 1 Then
oTxtFind = oDialog.GetControl(&quot;txtFind&quot;)
sFind = oTxtFind.Text
WriteConfig(&quot;SearchTerm&quot;,sFind)
Do While Enum.hasMoreElements
TE = Enum.nextElement
If TE.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
TP = TE.createEnumeration
While TP.hasmoreElements
TPE = TP.nextElement
If TPE.supportsService(&quot;com.sun.star.text.TextField&quot;) Then
If Instr(TPE.String, sFind) Then
sDim = ubound(Found())+1
Redim Preserve Found(sDim) As Object
Found(sDim) = TPE.TextField.getAnchor.getText.createTextCursorbyRange(TPE.TextField.getAnchor)
End If
End If
Wend
ElseIf TE.supportsService(&quot;com.sun.star.text.TextTable&quot;) Then
CellName = &quot;A1&quot;
Cell = TE.getCellByName(CellName)
tmpCellEnum = Cell.createEnumeration
tmpCellElement = tmpCellEnum.nextElement
Rows = TE.getRows
Cols = TE.getColumns
For RowIndex = 1 to Rows.getCount()
For ColIndex = 1 to Cols.getCount()
CellName = Chr(64 + ColIndex) &amp; RowIndex
Cell = TE.getCellByName(CellName)
CellEnum = Cell.createEnumeration
Do While CellEnum.hasMoreElements
CellElement = CellEnum.nextElement
If CellElement.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
TP = CellElement.createEnumeration
While TP.hasmoreElements
TPE = TP.nextElement
If TPE.supportsService(&quot;com.sun.star.text.TextField&quot;) Then
If Instr(TPE.String, sFind) Then
sDim = ubound(Found())+1
Redim Preserve Found(sDim) As Object
Found(sDim) = TPE.TextField.getAnchor.getText.createTextCursorbyRange(TPE.TextField.getAnchor)
End If
End If
Wend
EndIf
Loop
Next
Next
EndIf
Loop
If ubound(Found()) &lt; 1 Then
msgbox &quot;Nothing found&quot;
ElseIf ubound(Found()) &gt; 1 Then
nPos = 1
thiscomponent.getcurrentcontroller.select(Found(1))
oDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlgRepeatFind&quot;)
oPrev = oDialog.GetControl(&quot;butPrev&quot;)
oPrev.Enable = FALSE
oDialog.Execute()
Else
thiscomponent.getcurrentcontroller.select(Found(1))
End If
End If
End Sub
&apos;=======================================================
&apos; FindNext
&apos;-------------------------------------------------------
&apos; Goes to the next search result position.
&apos;=======================================================
Sub FindNext
If nPos &lt; ubound(Found()) Then
nPos = nPos + 1
thiscomponent.getcurrentcontroller.select(Found(nPos))
If nPos = ubound(Found()) Then
oNext = oDialog.GetControl(&quot;butNext&quot;)
oNext.Enable = FALSE
End If
If nPos &gt; 1 Then
oPrev = oDialog.GetControl(&quot;butPrev&quot;)
oPrev.Enable = TRUE
End If
End If
End Sub
&apos;=======================================================
&apos; FindPrev
&apos;-------------------------------------------------------
&apos; Goes to the previous search result position.
&apos;=======================================================
Sub FindPrev
If nPos &gt; 1 Then
nPos = nPos - 1
thiscomponent.getcurrentcontroller.select(Found(nPos))
If nPos = 1 Then
oPrev = oDialog.GetControl(&quot;butPrev&quot;)
oPrev.Enable = FALSE
End If
If nPos &lt; ubound(Found()) Then
oNext = oDialog.GetControl(&quot;butNext&quot;)
oNext.Enable = TRUE
End If
End If
End Sub
</script:module>