Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / sc / source / filter / inc / xecontent.hxx
blob07318a037ca43e8cc6d670621558dcfd7d02d867
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 #pragma once
22 #include <memory>
23 #include <rangelst.hxx>
24 #include "xladdress.hxx"
25 #include "xerecord.hxx"
26 #include "xeroot.hxx"
27 #include "xestring.hxx"
28 #include "xeextlst.hxx"
29 #include "xlformula.hxx"
31 #include <colorscale.hxx>
33 /* ============================================================================
34 Classes to export the big Excel document contents (related to several cells or
35 globals for the sheet or document).
36 - Shared string table
37 - Merged cells
38 - Hyperlinks
39 - Label ranges
40 - Conditional formatting
41 - Data validation
42 - Web Queries
43 ============================================================================ */
45 // Shared string table ========================================================
47 class XclExpSstImpl;
49 /** Provides export of the SST (shared string table) record.
50 @descr Contains all strings in the document and writes the SST. */
51 class XclExpSst : public XclExpRecordBase
53 public:
54 explicit XclExpSst();
55 virtual ~XclExpSst() override;
57 /** Inserts a new string into the table.
58 @return The index of the string in the SST, used in other records. */
59 sal_uInt32 Insert( const XclExpStringRef& xString );
61 /** Writes the complete SST and EXTSST records. */
62 virtual void Save( XclExpStream& rStrm ) override;
63 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
65 private:
66 typedef std::unique_ptr< XclExpSstImpl > XclExpSstImplPtr;
67 XclExpSstImplPtr mxImpl;
70 // Merged cells ===============================================================
72 /** Represents a MERGEDCELLS record containing all merged cell ranges in a sheet. */
73 class XclExpMergedcells : public XclExpRecordBase, protected XclExpRoot
75 public:
76 explicit XclExpMergedcells( const XclExpRoot& rRoot );
78 /** Appends a new range to the list of merged cell ranges. */
79 void AppendRange( const ScRange& rRange, sal_uInt32 nBaseXFId );
80 /** Returns the XF identifier of the top-left cell in a merged range. */
81 sal_uInt32 GetBaseXFId( const ScAddress& rPos ) const;
83 /** Writes the record, if it contains at least one merged cell range. */
84 virtual void Save( XclExpStream& rStrm ) override;
85 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
87 private:
88 ScRangeList maMergedRanges; /// All merged cell ranges of the sheet.
89 ScfUInt32Vec maBaseXFIds; /// The XF identifiers of the top-left cells.
92 // Hyperlinks =================================================================
94 class SvxURLField;
96 /** Provides export of hyperlink data. */
97 class XclExpHyperlink : public XclExpRecord
99 public:
100 /** Constructs the HLINK record from a URL text field. */
101 explicit XclExpHyperlink( const XclExpRoot& rRoot,
102 const SvxURLField& rUrlField, const ScAddress& rScPos );
103 virtual ~XclExpHyperlink() override;
105 /** Returns the cell representation text or 0, if not available. */
106 const OUString* GetRepr() const { return m_Repr.isEmpty() ? nullptr : &m_Repr; }
108 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
110 void WriteEmbeddedData( XclExpStream& rStrm );
112 /** Builds file name from the passed file URL. Tries to convert to relative file name.
113 @param rnLevel (out-param) The parent directory level.
114 @param rbRel (out-param) true = path is relative.
115 @param bEncoded if true return an IURI encoded name, not a DOS name. */
116 static OUString BuildFileName(
117 sal_uInt16& rnLevel, bool& rbRel,
118 const OUString& rUrl, const XclExpRoot& rRoot, bool bEncoded );
119 private:
121 /** Writes the body of the HLINK record. */
122 virtual void WriteBody( XclExpStream& rStrm ) override;
124 private:
125 typedef std::unique_ptr< SvStream > SvStreamPtr;
127 ScAddress maScPos; /// Position of the hyperlink.
128 OUString m_Repr; /// Cell representation text.
129 SvStreamPtr mxVarData; /// Buffer stream with variable data.
130 sal_uInt32 mnFlags; /// Option flags.
131 XclExpStringRef mxTextMark; /// Location within m_Repr
132 OUString msTarget; /// Target URL
135 typedef XclExpRecordList< XclExpHyperlink > XclExpHyperlinkList;
137 // Label ranges ===============================================================
139 /** Provides export of the row/column label range list of a sheet. */
140 class XclExpLabelranges : public XclExpRecordBase, protected XclExpRoot
142 public:
143 /** Fills the cell range lists with all ranges of the current sheet. */
144 explicit XclExpLabelranges( const XclExpRoot& rRoot );
146 /** Writes the LABELRANGES record if it contains at least one range. */
147 virtual void Save( XclExpStream& rStrm ) override;
149 private:
150 /** Fills the specified range list with all label headers of the current sheet.
151 @param rRanges The cell range list to fill.
152 @param xLabelRangesRef The core range list with all ranges.
153 @param nScTab The current Calc sheet index. */
154 static void FillRangeList( ScRangeList& rScRanges,
155 const ScRangePairListRef& xLabelRangesRef, SCTAB nScTab );
157 private:
158 ScRangeList maRowRanges; /// Cell range list for row labels.
159 ScRangeList maColRanges; /// Cell range list for column labels.
162 // Conditional formatting =====================================================
164 class XclExpCFImpl;
166 /** Represents a CF record that contains one condition of a conditional format. */
167 class XclExpCF : public XclExpRecord, protected XclExpRoot
169 public:
170 explicit XclExpCF( const XclExpRoot& rRoot, const ScCondFormatEntry& rFormatEntry, sal_Int32 nPriority, ScAddress aOrigin );
171 virtual ~XclExpCF() override;
173 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
175 private:
176 /** Writes the body of the CF record. */
177 virtual void WriteBody( XclExpStream& rStrm ) override;
179 private:
180 typedef std::unique_ptr< XclExpCFImpl > XclExpCFImplPtr;
181 XclExpCFImplPtr mxImpl;
184 class XclExpDateFormat : public XclExpRecord, protected XclExpRoot
186 public:
187 explicit XclExpDateFormat( const XclExpRoot& rRoot, const ScCondDateFormatEntry& rFormatEntry, sal_Int32 nPriority );
188 virtual ~XclExpDateFormat() override;
190 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
192 private:
193 const ScCondDateFormatEntry& mrFormatEntry;
194 sal_Int32 mnPriority;
197 class XclExpCfvo : public XclExpRecord, protected XclExpRoot
199 public:
200 explicit XclExpCfvo( const XclExpRoot& rRoot, const ScColorScaleEntry& rFormatEntry, const ScAddress& rPos, bool bFirst = true);
202 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
203 private:
204 const ScColorScaleEntry& mrEntry;
205 ScAddress maSrcPos;
206 bool mbFirst;
209 class XclExpColScaleCol : public XclExpRecord, protected XclExpRoot
211 public:
212 explicit XclExpColScaleCol( const XclExpRoot& rRoot, const Color& rColor);
213 virtual ~XclExpColScaleCol() override;
215 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
216 private:
217 const Color& mrColor;
220 /** Represents a CONDFMT record that contains all conditions of a conditional format.
221 @descr Contains the conditions which are stored in CF records. */
222 class XclExpCondfmt : public XclExpRecord, protected XclExpRoot
224 public:
225 explicit XclExpCondfmt( const XclExpRoot& rRoot, const ScConditionalFormat& rCondFormat, const XclExtLstRef& xExtLst, sal_Int32& rIndex );
226 virtual ~XclExpCondfmt() override;
228 /** Returns true, if this conditional format contains at least one cell range and CF record. */
229 bool IsValidForBinary() const;
230 bool IsValidForXml() const;
232 /** Writes the CONDFMT record with following CF records, if there is valid data. */
233 virtual void Save( XclExpStream& rStrm ) override;
234 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
236 private:
237 /** Writes the body of the CONDFMT record. */
238 virtual void WriteBody( XclExpStream& rStrm ) override;
240 private:
241 XclExpRecordList< XclExpRecord >
242 maCFList; /// List of CF records.
243 XclRangeList maXclRanges; /// Cell ranges for this conditional format.
244 OUString msSeqRef; /// OOXML Sequence of References
247 class XclExpColorScale: public XclExpRecord, protected XclExpRoot
249 public:
250 explicit XclExpColorScale( const XclExpRoot& rRoot, const ScColorScaleFormat& rFormat, sal_Int32 nPriority );
252 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
253 private:
254 typedef XclExpRecordList< XclExpCfvo > XclExpCfvoList;
255 typedef XclExpRecordList< XclExpColScaleCol > XclExpColScaleColList;
257 XclExpCfvoList maCfvoList;
258 XclExpColScaleColList maColList;
259 sal_Int32 mnPriority;
262 class XclExpDataBar : public XclExpRecord, protected XclExpRoot
264 public:
265 explicit XclExpDataBar( const XclExpRoot& rRoot, const ScDataBarFormat& rFormat, sal_Int32 nPriority, OString aGUID);
267 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
268 private:
269 std::unique_ptr<XclExpCfvo> mpCfvoLowerLimit;
270 std::unique_ptr<XclExpCfvo> mpCfvoUpperLimit;
271 std::unique_ptr<XclExpColScaleCol> mpCol;
273 const ScDataBarFormat& mrFormat;
274 sal_Int32 mnPriority;
275 OString maGUID;
278 class XclExpIconSet : public XclExpRecord, protected XclExpRoot
280 public:
281 explicit XclExpIconSet( const XclExpRoot& rRoot, const ScIconSetFormat& rFormat, sal_Int32 nPriority );
283 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
284 private:
285 typedef XclExpRecordList< XclExpCfvo > XclExpCfvoList;
287 XclExpCfvoList maCfvoList;
288 const ScIconSetFormat& mrFormat;
289 sal_Int32 mnPriority;
292 /** Contains all conditional formats of a specific sheet. */
293 class XclExpCondFormatBuffer : public XclExpRecordBase, protected XclExpRoot
295 public:
296 /** Constructs CONDFMT and CF records containing the conditional formats of the current sheet. */
297 explicit XclExpCondFormatBuffer( const XclExpRoot& rRoot, const XclExtLstRef& xExtLst );
299 /** Writes all contained CONDFMT records with their CF records. */
300 virtual void Save( XclExpStream& rStrm ) override;
301 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
303 private:
304 typedef XclExpRecordList< XclExpCondfmt > XclExpCondfmtList;
305 XclExpCondfmtList maCondfmtList; /// List of CONDFMT records.
308 // Data Validation ============================================================
310 /** Provides export of the data of a DV record.
311 @descr This record contains the settings for a data validation. In detail
312 this is a pointer to the core validation data and a cell range list with all
313 affected cells. The handle index is used to optimize list search algorithm. */
314 class XclExpDV : public XclExpRecord, protected XclExpRoot
316 public:
317 explicit XclExpDV( const XclExpRoot& rRoot, sal_uInt32 nScHandle );
318 virtual ~XclExpDV() override;
320 /** Returns the core handle of the validation data. */
321 sal_uInt32 GetScHandle() const { return mnScHandle; }
323 /** Inserts a new cell range into the cell range list. */
324 void InsertCellRange( const ScRange& rPos );
325 /** Converts the Calc range list to the Excel range list.
326 @return false = Resulting range list empty - do not write this record. */
327 bool Finalize();
329 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
331 private:
332 /** Writes the body of the DV record. */
333 virtual void WriteBody( XclExpStream& rStrm ) override;
335 private:
336 ScRangeList maScRanges; /// Calc range list with all affected cells.
337 XclRangeList maXclRanges; /// Excel range list with all affected cells.
338 XclExpString maPromptTitle; /// The prompt title.
339 XclExpString maPromptText; /// The prompt text.
340 XclExpString maErrorTitle; /// The error title.
341 XclExpString maErrorText; /// The error text.
342 XclExpStringRef mxString1; /// String for first condition formula.
343 XclTokenArrayRef mxTokArr1; /// Formula for first condition.
344 OUString msFormula1; /// OOXML Formula for first condition.
345 OUString msList; /// x12ac:list for first condition.
346 XclTokenArrayRef mxTokArr2; /// Formula for second condition.
347 OUString msFormula2; /// OOXML Formula for second condition.
348 sal_uInt32 mnFlags; /// Miscellaneous flags.
349 sal_uInt32 mnScHandle; /// The core handle for quick list search.
352 /** This class contains the DV record list following the DVAL record. */
353 class XclExpDval : public XclExpRecord, protected XclExpRoot
355 public:
356 explicit XclExpDval( const XclExpRoot& rRoot );
357 virtual ~XclExpDval() override;
359 /** Inserts the cell range into the range list of the DV record with the specified handle. */
360 void InsertCellRange( const ScRange& rRange, sal_uInt32 nScHandle );
362 /** Writes the DVAL record and the DV record list. */
363 virtual void Save( XclExpStream& rStrm ) override;
364 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
366 private:
367 /** Searches for or creates a XclExpDV record object with the specified handle. */
368 XclExpDV& SearchOrCreateDv( sal_uInt32 nScHandle );
370 /** Writes the body of the DVAL record. */
371 virtual void WriteBody( XclExpStream& rStrm ) override;
373 private:
374 typedef XclExpRecordList< XclExpDV > XclExpDVList;
375 typedef XclExpDVList::RecordRefType XclExpDVRef;
377 XclExpDVList maDVList; /// List of DV records
378 XclExpDVRef mxLastFoundDV; /// For search optimization.
381 // Web Queries ================================================================
383 /** Contains all records for a web query (linked tables in an HTML document).
384 @descr mode 1 (entire document): mpQryTables==0, mbEntireDoc==true;
385 mode 2 (all tables): mpQryTables==0, mbEntireDoc==false;
386 mode 3 (custom range list): mpQryTables!=0, mbEntireDoc==false. */
387 class XclExpWebQuery : public XclExpRecordBase
389 public:
390 /** Constructs a web query record container with settings from Calc. */
391 explicit XclExpWebQuery(
392 const OUString& rRangeName,
393 const OUString& rUrl,
394 std::u16string_view rSource,
395 sal_Int32 nRefrSecs );
396 virtual ~XclExpWebQuery() override;
398 /** Writes all needed records for this web query. */
399 virtual void Save( XclExpStream& rStrm ) override;
401 private:
402 XclExpString maDestRange; /// Destination range.
403 XclExpString maUrl; /// Source document URL.
404 XclExpStringRef mxQryTables; /// List of source range names.
405 sal_Int16 mnRefresh; /// Refresh time in minutes.
406 bool mbEntireDoc; /// true = entire document.
409 /** Contains all web query records for this document. */
410 class XclExpWebQueryBuffer : public XclExpRecordList< XclExpWebQuery >
412 public:
413 explicit XclExpWebQueryBuffer( const XclExpRoot& rRoot );
416 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */