1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Find" script:language="StarBasic">&apos; *** MODULE FIND ***
4
5Dim oDialog AS Object
6Dim document AS Object
7Dim Found(0) As Object
8Dim nPos As Integer
9
10&apos;=======================================================
11&apos; Main
12&apos;-------------------------------------------------------
13&apos; Calls the Find routine to search in fields
14&apos;=======================================================
15Sub Main
16
17	If not IsHelpFile Then
18		msgbox(strErr_NoHelpFile)
19		Exit Sub
20	End If
21
22	BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
23	oDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlgFind&quot;)
24
25	oDoc = StarDesktop.CurrentComponent
26	Enum = oDoc.Text.createEnumeration
27
28	LastSearchTerm = ReadConfig(&quot;SearchTerm&quot;)
29	If LastSearchTerm &lt;&gt; &quot;&quot; Then
30		oTxtFind = oDialog.GetControl(&quot;txtFind&quot;)
31		oTxtFind.Text = LastSearchTerm
32	End If
33
34	If oDialog.execute() = 1 Then
35		oTxtFind = oDialog.GetControl(&quot;txtFind&quot;)
36		sFind = oTxtFind.Text
37		WriteConfig(&quot;SearchTerm&quot;,sFind)
38
39		Do While Enum.hasMoreElements
40			TE = Enum.nextElement
41			If TE.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
42				TP = TE.createEnumeration
43				While TP.hasmoreElements
44					TPE = TP.nextElement
45					If TPE.supportsService(&quot;com.sun.star.text.TextField&quot;) Then
46						If Instr(TPE.String, sFind) Then
47							sDim = ubound(Found())+1
48							Redim Preserve Found(sDim) As Object
49							Found(sDim) = TPE.TextField.getAnchor.getText.createTextCursorbyRange(TPE.TextField.getAnchor)
50						End If
51					End If
52				Wend
53			ElseIf TE.supportsService(&quot;com.sun.star.text.TextTable&quot;) Then
54				CellName = &quot;A1&quot;
55				Cell = TE.getCellByName(CellName)
56				tmpCellEnum = Cell.createEnumeration
57				tmpCellElement = tmpCellEnum.nextElement
58
59				Rows = TE.getRows
60				Cols = TE.getColumns
61
62				For RowIndex = 1 to Rows.getCount()
63					For ColIndex = 1 to Cols.getCount()
64						CellName = Chr(64 + ColIndex) &amp; RowIndex
65						Cell = TE.getCellByName(CellName)
66						CellEnum = Cell.createEnumeration
67
68						Do While CellEnum.hasMoreElements
69
70							CellElement = CellEnum.nextElement
71
72							If CellElement.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
73								TP = CellElement.createEnumeration
74								While TP.hasmoreElements
75									TPE = TP.nextElement
76									If TPE.supportsService(&quot;com.sun.star.text.TextField&quot;) Then
77										If Instr(TPE.String, sFind) Then
78											sDim = ubound(Found())+1
79											Redim Preserve Found(sDim) As Object
80											Found(sDim) = TPE.TextField.getAnchor.getText.createTextCursorbyRange(TPE.TextField.getAnchor)
81										End If
82									End If
83								Wend
84							EndIf
85
86						Loop
87
88					Next
89				Next
90
91			EndIf
92		Loop
93
94		If ubound(Found()) &lt; 1 	Then
95			msgbox &quot;Nothing found&quot;
96		ElseIf ubound(Found()) &gt; 1 	Then
97			nPos = 1
98			thiscomponent.getcurrentcontroller.select(Found(1))
99			oDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlgRepeatFind&quot;)
100			oPrev = oDialog.GetControl(&quot;butPrev&quot;)
101			oPrev.Enable = FALSE
102			oDialog.Execute()
103		Else
104			thiscomponent.getcurrentcontroller.select(Found(1))
105		End If
106	End If
107End Sub
108
109&apos;=======================================================
110&apos; FindNext
111&apos;-------------------------------------------------------
112&apos; Goes to the next search result position.
113&apos;=======================================================
114Sub FindNext
115	If nPos &lt; ubound(Found()) Then
116		nPos = nPos + 1
117		thiscomponent.getcurrentcontroller.select(Found(nPos))
118		If nPos = ubound(Found()) Then
119			oNext = oDialog.GetControl(&quot;butNext&quot;)
120			oNext.Enable = FALSE
121		End If
122		If nPos &gt; 1 Then
123			oPrev = oDialog.GetControl(&quot;butPrev&quot;)
124			oPrev.Enable = TRUE
125		End If
126	End If
127End Sub
128
129&apos;=======================================================
130&apos; FindPrev
131&apos;-------------------------------------------------------
132&apos; Goes to the previous search result position.
133&apos;=======================================================
134Sub FindPrev
135	If nPos &gt; 1 Then
136		nPos = nPos - 1
137		thiscomponent.getcurrentcontroller.select(Found(nPos))
138		If nPos = 1 Then
139			oPrev = oDialog.GetControl(&quot;butPrev&quot;)
140			oPrev.Enable = FALSE
141		End If
142		If nPos &lt; ubound(Found()) Then
143			oNext = oDialog.GetControl(&quot;butNext&quot;)
144			oNext.Enable = TRUE
145		End If
146	End If
147End Sub
148
149</script:module>