LibreOffice Module sc (master) 1
worksheetsettings.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <memory>
21#include <worksheetsettings.hxx>
22
23#include <com/sun/star/sheet/XSpreadsheet.hpp>
28#include <oox/token/properties.hxx>
29#include <oox/token/tokens.hxx>
30#include <pagesettings.hxx>
31#include <tabprotection.hxx>
32#include <document.hxx>
33#include <addressconverter.hxx>
34#include <biffhelper.hxx>
35
36namespace oox::xls {
37
38using namespace ::com::sun::star::uno;
39
40namespace {
41
42const sal_uInt8 BIFF12_SHEETPR_FILTERMODE = 0x01;
43
44const sal_uInt16 BIFF_SHEETPR_APPLYSTYLES = 0x0020;
45const sal_uInt16 BIFF_SHEETPR_SYMBOLSBELOW = 0x0040;
46const sal_uInt16 BIFF_SHEETPR_SYMBOLSRIGHT = 0x0080;
47const sal_uInt16 BIFF_SHEETPR_FITTOPAGES = 0x0100;
48
49} // namespace
50
52 mbFilterMode( false ),
53 mbApplyStyles( false ),
54 mbSummaryBelow( true ),
55 mbSummaryRight( true )
56{
57}
58
60 mnSpinCount( 0 ),
61 mnPasswordHash( 0 ),
62 mbSheet( false ),
63 mbObjects( false ),
64 mbScenarios( false ),
65 mbFormatCells( true ),
66 mbFormatColumns( true ),
67 mbFormatRows( true ),
68 mbInsertColumns( true ),
69 mbInsertRows( true ),
70 mbInsertHyperlinks( true ),
71 mbDeleteColumns( true ),
72 mbDeleteRows( true ),
73 mbSelectLocked( false ),
74 mbSort( true ),
75 mbAutoFilter( true ),
76 mbPivotTables( true ),
77 mbSelectUnlocked( false )
78{
79}
80
82 WorksheetHelper( rHelper ),
83 maPhoneticSett( rHelper )
84{
85}
86
88{
89 maSheetSettings.maCodeName = rAttribs.getString( XML_codeName, OUString() );
90 maSheetSettings.mbFilterMode = rAttribs.getBool( XML_filterMode, false );
91}
92
94{
95 maSheetSettings.maCodeName = rAttribs.getString( XML_codeName, OUString() );
96}
97
99{
101}
102
104{
105 maSheetSettings.mbApplyStyles = rAttribs.getBool( XML_applyStyles, false );
106 maSheetSettings.mbSummaryBelow = rAttribs.getBool( XML_summaryBelow, true );
107 maSheetSettings.mbSummaryRight = rAttribs.getBool( XML_summaryRight, true );
108}
109
111{
112 maSheetProt.maAlgorithmName = rAttribs.getString( XML_algorithmName, OUString());
113 maSheetProt.maHashValue = rAttribs.getString( XML_hashValue, OUString());
114 maSheetProt.maSaltValue = rAttribs.getString( XML_saltValue, OUString());
115 maSheetProt.mnSpinCount = rAttribs.getUnsigned( XML_spinCount, 0);
117 maSheetProt.mbSheet = rAttribs.getBool( XML_sheet, false );
118 maSheetProt.mbObjects = rAttribs.getBool( XML_objects, false );
119 maSheetProt.mbScenarios = rAttribs.getBool( XML_scenarios, false );
120 maSheetProt.mbFormatCells = rAttribs.getBool( XML_formatCells, true );
121 maSheetProt.mbFormatColumns = rAttribs.getBool( XML_formatColumns, true );
122 maSheetProt.mbFormatRows = rAttribs.getBool( XML_formatRows, true );
123 maSheetProt.mbInsertColumns = rAttribs.getBool( XML_insertColumns, true );
124 maSheetProt.mbInsertRows = rAttribs.getBool( XML_insertRows, true );
125 maSheetProt.mbInsertHyperlinks = rAttribs.getBool( XML_insertHyperlinks, true );
126 maSheetProt.mbDeleteColumns = rAttribs.getBool( XML_deleteColumns, true );
127 maSheetProt.mbDeleteRows = rAttribs.getBool( XML_deleteRows, true );
128 maSheetProt.mbSelectLocked = rAttribs.getBool( XML_selectLockedCells, false );
129 maSheetProt.mbSort = rAttribs.getBool( XML_sort, true );
130 maSheetProt.mbAutoFilter = rAttribs.getBool( XML_autoFilter, true );
131 maSheetProt.mbPivotTables = rAttribs.getBool( XML_pivotTables, true );
132 maSheetProt.mbSelectUnlocked = rAttribs.getBool( XML_selectUnlockedCells, false );
133}
134
136{
138 aProt.maTitle = rAttribs.getString( XML_name, OUString());
139 /* XXX ECMA-376/OOXML XMLSchema and ISO/IEC 29500 say 'securityDescriptor'
140 * would be an element, but Excel2013 stores it as attribute. */
141 aProt.maSecurityDescriptorXML = rAttribs.getString( XML_securityDescriptor, OUString());
142 /* XXX ECMA-376/OOXML or ISO/IEC 29500 do not even mention a 'password'
143 * attribute here (or anywhere else), but this is what Excel2013 writes,
144 * similar to BIFF, if the original file was a BIFF file. OOXML XMLschema
145 * and ISO/IEC 29500 instead define 'algorithmName', 'hashValue',
146 * 'saltValue' and 'spinCount' that are written if the protection was newly
147 * created. */
148 aProt.mnPasswordVerifier = rAttribs.getIntegerHex( XML_password, 0);
149 aProt.maPasswordHash.maAlgorithmName = rAttribs.getString( XML_algorithmName, OUString());
150 aProt.maPasswordHash.maHashValue = rAttribs.getString( XML_hashValue, OUString());
151 aProt.maPasswordHash.maSaltValue = rAttribs.getString( XML_saltValue, OUString());
152 aProt.maPasswordHash.mnSpinCount = rAttribs.getUnsigned( XML_spinCount, 0);
153 OUString aRefs( rAttribs.getString( XML_sqref, OUString()));
154 if (!aRefs.isEmpty())
155 {
156 std::unique_ptr<ScRangeList> xRangeList(new ScRangeList());
157 getAddressConverter().convertToCellRangeList( *xRangeList, aRefs, getSheetIndex(), true );
158 if (!xRangeList->empty())
159 {
160 aProt.maRangeList = xRangeList.release();
161 }
162 }
163 maSheetProt.maEnhancedProtections.push_back( aProt);
164}
165
167{
169 maSheetProt.mbSheet = rAttribs.getBool( XML_content, false );
170 maSheetProt.mbObjects = rAttribs.getBool( XML_objects, false );
171}
172
174{
176}
177
179{
180 sal_uInt16 nFlags1;
181 sal_uInt8 nFlags2;
182 nFlags1 = rStrm.readuInt16();
183 nFlags2 = rStrm.readuChar();
185 rStrm.skip( 8 ); // sync anchor cell
187 // sheet settings
188 maSheetSettings.mbFilterMode = getFlag( nFlags2, BIFF12_SHEETPR_FILTERMODE );
189 // outline settings, equal flags in all BIFFs
190 maSheetSettings.mbApplyStyles = getFlag( nFlags1, BIFF_SHEETPR_APPLYSTYLES );
191 maSheetSettings.mbSummaryRight = getFlag( nFlags1, BIFF_SHEETPR_SYMBOLSRIGHT );
192 maSheetSettings.mbSummaryBelow = getFlag( nFlags1, BIFF_SHEETPR_SYMBOLSBELOW );
193 /* Fit printout to width/height - for whatever reason, this flag is still
194 stored separated from the page settings */
195 getPageSettings().setFitToPagesMode( getFlag( nFlags1, BIFF_SHEETPR_FITTOPAGES ) );
196}
197
199{
200 rStrm.skip( 2 ); // flags, contains only the 'published' flag
202}
203
205{
206 maSheetProt.mnPasswordHash = rStrm.readuInt16();
207 // no flags field for all these boolean flags?!?
208 maSheetProt.mbSheet = rStrm.readInt32() != 0;
209 maSheetProt.mbObjects = rStrm.readInt32() == 0;
210 maSheetProt.mbScenarios = rStrm.readInt32() == 0;
211 maSheetProt.mbFormatCells = rStrm.readInt32() == 0;
212 maSheetProt.mbFormatColumns = rStrm.readInt32() == 0;
213 maSheetProt.mbFormatRows = rStrm.readInt32() == 0;
214 maSheetProt.mbInsertColumns = rStrm.readInt32() == 0;
215 maSheetProt.mbInsertRows = rStrm.readInt32() == 0;
216 maSheetProt.mbInsertHyperlinks = rStrm.readInt32() == 0;
217 maSheetProt.mbDeleteColumns = rStrm.readInt32() == 0;
218 maSheetProt.mbDeleteRows = rStrm.readInt32() == 0;
219 maSheetProt.mbSelectLocked = rStrm.readInt32() == 0;
220 maSheetProt.mbSort = rStrm.readInt32() == 0;
221 maSheetProt.mbAutoFilter = rStrm.readInt32() == 0;
222 maSheetProt.mbPivotTables = rStrm.readInt32() == 0;
223 maSheetProt.mbSelectUnlocked = rStrm.readInt32() == 0;
224}
225
227{
228 maSheetProt.mnPasswordHash = rStrm.readuInt16();
229 // no flags field for all these boolean flags?!?
230 maSheetProt.mbSheet = rStrm.readInt32() != 0;
231 maSheetProt.mbObjects = rStrm.readInt32() != 0;
232}
233
235{
237}
238
240{
241 // sheet protection
242 if( maSheetProt.mbSheet )
243 {
244 ScTableProtection aProtect;
245 aProtect.setProtected(true);
248 // Set the simple hash after the proper hash because setting the proper
249 // hash resets the simple hash, yet if the simple hash is present we
250 // may as well use it and more important want to keep it for saving the
251 // document again.
253 {
254 Sequence<sal_Int8> aPass{
257 aProtect.setPasswordHash(aPass, PASSHASH_XL);
258 }
274
276
278 }
279
280 // VBA code name
281 PropertySet aPropSet( getSheet() );
282 aPropSet.setProperty( PROP_CodeName, maSheetSettings.maCodeName );
283
284 // sheet tab color
286 {
287 ::Color nColor = maSheetSettings.maTabColor.getColor( getBaseFilter().getGraphicHelper() );
288 aPropSet.setProperty( PROP_TabColor, nColor );
289 }
290}
291
292} // namespace oox::xls
293
294/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SC_DLLPUBLIC void SetTabProtection(SCTAB nTab, const ScTableProtection *pProtect)
Definition: documen3.cxx:1922
sheet protection state container
void setOption(Option eOption, bool bEnabled)
void setEnhancedProtection(::std::vector< ScEnhancedProtection > &&rProt)
virtual void setPasswordHash(const css::uno::Sequence< sal_Int8 > &aPassword, ScPasswordHash eHash, ScPasswordHash eHash2=PASSHASH_UNSPECIFIED) override
virtual void setProtected(bool bProtected) override
std::optional< sal_uInt32 > getUnsigned(sal_Int32 nAttrToken) const
std::optional< sal_Int32 > getIntegerHex(sal_Int32 nAttrToken) const
std::optional< OUString > getString(sal_Int32 nAttrToken) const
std::optional< bool > getBool(sal_Int32 nAttrToken) const
bool setProperty(sal_Int32 nPropId, const Type &rValue)
::Color getColor(const GraphicHelper &rGraphicHelper, ::Color nPhClr=API_RGB_TRANSPARENT) const
void convertToCellRangeList(ScRangeList &orRanges, std::u16string_view aString, sal_Int16 nSheet, bool bTrackOverflow)
Tries to convert the passed string to a cell range list.
bool isAuto() const
Returns true, if the color is set to automatic.
void importColor(const AttributeList &rAttribs)
Imports the color from the passed attribute list.
void setFitToPagesMode(bool bFitToPages)
Sets whether percentual scaling or fit to width/height scaling is used.
void importPhoneticPr(const AttributeList &rAttribs)
Imports phonetic settings from the phoneticPr element.
Definition: richstring.cxx:207
AddressConverter & getAddressConverter() const
Returns the converter for string to cell address/range conversion.
::oox::core::FilterBase & getBaseFilter() const
Returns the base filter object (base class of all filters).
PageSettings & getPageSettings() const
Returns the page/print settings for this sheet.
SCTAB getSheetIndex() const
Returns the index of the current sheet.
const css::uno::Reference< css::sheet::XSpreadsheet > & getSheet() const
Returns the XSpreadsheet interface of the current sheet.
void importSheetProtection(const AttributeList &rAttribs)
Imports protection settings from the sheetProtection element.
void importProtectedRange(const AttributeList &rAttribs)
Imports enhanced protection settings from the protectedRange element.
void importOutlinePr(const AttributeList &rAttribs)
Imports outline settings from the outlinePr element.
void importPhoneticPr(const AttributeList &rAttribs)
Imports phonetic settings from the phoneticPr element.
void importChartSheetPr(const AttributeList &rAttribs)
Imports chart sheet settings from the sheetPr element.
SheetSettingsModel maSheetSettings
WorksheetSettings(const WorksheetHelper &rHelper)
void finalizeImport()
Converts the imported worksheet settings.
void importSheetPr(const AttributeList &rAttribs)
Imports sheet settings from the sheetPr element.
void importTabColor(const AttributeList &rAttribs)
Imports the sheet tab color from the tabColor element.
void importChartProtection(const AttributeList &rAttribs)
Imports protection settings from the sheetProtection element of a chart sheet.
SheetProtectionModel maSheetProt
void SvStream & rStrm
OOX_DLLPUBLIC sal_uInt16 getPasswordHash(const AttributeList &rAttribs, sal_Int32 nElement)
bool getFlag(Type nBitField, Type nMask)
Container for the Excel EnhancedProtection feature.
ScOoxPasswordHash maPasswordHash
OUString maSecurityDescriptorXML
sal_uInt32 mnPasswordVerifier
ScRangeListRef maRangeList
OUString maSaltValue
base64 encoded hash value
OUString maHashValue
"SHA-512", ...
sal_uInt32 mnSpinCount
base64 encoded salt value
OUString maAlgorithmName
bool mbDeleteColumns
True = insert hyperlinks locked.
bool mbInsertRows
True = insert columns locked.
bool mbSort
True = select locked cells locked.
bool mbFormatCells
True = scenarios locked.
OUString maSaltValue
Hash value computed by the algorithm, base-64 encoded.
bool mbSelectUnlocked
True = pivot tables locked.
sal_uInt32 mnSpinCount
Salt value to be prepended to the password, base-64 encoded.
bool mbSelectLocked
True = delete rows locked.
bool mbObjects
True = sheet protection enabled, locked cells are protected.
bool mbFormatRows
True = format columns locked.
sal_uInt16 mnPasswordHash
Spin count, iterations to run algorithm.
bool mbInsertColumns
True = format rows locked.
bool mbFormatColumns
True = format cells locked.
bool mbScenarios
True = objects locked.
OUString maHashValue
Algorithm name, "SHA-512", "SHA-1", ...
bool mbInsertHyperlinks
True = insert rows locked.
bool mbDeleteRows
True = delete columns locked.
bool mbPivotTables
True = autofilters locked.
bool mbAutoFilter
True = sorting locked.
::std::vector< ScEnhancedProtection > maEnhancedProtections
True = select unlocked cells locked.
bool mbSheet
Hash value from sheet protection password. (unrelated to the above)
SheetSettingsModel()
True = column outline symbols right of group.
bool mbApplyStyles
True = sheet contains active filter.
bool mbFilterMode
Sheet tab color.
Color maTabColor
VBA module codename.
bool mbSummaryBelow
True = automatic styles when creating outlines.
bool mbSummaryRight
True = row outline symbols below group.
@ PASSHASH_XL
unsigned char sal_uInt8
signed char sal_Int8