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 : #ifndef SC_XICONTENT_HXX
21 : #define SC_XICONTENT_HXX
22 :
23 : #include "global.hxx"
24 : #include "rangelst.hxx"
25 : #include "xlcontent.hxx"
26 : #include "xistring.hxx"
27 : #include "xiroot.hxx"
28 : #include "validat.hxx"
29 : #include "tabprotection.hxx"
30 :
31 : #include <map>
32 : #include <boost/ptr_container/ptr_vector.hpp>
33 : #include <boost/noncopyable.hpp>
34 :
35 : /* ============================================================================
36 : Classes to import the big Excel document contents (related to several cells or
37 : globals for the document).
38 : - Shared
39 : tables
40 : - Hyperlinks
41 : - Label ranges
42 : - Conditional formatting
43 : - Data validation
44 : - Web queries
45 : - Stream decryption
46 : ============================================================================ */
47 :
48 : // Shared string table ========================================================
49 :
50 : /** The SST (shared string table) contains all strings used in a BIFF8 file.
51 :
52 : This class loads the SST, provides access to the strings, and is able to
53 : create Calc string or edit cells.
54 : */
55 0 : class XclImpSst : protected XclImpRoot
56 : {
57 : public:
58 : explicit XclImpSst( const XclImpRoot& rRoot );
59 :
60 : /** Reads the entire SST record.
61 : @descr Import stream must be located at start of a SST record. */
62 : void ReadSst( XclImpStream& rStrm );
63 :
64 : /** Returns a pointer to the string with the passed index. */
65 : const XclImpString* GetString( sal_uInt32 nSstIndex ) const;
66 :
67 : private:
68 : typedef ::std::vector< XclImpString > XclImpStringVec;
69 : XclImpStringVec maStrings; /// List with all strings in the SST.
70 : };
71 :
72 : // Hyperlinks =================================================================
73 :
74 : /** Provides importing hyperlinks and inserting them into a document. */
75 : class XclImpHyperlink : private boost::noncopyable
76 : {
77 : public:
78 : /** Reads a HLINK record and inserts it into the document.
79 : @descr Import stream must be located at start of a HLINK record. */
80 : static void ReadHlink( XclImpStream& rStrm );
81 :
82 : /** Reads the (undocumented) embedded hyperlink data and returns the URL. */
83 : static OUString ReadEmbeddedData( XclImpStream& rStrm );
84 :
85 : /** Inserts the URL into a range of cells. Does not modify value or formula cells. */
86 : static void InsertUrl( XclImpRoot& rRoot, const XclRange& rXclRange, const OUString& rUrl );
87 :
88 : /** Convert the sheet name with invalid character(s) in URL when the URL is
89 : to a location within the same document (e.g. #'Sheet&Name'.A1). */
90 : static void ConvertToValidTabName(OUString& rName);
91 :
92 : private:
93 : /** We don't want anybody to instantiate this class, since it is just a
94 : collection of static methods. To enforce this, the default constructor
95 : is made private */
96 : XclImpHyperlink();
97 : };
98 :
99 : // Label ranges ===============================================================
100 :
101 : /** Provides importing label ranges and inserting them into a document. */
102 : class XclImpLabelranges : private boost::noncopyable
103 : {
104 : public:
105 : /** Reads a LABELRANGES record and inserts the label ranges into the document.
106 : @descr Import stream must be located at start of a LABELRANGES record. */
107 : static void ReadLabelranges( XclImpStream& rStrm );
108 :
109 : private:
110 : /** We don't want anybody to instantiate this class, since it is just a
111 : collection of static methods. To enforce this, the default constructor
112 : is made private */
113 : XclImpLabelranges();
114 : };
115 :
116 : // Conditional formatting =====================================================
117 :
118 : class ScConditionalFormat;
119 :
120 : /** Represents a conditional format with condition formulas, and formatting attributes. */
121 : class XclImpCondFormat : protected XclImpRoot
122 : {
123 : public:
124 : explicit XclImpCondFormat( const XclImpRoot& rRoot, sal_uInt32 nFormatIndex );
125 : virtual ~XclImpCondFormat();
126 :
127 : /** Reads a CONDFMT record and initializes this conditional format. */
128 : void ReadCondfmt( XclImpStream& rStrm );
129 : /** Reads a CF record and adds a new condition and the formatting attributes. */
130 : void ReadCF( XclImpStream& rStrm );
131 :
132 : /** Inserts this conditional format into the document. */
133 : void Apply();
134 :
135 : private:
136 : typedef ::std::auto_ptr< ScConditionalFormat > ScCondFmtPtr;
137 :
138 : ScRangeList maRanges; /// Destination cell ranges.
139 : ScCondFmtPtr mxScCondFmt; /// Calc conditional format.
140 : sal_uInt32 mnFormatIndex; /// Index of this conditional format in list.
141 : sal_uInt16 mnCondCount; /// Number of conditions to be inserted.
142 : sal_uInt16 mnCondIndex; /// Condition index to be inserted next.
143 : };
144 :
145 : /** Imports and collects all conditional formatting of a sheet. */
146 0 : class XclImpCondFormatManager : protected XclImpRoot
147 : {
148 : public:
149 : explicit XclImpCondFormatManager( const XclImpRoot& rRoot );
150 :
151 : /** Reads a CONDFMT record and starts a new conditional format to be filled from CF records. */
152 : void ReadCondfmt( XclImpStream& rStrm );
153 : /** Reads a CF record and inserts the formatting data to the current conditional format. */
154 : void ReadCF( XclImpStream& rStrm );
155 :
156 : /** Inserts the conditional formatting into the document. */
157 : void Apply();
158 :
159 : private:
160 : typedef boost::ptr_vector< XclImpCondFormat > XclImpCondFmtList;
161 : XclImpCondFmtList maCondFmtList; /// List with all conditional formatting.
162 : };
163 :
164 : // Data Validation ============================================================
165 :
166 : /** Imports validation data. */
167 0 : class XclImpValidationManager : protected XclImpRoot
168 : {
169 : public:
170 : explicit XclImpValidationManager( const XclImpRoot& rRoot );
171 :
172 : /** Reads a DVAL record and sets marks the dropdown arrow control to be ignored. */
173 : void ReadDval( XclImpStream& rStrm );
174 : /** Reads a DV record and inserts validation data into the document. */
175 : void ReadDV( XclImpStream& rStrm );
176 :
177 : void Apply();
178 : private:
179 0 : struct DVItem
180 : {
181 : ScRangeList maRanges;
182 : ScValidationData maValidData;
183 :
184 : explicit DVItem ( const ScRangeList& rRanges, const ScValidationData& rValidData );
185 : };
186 : typedef ::boost::ptr_vector<DVItem> DVItemList;
187 :
188 : DVItemList maDVItems;
189 : };
190 :
191 : // Web queries ================================================================
192 :
193 : /** Stores the data of one web query. */
194 0 : class XclImpWebQuery : private boost::noncopyable
195 : {
196 : public:
197 : explicit XclImpWebQuery( const ScRange& rDestRange );
198 :
199 : /** Reads a PARAMQRY record and sets data to the web query. */
200 : void ReadParamqry( XclImpStream& rStrm );
201 : /** Reads a WQSTRING record and sets URL. */
202 : void ReadWqstring( XclImpStream& rStrm );
203 : /** Reads a WEBQRYSETTINGS record and sets refresh rate. */
204 : void ReadWqsettings( XclImpStream& rStrm );
205 : /** Reads a WEBQRYTABLES record and sets source range list. */
206 : void ReadWqtables( XclImpStream& rStrm );
207 :
208 : /** Inserts the web query into the document. */
209 : void Apply( ScDocument& rDoc, const OUString& rFilterName );
210 :
211 : private:
212 : /** Specifies the type of the web query (which ranges are imported). */
213 : enum XclImpWebQueryMode
214 : {
215 : xlWQUnknown, /// Not specified.
216 : xlWQDocument, /// Entire document.
217 : xlWQAllTables, /// All tables.
218 : xlWQSpecTables /// Specific tables.
219 : };
220 :
221 : OUString maURL; /// Source document URL.
222 : OUString maTables; /// List of source range names.
223 : ScRange maDestRange; /// Destination range.
224 : XclImpWebQueryMode meMode; /// Current mode of the web query.
225 : sal_uInt16 mnRefresh; /// Refresh time in minutes.
226 : };
227 :
228 0 : class XclImpWebQueryBuffer : protected XclImpRoot
229 : {
230 : public:
231 : explicit XclImpWebQueryBuffer( const XclImpRoot& rRoot );
232 :
233 : /** Reads the QSI record and creates a new web query in the buffer. */
234 : void ReadQsi( XclImpStream& rStrm );
235 : /** Reads a PARAMQRY record and sets data to the current web query. */
236 : void ReadParamqry( XclImpStream& rStrm );
237 : /** Reads a WQSTRING record and sets URL to the current web query. */
238 : void ReadWqstring( XclImpStream& rStrm );
239 : /** Reads a WEBQRYSETTINGS record and sets refresh rate to the current web query. */
240 : void ReadWqsettings( XclImpStream& rStrm );
241 : /** Reads a WEBQRYTABLES record and sets source range list to the current web query. */
242 : void ReadWqtables( XclImpStream& rStrm );
243 :
244 : /** Inserts all web queries into the document. */
245 : void Apply();
246 :
247 : private:
248 : typedef boost::ptr_vector< XclImpWebQuery > XclImpWebQueryList;
249 : XclImpWebQueryList maWQList; /// List of the web query objects.
250 : };
251 :
252 : // Decryption =================================================================
253 :
254 : /** Provides static functions to import stream decryption settings. */
255 : class XclImpDecryptHelper : private boost::noncopyable
256 : {
257 : public:
258 : /** Reads the FILEPASS record, queries a password and sets decryption algorihm.
259 : @return Error code that may cause an error message after import. */
260 : static ErrCode ReadFilepass( XclImpStream& rStrm );
261 :
262 : private:
263 : /** We don't want anybody to instantiate this class, since it is just a
264 : collection of static methods. To enforce this, the default constructor
265 : is made private */
266 : XclImpDecryptHelper();
267 : };
268 :
269 : // Document protection ========================================================
270 :
271 0 : class XclImpDocProtectBuffer : protected XclImpRoot
272 : {
273 : public:
274 : explicit XclImpDocProtectBuffer( const XclImpRoot& rRoot );
275 :
276 : /** document structure protection flag */
277 : void ReadDocProtect( XclImpStream& rStrm );
278 :
279 : /** document windows properties protection flag */
280 : void ReadWinProtect( XclImpStream& rStrm );
281 :
282 : void ReadPasswordHash( XclImpStream& rStrm );
283 :
284 : void Apply() const;
285 :
286 : private:
287 : sal_uInt16 mnPassHash;
288 : bool mbDocProtect:1;
289 : bool mbWinProtect:1;
290 : };
291 :
292 : // Sheet protection ===========================================================
293 :
294 0 : class XclImpSheetProtectBuffer : protected XclImpRoot
295 : {
296 : public:
297 : explicit XclImpSheetProtectBuffer( const XclImpRoot& rRoot );
298 :
299 : void ReadProtect( XclImpStream& rStrm, SCTAB nTab );
300 :
301 : void ReadOptions( XclImpStream& rStrm, SCTAB nTab );
302 :
303 : void AppendEnhancedProtection( const ScEnhancedProtection & rProt, SCTAB nTab );
304 :
305 : void ReadPasswordHash( XclImpStream& rStrm, SCTAB nTab );
306 :
307 : void Apply() const;
308 :
309 : private:
310 0 : struct Sheet
311 : {
312 : bool mbProtected;
313 : sal_uInt16 mnPasswordHash;
314 : sal_uInt16 mnOptions;
315 : ::std::vector< ScEnhancedProtection > maEnhancedProtections;
316 :
317 : Sheet();
318 : Sheet(const Sheet& r);
319 : };
320 :
321 : Sheet* GetSheetItem( SCTAB nTab );
322 :
323 : private:
324 : typedef ::std::map<SCTAB, Sheet> ProtectedSheetMap;
325 : ProtectedSheetMap maProtectedSheets;
326 : };
327 :
328 : #endif
329 :
330 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|