1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?> 2cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3*3e02b54dSAndrew Rist<!--*********************************************************** 4*3e02b54dSAndrew Rist * 5*3e02b54dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 6*3e02b54dSAndrew Rist * or more contributor license agreements. See the NOTICE file 7*3e02b54dSAndrew Rist * distributed with this work for additional information 8*3e02b54dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 9*3e02b54dSAndrew Rist * to you under the Apache License, Version 2.0 (the 10*3e02b54dSAndrew Rist * "License"); you may not use this file except in compliance 11*3e02b54dSAndrew Rist * with the License. You may obtain a copy of the License at 12*3e02b54dSAndrew Rist * 13*3e02b54dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 14*3e02b54dSAndrew Rist * 15*3e02b54dSAndrew Rist * Unless required by applicable law or agreed to in writing, 16*3e02b54dSAndrew Rist * software distributed under the License is distributed on an 17*3e02b54dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18*3e02b54dSAndrew Rist * KIND, either express or implied. See the License for the 19*3e02b54dSAndrew Rist * specific language governing permissions and limitations 20*3e02b54dSAndrew Rist * under the License. 21*3e02b54dSAndrew Rist * 22*3e02b54dSAndrew Rist ***********************************************************--> 23cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="ChangeAllChars" script:language="StarBasic">' This macro replaces all characters in a writer-documet through "x" or "X" signs. 24cdf0e10cSrcweir' It works on the currently activated document. 25cdf0e10cSrcweirPrivate const UPPERREPLACECHAR = "X" 26cdf0e10cSrcweirPrivate const LOWERREPLACECHAR = "x" 27cdf0e10cSrcweir 28cdf0e10cSrcweirPrivate MSGBOXTITLE 29cdf0e10cSrcweirPrivate NOTSAVEDTEXT 30cdf0e10cSrcweirPrivate WARNING 31cdf0e10cSrcweir 32cdf0e10cSrcweirSub ChangeAllChars ' Change all chars in the active document 33cdf0e10cSrcweirDim oSheets, oPages as Object 34cdf0e10cSrcweirDim i as Integer 35cdf0e10cSrcweirConst MBYES = 6 36cdf0e10cSrcweirConst MBABORT = 2 37cdf0e10cSrcweirConst MBNO = 7 38cdf0e10cSrcweir BasicLibraries.LoadLibrary("Tools") 39cdf0e10cSrcweir MSGBOXTITLE = "Change All Characters to an '" & UPPERREPLACECHAR & "'" 40cdf0e10cSrcweir NOTSAVEDTEXT = "This document has already been modified: All characters will be changed to an " & UPPERREPLACECHAR & "'. Should the document be saved now?" 41cdf0e10cSrcweir WARNING = "This macro changes all characters and numbers to an '" & UPPERREPLACECHAR & "' in this document." 42cdf0e10cSrcweir 43cdf0e10cSrcweir On Local Error GoTo NODOCUMENT 44cdf0e10cSrcweir oDocument = StarDesktop.ActiveFrame.Controller.Model 45cdf0e10cSrcweir NODOCUMENT: 46cdf0e10cSrcweir If Err <> 0 Then 47cdf0e10cSrcweir Msgbox(WARNING & chr(13) & "First, activate a Writer document." , 16, GetProductName()) 48cdf0e10cSrcweir Exit Sub 49cdf0e10cSrcweir End If 50cdf0e10cSrcweir On Local Error Goto 0 51cdf0e10cSrcweir 52cdf0e10cSrcweir sDocType = GetDocumentType(oDocument) 53cdf0e10cSrcweir 54cdf0e10cSrcweir If oDocument.IsModified And oDocument.Url <> "" Then 55cdf0e10cSrcweir Status = MsgBox(NOTSAVEDTEXT, 3+32, MSGBOXTITLE) 56cdf0e10cSrcweir Select Case Status 57cdf0e10cSrcweir Case MBYES 58cdf0e10cSrcweir oDocument.Store 59cdf0e10cSrcweir Case MBABORT, MBNO 60cdf0e10cSrcweir End 61cdf0e10cSrcweir End Select 62cdf0e10cSrcweir Else 63cdf0e10cSrcweir Status = MsgBox(WARNING, 3+32, MSGBOXTITLE) 64cdf0e10cSrcweir If Status = MBNO Or Status = MBABORT Then ' No, Abort 65cdf0e10cSrcweir End 66cdf0e10cSrcweir End If 67cdf0e10cSrcweir End If 68cdf0e10cSrcweir 69cdf0e10cSrcweir Select Case sDocType 70cdf0e10cSrcweir Case "swriter" 71cdf0e10cSrcweir ReplaceAllStrings(oDocument) 72cdf0e10cSrcweir 73cdf0e10cSrcweir Case Else 74cdf0e10cSrcweir Msgbox("This macro only works with Writer documents.", 16, GetProductName()) 75cdf0e10cSrcweir End Select 76cdf0e10cSrcweirEnd Sub 77cdf0e10cSrcweir 78cdf0e10cSrcweir 79cdf0e10cSrcweirSub ReplaceAllStrings(oContainer as Object) 80cdf0e10cSrcweir ReplaceStrings(oContainer, "[a-z]", LOWERREPLACECHAR) 81cdf0e10cSrcweir ReplaceStrings(oContainer, "[à-þ]", LOWERREPLACECHAR) 82cdf0e10cSrcweir ReplaceStrings(oContainer, "[A-Z]", UPPERREPLACECHAR) 83cdf0e10cSrcweir ReplaceStrings(oContainer, "[À-ß]", UPPERREPLACECHAR) 84cdf0e10cSrcweir ReplaceStrings(oContainer, "[0-9]", UPPERREPLACECHAR) 85cdf0e10cSrcweirEnd Sub 86cdf0e10cSrcweir 87cdf0e10cSrcweir 88cdf0e10cSrcweirSub ReplaceStrings(oContainer as Object, sSearchString, sReplaceString as String) 89cdf0e10cSrcweir oReplaceDesc = oContainer.createReplaceDescriptor() 90cdf0e10cSrcweir oReplaceDesc.SearchCaseSensitive = True 91cdf0e10cSrcweir oReplaceDesc.SearchRegularExpression = True 92cdf0e10cSrcweir oReplaceDesc.Searchstring = sSearchString 93cdf0e10cSrcweir oReplaceDesc.ReplaceString = sReplaceString 94cdf0e10cSrcweir oReplCount = oContainer.ReplaceAll(oReplaceDesc) 95*3e02b54dSAndrew RistEnd Sub</script:module> 96