Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / filter / inc / xicontent.hxx
blob371cc72ca12005ea781ec76b72b78a9208c229ba
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_XICONTENT_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_XICONTENT_HXX
23 #include <rangelst.hxx>
24 #include "xistring.hxx"
25 #include "xiroot.hxx"
26 #include <validat.hxx>
27 #include <tabprotection.hxx>
29 #include <map>
30 #include <vector>
31 #include <memory>
33 class ErrCode;
34 struct XclRange;
36 /* ============================================================================
37 Classes to import the big Excel document contents (related to several cells or
38 globals for the document).
39 - Shared
40 tables
41 - Hyperlinks
42 - Label ranges
43 - Conditional formatting
44 - Data validation
45 - Web queries
46 - Stream decryption
47 ============================================================================ */
49 // Shared string table ========================================================
51 /** The SST (shared string table) contains all strings used in a BIFF8 file.
53 This class loads the SST, provides access to the strings, and is able to
54 create Calc string or edit cells.
56 class XclImpSst : protected XclImpRoot
58 public:
59 explicit XclImpSst( const XclImpRoot& rRoot );
61 /** Reads the entire SST record.
62 @descr Import stream must be located at start of a SST record. */
63 void ReadSst( XclImpStream& rStrm );
65 /** Returns a pointer to the string with the passed index. */
66 const XclImpString* GetString( sal_uInt32 nSstIndex ) const;
68 private:
69 typedef ::std::vector< XclImpString > XclImpStringVec;
70 XclImpStringVec maStrings; /// List with all strings in the SST.
73 // Hyperlinks =================================================================
75 /** Provides importing hyperlinks and inserting them into a document. */
76 class XclImpHyperlink
78 public:
79 /** delete copy constructor */
80 XclImpHyperlink(const XclImpHyperlink&) = delete;
81 /** delete copy-assignment operator */
82 const XclImpHyperlink& operator=(const XclImpHyperlink&) = delete;
83 /** We don't want anybody to instantiate this class, since it is just a
84 collection of static methods. */
85 XclImpHyperlink() = delete;
87 /** Reads a HLINK record and inserts it into the document.
88 @descr Import stream must be located at start of a HLINK record. */
89 static void ReadHlink( XclImpStream& rStrm );
91 /** Reads the (undocumented) embedded hyperlink data and returns the URL. */
92 static OUString ReadEmbeddedData( XclImpStream& rStrm );
94 /** Inserts the URL into a range of cells. Does not modify value or formula cells. */
95 static void InsertUrl( XclImpRoot& rRoot, const XclRange& rXclRange, const OUString& rUrl );
97 /** Convert the sheet name with invalid character(s) in URL when the URL is
98 to a location within the same document (e.g. #'Sheet&Name'.A1). */
99 static void ConvertToValidTabName(OUString& rName);
102 // Label ranges ===============================================================
104 /** Provides importing label ranges and inserting them into a document. */
105 class XclImpLabelranges
107 public:
108 /** delete copy constructor */
109 XclImpLabelranges(const XclImpLabelranges&) = delete;
110 /** delete copy-assignment operator */
111 const XclImpLabelranges& operator=(const XclImpLabelranges&) = delete;
112 /** We don't want anybody to instantiate this class, since it is just a
113 collection of static methods. */
114 XclImpLabelranges() = delete;
115 /** Reads a LABELRANGES record and inserts the label ranges into the document.
116 @descr Import stream must be located at start of a LABELRANGES record. */
117 static void ReadLabelranges( XclImpStream& rStrm );
120 // Conditional formatting =====================================================
122 /** Represents a conditional format with condition formulas, and formatting attributes. */
123 class XclImpCondFormat : protected XclImpRoot
125 public:
126 explicit XclImpCondFormat( const XclImpRoot& rRoot, sal_uInt32 nFormatIndex );
127 virtual ~XclImpCondFormat() override;
129 /** Reads a CONDFMT record and initializes this conditional format. */
130 void ReadCondfmt( XclImpStream& rStrm );
131 /** Reads a CF record and adds a new condition and the formatting attributes. */
132 void ReadCF( XclImpStream& rStrm );
134 /** Inserts this conditional format into the document. */
135 void Apply();
137 private:
138 typedef ::std::unique_ptr< ScConditionalFormat > ScCondFmtPtr;
140 ScRangeList maRanges; /// Destination cell ranges.
141 ScCondFmtPtr mxScCondFmt; /// Calc conditional format.
142 sal_uInt32 const mnFormatIndex; /// Index of this conditional format in list.
143 sal_uInt16 mnCondCount; /// Number of conditions to be inserted.
144 sal_uInt16 mnCondIndex; /// Condition index to be inserted next.
147 /** Imports and collects all conditional formatting of a sheet. */
148 class XclImpCondFormatManager : protected XclImpRoot
150 public:
151 explicit XclImpCondFormatManager( const XclImpRoot& rRoot );
153 /** Reads a CONDFMT record and starts a new conditional format to be filled from CF records. */
154 void ReadCondfmt( XclImpStream& rStrm );
155 /** Reads a CF record and inserts the formatting data to the current conditional format. */
156 void ReadCF( XclImpStream& rStrm );
158 /** Inserts the conditional formatting into the document. */
159 void Apply();
161 private:
162 typedef std::vector< std::unique_ptr<XclImpCondFormat> > XclImpCondFmtList;
163 XclImpCondFmtList maCondFmtList; /// List with all conditional formatting.
166 // Data Validation ============================================================
168 /** Imports validation data. */
169 class XclImpValidationManager : protected XclImpRoot
171 public:
172 explicit XclImpValidationManager( const XclImpRoot& rRoot );
174 /** Reads a DVAL record and sets marks the dropdown arrow control to be ignored. */
175 static void ReadDval( XclImpStream& rStrm );
176 /** Reads a DV record and inserts validation data into the document. */
177 void ReadDV( XclImpStream& rStrm );
179 void Apply();
180 private:
181 struct DVItem
183 ScRangeList maRanges;
184 ScValidationData maValidData;
186 explicit DVItem ( const ScRangeList& rRanges, const ScValidationData& rValidData );
188 typedef std::vector< std::unique_ptr<DVItem> > DVItemList;
190 DVItemList maDVItems;
193 // Web queries ================================================================
195 /** Stores the data of one web query. */
196 class XclImpWebQuery
198 public:
199 explicit XclImpWebQuery( const ScRange& rDestRange );
201 /** Reads a PARAMQRY record and sets data to the web query. */
202 void ReadParamqry( XclImpStream& rStrm );
203 /** Reads a WQSTRING record and sets URL. */
204 void ReadWqstring( XclImpStream& rStrm );
205 /** Reads a WEBQRYSETTINGS record and sets refresh rate. */
206 void ReadWqsettings( XclImpStream& rStrm );
207 /** Reads a WEBQRYTABLES record and sets source range list. */
208 void ReadWqtables( XclImpStream& rStrm );
210 /** Inserts the web query into the document. */
211 void Apply( ScDocument& rDoc, const OUString& rFilterName );
213 private:
214 /** Specifies the type of the web query (which ranges are imported). */
215 enum XclImpWebQueryMode
217 xlWQUnknown, /// Not specified.
218 xlWQDocument, /// Entire document.
219 xlWQAllTables, /// All tables.
220 xlWQSpecTables /// Specific tables.
223 OUString maURL; /// Source document URL.
224 OUString maTables; /// List of source range names.
225 ScRange const maDestRange; /// Destination range.
226 XclImpWebQueryMode meMode; /// Current mode of the web query.
227 sal_uInt16 mnRefresh; /// Refresh time in minutes.
230 class XclImpWebQueryBuffer : protected XclImpRoot
232 public:
233 explicit XclImpWebQueryBuffer( const XclImpRoot& rRoot );
235 /** Reads the QSI record and creates a new web query in the buffer. */
236 void ReadQsi( XclImpStream& rStrm );
237 /** Reads a PARAMQRY record and sets data to the current web query. */
238 void ReadParamqry( XclImpStream& rStrm );
239 /** Reads a WQSTRING record and sets URL to the current web query. */
240 void ReadWqstring( XclImpStream& rStrm );
241 /** Reads a WEBQRYSETTINGS record and sets refresh rate to the current web query. */
242 void ReadWqsettings( XclImpStream& rStrm );
243 /** Reads a WEBQRYTABLES record and sets source range list to the current web query. */
244 void ReadWqtables( XclImpStream& rStrm );
246 /** Inserts all web queries into the document. */
247 void Apply();
249 private:
250 typedef std::vector< XclImpWebQuery > XclImpWebQueryList;
251 XclImpWebQueryList maWQList; /// List of the web query objects.
254 // Decryption =================================================================
256 /** Provides static functions to import stream decryption settings. */
257 class XclImpDecryptHelper
259 public:
260 /** delete copy constructor */
261 XclImpDecryptHelper(const XclImpDecryptHelper&) = delete;
262 /** delete copy-assignment operator */
263 const XclImpDecryptHelper& operator=(const XclImpDecryptHelper&) = delete;
264 /** We don't want anybody to instantiate this class, since it is just a
265 collection of static methods. */
266 XclImpDecryptHelper() = delete;
268 /** Reads the FILEPASS record, queries a password and sets decryption algorithm.
269 @return Error code that may cause an error message after import. */
270 static const ErrCode& ReadFilepass( XclImpStream& rStrm );
273 // Document protection ========================================================
275 class XclImpDocProtectBuffer : protected XclImpRoot
277 public:
278 explicit XclImpDocProtectBuffer( const XclImpRoot& rRoot );
280 /** document structure protection flag */
281 void ReadDocProtect( XclImpStream& rStrm );
283 /** document windows properties protection flag */
284 void ReadWinProtect( XclImpStream& rStrm );
286 void ReadPasswordHash( XclImpStream& rStrm );
288 void Apply() const;
290 private:
291 sal_uInt16 mnPassHash;
292 bool mbDocProtect:1;
293 bool mbWinProtect:1;
296 // Sheet protection ===========================================================
298 class XclImpSheetProtectBuffer : protected XclImpRoot
300 public:
301 explicit XclImpSheetProtectBuffer( const XclImpRoot& rRoot );
303 void ReadProtect( XclImpStream& rStrm, SCTAB nTab );
305 void ReadOptions( XclImpStream& rStrm, SCTAB nTab );
307 void AppendEnhancedProtection( const ScEnhancedProtection & rProt, SCTAB nTab );
309 void ReadPasswordHash( XclImpStream& rStrm, SCTAB nTab );
311 void Apply() const;
313 private:
314 struct Sheet
316 bool mbProtected;
317 sal_uInt16 mnPasswordHash;
318 sal_uInt16 mnOptions;
319 ::std::vector< ScEnhancedProtection > maEnhancedProtections;
321 Sheet();
322 Sheet(const Sheet& r);
325 Sheet* GetSheetItem( SCTAB nTab );
327 private:
328 typedef ::std::map<SCTAB, Sheet> ProtectedSheetMap;
329 ProtectedSheetMap maProtectedSheets;
332 #endif
334 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */