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/sheet/XSpreadsheet.hpp>
24 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
25 #include <com/sun/star/table/CellRangeAddress.hpp>
26 #include <com/sun/star/table/CellAddress.hpp>
27 #include <com/sun/star/drawing/XShapes.hpp>
28 #include <com/sun/star/table/XCellRange.hpp>
30 #include "address.hxx"
32 namespace com
{ namespace sun
{ namespace star
{
33 namespace beans
{ class XPropertySet
; }
36 #include <boost/scoped_ptr.hpp>
37 #include <unordered_map>
40 class SvXMLExportPropertyMapper
;
41 class ScMyMergedRangesContainer
;
42 class ScMyValidationsContainer
;
43 class ScMyNotEmptyCellsIterator
;
44 class ScChangeTrackingExportHelper
;
47 class ScFormatRangeStyles
;
48 class ScRowFormatRanges
;
49 class ScMyOpenCloseColumnRowGroup
;
50 class ScMyAreaLinksContainer
;
51 class ScMyDetectiveOpContainer
;
55 class ScMyDefaultStyles
;
56 class XMLNumberFormatAttributesExportHelper
;
57 class ScChartListener
;
60 class ScXMLCachedRowAttrAccess
;
62 class ScXMLEditAttributeMap
;
68 class CompileFormulaContext
;
73 class ScXMLExport
: public SvXMLExport
76 com::sun::star::uno::Reference
<com::sun::star::sheet::XSpreadsheet
> xCurrentTable
;
77 com::sun::star::uno::Reference
<com::sun::star::table::XCellRange
> xCurrentTableCellRange
;
79 com::sun::star::uno::Reference
<com::sun::star::io::XInputStream
> xSourceStream
;
80 sal_Int32 nSourceStreamPos
;
82 mutable boost::scoped_ptr
<ScXMLEditAttributeMap
> mpEditAttrMap
;
83 boost::scoped_ptr
<ScMyNotEmptyCellsIterator
> mpCellsItr
;
84 boost::scoped_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 XMLNumberFormatAttributesExportHelper
* pNumberFormatAttributesExportHelper
;
95 typedef std::unordered_map
<sal_Int32
, sal_Int32
> NumberFormatIndexMap
;
96 NumberFormatIndexMap aNumFmtIndexMap
;
97 ScMySharedData
* pSharedData
;
98 ScColumnStyles
* pColumnStyles
;
99 ScRowStyles
* pRowStyles
;
100 ScFormatRangeStyles
* pCellStyles
;
101 ScRowFormatRanges
* pRowFormatRanges
;
102 std::vector
<OUString
> aTableStyles
;
103 com::sun::star::table::CellRangeAddress aRowHeaderRange
;
104 ScMyOpenCloseColumnRowGroup
* pGroupColumns
;
105 ScMyOpenCloseColumnRowGroup
* pGroupRows
;
106 ScMyDefaultStyles
* pDefaults
;
107 ScChartListener
* pChartListener
;
108 const ScMyCell
* pCurrentCell
;
110 ScMyMergedRangesContainer
* pMergedRangesContainer
;
111 ScMyValidationsContainer
* pValidationsContainer
;
112 ScChangeTrackingExportHelper
* pChangeTrackingExportHelper
;
113 const OUString sLayerID
;
114 const OUString sCaptionShape
;
115 OUString sExternalRefTabStyleName
;
117 OUString sAttrStyleName
;
118 OUString sAttrColumnsRepeated
;
119 OUString sAttrFormula
;
120 OUString sAttrValueType
;
121 OUString sAttrStringValue
;
123 OUString sElemCoveredCell
;
129 sal_Int32 nProgressCount
;
130 sal_uInt16 nCurrentTable
;
135 sal_Int32
GetNumberFormatStyleIndex(sal_Int32 nNumFmt
) const;
136 void CollectSharedData(sal_Int32
& nTableCount
, sal_Int32
& nShapesCount
);
137 void CollectShapesAutoStyles(const sal_Int32 nTableCount
);
138 void WriteTablesView(const com::sun::star::uno::Any
& aTableView
);
139 void WriteView(const com::sun::star::uno::Any
& aView
);
140 virtual void _ExportFontDecls() SAL_OVERRIDE
;
141 virtual void _ExportStyles( bool bUsed
) SAL_OVERRIDE
;
142 virtual void _ExportAutoStyles() SAL_OVERRIDE
;
143 virtual void _ExportMasterStyles() SAL_OVERRIDE
;
144 virtual void SetBodyAttributes() SAL_OVERRIDE
;
145 virtual void _ExportContent() SAL_OVERRIDE
;
146 virtual void _ExportMeta() SAL_OVERRIDE
;
148 void CollectInternalShape( ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
> xShape
);
150 static com::sun::star::table::CellRangeAddress
GetEndAddress(const com::sun::star::uno::Reference
<com::sun::star::sheet::XSpreadsheet
>& xTable
,
151 const sal_Int32 nTable
);
152 // ScMyEmptyDatabaseRangesContainer GetEmptyDatabaseRanges();
153 void GetAreaLinks( ScMyAreaLinksContainer
& rAreaLinks
);
154 void GetDetectiveOpList( ScMyDetectiveOpContainer
& rDetOp
);
155 void WriteSingleColumn(const sal_Int32 nRepeatColumns
, const sal_Int32 nStyleIndex
,
156 const sal_Int32 nIndex
, const bool bIsAutoStyle
, const bool bIsVisible
);
157 void WriteColumn(const sal_Int32 nColumn
, const sal_Int32 nRepeatColumns
,
158 const sal_Int32 nStyleIndex
, const bool bIsVisible
);
159 void OpenHeaderColumn();
160 void CloseHeaderColumn();
161 void ExportColumns(const sal_Int32 nTable
, const com::sun::star::table::CellRangeAddress
& aColumnHeaderRange
, const bool bHasColumnHeader
);
162 void ExportExternalRefCacheStyles();
163 void ExportCellTextAutoStyles(sal_Int32 nTable
);
164 void ExportFormatRanges(const sal_Int32 nStartCol
, const sal_Int32 nStartRow
,
165 const sal_Int32 nEndCol
, const sal_Int32 nEndRow
, const sal_Int32 nSheet
);
166 void WriteRowContent();
167 void WriteRowStartTag(const sal_Int32 nIndex
, const sal_Int32 nEmptyRows
, bool bHidden
, bool bFiltered
);
168 void OpenHeaderRows();
169 void CloseHeaderRows();
170 void OpenNewRow(const sal_Int32 nIndex
, const sal_Int32 nStartRow
, const sal_Int32 nEmptyRows
,
171 bool bHidden
, bool bFiltered
);
172 void OpenAndCloseRow(const sal_Int32 nIndex
, const sal_Int32 nStartRow
, const sal_Int32 nEmptyRows
,
173 bool bHidden
, bool bFiltered
);
174 void OpenRow(const sal_Int32 nTable
, const sal_Int32 nStartRow
, const sal_Int32 nRepeatRow
, ScXMLCachedRowAttrAccess
& rRowAttr
);
175 void CloseRow(const sal_Int32 nRow
);
176 void GetColumnRowHeader(bool& bHasColumnHeader
, com::sun::star::table::CellRangeAddress
& aColumnHeaderRange
,
177 bool& bHasRowHeader
, com::sun::star::table::CellRangeAddress
& aRowHeaderRange
,
178 OUString
& rPrintRanges
) const;
179 static void FillFieldGroup(ScOutlineArray
* pFields
, ScMyOpenCloseColumnRowGroup
* pGroups
);
180 void FillColumnRowGroups();
182 bool GetMerged (const com::sun::star::table::CellRangeAddress
* pCellRange
,
183 const com::sun::star::uno::Reference
<com::sun::star::sheet::XSpreadsheet
>& xTable
);
185 void WriteTable(sal_Int32 nTable
, const ::com::sun::star::uno::Reference
< ::com::sun::star::sheet::XSpreadsheet
>& xTable
);
186 void WriteCell(ScMyCell
& aCell
, sal_Int32 nEqualCellCount
);
187 void WriteEditCell(const EditTextObject
* pText
);
188 void WriteMultiLineFormulaResult(const ScFormulaCell
* pCell
);
189 void WriteAreaLink(const ScMyCell
& rMyCell
);
190 void WriteAnnotation(ScMyCell
& rMyCell
);
191 void WriteDetective(const ScMyCell
& rMyCell
);
192 void ExportShape(const com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
>& xShape
, com::sun::star::awt::Point
* pPoint
);
193 void WriteShapes(const ScMyCell
& rMyCell
);
194 void WriteTableShapes();
195 void SetRepeatAttribute(sal_Int32 nEqualCellCount
, bool bIncProgress
);
197 static bool IsCellTypeEqual (const ScMyCell
& aCell1
, const ScMyCell
& aCell2
);
198 static bool IsEditCell(ScMyCell
& rCell
);
199 bool IsCellEqual(ScMyCell
& aCell1
, ScMyCell
& aCell2
);
201 void WriteCalculationSettings(const com::sun::star::uno::Reference
<com::sun::star::sheet::XSpreadsheetDocument
>& xSpreadDoc
);
202 void WriteTableSource();
203 void WriteScenario(); // core implementation
204 void WriteTheLabelRanges(const com::sun::star::uno::Reference
< com::sun::star::sheet::XSpreadsheetDocument
>& xSpreadDoc
);
205 void WriteLabelRanges( const com::sun::star::uno::Reference
< com::sun::star::container::XIndexAccess
>& xRangesIAccess
, bool bColumn
);
206 void WriteNamedExpressions();
207 void WriteDataStream();
208 void WriteNamedRange(ScRangeName
* pRangeName
);
209 void ExportConditionalFormat(SCTAB nTab
);
210 void WriteExternalRefCaches();
211 void WriteConsolidation(); // core implementation
213 void CollectUserDefinedNamespaces(const SfxItemPool
* pPool
, sal_uInt16 nAttrib
);
215 void AddStyleFromCells(
216 const com::sun::star::uno::Reference
< com::sun::star::beans::XPropertySet
>& xProperties
,
217 const com::sun::star::uno::Reference
< com::sun::star::sheet::XSpreadsheet
>& xTable
,
218 sal_Int32 nTable
, const OUString
* pOldName
);
219 void AddStyleFromColumn(
220 const com::sun::star::uno::Reference
< com::sun::star::beans::XPropertySet
>& xColumnProperties
,
221 const OUString
* pOldName
, sal_Int32
& rIndex
, bool& rIsVisible
);
222 void AddStyleFromRow(
223 const com::sun::star::uno::Reference
< com::sun::star::beans::XPropertySet
>& xRowProperties
,
224 const OUString
* pOldName
, sal_Int32
& rIndex
);
226 void IncrementProgressBar(bool bFlush
, sal_Int32 nInc
= 1);
228 void CopySourceStream( sal_Int32 nStartOffset
, sal_Int32 nEndOffset
, sal_Int32
& rNewStart
, sal_Int32
& rNewEnd
);
230 const ScXMLEditAttributeMap
& GetEditAttributeMap() const;
233 virtual SvXMLAutoStylePoolP
* CreateAutoStylePool() SAL_OVERRIDE
;
234 virtual XMLPageExport
* CreatePageExport() SAL_OVERRIDE
;
235 virtual XMLShapeExport
* CreateShapeExport() SAL_OVERRIDE
;
236 virtual XMLFontAutoStylePool
* CreateFontAutoStylePool() SAL_OVERRIDE
;
239 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rContext
,
240 OUString
const & implementationName
, SvXMLExportFlags nExportFlag
);
242 virtual ~ScXMLExport();
244 static sal_Int16
GetMeasureUnit();
245 inline ScDocument
* GetDocument() { return pDoc
; }
246 inline const ScDocument
* GetDocument() const { return pDoc
; }
247 bool IsMatrix (const ScAddress
& aCell
,
248 com::sun::star::table::CellRangeAddress
& aCellAddress
, bool& bIsFirst
) const;
250 rtl::Reference
< XMLPropertySetMapper
> GetCellStylesPropertySetMapper() { return xCellStylesPropertySetMapper
; }
251 rtl::Reference
< XMLPropertySetMapper
> GetTableStylesPropertySetMapper() { return xTableStylesPropertySetMapper
; }
253 void SetSourceStream( const com::sun::star::uno::Reference
<com::sun::star::io::XInputStream
>& xNewStream
);
255 void GetChangeTrackViewSettings(com::sun::star::uno::Sequence
<com::sun::star::beans::PropertyValue
>& rProps
);
256 virtual void GetViewSettings(com::sun::star::uno::Sequence
<com::sun::star::beans::PropertyValue
>& rProps
) SAL_OVERRIDE
;
257 virtual void GetConfigurationSettings(com::sun::star::uno::Sequence
<com::sun::star::beans::PropertyValue
>& rProps
) SAL_OVERRIDE
;
259 virtual void exportAnnotationMeta( const com::sun::star::uno::Reference
< com::sun::star::drawing::XShape
>& xShape
) SAL_OVERRIDE
;
261 void CreateSharedData(const sal_Int32 nTableCount
);
262 void SetSharedData(ScMySharedData
* pTemp
) { pSharedData
= pTemp
; }
263 ScMySharedData
* GetSharedData() { return pSharedData
; }
264 XMLNumberFormatAttributesExportHelper
* GetNumberFormatAttributesExportHelper();
266 // Export the document.
267 virtual sal_uInt32
exportDoc( enum ::xmloff::token::XMLTokenEnum eClass
= ::xmloff::token::XML_TOKEN_INVALID
) SAL_OVERRIDE
;
270 virtual void SAL_CALL
setSourceDocument( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XComponent
>& xDoc
) throw(::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
273 virtual sal_Bool SAL_CALL
filter( const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& aDescriptor
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
274 virtual void SAL_CALL
cancel() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
277 virtual void SAL_CALL
initialize( const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>& aArguments
) throw(::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
280 virtual sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
< sal_Int8
>& aIdentifier
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
282 virtual void DisposingModel() SAL_OVERRIDE
;
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */