update dev300-m58
[ooovba.git] / oox / source / xls / worksheetsettings.cxx
blobd791e4801217219485da92e8ef36fa51d5fedcee
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: worksheetsettings.cxx,v $
10 * $Revision: 1.5.4.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "oox/xls/worksheetsettings.hxx"
32 #include <com/sun/star/util/XProtectable.hpp>
33 #include "oox/helper/attributelist.hxx"
34 #include "oox/helper/recordinputstream.hxx"
35 #include "oox/xls/biffinputstream.hxx"
36 #include "oox/xls/pagesettings.hxx"
37 #include "oox/xls/workbooksettings.hxx"
39 using ::rtl::OUString;
40 using ::com::sun::star::uno::Exception;
41 using ::com::sun::star::uno::Reference;
42 using ::com::sun::star::uno::UNO_QUERY_THROW;
43 using ::com::sun::star::util::XProtectable;
44 using ::oox::core::CodecHelper;
46 namespace oox {
47 namespace xls {
49 // ============================================================================
51 namespace {
53 const sal_uInt8 OOBIN_SHEETPR_FILTERMODE = 0x01;
54 const sal_uInt8 OOBIN_SHEETPR_EVAL_CF = 0x02;
56 const sal_uInt16 BIFF_SHEETPR_DIALOGSHEET = 0x0010;
57 const sal_uInt16 BIFF_SHEETPR_APPLYSTYLES = 0x0020;
58 const sal_uInt16 BIFF_SHEETPR_SYMBOLSBELOW = 0x0040;
59 const sal_uInt16 BIFF_SHEETPR_SYMBOLSRIGHT = 0x0080;
60 const sal_uInt16 BIFF_SHEETPR_FITTOPAGES = 0x0100;
61 const sal_uInt16 BIFF_SHEETPR_SKIPEXT = 0x0200; /// BIFF3-BIFF4
63 const sal_uInt16 BIFF_SHEETPROT_OBJECTS = 0x0001;
64 const sal_uInt16 BIFF_SHEETPROT_SCENARIOS = 0x0002;
65 const sal_uInt16 BIFF_SHEETPROT_FORMAT_CELLS = 0x0004;
66 const sal_uInt16 BIFF_SHEETPROT_FORMAT_COLUMNS = 0x0008;
67 const sal_uInt16 BIFF_SHEETPROT_FORMAT_ROWS = 0x0010;
68 const sal_uInt16 BIFF_SHEETPROT_INSERT_COLUMNS = 0x0020;
69 const sal_uInt16 BIFF_SHEETPROT_INSERT_ROWS = 0x0040;
70 const sal_uInt16 BIFF_SHEETPROT_INSERT_HLINKS = 0x0080;
71 const sal_uInt16 BIFF_SHEETPROT_DELETE_COLUMNS = 0x0100;
72 const sal_uInt16 BIFF_SHEETPROT_DELETE_ROWS = 0x0200;
73 const sal_uInt16 BIFF_SHEETPROT_SELECT_LOCKED = 0x0400;
74 const sal_uInt16 BIFF_SHEETPROT_SORT = 0x0800;
75 const sal_uInt16 BIFF_SHEETPROT_AUTOFILTER = 0x1000;
76 const sal_uInt16 BIFF_SHEETPROT_PIVOTTABLES = 0x2000;
77 const sal_uInt16 BIFF_SHEETPROT_SELECT_UNLOCKED = 0x4000;
79 } // namespace
81 // ============================================================================
83 SheetSettingsModel::SheetSettingsModel() :
84 mbFilterMode( false ),
85 mbApplyStyles( false ),
86 mbSummaryBelow( true ),
87 mbSummaryRight( true )
91 // ============================================================================
93 SheetProtectionModel::SheetProtectionModel() :
94 mnPasswordHash( 0 ),
95 mbSheet( false ),
96 mbObjects( false ),
97 mbScenarios( false ),
98 mbFormatCells( true ),
99 mbFormatColumns( true ),
100 mbFormatRows( true ),
101 mbInsertColumns( true ),
102 mbInsertRows( true ),
103 mbInsertHyperlinks( true ),
104 mbDeleteColumns( true ),
105 mbDeleteRows( true ),
106 mbSelectLocked( false ),
107 mbSort( true ),
108 mbAutoFilter( true ),
109 mbPivotTables( true ),
110 mbSelectUnlocked( false )
114 // ============================================================================
116 WorksheetSettings::WorksheetSettings( const WorksheetHelper& rHelper ) :
117 WorksheetHelper( rHelper ),
118 maPhoneticSett( rHelper )
122 void WorksheetSettings::importSheetPr( const AttributeList& rAttribs )
124 maSheetSettings.maCodeName = rAttribs.getString( XML_codeName, OUString() );
125 maSheetSettings.mbFilterMode = rAttribs.getBool( XML_filterMode, false );
128 void WorksheetSettings::importChartSheetPr( const AttributeList& rAttribs )
130 maSheetSettings.maCodeName = rAttribs.getString( XML_codeName, OUString() );
133 void WorksheetSettings::importTabColor( const AttributeList& rAttribs )
135 maSheetSettings.maTabColor.importColor( rAttribs );
138 void WorksheetSettings::importOutlinePr( const AttributeList& rAttribs )
140 maSheetSettings.mbApplyStyles = rAttribs.getBool( XML_applyStyles, false );
141 maSheetSettings.mbSummaryBelow = rAttribs.getBool( XML_summaryBelow, true );
142 maSheetSettings.mbSummaryRight = rAttribs.getBool( XML_summaryRight, true );
145 void WorksheetSettings::importSheetProtection( const AttributeList& rAttribs )
147 maSheetProt.mnPasswordHash = CodecHelper::getPasswordHash( rAttribs, XML_password );
148 maSheetProt.mbSheet = rAttribs.getBool( XML_sheet, false );
149 maSheetProt.mbObjects = rAttribs.getBool( XML_objects, false );
150 maSheetProt.mbScenarios = rAttribs.getBool( XML_scenarios, false );
151 maSheetProt.mbFormatCells = rAttribs.getBool( XML_formatCells, true );
152 maSheetProt.mbFormatColumns = rAttribs.getBool( XML_formatColumns, true );
153 maSheetProt.mbFormatRows = rAttribs.getBool( XML_formatRows, true );
154 maSheetProt.mbInsertColumns = rAttribs.getBool( XML_insertColumns, true );
155 maSheetProt.mbInsertRows = rAttribs.getBool( XML_insertRows, true );
156 maSheetProt.mbInsertHyperlinks = rAttribs.getBool( XML_insertHyperlinks, true );
157 maSheetProt.mbDeleteColumns = rAttribs.getBool( XML_deleteColumns, true );
158 maSheetProt.mbDeleteRows = rAttribs.getBool( XML_deleteRows, true );
159 maSheetProt.mbSelectLocked = rAttribs.getBool( XML_selectLockedCells, false );
160 maSheetProt.mbSort = rAttribs.getBool( XML_sort, true );
161 maSheetProt.mbAutoFilter = rAttribs.getBool( XML_autoFilter, true );
162 maSheetProt.mbPivotTables = rAttribs.getBool( XML_pivotTables, true );
163 maSheetProt.mbSelectUnlocked = rAttribs.getBool( XML_selectUnlockedCells, false );
166 void WorksheetSettings::importChartProtection( const AttributeList& rAttribs )
168 maSheetProt.mnPasswordHash = CodecHelper::getPasswordHash( rAttribs, XML_password );
169 maSheetProt.mbSheet = rAttribs.getBool( XML_content, false );
170 maSheetProt.mbObjects = rAttribs.getBool( XML_objects, false );
173 void WorksheetSettings::importPhoneticPr( const AttributeList& rAttribs )
175 maPhoneticSett.importPhoneticPr( rAttribs );
178 void WorksheetSettings::importSheetPr( RecordInputStream& rStrm )
180 sal_uInt16 nFlags1;
181 sal_uInt8 nFlags2;
182 rStrm >> nFlags1 >> nFlags2 >> maSheetSettings.maTabColor;
183 rStrm.skip( 8 ); // sync anchor cell
184 rStrm >> maSheetSettings.maCodeName;
185 // sheet settings
186 maSheetSettings.mbFilterMode = getFlag( nFlags2, OOBIN_SHEETPR_FILTERMODE );
187 // outline settings, equal flags in BIFF and OOBIN
188 maSheetSettings.mbApplyStyles = getFlag( nFlags1, BIFF_SHEETPR_APPLYSTYLES );
189 maSheetSettings.mbSummaryRight = getFlag( nFlags1, BIFF_SHEETPR_SYMBOLSRIGHT );
190 maSheetSettings.mbSummaryBelow = getFlag( nFlags1, BIFF_SHEETPR_SYMBOLSBELOW );
191 /* Fit printout to width/height - for whatever reason, this flag is still
192 stored separated from the page settings */
193 getPageSettings().setFitToPagesMode( getFlag( nFlags1, BIFF_SHEETPR_FITTOPAGES ) );
196 void WorksheetSettings::importChartSheetPr( RecordInputStream& rStrm )
198 rStrm.skip( 2 ); // flags, contains only the 'published' flag
199 rStrm >> maSheetSettings.maTabColor >> maSheetSettings.maCodeName;
202 void WorksheetSettings::importSheetProtection( RecordInputStream& rStrm )
204 rStrm >> maSheetProt.mnPasswordHash;
205 // no flags field for all these boolean flags?!?
206 maSheetProt.mbSheet = rStrm.readInt32() != 0;
207 maSheetProt.mbObjects = rStrm.readInt32() != 0;
208 maSheetProt.mbScenarios = rStrm.readInt32() != 0;
209 maSheetProt.mbFormatCells = rStrm.readInt32() != 0;
210 maSheetProt.mbFormatColumns = rStrm.readInt32() != 0;
211 maSheetProt.mbFormatRows = rStrm.readInt32() != 0;
212 maSheetProt.mbInsertColumns = rStrm.readInt32() != 0;
213 maSheetProt.mbInsertRows = rStrm.readInt32() != 0;
214 maSheetProt.mbInsertHyperlinks = rStrm.readInt32() != 0;
215 maSheetProt.mbDeleteColumns = rStrm.readInt32() != 0;
216 maSheetProt.mbDeleteRows = rStrm.readInt32() != 0;
217 maSheetProt.mbSelectLocked = rStrm.readInt32() != 0;
218 maSheetProt.mbSort = rStrm.readInt32() != 0;
219 maSheetProt.mbAutoFilter = rStrm.readInt32() != 0;
220 maSheetProt.mbPivotTables = rStrm.readInt32() != 0;
221 maSheetProt.mbSelectUnlocked = rStrm.readInt32() != 0;
224 void WorksheetSettings::importChartProtection( RecordInputStream& rStrm )
226 rStrm >> maSheetProt.mnPasswordHash;
227 // no flags field for all these boolean flags?!?
228 maSheetProt.mbSheet = rStrm.readInt32() != 0;
229 maSheetProt.mbObjects = rStrm.readInt32() != 0;
232 void WorksheetSettings::importPhoneticPr( RecordInputStream& rStrm )
234 maPhoneticSett.importPhoneticPr( rStrm );
237 void WorksheetSettings::importSheetPr( BiffInputStream& rStrm )
239 sal_uInt16 nFlags;
240 rStrm >> nFlags;
241 // worksheet vs. dialogsheet
242 if( getFlag( nFlags, BIFF_SHEETPR_DIALOGSHEET ) )
244 OSL_ENSURE( getSheetType() == SHEETTYPE_WORKSHEET, "WorksheetSettings::importSheetPr - unexpected sheet type" );
245 setSheetType( SHEETTYPE_DIALOGSHEET );
247 // outline settings
248 maSheetSettings.mbApplyStyles = getFlag( nFlags, BIFF_SHEETPR_APPLYSTYLES );
249 maSheetSettings.mbSummaryRight = getFlag( nFlags, BIFF_SHEETPR_SYMBOLSRIGHT );
250 maSheetSettings.mbSummaryBelow = getFlag( nFlags, BIFF_SHEETPR_SYMBOLSBELOW );
251 // fit printout to width/height
252 getPageSettings().setFitToPagesMode( getFlag( nFlags, BIFF_SHEETPR_FITTOPAGES ) );
253 // save external linked values, in BIFF5-BIFF8 moved to BOOKBOOK record
254 if( getBiff() <= BIFF4 )
255 getWorkbookSettings().setSaveExtLinkValues( !getFlag( nFlags, BIFF_SHEETPR_SKIPEXT ) );
258 void WorksheetSettings::importProtect( BiffInputStream& rStrm )
260 maSheetProt.mbSheet = rStrm.readuInt16() != 0;
263 void WorksheetSettings::importObjectProtect( BiffInputStream& rStrm )
265 maSheetProt.mbObjects = rStrm.readuInt16() != 0;
268 void WorksheetSettings::importScenProtect( BiffInputStream& rStrm )
270 maSheetProt.mbScenarios = rStrm.readuInt16() != 0;
273 void WorksheetSettings::importPassword( BiffInputStream& rStrm )
275 rStrm >> maSheetProt.mnPasswordHash;
278 void WorksheetSettings::importSheetProtection( BiffInputStream& rStrm )
280 rStrm.skip( 19 );
281 sal_uInt16 nFlags = rStrm.readuInt16();
282 // set flag means protection is disabled
283 maSheetProt.mbObjects = !getFlag( nFlags, BIFF_SHEETPROT_OBJECTS );
284 maSheetProt.mbScenarios = !getFlag( nFlags, BIFF_SHEETPROT_SCENARIOS );
285 maSheetProt.mbFormatCells = !getFlag( nFlags, BIFF_SHEETPROT_FORMAT_CELLS );
286 maSheetProt.mbFormatColumns = !getFlag( nFlags, BIFF_SHEETPROT_FORMAT_COLUMNS );
287 maSheetProt.mbFormatRows = !getFlag( nFlags, BIFF_SHEETPROT_FORMAT_ROWS );
288 maSheetProt.mbInsertColumns = !getFlag( nFlags, BIFF_SHEETPROT_INSERT_COLUMNS );
289 maSheetProt.mbInsertRows = !getFlag( nFlags, BIFF_SHEETPROT_INSERT_ROWS );
290 maSheetProt.mbInsertHyperlinks = !getFlag( nFlags, BIFF_SHEETPROT_INSERT_HLINKS );
291 maSheetProt.mbDeleteColumns = !getFlag( nFlags, BIFF_SHEETPROT_DELETE_COLUMNS );
292 maSheetProt.mbDeleteRows = !getFlag( nFlags, BIFF_SHEETPROT_DELETE_ROWS );
293 maSheetProt.mbSelectLocked = !getFlag( nFlags, BIFF_SHEETPROT_SELECT_LOCKED );
294 maSheetProt.mbSort = !getFlag( nFlags, BIFF_SHEETPROT_SORT );
295 maSheetProt.mbAutoFilter = !getFlag( nFlags, BIFF_SHEETPROT_AUTOFILTER );
296 maSheetProt.mbPivotTables = !getFlag( nFlags, BIFF_SHEETPROT_PIVOTTABLES );
297 maSheetProt.mbSelectUnlocked = !getFlag( nFlags, BIFF_SHEETPROT_SELECT_UNLOCKED );
300 void WorksheetSettings::importPhoneticPr( BiffInputStream& rStrm )
302 maPhoneticSett.importPhoneticPr( rStrm );
305 void WorksheetSettings::finalizeImport()
307 if( maSheetProt.mbSheet ) try
309 Reference< XProtectable > xProtectable( getSheet(), UNO_QUERY_THROW );
310 xProtectable->protect( OUString() );
312 catch( Exception& )
317 // ============================================================================
319 } // namespace xls
320 } // namespace oox