xref: /AOO41X/main/helpauthoring/HelpAuthoring/Find.xba (revision 54628ca40d27d15cc98fe861da7fff7e60c2f7d6)
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<!--***********************************************************
4 *
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements.  See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership.  The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License.  You may obtain a copy of the License at
12 *
13 *   http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied.  See the License for the
19 * specific language governing permissions and limitations
20 * under the License.
21 *
22 ***********************************************************-->
23<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Find" script:language="StarBasic">&apos; *** MODULE FIND ***
24
25Dim oDialog AS Object
26Dim document AS Object
27Dim Found(0) As Object
28Dim nPos As Integer
29
30&apos;=======================================================
31&apos; Main
32&apos;-------------------------------------------------------
33&apos; Calls the Find routine to search in fields
34&apos;=======================================================
35Sub Main
36
37    If not IsHelpFile Then
38        msgbox(strErr_NoHelpFile)
39        Exit Sub
40    End If
41
42    BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
43    oDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlgFind&quot;)
44
45    oDoc = StarDesktop.CurrentComponent
46    Enum = oDoc.Text.createEnumeration
47
48    LastSearchTerm = ReadConfig(&quot;SearchTerm&quot;)
49    If LastSearchTerm &lt;&gt; &quot;&quot; Then
50        oTxtFind = oDialog.GetControl(&quot;txtFind&quot;)
51        oTxtFind.Text = LastSearchTerm
52    End If
53
54    If oDialog.execute() = 1 Then
55        oTxtFind = oDialog.GetControl(&quot;txtFind&quot;)
56        sFind = oTxtFind.Text
57        WriteConfig(&quot;SearchTerm&quot;,sFind)
58
59        Do While Enum.hasMoreElements
60            TE = Enum.nextElement
61            If TE.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
62                TP = TE.createEnumeration
63                While TP.hasmoreElements
64                    TPE = TP.nextElement
65                    If TPE.supportsService(&quot;com.sun.star.text.TextField&quot;) Then
66                        If Instr(TPE.String, sFind) Then
67                            sDim = ubound(Found())+1
68                            Redim Preserve Found(sDim) As Object
69                            Found(sDim) = TPE.TextField.getAnchor.getText.createTextCursorbyRange(TPE.TextField.getAnchor)
70                        End If
71                    End If
72                Wend
73            ElseIf TE.supportsService(&quot;com.sun.star.text.TextTable&quot;) Then
74                CellName = &quot;A1&quot;
75                Cell = TE.getCellByName(CellName)
76                tmpCellEnum = Cell.createEnumeration
77                tmpCellElement = tmpCellEnum.nextElement
78
79                Rows = TE.getRows
80                Cols = TE.getColumns
81
82                For RowIndex = 1 to Rows.getCount()
83                    For ColIndex = 1 to Cols.getCount()
84                        CellName = Chr(64 + ColIndex) &amp; RowIndex
85                        Cell = TE.getCellByName(CellName)
86                        CellEnum = Cell.createEnumeration
87
88                        Do While CellEnum.hasMoreElements
89
90                            CellElement = CellEnum.nextElement
91
92                            If CellElement.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
93                                TP = CellElement.createEnumeration
94                                While TP.hasmoreElements
95                                    TPE = TP.nextElement
96                                    If TPE.supportsService(&quot;com.sun.star.text.TextField&quot;) Then
97                                        If Instr(TPE.String, sFind) Then
98                                            sDim = ubound(Found())+1
99                                            Redim Preserve Found(sDim) As Object
100                                            Found(sDim) = TPE.TextField.getAnchor.getText.createTextCursorbyRange(TPE.TextField.getAnchor)
101                                        End If
102                                    End If
103                                Wend
104                            EndIf
105
106                        Loop
107
108                    Next
109                Next
110
111            EndIf
112        Loop
113
114        If ubound(Found()) &lt; 1   Then
115            msgbox &quot;Nothing found&quot;
116        ElseIf ubound(Found()) &gt; 1   Then
117            nPos = 1
118            thiscomponent.getcurrentcontroller.select(Found(1))
119            oDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlgRepeatFind&quot;)
120            oPrev = oDialog.GetControl(&quot;butPrev&quot;)
121            oPrev.Enable = FALSE
122            oDialog.Execute()
123        Else
124            thiscomponent.getcurrentcontroller.select(Found(1))
125        End If
126    End If
127End Sub
128
129&apos;=======================================================
130&apos; FindNext
131&apos;-------------------------------------------------------
132&apos; Goes to the next search result position.
133&apos;=======================================================
134Sub FindNext
135    If nPos &lt; ubound(Found()) Then
136        nPos = nPos + 1
137        thiscomponent.getcurrentcontroller.select(Found(nPos))
138        If nPos = ubound(Found()) Then
139            oNext = oDialog.GetControl(&quot;butNext&quot;)
140            oNext.Enable = FALSE
141        End If
142        If nPos &gt; 1 Then
143            oPrev = oDialog.GetControl(&quot;butPrev&quot;)
144            oPrev.Enable = TRUE
145        End If
146    End If
147End Sub
148
149&apos;=======================================================
150&apos; FindPrev
151&apos;-------------------------------------------------------
152&apos; Goes to the previous search result position.
153&apos;=======================================================
154Sub FindPrev
155    If nPos &gt; 1 Then
156        nPos = nPos - 1
157        thiscomponent.getcurrentcontroller.select(Found(nPos))
158        If nPos = 1 Then
159            oPrev = oDialog.GetControl(&quot;butPrev&quot;)
160            oPrev.Enable = FALSE
161        End If
162        If nPos &lt; ubound(Found()) Then
163            oNext = oDialog.GetControl(&quot;butNext&quot;)
164            oNext.Enable = TRUE
165        End If
166    End If
167End Sub
168
169</script:module>
170