Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / wizards / source / gimmicks / ChangeAllChars.xba
blobcdcbc962335dc05f60b8c6fd632c8e97af7cd273
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3 <!--
4 * This file is part of the LibreOffice project.
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 * This file incorporates work covered by the following license notice:
12 * Licensed to the Apache Software Foundation (ASF) under one or more
13 * contributor license agreements. See the NOTICE file distributed
14 * with this work for additional information regarding copyright
15 * ownership. The ASF licenses this file to you under the Apache
16 * License, Version 2.0 (the "License"); you may not use this file
17 * except in compliance with the License. You may obtain a copy of
18 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 -->
20 <script:module xmlns:script="http://openoffice.org/2000/script" script:name="ChangeAllChars" script:language="StarBasic">&apos; This macro replaces all characters in a writer-document through &quot;x&quot; or &quot;X&quot; signs.
21 &apos; It works on the currently activated document.
22 Private const UPPERREPLACECHAR = &quot;X&quot;
23 Private const LOWERREPLACECHAR = &quot;x&quot;
25 Private MSGBOXTITLE
26 Private NOTSAVEDTEXT
27 Private WARNING
29 Sub ChangeAllChars &apos; Change all chars in the active document
30 Dim oSheets, oPages as Object
31 Dim i as Integer
32 Const MBYES = 6
33 Const MBABORT = 2
34 Const MBNO = 7
35 BasicLibraries.LoadLibrary(&quot;Tools&quot;)
36 MSGBOXTITLE = &quot;Change All Characters to an &apos;&quot; &amp; UPPERREPLACECHAR &amp; &quot;&apos;&quot;
37 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;
38 WARNING = &quot;This macro changes all characters and numbers to an &apos;&quot; &amp; UPPERREPLACECHAR &amp; &quot;&apos; in this document.&quot;
40 On Local Error GoTo NODOCUMENT
41 oDocument = StarDesktop.ActiveFrame.Controller.Model
42 NODOCUMENT:
43 If Err &lt;&gt; 0 Then
44 Msgbox(WARNING &amp; chr(13) &amp; &quot;First, activate a Writer document.&quot; , 16, GetProductName())
45 Exit Sub
46 End If
47 On Local Error Goto 0
49 sDocType = GetDocumentType(oDocument)
51 If oDocument.IsModified And oDocument.Url &lt;&gt; &quot;&quot; Then
52 Status = MsgBox(NOTSAVEDTEXT, 3+32, MSGBOXTITLE)
53 Select Case Status
54 Case MBYES
55 oDocument.Store
56 Case MBABORT, MBNO
57 End
58 End Select
59 Else
60 Status = MsgBox(WARNING, 3+32, MSGBOXTITLE)
61 If Status = MBNO Or Status = MBABORT Then &apos; No, Abort
62 End
63 End If
64 End If
66 Select Case sDocType
67 Case &quot;swriter&quot;
68 ReplaceAllStrings(oDocument)
70 Case Else
71 Msgbox(&quot;This macro only works with Writer documents.&quot;, 16, GetProductName())
72 End Select
73 End Sub
76 Sub ReplaceAllStrings(oContainer as Object)
77 ReplaceStrings(oContainer, &quot;[a-z]&quot;, LOWERREPLACECHAR)
78 ReplaceStrings(oContainer, &quot;[à-þ]&quot;, LOWERREPLACECHAR)
79 ReplaceStrings(oContainer, &quot;[A-Z]&quot;, UPPERREPLACECHAR)
80 ReplaceStrings(oContainer, &quot;[À-ß]&quot;, UPPERREPLACECHAR)
81 ReplaceStrings(oContainer, &quot;[0-9]&quot;, UPPERREPLACECHAR)
82 End Sub
85 Sub ReplaceStrings(oContainer as Object, sSearchString, sReplaceString as String)
86 oReplaceDesc = oContainer.createReplaceDescriptor()
87 oReplaceDesc.SearchCaseSensitive = True
88 oReplaceDesc.SearchRegularExpression = True
89 oReplaceDesc.Searchstring = sSearchString
90 oReplaceDesc.ReplaceString = sReplaceString
91 oReplCount = oContainer.ReplaceAll(oReplaceDesc)
92 End Sub</script:module>