Line data Source code
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 "worksheetsettings.hxx"
21 :
22 : #include <com/sun/star/util/XProtectable.hpp>
23 : #include "oox/core/filterbase.hxx"
24 : #include "oox/helper/attributelist.hxx"
25 : #include "oox/token/properties.hxx"
26 : #include "biffinputstream.hxx"
27 : #include "pagesettings.hxx"
28 : #include "workbooksettings.hxx"
29 :
30 : namespace oox {
31 : namespace xls {
32 :
33 : // ============================================================================
34 :
35 : using namespace ::com::sun::star::beans;
36 : using namespace ::com::sun::star::uno;
37 : using namespace ::com::sun::star::util;
38 :
39 : using ::oox::core::CodecHelper;
40 :
41 : // ============================================================================
42 :
43 : namespace {
44 :
45 : const sal_uInt8 BIFF12_SHEETPR_FILTERMODE = 0x01;
46 : const sal_uInt8 BIFF12_SHEETPR_EVAL_CF = 0x02;
47 :
48 : const sal_uInt32 BIFF_SHEETEXT_NOTABCOLOR = 0x7F;
49 :
50 : const sal_uInt16 BIFF_SHEETPR_DIALOGSHEET = 0x0010;
51 : const sal_uInt16 BIFF_SHEETPR_APPLYSTYLES = 0x0020;
52 : const sal_uInt16 BIFF_SHEETPR_SYMBOLSBELOW = 0x0040;
53 : const sal_uInt16 BIFF_SHEETPR_SYMBOLSRIGHT = 0x0080;
54 : const sal_uInt16 BIFF_SHEETPR_FITTOPAGES = 0x0100;
55 : const sal_uInt16 BIFF_SHEETPR_SKIPEXT = 0x0200; // BIFF3-BIFF4
56 :
57 : const sal_uInt32 BIFF_SHEETPROT_OBJECTS = 0x00000001;
58 : const sal_uInt32 BIFF_SHEETPROT_SCENARIOS = 0x00000002;
59 : const sal_uInt32 BIFF_SHEETPROT_FORMAT_CELLS = 0x00000004;
60 : const sal_uInt32 BIFF_SHEETPROT_FORMAT_COLUMNS = 0x00000008;
61 : const sal_uInt32 BIFF_SHEETPROT_FORMAT_ROWS = 0x00000010;
62 : const sal_uInt32 BIFF_SHEETPROT_INSERT_COLUMNS = 0x00000020;
63 : const sal_uInt32 BIFF_SHEETPROT_INSERT_ROWS = 0x00000040;
64 : const sal_uInt32 BIFF_SHEETPROT_INSERT_HLINKS = 0x00000080;
65 : const sal_uInt32 BIFF_SHEETPROT_DELETE_COLUMNS = 0x00000100;
66 : const sal_uInt32 BIFF_SHEETPROT_DELETE_ROWS = 0x00000200;
67 : const sal_uInt32 BIFF_SHEETPROT_SELECT_LOCKED = 0x00000400;
68 : const sal_uInt32 BIFF_SHEETPROT_SORT = 0x00000800;
69 : const sal_uInt32 BIFF_SHEETPROT_AUTOFILTER = 0x00001000;
70 : const sal_uInt32 BIFF_SHEETPROT_PIVOTTABLES = 0x00002000;
71 : const sal_uInt32 BIFF_SHEETPROT_SELECT_UNLOCKED = 0x00004000;
72 :
73 : } // namespace
74 :
75 : // ============================================================================
76 :
77 43 : SheetSettingsModel::SheetSettingsModel() :
78 : mbFilterMode( false ),
79 : mbApplyStyles( false ),
80 : mbSummaryBelow( true ),
81 43 : mbSummaryRight( true )
82 : {
83 43 : }
84 :
85 : // ============================================================================
86 :
87 43 : SheetProtectionModel::SheetProtectionModel() :
88 : mnPasswordHash( 0 ),
89 : mbSheet( false ),
90 : mbObjects( false ),
91 : mbScenarios( false ),
92 : mbFormatCells( true ),
93 : mbFormatColumns( true ),
94 : mbFormatRows( true ),
95 : mbInsertColumns( true ),
96 : mbInsertRows( true ),
97 : mbInsertHyperlinks( true ),
98 : mbDeleteColumns( true ),
99 : mbDeleteRows( true ),
100 : mbSelectLocked( false ),
101 : mbSort( true ),
102 : mbAutoFilter( true ),
103 : mbPivotTables( true ),
104 43 : mbSelectUnlocked( false )
105 : {
106 43 : }
107 :
108 : // ============================================================================
109 :
110 43 : WorksheetSettings::WorksheetSettings( const WorksheetHelper& rHelper ) :
111 : WorksheetHelper( rHelper ),
112 43 : maPhoneticSett( rHelper )
113 : {
114 43 : }
115 :
116 29 : void WorksheetSettings::importSheetPr( const AttributeList& rAttribs )
117 : {
118 29 : maSheetSettings.maCodeName = rAttribs.getString( XML_codeName, OUString() );
119 29 : maSheetSettings.mbFilterMode = rAttribs.getBool( XML_filterMode, false );
120 29 : }
121 :
122 0 : void WorksheetSettings::importChartSheetPr( const AttributeList& rAttribs )
123 : {
124 0 : maSheetSettings.maCodeName = rAttribs.getString( XML_codeName, OUString() );
125 0 : }
126 :
127 0 : void WorksheetSettings::importTabColor( const AttributeList& rAttribs )
128 : {
129 0 : maSheetSettings.maTabColor.importColor( rAttribs );
130 0 : }
131 :
132 0 : void WorksheetSettings::importOutlinePr( const AttributeList& rAttribs )
133 : {
134 0 : maSheetSettings.mbApplyStyles = rAttribs.getBool( XML_applyStyles, false );
135 0 : maSheetSettings.mbSummaryBelow = rAttribs.getBool( XML_summaryBelow, true );
136 0 : maSheetSettings.mbSummaryRight = rAttribs.getBool( XML_summaryRight, true );
137 0 : }
138 :
139 0 : void WorksheetSettings::importSheetProtection( const AttributeList& rAttribs )
140 : {
141 0 : maSheetProt.mnPasswordHash = CodecHelper::getPasswordHash( rAttribs, XML_password );
142 0 : maSheetProt.mbSheet = rAttribs.getBool( XML_sheet, false );
143 0 : maSheetProt.mbObjects = rAttribs.getBool( XML_objects, false );
144 0 : maSheetProt.mbScenarios = rAttribs.getBool( XML_scenarios, false );
145 0 : maSheetProt.mbFormatCells = rAttribs.getBool( XML_formatCells, true );
146 0 : maSheetProt.mbFormatColumns = rAttribs.getBool( XML_formatColumns, true );
147 0 : maSheetProt.mbFormatRows = rAttribs.getBool( XML_formatRows, true );
148 0 : maSheetProt.mbInsertColumns = rAttribs.getBool( XML_insertColumns, true );
149 0 : maSheetProt.mbInsertRows = rAttribs.getBool( XML_insertRows, true );
150 0 : maSheetProt.mbInsertHyperlinks = rAttribs.getBool( XML_insertHyperlinks, true );
151 0 : maSheetProt.mbDeleteColumns = rAttribs.getBool( XML_deleteColumns, true );
152 0 : maSheetProt.mbDeleteRows = rAttribs.getBool( XML_deleteRows, true );
153 0 : maSheetProt.mbSelectLocked = rAttribs.getBool( XML_selectLockedCells, false );
154 0 : maSheetProt.mbSort = rAttribs.getBool( XML_sort, true );
155 0 : maSheetProt.mbAutoFilter = rAttribs.getBool( XML_autoFilter, true );
156 0 : maSheetProt.mbPivotTables = rAttribs.getBool( XML_pivotTables, true );
157 0 : maSheetProt.mbSelectUnlocked = rAttribs.getBool( XML_selectUnlockedCells, false );
158 0 : }
159 :
160 0 : void WorksheetSettings::importChartProtection( const AttributeList& rAttribs )
161 : {
162 0 : maSheetProt.mnPasswordHash = CodecHelper::getPasswordHash( rAttribs, XML_password );
163 0 : maSheetProt.mbSheet = rAttribs.getBool( XML_content, false );
164 0 : maSheetProt.mbObjects = rAttribs.getBool( XML_objects, false );
165 0 : }
166 :
167 3 : void WorksheetSettings::importPhoneticPr( const AttributeList& rAttribs )
168 : {
169 3 : maPhoneticSett.importPhoneticPr( rAttribs );
170 3 : }
171 :
172 0 : void WorksheetSettings::importSheetPr( SequenceInputStream& rStrm )
173 : {
174 : sal_uInt16 nFlags1;
175 : sal_uInt8 nFlags2;
176 0 : rStrm >> nFlags1 >> nFlags2 >> maSheetSettings.maTabColor;
177 0 : rStrm.skip( 8 ); // sync anchor cell
178 0 : rStrm >> maSheetSettings.maCodeName;
179 : // sheet settings
180 0 : maSheetSettings.mbFilterMode = getFlag( nFlags2, BIFF12_SHEETPR_FILTERMODE );
181 : // outline settings, equal flags in all BIFFs
182 0 : maSheetSettings.mbApplyStyles = getFlag( nFlags1, BIFF_SHEETPR_APPLYSTYLES );
183 0 : maSheetSettings.mbSummaryRight = getFlag( nFlags1, BIFF_SHEETPR_SYMBOLSRIGHT );
184 0 : maSheetSettings.mbSummaryBelow = getFlag( nFlags1, BIFF_SHEETPR_SYMBOLSBELOW );
185 : /* Fit printout to width/height - for whatever reason, this flag is still
186 : stored separated from the page settings */
187 0 : getPageSettings().setFitToPagesMode( getFlag( nFlags1, BIFF_SHEETPR_FITTOPAGES ) );
188 0 : }
189 :
190 0 : void WorksheetSettings::importChartSheetPr( SequenceInputStream& rStrm )
191 : {
192 0 : rStrm.skip( 2 ); // flags, contains only the 'published' flag
193 0 : rStrm >> maSheetSettings.maTabColor >> maSheetSettings.maCodeName;
194 0 : }
195 :
196 0 : void WorksheetSettings::importSheetProtection( SequenceInputStream& rStrm )
197 : {
198 0 : rStrm >> maSheetProt.mnPasswordHash;
199 : // no flags field for all these boolean flags?!?
200 0 : maSheetProt.mbSheet = rStrm.readInt32() != 0;
201 0 : maSheetProt.mbObjects = rStrm.readInt32() != 0;
202 0 : maSheetProt.mbScenarios = rStrm.readInt32() != 0;
203 0 : maSheetProt.mbFormatCells = rStrm.readInt32() != 0;
204 0 : maSheetProt.mbFormatColumns = rStrm.readInt32() != 0;
205 0 : maSheetProt.mbFormatRows = rStrm.readInt32() != 0;
206 0 : maSheetProt.mbInsertColumns = rStrm.readInt32() != 0;
207 0 : maSheetProt.mbInsertRows = rStrm.readInt32() != 0;
208 0 : maSheetProt.mbInsertHyperlinks = rStrm.readInt32() != 0;
209 0 : maSheetProt.mbDeleteColumns = rStrm.readInt32() != 0;
210 0 : maSheetProt.mbDeleteRows = rStrm.readInt32() != 0;
211 0 : maSheetProt.mbSelectLocked = rStrm.readInt32() != 0;
212 0 : maSheetProt.mbSort = rStrm.readInt32() != 0;
213 0 : maSheetProt.mbAutoFilter = rStrm.readInt32() != 0;
214 0 : maSheetProt.mbPivotTables = rStrm.readInt32() != 0;
215 0 : maSheetProt.mbSelectUnlocked = rStrm.readInt32() != 0;
216 0 : }
217 :
218 0 : void WorksheetSettings::importChartProtection( SequenceInputStream& rStrm )
219 : {
220 0 : rStrm >> maSheetProt.mnPasswordHash;
221 : // no flags field for all these boolean flags?!?
222 0 : maSheetProt.mbSheet = rStrm.readInt32() != 0;
223 0 : maSheetProt.mbObjects = rStrm.readInt32() != 0;
224 0 : }
225 :
226 0 : void WorksheetSettings::importPhoneticPr( SequenceInputStream& rStrm )
227 : {
228 0 : maPhoneticSett.importPhoneticPr( rStrm );
229 0 : }
230 :
231 43 : void WorksheetSettings::finalizeImport()
232 : {
233 : // sheet protection
234 43 : if( maSheetProt.mbSheet ) try
235 : {
236 0 : Reference< XProtectable > xProtectable( getSheet(), UNO_QUERY_THROW );
237 0 : xProtectable->protect( OUString() );
238 : }
239 0 : catch( Exception& )
240 : {
241 : }
242 :
243 : // VBA code name
244 43 : PropertySet aPropSet( getSheet() );
245 43 : aPropSet.setProperty( PROP_CodeName, maSheetSettings.maCodeName );
246 :
247 : // sheet tab color
248 43 : if( !maSheetSettings.maTabColor.isAuto() )
249 : {
250 43 : sal_Int32 nColor = maSheetSettings.maTabColor.getColor( getBaseFilter().getGraphicHelper() );
251 43 : aPropSet.setProperty( PROP_TabColor, nColor );
252 43 : }
253 43 : }
254 :
255 : // ============================================================================
256 :
257 : } // namespace xls
258 15 : } // namespace oox
259 :
260 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|