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">&apos; This macro replaces all characters in a writer-documet through &quot;x&quot; or &quot;X&quot; signs.
24cdf0e10cSrcweir&apos; It works on the currently activated document.
25cdf0e10cSrcweirPrivate const UPPERREPLACECHAR = &quot;X&quot;
26cdf0e10cSrcweirPrivate const LOWERREPLACECHAR = &quot;x&quot;
27cdf0e10cSrcweir
28cdf0e10cSrcweirPrivate MSGBOXTITLE
29cdf0e10cSrcweirPrivate NOTSAVEDTEXT
30cdf0e10cSrcweirPrivate WARNING
31cdf0e10cSrcweir
32cdf0e10cSrcweirSub ChangeAllChars   &apos; 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(&quot;Tools&quot;)
39cdf0e10cSrcweir	MSGBOXTITLE = &quot;Change All Characters to an &apos;&quot; &amp; UPPERREPLACECHAR &amp; &quot;&apos;&quot;
40cdf0e10cSrcweir	NOTSAVEDTEXT = &quot;This document has already been modified: All characters will be changed to an &quot; &amp; UPPERREPLACECHAR &amp; &quot;&apos;. Should the document be saved now?&quot;
41cdf0e10cSrcweir	WARNING = &quot;This macro changes all characters and numbers to an &apos;&quot; &amp; UPPERREPLACECHAR &amp; &quot;&apos; in this document.&quot;
42cdf0e10cSrcweir
43cdf0e10cSrcweir	On Local Error GoTo NODOCUMENT
44cdf0e10cSrcweir	oDocument = StarDesktop.ActiveFrame.Controller.Model
45cdf0e10cSrcweir	NODOCUMENT:
46cdf0e10cSrcweir	If Err &lt;&gt; 0 Then
47cdf0e10cSrcweir		Msgbox(WARNING &amp; chr(13) &amp; &quot;First, activate a Writer document.&quot; , 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 &lt;&gt; &quot;&quot; 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  &apos; No, Abort
65cdf0e10cSrcweir			End
66cdf0e10cSrcweir		End If
67cdf0e10cSrcweir	End If
68cdf0e10cSrcweir
69cdf0e10cSrcweir	Select Case sDocType
70cdf0e10cSrcweir		Case &quot;swriter&quot;
71cdf0e10cSrcweir			ReplaceAllStrings(oDocument)
72cdf0e10cSrcweir
73cdf0e10cSrcweir		Case Else
74cdf0e10cSrcweir			Msgbox(&quot;This macro only works with Writer documents.&quot;, 16, GetProductName())
75cdf0e10cSrcweir	End Select
76cdf0e10cSrcweirEnd Sub
77cdf0e10cSrcweir
78cdf0e10cSrcweir
79cdf0e10cSrcweirSub ReplaceAllStrings(oContainer as Object)
80cdf0e10cSrcweir	ReplaceStrings(oContainer, &quot;[a-z]&quot;, LOWERREPLACECHAR)
81cdf0e10cSrcweir	ReplaceStrings(oContainer, &quot;[à-þ]&quot;, LOWERREPLACECHAR)
82cdf0e10cSrcweir	ReplaceStrings(oContainer, &quot;[A-Z]&quot;, UPPERREPLACECHAR)
83cdf0e10cSrcweir	ReplaceStrings(oContainer, &quot;[À-ß]&quot;, UPPERREPLACECHAR)
84cdf0e10cSrcweir	ReplaceStrings(oContainer, &quot;[0-9]&quot;, 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