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