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 INCLUDED_SC_SOURCE_FILTER_INC_XICONTENT_HXX 21 #define INCLUDED_SC_SOURCE_FILTER_INC_XICONTENT_HXX 22 23 #include <rangelst.hxx> 24 #include "xistring.hxx" 25 #include "xiroot.hxx" 26 #include <validat.hxx> 27 #include <tabprotection.hxx> 28 29 #include <map> 30 #include <vector> 31 #include <memory> 32 33 class ErrCode; 34 struct XclRange; 35 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 ============================================================================ */ 48 49 // Shared string table ======================================================== 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 private: 69 typedef ::std::vector< XclImpString > XclImpStringVec; 70 XclImpStringVec maStrings; /// List with all strings in the SST. 71 }; 72 73 // Hyperlinks ================================================================= 74 75 /** Provides importing hyperlinks and inserting them into a document. */ 76 class XclImpHyperlink 77 { 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; 86 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 ); 90 91 /** Reads the (undocumented) embedded hyperlink data and returns the URL. */ 92 static OUString ReadEmbeddedData( XclImpStream& rStrm ); 93 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 ); 96 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); 100 }; 101 102 // Label ranges =============================================================== 103 104 /** Provides importing label ranges and inserting them into a document. */ 105 class XclImpLabelranges 106 { 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 ); 118 }; 119 120 // Conditional formatting ===================================================== 121 122 /** Represents a conditional format with condition formulas, and formatting attributes. */ 123 class XclImpCondFormat : protected XclImpRoot 124 { 125 public: 126 explicit XclImpCondFormat( const XclImpRoot& rRoot, sal_uInt32 nFormatIndex ); 127 virtual ~XclImpCondFormat() override; 128 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 ); 133 134 /** Inserts this conditional format into the document. */ 135 void Apply(); 136 137 private: 138 typedef ::std::unique_ptr< ScConditionalFormat > ScCondFmtPtr; 139 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. 145 }; 146 147 /** Imports and collects all conditional formatting of a sheet. */ 148 class XclImpCondFormatManager : protected XclImpRoot 149 { 150 public: 151 explicit XclImpCondFormatManager( const XclImpRoot& rRoot ); 152 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 ); 157 158 /** Inserts the conditional formatting into the document. */ 159 void Apply(); 160 161 private: 162 typedef std::vector< std::unique_ptr<XclImpCondFormat> > XclImpCondFmtList; 163 XclImpCondFmtList maCondFmtList; /// List with all conditional formatting. 164 }; 165 166 // Data Validation ============================================================ 167 168 /** Imports validation data. */ 169 class XclImpValidationManager : protected XclImpRoot 170 { 171 public: 172 explicit XclImpValidationManager( const XclImpRoot& rRoot ); 173 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 ); 178 179 void Apply(); 180 private: 181 struct DVItem 182 { 183 ScRangeList maRanges; 184 ScValidationData maValidData; 185 186 explicit DVItem ( const ScRangeList& rRanges, const ScValidationData& rValidData ); 187 }; 188 typedef std::vector< std::unique_ptr<DVItem> > DVItemList; 189 190 DVItemList maDVItems; 191 }; 192 193 // Web queries ================================================================ 194 195 /** Stores the data of one web query. */ 196 class XclImpWebQuery 197 { 198 public: 199 explicit XclImpWebQuery( const ScRange& rDestRange ); 200 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 ); 209 210 /** Inserts the web query into the document. */ 211 void Apply( ScDocument& rDoc, const OUString& rFilterName ); 212 213 private: 214 /** Specifies the type of the web query (which ranges are imported). */ 215 enum XclImpWebQueryMode 216 { 217 xlWQUnknown, /// Not specified. 218 xlWQDocument, /// Entire document. 219 xlWQAllTables, /// All tables. 220 xlWQSpecTables /// Specific tables. 221 }; 222 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. 228 }; 229 230 class XclImpWebQueryBuffer : protected XclImpRoot 231 { 232 public: 233 explicit XclImpWebQueryBuffer( const XclImpRoot& rRoot ); 234 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 ); 245 246 /** Inserts all web queries into the document. */ 247 void Apply(); 248 249 private: 250 typedef std::vector< XclImpWebQuery > XclImpWebQueryList; 251 XclImpWebQueryList maWQList; /// List of the web query objects. 252 }; 253 254 // Decryption ================================================================= 255 256 /** Provides static functions to import stream decryption settings. */ 257 class XclImpDecryptHelper 258 { 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; 267 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 ); 271 }; 272 273 // Document protection ======================================================== 274 275 class XclImpDocProtectBuffer : protected XclImpRoot 276 { 277 public: 278 explicit XclImpDocProtectBuffer( const XclImpRoot& rRoot ); 279 280 /** document structure protection flag */ 281 void ReadDocProtect( XclImpStream& rStrm ); 282 283 /** document windows properties protection flag */ 284 void ReadWinProtect( XclImpStream& rStrm ); 285 286 void ReadPasswordHash( XclImpStream& rStrm ); 287 288 void Apply() const; 289 290 private: 291 sal_uInt16 mnPassHash; 292 bool mbDocProtect:1; 293 bool mbWinProtect:1; 294 }; 295 296 // Sheet protection =========================================================== 297 298 class XclImpSheetProtectBuffer : protected XclImpRoot 299 { 300 public: 301 explicit XclImpSheetProtectBuffer( const XclImpRoot& rRoot ); 302 303 void ReadProtect( XclImpStream& rStrm, SCTAB nTab ); 304 305 void ReadOptions( XclImpStream& rStrm, SCTAB nTab ); 306 307 void AppendEnhancedProtection( const ScEnhancedProtection & rProt, SCTAB nTab ); 308 309 void ReadPasswordHash( XclImpStream& rStrm, SCTAB nTab ); 310 311 void Apply() const; 312 313 private: 314 struct Sheet 315 { 316 bool mbProtected; 317 sal_uInt16 mnPasswordHash; 318 sal_uInt16 mnOptions; 319 ::std::vector< ScEnhancedProtection > maEnhancedProtections; 320 321 Sheet(); 322 Sheet(const Sheet& r); 323 }; 324 325 Sheet* GetSheetItem( SCTAB nTab ); 326 327 private: 328 typedef ::std::map<SCTAB, Sheet> ProtectedSheetMap; 329 ProtectedSheetMap maProtectedSheets; 330 }; 331 332 #endif 333 334 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 335