Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / sc / source / filter / xml / xmlexprt.hxx
blob8ab8901d4671286de1cdf675315fc2fb96c4f4cb
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 .
19 #pragma once
21 #include <xmloff/xmlexp.hxx>
22 #include <com/sun/star/table/CellRangeAddress.hpp>
23 #include <com/sun/star/io/XInputStream.hpp>
25 #include <address.hxx>
27 #include <memory>
28 #include <unordered_map>
31 namespace com::sun::star {
32 namespace beans { class XPropertySet; }
35 namespace com::sun::star::table { class XCellRange; }
36 namespace com::sun::star::sheet { class XSpreadsheet; }
37 namespace com::sun::star::sheet { class XSpreadsheetDocument; }
39 namespace sc { class DataTransformation; }
41 class ScOutlineArray;
42 class SvXMLExportPropertyMapper;
43 class ScMyMergedRangesContainer;
44 class ScMyValidationsContainer;
45 class ScMyNotEmptyCellsIterator;
46 class ScChangeTrackingExportHelper;
47 class ScColumnStyles;
48 class ScRowStyles;
49 class ScFormatRangeStyles;
50 class ScRowFormatRanges;
51 class ScMyOpenCloseColumnRowGroup;
52 class ScMyAreaLinksContainer;
53 class ScMyDetectiveOpContainer;
54 struct ScMyCell;
55 class ScDocument;
56 class ScMySharedData;
57 class ScMyDefaultStyles;
58 class XMLNumberFormatAttributesExportHelper;
59 class SfxItemPool;
60 class ScXMLCachedRowAttrAccess;
61 class ScRangeName;
62 class ScXMLEditAttributeMap;
63 class EditTextObject;
64 class ScFormulaCell;
66 namespace sc {
68 class CompileFormulaContext;
73 class ScXMLExport : public SvXMLExport
75 ScDocument* pDoc;
76 css::uno::Reference <css::sheet::XSpreadsheet> xCurrentTable;
78 css::uno::Reference<css::io::XInputStream> xSourceStream;
79 sal_Int32 nSourceStreamPos;
81 mutable std::unique_ptr<ScXMLEditAttributeMap> mpEditAttrMap;
82 std::unique_ptr<ScMyNotEmptyCellsIterator> mpCellsItr;
83 std::unique_ptr<sc::CompileFormulaContext> mpCompileFormulaCxt;
84 rtl::Reference < XMLPropertyHandlerFactory > xScPropHdlFactory;
85 rtl::Reference < XMLPropertySetMapper > xCellStylesPropertySetMapper;
86 rtl::Reference < XMLPropertySetMapper > xColumnStylesPropertySetMapper;
87 rtl::Reference < XMLPropertySetMapper > xRowStylesPropertySetMapper;
88 rtl::Reference < XMLPropertySetMapper > xTableStylesPropertySetMapper;
89 rtl::Reference < SvXMLExportPropertyMapper > xCellStylesExportPropertySetMapper;
90 rtl::Reference < SvXMLExportPropertyMapper > xColumnStylesExportPropertySetMapper;
91 rtl::Reference < SvXMLExportPropertyMapper > xRowStylesExportPropertySetMapper;
92 rtl::Reference < SvXMLExportPropertyMapper > xTableStylesExportPropertySetMapper;
93 std::unique_ptr<XMLNumberFormatAttributesExportHelper> pNumberFormatAttributesExportHelper;
94 typedef std::unordered_map<sal_Int32, sal_Int32> NumberFormatIndexMap;
95 NumberFormatIndexMap aNumFmtIndexMap;
96 std::unique_ptr<ScMySharedData> pSharedData;
97 std::unique_ptr<ScColumnStyles> pColumnStyles;
98 std::unique_ptr<ScRowStyles> pRowStyles;
99 std::unique_ptr<ScFormatRangeStyles> pCellStyles;
100 std::unique_ptr<ScRowFormatRanges> pRowFormatRanges;
101 std::vector<OUString> aTableStyles;
102 ScRange aRowHeaderRange;
103 std::unique_ptr<ScMyOpenCloseColumnRowGroup> pGroupColumns;
104 std::unique_ptr<ScMyOpenCloseColumnRowGroup> pGroupRows;
105 std::unique_ptr<ScMyDefaultStyles> pDefaults;
106 const ScMyCell* pCurrentCell;
108 std::unique_ptr<ScMyMergedRangesContainer> pMergedRangesContainer;
109 std::unique_ptr<ScMyValidationsContainer> pValidationsContainer;
110 std::unique_ptr<ScChangeTrackingExportHelper> pChangeTrackingExportHelper;
111 OUString sExternalRefTabStyleName;
112 OUString sAttrName;
113 OUString sAttrStyleName;
114 OUString sAttrColumnsRepeated;
115 OUString sAttrFormula;
116 OUString sAttrValueType;
117 OUString sAttrStringValue;
118 OUString sElemCell;
119 OUString sElemCoveredCell;
120 OUString sElemCol;
121 OUString sElemRow;
122 OUString sElemTab;
123 OUString sElemP;
124 sal_Int32 nOpenRow;
125 sal_Int32 nProgressCount;
126 sal_uInt16 nCurrentTable;
127 bool bHasRowHeader;
128 bool bRowHeaderOpen;
130 sal_Int32 GetNumberFormatStyleIndex(sal_Int32 nNumFmt) const;
131 void CollectSharedData(SCTAB& nTableCount, sal_Int32& nShapesCount);
132 void CollectShapesAutoStyles(SCTAB nTableCount);
133 void RegisterDefinedStyleNames( const css::uno::Reference< css::sheet::XSpreadsheetDocument > & xSpreadDoc );
134 virtual void ExportFontDecls_() override;
135 virtual void ExportStyles_( bool bUsed ) override;
136 virtual void ExportAutoStyles_() override;
137 virtual void ExportMasterStyles_() override;
138 virtual void SetBodyAttributes() override;
139 virtual void ExportContent_() override;
140 virtual void ExportMeta_() override;
142 void CollectInternalShape( css::uno::Reference< css::drawing::XShape > const & xShape );
144 static css::table::CellRangeAddress GetEndAddress(const css::uno::Reference<css::sheet::XSpreadsheet>& xTable);
145 void GetAreaLinks( ScMyAreaLinksContainer& rAreaLinks );
146 void GetDetectiveOpList( ScMyDetectiveOpContainer& rDetOp );
147 void WriteSingleColumn(const sal_Int32 nRepeatColumns, const sal_Int32 nStyleIndex,
148 const sal_Int32 nIndex, const bool bIsAutoStyle, const bool bIsVisible);
149 void WriteColumn(const sal_Int32 nColumn, const sal_Int32 nRepeatColumns,
150 const sal_Int32 nStyleIndex, const bool bIsVisible);
151 void OpenHeaderColumn();
152 void CloseHeaderColumn();
153 void ExportColumns(const sal_Int32 nTable, const ScRange& aColumnHeaderRange, const bool bHasColumnHeader);
154 void ExportExternalRefCacheStyles();
155 void ExportCellTextAutoStyles(sal_Int32 nTable);
156 void ExportFormatRanges(const sal_Int32 nStartCol, const sal_Int32 nStartRow,
157 const sal_Int32 nEndCol, const sal_Int32 nEndRow, const sal_Int32 nSheet);
158 void WriteRowContent();
159 void WriteRowStartTag(const sal_Int32 nIndex, const sal_Int32 nEmptyRows, bool bHidden, bool bFiltered);
160 void OpenHeaderRows();
161 void CloseHeaderRows();
162 void OpenNewRow(const sal_Int32 nIndex, const sal_Int32 nStartRow, const sal_Int32 nEmptyRows,
163 bool bHidden, bool bFiltered);
164 void OpenAndCloseRow(const sal_Int32 nIndex, const sal_Int32 nStartRow, const sal_Int32 nEmptyRows,
165 bool bHidden, bool bFiltered);
166 void OpenRow(const sal_Int32 nTable, const sal_Int32 nStartRow, const sal_Int32 nRepeatRow, ScXMLCachedRowAttrAccess& rRowAttr);
167 void CloseRow(const sal_Int32 nRow);
168 void GetColumnRowHeader(bool& bHasColumnHeader, ScRange& aColumnHeaderRange,
169 bool& bHasRowHeader, ScRange& aRowHeaderRange, OUString& rPrintRanges) const;
170 static void FillFieldGroup(ScOutlineArray* pFields, ScMyOpenCloseColumnRowGroup* pGroups);
171 void FillColumnRowGroups();
173 bool GetMerged (const css::table::CellRangeAddress* pCellRange,
174 const css::uno::Reference <css::sheet::XSpreadsheet>& xTable);
176 void WriteTable(sal_Int32 nTable, const css::uno::Reference< css::sheet::XSpreadsheet>& xTable);
177 void WriteCell(ScMyCell& aCell, sal_Int32 nEqualCellCount);
178 void WriteEditCell(const EditTextObject* pText);
179 void WriteMultiLineFormulaResult(const ScFormulaCell* pCell);
180 void WriteAreaLink(const ScMyCell& rMyCell);
181 void WriteAnnotation(const ScMyCell& rMyCell);
182 void WriteDetective(const ScMyCell& rMyCell);
183 void ExportShape(const css::uno::Reference < css::drawing::XShape >& xShape, css::awt::Point* pPoint);
184 void WriteShapes(const ScMyCell& rMyCell);
185 void WriteTableShapes();
186 void SetRepeatAttribute(sal_Int32 nEqualCellCount, bool bIncProgress);
188 static bool IsEditCell(const ScMyCell& rCell);
189 bool IsCellEqual(const ScMyCell& aCell1, const ScMyCell& aCell2);
191 void WriteCalculationSettings(const css::uno::Reference <css::sheet::XSpreadsheetDocument>& xSpreadDoc);
192 void WriteTableSource();
193 void WriteScenario(); // core implementation
194 void WriteTheLabelRanges(const css::uno::Reference< css::sheet::XSpreadsheetDocument >& xSpreadDoc);
195 void WriteLabelRanges( const css::uno::Reference< css::container::XIndexAccess >& xRangesIAccess, bool bColumn );
196 void WriteNamedExpressions();
197 void WriteExternalDataMapping();
198 void WriteExternalDataTransformations(const std::vector<std::shared_ptr<sc::DataTransformation>>& aDataTransformations);
199 void WriteDataStream();
200 void WriteNamedRange(ScRangeName* pRangeName);
201 void exportSparklineGroups(SCTAB nTab);
202 void ExportConditionalFormat(SCTAB nTab);
203 void WriteExternalRefCaches();
204 void WriteConsolidation(); // core implementation
206 void CollectUserDefinedNamespaces(const SfxItemPool* pPool, sal_uInt16 nAttrib);
208 void AddStyleFromCells(
209 const css::uno::Reference< css::beans::XPropertySet >& xProperties,
210 const css::uno::Reference< css::sheet::XSpreadsheet >& xTable,
211 sal_Int32 nTable, const OUString* pOldName );
212 void AddStyleFromColumn(
213 const css::uno::Reference< css::beans::XPropertySet >& xColumnProperties,
214 const OUString* pOldName, sal_Int32& rIndex, bool& rIsVisible );
215 void AddStyleFromRow(
216 const css::uno::Reference< css::beans::XPropertySet >& xRowProperties,
217 const OUString* pOldName, sal_Int32& rIndex );
219 void IncrementProgressBar(bool bFlush, sal_Int32 nInc = 1);
221 void CopySourceStream( sal_Int32 nStartOffset, sal_Int32 nEndOffset, sal_Int32& rNewStart, sal_Int32& rNewEnd );
223 const ScXMLEditAttributeMap& GetEditAttributeMap() const;
225 protected:
226 virtual SvXMLAutoStylePoolP* CreateAutoStylePool() override;
227 virtual XMLPageExport* CreatePageExport() override;
228 virtual XMLShapeExport* CreateShapeExport() override;
229 virtual XMLFontAutoStylePool* CreateFontAutoStylePool() override;
230 public:
231 ScXMLExport(
232 const css::uno::Reference< css::uno::XComponentContext >& rContext,
233 OUString const & implementationName, SvXMLExportFlags nExportFlag);
235 virtual ~ScXMLExport() override;
237 void collectAutoStyles() override;
239 static sal_Int16 GetMeasureUnit();
240 ScDocument* GetDocument() { return pDoc; }
241 const ScDocument* GetDocument() const { return pDoc; }
242 bool IsMatrix (const ScAddress& aCell,
243 ScRange& aCellAddress, bool& bIsFirst) const;
245 const rtl::Reference < XMLPropertySetMapper >& GetCellStylesPropertySetMapper() const { return xCellStylesPropertySetMapper; }
246 const rtl::Reference < XMLPropertySetMapper >& GetTableStylesPropertySetMapper() const { return xTableStylesPropertySetMapper; }
248 void SetSourceStream( const css::uno::Reference<css::io::XInputStream>& xNewStream );
250 void GetChangeTrackViewSettings(css::uno::Sequence<css::beans::PropertyValue>& rProps);
251 virtual void GetViewSettings(css::uno::Sequence<css::beans::PropertyValue>& rProps) override;
252 virtual void GetConfigurationSettings(css::uno::Sequence<css::beans::PropertyValue>& rProps) override;
254 virtual void exportAnnotationMeta( const css::uno::Reference < css::drawing::XShape >& xShape) override;
256 void SetSharedData(std::unique_ptr<ScMySharedData> pTemp);
257 ScMySharedData* GetSharedData() { return pSharedData.get(); }
258 std::unique_ptr<ScMySharedData> ReleaseSharedData();
259 XMLNumberFormatAttributesExportHelper* GetNumberFormatAttributesExportHelper();
261 // Export the document.
262 virtual ErrCode exportDoc( enum ::xmloff::token::XMLTokenEnum eClass = ::xmloff::token::XML_TOKEN_INVALID ) override;
264 // XExporter
265 virtual void SAL_CALL setSourceDocument( const css::uno::Reference< css::lang::XComponent >& xDoc ) override;
267 // XFilter
268 virtual sal_Bool SAL_CALL filter( const css::uno::Sequence< css::beans::PropertyValue >& aDescriptor ) override;
269 virtual void SAL_CALL cancel() override;
271 // XInitialization
272 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
274 // XUnoTunnel
275 virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override;
277 virtual void DisposingModel() override;
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */