1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef INCLUDED_SC_SOURCE_FILTER_XML_XMLEXPRT_HXX
20 #define INCLUDED_SC_SOURCE_FILTER_XML_XMLEXPRT_HXX
22 #include <xmloff/xmlexp.hxx>
23 #include <com/sun/star/table/CellRangeAddress.hpp>
24 #include <com/sun/star/io/XInputStream.hpp>
26 #include <address.hxx>
29 #include <unordered_map>
32 namespace com
{ namespace sun
{ namespace star
{
33 namespace beans
{ class XPropertySet
; }
36 namespace com
{ namespace sun
{ namespace star
{ namespace table
{ class XCellRange
; } } } }
37 namespace com
{ namespace sun
{ namespace star
{ namespace sheet
{ class XSpreadsheet
; } } } }
38 namespace com
{ namespace sun
{ namespace star
{ namespace sheet
{ class XSpreadsheetDocument
; } } } }
40 namespace sc
{ class DataTransformation
; }
43 class SvXMLExportPropertyMapper
;
44 class ScMyMergedRangesContainer
;
45 class ScMyValidationsContainer
;
46 class ScMyNotEmptyCellsIterator
;
47 class ScChangeTrackingExportHelper
;
50 class ScFormatRangeStyles
;
51 class ScRowFormatRanges
;
52 class ScMyOpenCloseColumnRowGroup
;
53 class ScMyAreaLinksContainer
;
54 class ScMyDetectiveOpContainer
;
58 class ScMyDefaultStyles
;
59 class XMLNumberFormatAttributesExportHelper
;
61 class ScXMLCachedRowAttrAccess
;
63 class ScXMLEditAttributeMap
;
69 class CompileFormulaContext
;
74 class ScXMLExport
: public SvXMLExport
77 css::uno::Reference
<css::sheet::XSpreadsheet
> xCurrentTable
;
79 css::uno::Reference
<css::io::XInputStream
> xSourceStream
;
80 sal_Int32 nSourceStreamPos
;
82 mutable std::unique_ptr
<ScXMLEditAttributeMap
> mpEditAttrMap
;
83 std::unique_ptr
<ScMyNotEmptyCellsIterator
> mpCellsItr
;
84 std::unique_ptr
<sc::CompileFormulaContext
> mpCompileFormulaCxt
;
85 rtl::Reference
< XMLPropertyHandlerFactory
> xScPropHdlFactory
;
86 rtl::Reference
< XMLPropertySetMapper
> xCellStylesPropertySetMapper
;
87 rtl::Reference
< XMLPropertySetMapper
> xColumnStylesPropertySetMapper
;
88 rtl::Reference
< XMLPropertySetMapper
> xRowStylesPropertySetMapper
;
89 rtl::Reference
< XMLPropertySetMapper
> xTableStylesPropertySetMapper
;
90 rtl::Reference
< SvXMLExportPropertyMapper
> xCellStylesExportPropertySetMapper
;
91 rtl::Reference
< SvXMLExportPropertyMapper
> xColumnStylesExportPropertySetMapper
;
92 rtl::Reference
< SvXMLExportPropertyMapper
> xRowStylesExportPropertySetMapper
;
93 rtl::Reference
< SvXMLExportPropertyMapper
> xTableStylesExportPropertySetMapper
;
94 std::unique_ptr
<XMLNumberFormatAttributesExportHelper
> pNumberFormatAttributesExportHelper
;
95 typedef std::unordered_map
<sal_Int32
, sal_Int32
> NumberFormatIndexMap
;
96 NumberFormatIndexMap aNumFmtIndexMap
;
97 std::unique_ptr
<ScMySharedData
> pSharedData
;
98 std::unique_ptr
<ScColumnStyles
> pColumnStyles
;
99 std::unique_ptr
<ScRowStyles
> pRowStyles
;
100 std::unique_ptr
<ScFormatRangeStyles
> pCellStyles
;
101 std::unique_ptr
<ScRowFormatRanges
> pRowFormatRanges
;
102 std::vector
<OUString
> aTableStyles
;
103 ScRange aRowHeaderRange
;
104 std::unique_ptr
<ScMyOpenCloseColumnRowGroup
> pGroupColumns
;
105 std::unique_ptr
<ScMyOpenCloseColumnRowGroup
> pGroupRows
;
106 std::unique_ptr
<ScMyDefaultStyles
> pDefaults
;
107 const ScMyCell
* pCurrentCell
;
109 std::unique_ptr
<ScMyMergedRangesContainer
> pMergedRangesContainer
;
110 std::unique_ptr
<ScMyValidationsContainer
> pValidationsContainer
;
111 std::unique_ptr
<ScChangeTrackingExportHelper
> pChangeTrackingExportHelper
;
112 OUString sExternalRefTabStyleName
;
114 OUString sAttrStyleName
;
115 OUString sAttrColumnsRepeated
;
116 OUString sAttrFormula
;
117 OUString sAttrValueType
;
118 OUString sAttrStringValue
;
120 OUString sElemCoveredCell
;
126 sal_Int32 nProgressCount
;
127 sal_uInt16 nCurrentTable
;
131 sal_Int32
GetNumberFormatStyleIndex(sal_Int32 nNumFmt
) const;
132 void CollectSharedData(SCTAB
& nTableCount
, sal_Int32
& nShapesCount
);
133 void CollectShapesAutoStyles(SCTAB nTableCount
);
134 void RegisterDefinedStyleNames( const css::uno::Reference
< css::sheet::XSpreadsheetDocument
> & xSpreadDoc
);
135 virtual void ExportFontDecls_() override
;
136 virtual void ExportStyles_( bool bUsed
) override
;
137 virtual void ExportAutoStyles_() override
;
138 virtual void ExportMasterStyles_() override
;
139 virtual void SetBodyAttributes() override
;
140 virtual void ExportContent_() override
;
141 virtual void ExportMeta_() override
;
143 void CollectInternalShape( css::uno::Reference
< css::drawing::XShape
> const & xShape
);
145 static css::table::CellRangeAddress
GetEndAddress(const css::uno::Reference
<css::sheet::XSpreadsheet
>& xTable
);
146 void GetAreaLinks( ScMyAreaLinksContainer
& rAreaLinks
);
147 void GetDetectiveOpList( ScMyDetectiveOpContainer
& rDetOp
);
148 void WriteSingleColumn(const sal_Int32 nRepeatColumns
, const sal_Int32 nStyleIndex
,
149 const sal_Int32 nIndex
, const bool bIsAutoStyle
, const bool bIsVisible
);
150 void WriteColumn(const sal_Int32 nColumn
, const sal_Int32 nRepeatColumns
,
151 const sal_Int32 nStyleIndex
, const bool bIsVisible
);
152 void OpenHeaderColumn();
153 void CloseHeaderColumn();
154 void ExportColumns(const sal_Int32 nTable
, const ScRange
& aColumnHeaderRange
, const bool bHasColumnHeader
);
155 void ExportExternalRefCacheStyles();
156 void ExportCellTextAutoStyles(sal_Int32 nTable
);
157 void ExportFormatRanges(const sal_Int32 nStartCol
, const sal_Int32 nStartRow
,
158 const sal_Int32 nEndCol
, const sal_Int32 nEndRow
, const sal_Int32 nSheet
);
159 void WriteRowContent();
160 void WriteRowStartTag(const sal_Int32 nIndex
, const sal_Int32 nEmptyRows
, bool bHidden
, bool bFiltered
);
161 void OpenHeaderRows();
162 void CloseHeaderRows();
163 void OpenNewRow(const sal_Int32 nIndex
, const sal_Int32 nStartRow
, const sal_Int32 nEmptyRows
,
164 bool bHidden
, bool bFiltered
);
165 void OpenAndCloseRow(const sal_Int32 nIndex
, const sal_Int32 nStartRow
, const sal_Int32 nEmptyRows
,
166 bool bHidden
, bool bFiltered
);
167 void OpenRow(const sal_Int32 nTable
, const sal_Int32 nStartRow
, const sal_Int32 nRepeatRow
, ScXMLCachedRowAttrAccess
& rRowAttr
);
168 void CloseRow(const sal_Int32 nRow
);
169 void GetColumnRowHeader(bool& bHasColumnHeader
, ScRange
& aColumnHeaderRange
,
170 bool& bHasRowHeader
, ScRange
& aRowHeaderRange
, OUString
& rPrintRanges
) const;
171 static void FillFieldGroup(ScOutlineArray
* pFields
, ScMyOpenCloseColumnRowGroup
* pGroups
);
172 void FillColumnRowGroups();
174 bool GetMerged (const css::table::CellRangeAddress
* pCellRange
,
175 const css::uno::Reference
<css::sheet::XSpreadsheet
>& xTable
);
177 void WriteTable(sal_Int32 nTable
, const css::uno::Reference
< css::sheet::XSpreadsheet
>& xTable
);
178 void WriteCell(ScMyCell
& aCell
, sal_Int32 nEqualCellCount
);
179 void WriteEditCell(const EditTextObject
* pText
);
180 void WriteMultiLineFormulaResult(const ScFormulaCell
* pCell
);
181 void WriteAreaLink(const ScMyCell
& rMyCell
);
182 void WriteAnnotation(ScMyCell
& rMyCell
);
183 void WriteDetective(const ScMyCell
& rMyCell
);
184 void ExportShape(const css::uno::Reference
< css::drawing::XShape
>& xShape
, css::awt::Point
* pPoint
);
185 void WriteShapes(const ScMyCell
& rMyCell
);
186 void WriteTableShapes();
187 void SetRepeatAttribute(sal_Int32 nEqualCellCount
, bool bIncProgress
);
189 static bool IsEditCell(const ScMyCell
& rCell
);
190 bool IsCellEqual(const ScMyCell
& aCell1
, const ScMyCell
& aCell2
);
192 void WriteCalculationSettings(const css::uno::Reference
<css::sheet::XSpreadsheetDocument
>& xSpreadDoc
);
193 void WriteTableSource();
194 void WriteScenario(); // core implementation
195 void WriteTheLabelRanges(const css::uno::Reference
< css::sheet::XSpreadsheetDocument
>& xSpreadDoc
);
196 void WriteLabelRanges( const css::uno::Reference
< css::container::XIndexAccess
>& xRangesIAccess
, bool bColumn
);
197 void WriteNamedExpressions();
198 void WriteExternalDataMapping();
199 void WriteExternalDataTransformations(const std::vector
<std::shared_ptr
<sc::DataTransformation
>>& aDataTransformations
);
200 void WriteDataStream();
201 void WriteNamedRange(ScRangeName
* pRangeName
);
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;
226 virtual SvXMLAutoStylePoolP
* CreateAutoStylePool() override
;
227 virtual XMLPageExport
* CreatePageExport() override
;
228 virtual XMLShapeExport
* CreateShapeExport() override
;
229 virtual XMLFontAutoStylePool
* CreateFontAutoStylePool() override
;
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
;
265 virtual void SAL_CALL
setSourceDocument( const css::uno::Reference
< css::lang::XComponent
>& xDoc
) override
;
268 virtual sal_Bool SAL_CALL
filter( const css::uno::Sequence
< css::beans::PropertyValue
>& aDescriptor
) override
;
269 virtual void SAL_CALL
cancel() override
;
272 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
275 virtual sal_Int64 SAL_CALL
getSomething( const css::uno::Sequence
< sal_Int8
>& aIdentifier
) override
;
277 virtual void DisposingModel() override
;
282 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */