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