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">' *** 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'======================================================= 11*1ecadb57SMathias Bauer' Main 12*1ecadb57SMathias Bauer'------------------------------------------------------- 13*1ecadb57SMathias Bauer' Calls the Find routine to search in fields 14*1ecadb57SMathias Bauer'======================================================= 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("HelpAuthoring") 23*1ecadb57SMathias Bauer oDialog = LoadDialog("HelpAuthoring", "dlgFind") 24*1ecadb57SMathias Bauer 25*1ecadb57SMathias Bauer oDoc = StarDesktop.CurrentComponent 26*1ecadb57SMathias Bauer Enum = oDoc.Text.createEnumeration 27*1ecadb57SMathias Bauer 28*1ecadb57SMathias Bauer LastSearchTerm = ReadConfig("SearchTerm") 29*1ecadb57SMathias Bauer If LastSearchTerm <> "" Then 30*1ecadb57SMathias Bauer oTxtFind = oDialog.GetControl("txtFind") 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("txtFind") 36*1ecadb57SMathias Bauer sFind = oTxtFind.Text 37*1ecadb57SMathias Bauer WriteConfig("SearchTerm",sFind) 38*1ecadb57SMathias Bauer 39*1ecadb57SMathias Bauer Do While Enum.hasMoreElements 40*1ecadb57SMathias Bauer TE = Enum.nextElement 41*1ecadb57SMathias Bauer If TE.supportsService("com.sun.star.text.Paragraph") 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("com.sun.star.text.TextField") 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("com.sun.star.text.TextTable") Then 54*1ecadb57SMathias Bauer CellName = "A1" 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) & 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("com.sun.star.text.Paragraph") 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("com.sun.star.text.TextField") 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()) < 1 Then 95*1ecadb57SMathias Bauer msgbox "Nothing found" 96*1ecadb57SMathias Bauer ElseIf ubound(Found()) > 1 Then 97*1ecadb57SMathias Bauer nPos = 1 98*1ecadb57SMathias Bauer thiscomponent.getcurrentcontroller.select(Found(1)) 99*1ecadb57SMathias Bauer oDialog = LoadDialog("HelpAuthoring", "dlgRepeatFind") 100*1ecadb57SMathias Bauer oPrev = oDialog.GetControl("butPrev") 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'======================================================= 110*1ecadb57SMathias Bauer' FindNext 111*1ecadb57SMathias Bauer'------------------------------------------------------- 112*1ecadb57SMathias Bauer' Goes to the next search result position. 113*1ecadb57SMathias Bauer'======================================================= 114*1ecadb57SMathias BauerSub FindNext 115*1ecadb57SMathias Bauer If nPos < 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("butNext") 120*1ecadb57SMathias Bauer oNext.Enable = FALSE 121*1ecadb57SMathias Bauer End If 122*1ecadb57SMathias Bauer If nPos > 1 Then 123*1ecadb57SMathias Bauer oPrev = oDialog.GetControl("butPrev") 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'======================================================= 130*1ecadb57SMathias Bauer' FindPrev 131*1ecadb57SMathias Bauer'------------------------------------------------------- 132*1ecadb57SMathias Bauer' Goes to the previous search result position. 133*1ecadb57SMathias Bauer'======================================================= 134*1ecadb57SMathias BauerSub FindPrev 135*1ecadb57SMathias Bauer If nPos > 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("butPrev") 140*1ecadb57SMathias Bauer oPrev.Enable = FALSE 141*1ecadb57SMathias Bauer End If 142*1ecadb57SMathias Bauer If nPos < ubound(Found()) Then 143*1ecadb57SMathias Bauer oNext = oDialog.GetControl("butNext") 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>