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