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