Bump version to 4.1-6
[LibreOffice.git] / wizards / source / euro / Protect.xba
blob32badc3f51640e94e380e27b9c418a330689e6cc
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="Protect" script:language="StarBasic">REM ***** BASIC *****
21 Option Explicit
23 Public PWIndex as Integer
26 Function UnprotectSheetsWithPassWord(oSheets as Object, bDoUnProtect as Boolean)
27 Dim i as Integer
28 Dim MaxIndex as Integer
29 Dim iMsgResult as Integer
30 PWIndex = -1
31 If bDocHasProtectedSheets Then
32 If Not bDoUnprotect Then
33 &apos; At First query if sheets shall generally be unprotected
34 iMsgResult = Msgbox(sMsgUNPROTECT,36,sMsgDLGTITLE)
35 bDoUnProtect = iMsgResult = 6
36 End If
37 If bDoUnProtect Then
38 MaxIndex = oSheets.Count-1
39 For i = 0 To MaxIndex
40 bDocHasProtectedSheets = Not UnprotectSheet(oSheets(i))
41 If bDocHasProtectedSheets Then
42 ReprotectSheets()
43 Exit For
44 End If
45 Next i
46 If PWIndex = -1 Then
47 ReDim UnProtectList() as String
48 Else
49 ReDim Preserve UnProtectList(PWIndex) as String
50 End If
51 Else
52 Msgbox (sMsgSHEETSNOPROTECT, 64, sMsgDLGTITLE)
53 End If
54 End If
55 UnProtectSheetsWithPassword = bDocHasProtectedSheets
56 End Function
59 Function UnprotectSheet(oListSheet as Object)
60 Dim ListSheetName as String
61 Dim sStatustext as String
62 Dim i as Integer
63 Dim bOneSheetIsUnprotected as Boolean
64 i = -1
65 ListSheetName = oListSheet.Name
66 If oListSheet.IsProtected Then
67 oListSheet.Unprotect(&quot;&quot;)
68 If oListSheet.IsProtected Then
69 &apos; Sheet is protected by a Password
70 bOneSheetIsUnProtected = UnprotectSheetWithDialog(oListSheet, ListSheetName)
71 UnProtectSheet() = bOneSheetIsUnProtected
72 Else
73 &apos; The Sheet could be unprotected without a password
74 AddSheettoUnprotectionlist(ListSheetName,&quot;&quot;)
75 UnprotectSheet() = True
76 End If
77 Else
78 UnprotectSheet() = True
79 End If
80 End Function
83 Function UnprotectSheetWithDialog(oListSheet as Object, ListSheetName as String) as Boolean
84 Dim PWIsCorrect as Boolean
85 Dim QueryText as String
86 oDocument.CurrentController.SetActiveSheet(oListSheet)
87 QueryText = ReplaceString(sMsgPWPROTECT,&quot;&apos;&quot; &amp; ListSheetName &amp; &quot;&apos;&quot;, &quot;%1TableName%1&quot;)
88 &apos;&quot;Please insert the password to unprotect the sheet &apos;&quot; &amp; ListSheetName&apos;&quot;
90 ExecutePasswordDialog(QueryText)
91 If bCancelProtection Then
92 bCancelProtection = False
93 Msgbox (sMsgSHEETSNOPROTECT, 64, sMsgDLGTITLE)
94 UnprotectSheetWithDialog() = False
95 exit Function
96 End If
97 oListSheet.Unprotect(Password)
98 If oListSheet.IsProtected Then
99 PWIsCorrect = False
100 Msgbox (sMsgWRONGPW, 64, sMsgDLGTITLE)
101 Else
102 &apos; Sheet could be unprotected
103 AddSheettoUnprotectionlist(ListSheetName,Password)
104 PWIsCorrect = True
105 End If
106 Loop Until PWIsCorrect
107 UnprotectSheetWithDialog() = True
108 End Function
111 Sub ExecutePasswordDialog(QueryText as String)
112 With PasswordModel
113 .Title = QueryText
114 .hlnPassword.Label = sMsgPASSWORD
115 .cmdCancel.Label = sMsgCANCEL
116 .cmdHelp.Label = sHELP
117 .cmdGoOn.Label = sMsgOK
118 .cmdGoOn.DefaultButton = True
119 End With
120 DialogPassword.Execute
121 End Sub
123 Sub ReadPassword()
124 Password = PasswordModel.txtPassword.Text
125 DialogPassword.EndExecute
126 End Sub
129 Sub RejectPassword()
130 bCancelProtection = True
131 DialogPassword.EndExecute
132 End Sub
135 &apos; Reprotects the previousliy protected sheets
136 &apos; The passwordinformation is stored in the List &apos;UnProtectList()&apos;
137 Sub ReprotectSheets()
138 Dim i as Integer
139 Dim oProtectSheet as Object
140 Dim ProtectList() as String
141 Dim SheetName as String
142 Dim SheetPassword as String
143 If PWIndex &gt; -1 Then
144 SetStatusLineText(sStsREPROTECT)
145 For i = 0 To PWIndex
146 ProtectList() = ArrayOutOfString(UnProtectList(i),&quot;;&quot;)
147 SheetName = ProtectList(0)
148 If Ubound(ProtectList()) &gt; 0 Then
149 SheetPassWord = ProtectList(1)
150 Else
151 SheetPassword = &quot;&quot;
152 End If
153 oProtectSheet = oSheets.GetbyName(SheetName)
154 If Not oProtectSheet.IsProtected Then
155 oProtectSheet.Protect(SheetPassWord)
156 End If
157 Next i
158 SetStatusLineText(&quot;&quot;)
159 End If
160 PWIndex = -1
161 ReDim UnProtectList()
162 End Sub
165 &apos; Add a Sheet to the list of sheets that finally have to be
166 &apos; unprotected
167 Sub AddSheettoUnprotectionlist(ListSheetName as String, Password as String)
168 Dim MaxIndex as Integer
169 MaxIndex = Ubound(UnProtectList())
170 PWIndex = PWIndex + 1
171 If PWIndex &gt; MaxIndex Then
172 ReDim Preserve UnprotectList(MaxIndex + SBRANGEUBOUND)
173 End If
174 UnprotectList(PWIndex) = ListSheetName &amp; &quot;;&quot; &amp; Password
175 End Sub
178 Function CheckSheetProtection(oSheets as Object) as Boolean
179 Dim MaxIndex as Integer
180 Dim i as Integer
181 Dim bProtectedSheets as Boolean
182 bProtectedSheets = False
183 MaxIndex = oSheets.Count-1
184 For i = 0 To MaxIndex
185 bProtectedSheets = oSheets(i).IsProtected
186 If bProtectedSheets Then
187 CheckSheetProtection() = True
188 Exit Function
189 End If
190 Next i
191 CheckSheetProtection() = False
192 End Function</script:module>