1*cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2*cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*cdf0e10cSrcweir<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.
4*cdf0e10cSrcweir&apos; It works on the currently activated document.
5*cdf0e10cSrcweirPrivate const UPPERREPLACECHAR = &quot;X&quot;
6*cdf0e10cSrcweirPrivate const LOWERREPLACECHAR = &quot;x&quot;
7*cdf0e10cSrcweir
8*cdf0e10cSrcweirPrivate MSGBOXTITLE
9*cdf0e10cSrcweirPrivate NOTSAVEDTEXT
10*cdf0e10cSrcweirPrivate WARNING
11*cdf0e10cSrcweir
12*cdf0e10cSrcweirSub ChangeAllChars   &apos; Change all chars in the active document
13*cdf0e10cSrcweirDim oSheets, oPages as Object
14*cdf0e10cSrcweirDim i as Integer
15*cdf0e10cSrcweirConst MBYES = 6
16*cdf0e10cSrcweirConst MBABORT = 2
17*cdf0e10cSrcweirConst MBNO = 7
18*cdf0e10cSrcweir	BasicLibraries.LoadLibrary(&quot;Tools&quot;)
19*cdf0e10cSrcweir	MSGBOXTITLE = &quot;Change All Characters to an &apos;&quot; &amp; UPPERREPLACECHAR &amp; &quot;&apos;&quot;
20*cdf0e10cSrcweir	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;
21*cdf0e10cSrcweir	WARNING = &quot;This macro changes all characters and numbers to an &apos;&quot; &amp; UPPERREPLACECHAR &amp; &quot;&apos; in this document.&quot;
22*cdf0e10cSrcweir
23*cdf0e10cSrcweir	On Local Error GoTo NODOCUMENT
24*cdf0e10cSrcweir	oDocument = StarDesktop.ActiveFrame.Controller.Model
25*cdf0e10cSrcweir	NODOCUMENT:
26*cdf0e10cSrcweir	If Err &lt;&gt; 0 Then
27*cdf0e10cSrcweir		Msgbox(WARNING &amp; chr(13) &amp; &quot;First, activate a Writer document.&quot; , 16, GetProductName())
28*cdf0e10cSrcweir		Exit Sub
29*cdf0e10cSrcweir	End If
30*cdf0e10cSrcweir	On Local Error Goto 0
31*cdf0e10cSrcweir
32*cdf0e10cSrcweir	sDocType = GetDocumentType(oDocument)
33*cdf0e10cSrcweir
34*cdf0e10cSrcweir	If oDocument.IsModified And oDocument.Url &lt;&gt; &quot;&quot; Then
35*cdf0e10cSrcweir		Status = MsgBox(NOTSAVEDTEXT, 3+32, MSGBOXTITLE)
36*cdf0e10cSrcweir		Select Case Status
37*cdf0e10cSrcweir			Case MBYES
38*cdf0e10cSrcweir				oDocument.Store
39*cdf0e10cSrcweir			Case MBABORT, MBNO
40*cdf0e10cSrcweir				End
41*cdf0e10cSrcweir		End Select
42*cdf0e10cSrcweir	Else
43*cdf0e10cSrcweir		Status = MsgBox(WARNING, 3+32, MSGBOXTITLE)
44*cdf0e10cSrcweir		If Status = MBNO Or Status = MBABORT Then  &apos; No, Abort
45*cdf0e10cSrcweir			End
46*cdf0e10cSrcweir		End If
47*cdf0e10cSrcweir	End If
48*cdf0e10cSrcweir
49*cdf0e10cSrcweir	Select Case sDocType
50*cdf0e10cSrcweir		Case &quot;swriter&quot;
51*cdf0e10cSrcweir			ReplaceAllStrings(oDocument)
52*cdf0e10cSrcweir
53*cdf0e10cSrcweir		Case Else
54*cdf0e10cSrcweir			Msgbox(&quot;This macro only works with Writer documents.&quot;, 16, GetProductName())
55*cdf0e10cSrcweir	End Select
56*cdf0e10cSrcweirEnd Sub
57*cdf0e10cSrcweir
58*cdf0e10cSrcweir
59*cdf0e10cSrcweirSub ReplaceAllStrings(oContainer as Object)
60*cdf0e10cSrcweir	ReplaceStrings(oContainer, &quot;[a-z]&quot;, LOWERREPLACECHAR)
61*cdf0e10cSrcweir	ReplaceStrings(oContainer, &quot;[à-þ]&quot;, LOWERREPLACECHAR)
62*cdf0e10cSrcweir	ReplaceStrings(oContainer, &quot;[A-Z]&quot;, UPPERREPLACECHAR)
63*cdf0e10cSrcweir	ReplaceStrings(oContainer, &quot;[À-ß]&quot;, UPPERREPLACECHAR)
64*cdf0e10cSrcweir	ReplaceStrings(oContainer, &quot;[0-9]&quot;, UPPERREPLACECHAR)
65*cdf0e10cSrcweirEnd Sub
66*cdf0e10cSrcweir
67*cdf0e10cSrcweir
68*cdf0e10cSrcweirSub ReplaceStrings(oContainer as Object, sSearchString, sReplaceString  as String)
69*cdf0e10cSrcweir	oReplaceDesc = oContainer.createReplaceDescriptor()
70*cdf0e10cSrcweir	oReplaceDesc.SearchCaseSensitive = True
71*cdf0e10cSrcweir	oReplaceDesc.SearchRegularExpression = True
72*cdf0e10cSrcweir	oReplaceDesc.Searchstring = sSearchString
73*cdf0e10cSrcweir	oReplaceDesc.ReplaceString = sReplaceString
74*cdf0e10cSrcweir	oReplCount = oContainer.ReplaceAll(oReplaceDesc)
75*cdf0e10cSrcweirEnd Sub</script:module>