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">' *** MODULE FIND *** 24 25Dim oDialog AS Object 26Dim document AS Object 27Dim Found(0) As Object 28Dim nPos As Integer 29 30'======================================================= 31' Main 32'------------------------------------------------------- 33' Calls the Find routine to search in fields 34'======================================================= 35Sub Main 36 37 If not IsHelpFile Then 38 msgbox(strErr_NoHelpFile) 39 Exit Sub 40 End If 41 42 BasicLibraries.LoadLibrary("HelpAuthoring") 43 oDialog = LoadDialog("HelpAuthoring", "dlgFind") 44 45 oDoc = StarDesktop.CurrentComponent 46 Enum = oDoc.Text.createEnumeration 47 48 LastSearchTerm = ReadConfig("SearchTerm") 49 If LastSearchTerm <> "" Then 50 oTxtFind = oDialog.GetControl("txtFind") 51 oTxtFind.Text = LastSearchTerm 52 End If 53 54 If oDialog.execute() = 1 Then 55 oTxtFind = oDialog.GetControl("txtFind") 56 sFind = oTxtFind.Text 57 WriteConfig("SearchTerm",sFind) 58 59 Do While Enum.hasMoreElements 60 TE = Enum.nextElement 61 If TE.supportsService("com.sun.star.text.Paragraph") Then 62 TP = TE.createEnumeration 63 While TP.hasmoreElements 64 TPE = TP.nextElement 65 If TPE.supportsService("com.sun.star.text.TextField") 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("com.sun.star.text.TextTable") Then 74 CellName = "A1" 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) & 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("com.sun.star.text.Paragraph") Then 93 TP = CellElement.createEnumeration 94 While TP.hasmoreElements 95 TPE = TP.nextElement 96 If TPE.supportsService("com.sun.star.text.TextField") 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()) < 1 Then 115 msgbox "Nothing found" 116 ElseIf ubound(Found()) > 1 Then 117 nPos = 1 118 thiscomponent.getcurrentcontroller.select(Found(1)) 119 oDialog = LoadDialog("HelpAuthoring", "dlgRepeatFind") 120 oPrev = oDialog.GetControl("butPrev") 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'======================================================= 130' FindNext 131'------------------------------------------------------- 132' Goes to the next search result position. 133'======================================================= 134Sub FindNext 135 If nPos < ubound(Found()) Then 136 nPos = nPos + 1 137 thiscomponent.getcurrentcontroller.select(Found(nPos)) 138 If nPos = ubound(Found()) Then 139 oNext = oDialog.GetControl("butNext") 140 oNext.Enable = FALSE 141 End If 142 If nPos > 1 Then 143 oPrev = oDialog.GetControl("butPrev") 144 oPrev.Enable = TRUE 145 End If 146 End If 147End Sub 148 149'======================================================= 150' FindPrev 151'------------------------------------------------------- 152' Goes to the previous search result position. 153'======================================================= 154Sub FindPrev 155 If nPos > 1 Then 156 nPos = nPos - 1 157 thiscomponent.getcurrentcontroller.select(Found(nPos)) 158 If nPos = 1 Then 159 oPrev = oDialog.GetControl("butPrev") 160 oPrev.Enable = FALSE 161 End If 162 If nPos < ubound(Found()) Then 163 oNext = oDialog.GetControl("butNext") 164 oNext.Enable = TRUE 165 End If 166 End If 167End Sub 168 169</script:module> 170