1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef OOX_XLS_WORKBOOKSETTINGS_HXX
25 #define OOX_XLS_WORKBOOKSETTINGS_HXX
26 
27 #include "oox/xls/workbookhelper.hxx"
28 
29 namespace com { namespace sun { namespace star { namespace util { struct Date; } } } }
30 
31 namespace oox {
32 namespace xls {
33 
34 // ============================================================================
35 
36 /** Settings for workbook write protection. */
37 struct FileSharingModel
38 {
39     ::rtl::OUString     maUserName;             /// User who added the write protection password.
40     sal_uInt16          mnPasswordHash;         /// Hash value of the write protection password.
41     bool                mbRecommendReadOnly;    /// True = recommend read-only mode on opening.
42 
43     explicit            FileSharingModel();
44 };
45 
46 // ============================================================================
47 
48 /** Global workbook settings. */
49 struct WorkbookSettingsModel
50 {
51     ::rtl::OUString     maCodeName;             /// VBA codename for the workbook.
52     sal_Int32           mnShowObjectMode;       /// Specifies how objects are shown.
53     sal_Int32           mnUpdateLinksMode;      /// Specifies how external links are updated.
54     sal_Int32           mnDefaultThemeVer;      /// Default theme version.
55     bool                mbDateMode1904;         /// True = null date is 1904-01-01.
56     bool                mbSaveExtLinkValues;    /// True = save cached cell values for external links.
57 
58     explicit            WorkbookSettingsModel();
59 
60     /** Sets BIFF object visibility mode. */
61     void                setBiffObjectMode( sal_uInt16 nObjMode );
62 };
63 
64 // ============================================================================
65 
66 /** Workbook calculation settings. */
67 struct CalcSettingsModel
68 {
69     double              mfIterateDelta;         /// Minimum change in circular references.
70     sal_Int32           mnCalcId;               /// Calculation engine identifier.
71     sal_Int32           mnRefMode;              /// Cell reference mode: A1 or R1C1.
72     sal_Int32           mnCalcMode;             /// Automatic or manual recalculation.
73     sal_Int32           mnIterateCount;         /// Number of iterations in circular references.
74     sal_Int32           mnProcCount;            /// Number of processors for concurrent calculation.
75     bool                mbCalcOnSave;           /// True = always recalculate formulas before save.
76     bool                mbCalcCompleted;        /// True = formulas have been recalculated before save.
77     bool                mbFullPrecision;        /// True = use full precision on calculation.
78     bool                mbIterate;              /// True = allow circular references.
79     bool                mbConcurrent;           /// True = concurrent calculation enabled.
80     bool                mbUseNlr;               /// True = use natural language references in formulas.
81 
82     explicit            CalcSettingsModel();
83 };
84 
85 // ============================================================================
86 
87 class WorkbookSettings : public WorkbookHelper
88 {
89 public:
90     explicit            WorkbookSettings( const WorkbookHelper& rHelper );
91 
92     /** Imports the fileSharing element containing write protection settings. */
93     void                importFileSharing( const AttributeList& rAttribs );
94     /** Imports the workbookPr element containing global workbook settings. */
95     void                importWorkbookPr( const AttributeList& rAttribs );
96     /** Imports the calcPr element containing workbook calculation settings. */
97     void                importCalcPr( const AttributeList& rAttribs );
98 
99     /** Imports the FILESHARING record containing write protection settings. */
100     void                importFileSharing( SequenceInputStream& rStrm );
101     /** Imports the WORKBOOKPR record containing global workbook settings. */
102     void                importWorkbookPr( SequenceInputStream& rStrm );
103     /** Imports the CALCPR record containing workbook calculation settings. */
104     void                importCalcPr( SequenceInputStream& rStrm );
105 
106     /** Sets the save external linked values flag, e.g. from the WSBOOL record. */
107     void                setSaveExtLinkValues( bool bSaveExtLinks );
108     /** Imports the BOOKBOOL record. */
109     void                importBookBool( BiffInputStream& rStrm );
110     /** Imports the CALCCOUNT record. */
111     void                importCalcCount( BiffInputStream& rStrm );
112     /** Imports the CALCMODE record. */
113     void                importCalcMode( BiffInputStream& rStrm );
114     /** Imports the CODENAME record. */
115     void                importCodeName( BiffInputStream& rStrm );
116     /** Imports the DATEMODE record. */
117     void                importDateMode( BiffInputStream& rStrm );
118     /** Imports the DELTA record. */
119     void                importDelta( BiffInputStream& rStrm );
120     /** Imports the FILESHARING record. */
121     void                importFileSharing( BiffInputStream& rStrm );
122     /** Imports the HIDEOBJ record. */
123     void                importHideObj( BiffInputStream& rStrm );
124     /** Imports the ITERATION record. */
125     void                importIteration( BiffInputStream& rStrm );
126     /** Imports the PRECISION record. */
127     void                importPrecision( BiffInputStream& rStrm );
128     /** Imports the REFMODE record. */
129     void                importRefMode( BiffInputStream& rStrm );
130     /** Imports the SAVERECALC record. */
131     void                importSaveRecalc( BiffInputStream& rStrm );
132     /** Imports the UNCALCED record. */
133     void                importUncalced( BiffInputStream& rStrm );
134     /** Imports the USESELFS record. */
135     void                importUsesElfs( BiffInputStream& rStrm );
136 
137     /** Converts the imported workbook settings. */
138     void                finalizeImport();
139 
140     /** Returns the show objects mode (considered a view setting in Calc). */
141     sal_Int16           getApiShowObjectMode() const;
142     /** Returns the nulldate of this workbook. */
143     ::com::sun::star::util::Date getNullDate() const;
144 
145 private:
146     /** Updates date mode and unit converter nulldate. */
147     void                setDateMode( bool bDateMode1904 );
148 
149 private:
150     FileSharingModel    maFileSharing;
151     WorkbookSettingsModel maBookSettings;
152     CalcSettingsModel   maCalcSettings;
153 };
154 
155 // ============================================================================
156 
157 } // namespace xls
158 } // namespace oox
159 
160 #endif
161