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