11ecadb57SMathias Bauer<?xml version="1.0" encoding="UTF-8"?>
21ecadb57SMathias Bauer<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*3e02b54dSAndrew Rist<!--***********************************************************
4*3e02b54dSAndrew Rist *
5*3e02b54dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
6*3e02b54dSAndrew Rist * or more contributor license agreements.  See the NOTICE file
7*3e02b54dSAndrew Rist * distributed with this work for additional information
8*3e02b54dSAndrew Rist * regarding copyright ownership.  The ASF licenses this file
9*3e02b54dSAndrew Rist * to you under the Apache License, Version 2.0 (the
10*3e02b54dSAndrew Rist * "License"); you may not use this file except in compliance
11*3e02b54dSAndrew Rist * with the License.  You may obtain a copy of the License at
12*3e02b54dSAndrew Rist *
13*3e02b54dSAndrew Rist *   http://www.apache.org/licenses/LICENSE-2.0
14*3e02b54dSAndrew Rist *
15*3e02b54dSAndrew Rist * Unless required by applicable law or agreed to in writing,
16*3e02b54dSAndrew Rist * software distributed under the License is distributed on an
17*3e02b54dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18*3e02b54dSAndrew Rist * KIND, either express or implied.  See the License for the
19*3e02b54dSAndrew Rist * specific language governing permissions and limitations
20*3e02b54dSAndrew Rist * under the License.
21*3e02b54dSAndrew Rist *
22*3e02b54dSAndrew Rist ***********************************************************-->
231ecadb57SMathias Bauer<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Find" script:language="StarBasic">&apos; *** MODULE FIND ***
241ecadb57SMathias Bauer
251ecadb57SMathias BauerDim oDialog AS Object
261ecadb57SMathias BauerDim document AS Object
271ecadb57SMathias BauerDim Found(0) As Object
281ecadb57SMathias BauerDim nPos As Integer
291ecadb57SMathias Bauer
301ecadb57SMathias Bauer&apos;=======================================================
311ecadb57SMathias Bauer&apos; Main
321ecadb57SMathias Bauer&apos;-------------------------------------------------------
331ecadb57SMathias Bauer&apos; Calls the Find routine to search in fields
341ecadb57SMathias Bauer&apos;=======================================================
351ecadb57SMathias BauerSub Main
361ecadb57SMathias Bauer
371ecadb57SMathias Bauer	If not IsHelpFile Then
381ecadb57SMathias Bauer		msgbox(strErr_NoHelpFile)
391ecadb57SMathias Bauer		Exit Sub
401ecadb57SMathias Bauer	End If
411ecadb57SMathias Bauer
421ecadb57SMathias Bauer	BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
431ecadb57SMathias Bauer	oDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlgFind&quot;)
441ecadb57SMathias Bauer
451ecadb57SMathias Bauer	oDoc = StarDesktop.CurrentComponent
461ecadb57SMathias Bauer	Enum = oDoc.Text.createEnumeration
471ecadb57SMathias Bauer
481ecadb57SMathias Bauer	LastSearchTerm = ReadConfig(&quot;SearchTerm&quot;)
491ecadb57SMathias Bauer	If LastSearchTerm &lt;&gt; &quot;&quot; Then
501ecadb57SMathias Bauer		oTxtFind = oDialog.GetControl(&quot;txtFind&quot;)
511ecadb57SMathias Bauer		oTxtFind.Text = LastSearchTerm
521ecadb57SMathias Bauer	End If
531ecadb57SMathias Bauer
541ecadb57SMathias Bauer	If oDialog.execute() = 1 Then
551ecadb57SMathias Bauer		oTxtFind = oDialog.GetControl(&quot;txtFind&quot;)
561ecadb57SMathias Bauer		sFind = oTxtFind.Text
571ecadb57SMathias Bauer		WriteConfig(&quot;SearchTerm&quot;,sFind)
581ecadb57SMathias Bauer
591ecadb57SMathias Bauer		Do While Enum.hasMoreElements
601ecadb57SMathias Bauer			TE = Enum.nextElement
611ecadb57SMathias Bauer			If TE.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
621ecadb57SMathias Bauer				TP = TE.createEnumeration
631ecadb57SMathias Bauer				While TP.hasmoreElements
641ecadb57SMathias Bauer					TPE = TP.nextElement
651ecadb57SMathias Bauer					If TPE.supportsService(&quot;com.sun.star.text.TextField&quot;) Then
661ecadb57SMathias Bauer						If Instr(TPE.String, sFind) Then
671ecadb57SMathias Bauer							sDim = ubound(Found())+1
681ecadb57SMathias Bauer							Redim Preserve Found(sDim) As Object
691ecadb57SMathias Bauer							Found(sDim) = TPE.TextField.getAnchor.getText.createTextCursorbyRange(TPE.TextField.getAnchor)
701ecadb57SMathias Bauer						End If
711ecadb57SMathias Bauer					End If
721ecadb57SMathias Bauer				Wend
731ecadb57SMathias Bauer			ElseIf TE.supportsService(&quot;com.sun.star.text.TextTable&quot;) Then
741ecadb57SMathias Bauer				CellName = &quot;A1&quot;
751ecadb57SMathias Bauer				Cell = TE.getCellByName(CellName)
761ecadb57SMathias Bauer				tmpCellEnum = Cell.createEnumeration
771ecadb57SMathias Bauer				tmpCellElement = tmpCellEnum.nextElement
781ecadb57SMathias Bauer
791ecadb57SMathias Bauer				Rows = TE.getRows
801ecadb57SMathias Bauer				Cols = TE.getColumns
811ecadb57SMathias Bauer
821ecadb57SMathias Bauer				For RowIndex = 1 to Rows.getCount()
831ecadb57SMathias Bauer					For ColIndex = 1 to Cols.getCount()
841ecadb57SMathias Bauer						CellName = Chr(64 + ColIndex) &amp; RowIndex
851ecadb57SMathias Bauer						Cell = TE.getCellByName(CellName)
861ecadb57SMathias Bauer						CellEnum = Cell.createEnumeration
871ecadb57SMathias Bauer
881ecadb57SMathias Bauer						Do While CellEnum.hasMoreElements
891ecadb57SMathias Bauer
901ecadb57SMathias Bauer							CellElement = CellEnum.nextElement
911ecadb57SMathias Bauer
921ecadb57SMathias Bauer							If CellElement.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
931ecadb57SMathias Bauer								TP = CellElement.createEnumeration
941ecadb57SMathias Bauer								While TP.hasmoreElements
951ecadb57SMathias Bauer									TPE = TP.nextElement
961ecadb57SMathias Bauer									If TPE.supportsService(&quot;com.sun.star.text.TextField&quot;) Then
971ecadb57SMathias Bauer										If Instr(TPE.String, sFind) Then
981ecadb57SMathias Bauer											sDim = ubound(Found())+1
991ecadb57SMathias Bauer											Redim Preserve Found(sDim) As Object
1001ecadb57SMathias Bauer											Found(sDim) = TPE.TextField.getAnchor.getText.createTextCursorbyRange(TPE.TextField.getAnchor)
1011ecadb57SMathias Bauer										End If
1021ecadb57SMathias Bauer									End If
1031ecadb57SMathias Bauer								Wend
1041ecadb57SMathias Bauer							EndIf
1051ecadb57SMathias Bauer
1061ecadb57SMathias Bauer						Loop
1071ecadb57SMathias Bauer
1081ecadb57SMathias Bauer					Next
1091ecadb57SMathias Bauer				Next
1101ecadb57SMathias Bauer
1111ecadb57SMathias Bauer			EndIf
1121ecadb57SMathias Bauer		Loop
1131ecadb57SMathias Bauer
1141ecadb57SMathias Bauer		If ubound(Found()) &lt; 1 	Then
1151ecadb57SMathias Bauer			msgbox &quot;Nothing found&quot;
1161ecadb57SMathias Bauer		ElseIf ubound(Found()) &gt; 1 	Then
1171ecadb57SMathias Bauer			nPos = 1
1181ecadb57SMathias Bauer			thiscomponent.getcurrentcontroller.select(Found(1))
1191ecadb57SMathias Bauer			oDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlgRepeatFind&quot;)
1201ecadb57SMathias Bauer			oPrev = oDialog.GetControl(&quot;butPrev&quot;)
1211ecadb57SMathias Bauer			oPrev.Enable = FALSE
1221ecadb57SMathias Bauer			oDialog.Execute()
1231ecadb57SMathias Bauer		Else
1241ecadb57SMathias Bauer			thiscomponent.getcurrentcontroller.select(Found(1))
1251ecadb57SMathias Bauer		End If
1261ecadb57SMathias Bauer	End If
1271ecadb57SMathias BauerEnd Sub
1281ecadb57SMathias Bauer
1291ecadb57SMathias Bauer&apos;=======================================================
1301ecadb57SMathias Bauer&apos; FindNext
1311ecadb57SMathias Bauer&apos;-------------------------------------------------------
1321ecadb57SMathias Bauer&apos; Goes to the next search result position.
1331ecadb57SMathias Bauer&apos;=======================================================
1341ecadb57SMathias BauerSub FindNext
1351ecadb57SMathias Bauer	If nPos &lt; ubound(Found()) Then
1361ecadb57SMathias Bauer		nPos = nPos + 1
1371ecadb57SMathias Bauer		thiscomponent.getcurrentcontroller.select(Found(nPos))
1381ecadb57SMathias Bauer		If nPos = ubound(Found()) Then
1391ecadb57SMathias Bauer			oNext = oDialog.GetControl(&quot;butNext&quot;)
1401ecadb57SMathias Bauer			oNext.Enable = FALSE
1411ecadb57SMathias Bauer		End If
1421ecadb57SMathias Bauer		If nPos &gt; 1 Then
1431ecadb57SMathias Bauer			oPrev = oDialog.GetControl(&quot;butPrev&quot;)
1441ecadb57SMathias Bauer			oPrev.Enable = TRUE
1451ecadb57SMathias Bauer		End If
1461ecadb57SMathias Bauer	End If
1471ecadb57SMathias BauerEnd Sub
1481ecadb57SMathias Bauer
1491ecadb57SMathias Bauer&apos;=======================================================
1501ecadb57SMathias Bauer&apos; FindPrev
1511ecadb57SMathias Bauer&apos;-------------------------------------------------------
1521ecadb57SMathias Bauer&apos; Goes to the previous search result position.
1531ecadb57SMathias Bauer&apos;=======================================================
1541ecadb57SMathias BauerSub FindPrev
1551ecadb57SMathias Bauer	If nPos &gt; 1 Then
1561ecadb57SMathias Bauer		nPos = nPos - 1
1571ecadb57SMathias Bauer		thiscomponent.getcurrentcontroller.select(Found(nPos))
1581ecadb57SMathias Bauer		If nPos = 1 Then
1591ecadb57SMathias Bauer			oPrev = oDialog.GetControl(&quot;butPrev&quot;)
1601ecadb57SMathias Bauer			oPrev.Enable = FALSE
1611ecadb57SMathias Bauer		End If
1621ecadb57SMathias Bauer		If nPos &lt; ubound(Found()) Then
1631ecadb57SMathias Bauer			oNext = oDialog.GetControl(&quot;butNext&quot;)
1641ecadb57SMathias Bauer			oNext.Enable = TRUE
1651ecadb57SMathias Bauer		End If
1661ecadb57SMathias Bauer	End If
1671ecadb57SMathias BauerEnd Sub
1681ecadb57SMathias Bauer
169*3e02b54dSAndrew Rist</script:module>
170