xref: /AOO41X/main/sc/source/filter/xml/xmlexprt.hxx (revision dffa72ded5962569065f7bed47aa44fcb9f744f1)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef SC_XMLEXPRT_HXX
24 #define SC_XMLEXPRT_HXX
25 
26 #include <xmloff/xmlexp.hxx>
27 #include <com/sun/star/sheet/XSpreadsheet.hpp>
28 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
29 #include <com/sun/star/table/CellRangeAddress.hpp>
30 #include <com/sun/star/table/CellAddress.hpp>
31 #include <com/sun/star/drawing/XShapes.hpp>
32 #include <com/sun/star/table/XCellRange.hpp>
33 
34 namespace com { namespace sun { namespace star {
35     namespace beans { class XPropertySet; }
36 } } }
37 
38 #include <hash_map>
39 
40 class ScOutlineArray;
41 class SvXMLExportPropertyMapper;
42 class ScMyShapesContainer;
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 ScChartListener;
60 class SfxItemPool;
61 class ScAddress;
62 class ScBaseCell;
63 
64 typedef std::vector< com::sun::star::uno::Reference < com::sun::star::drawing::XShapes > > ScMyXShapesVec;
65 
66 class ScXMLExport : public SvXMLExport
67 {
68     ScDocument*                 pDoc;
69     com::sun::star::uno::Reference <com::sun::star::sheet::XSpreadsheet> xCurrentTable;
70     com::sun::star::uno::Reference <com::sun::star::table::XCellRange> xCurrentTableCellRange;
71 
72     com::sun::star::uno::Reference<com::sun::star::io::XInputStream> xSourceStream;
73     sal_Int32                   nSourceStreamPos;
74 
75     UniReference < XMLPropertyHandlerFactory >  xScPropHdlFactory;
76     UniReference < XMLPropertySetMapper >       xCellStylesPropertySetMapper;
77     UniReference < XMLPropertySetMapper >       xColumnStylesPropertySetMapper;
78     UniReference < XMLPropertySetMapper >       xRowStylesPropertySetMapper;
79     UniReference < XMLPropertySetMapper >       xTableStylesPropertySetMapper;
80     UniReference < SvXMLExportPropertyMapper >  xCellStylesExportPropertySetMapper;
81     UniReference < SvXMLExportPropertyMapper >  xColumnStylesExportPropertySetMapper;
82     UniReference < SvXMLExportPropertyMapper >  xRowStylesExportPropertySetMapper;
83     UniReference < SvXMLExportPropertyMapper >  xTableStylesExportPropertySetMapper;
84     XMLNumberFormatAttributesExportHelper* pNumberFormatAttributesExportHelper;
85     typedef ::std::hash_map<sal_Int32, sal_Int32>  NumberFormatIndexMap;
86     NumberFormatIndexMap                aNumFmtIndexMap;
87     ScMySharedData*                     pSharedData;
88     ScColumnStyles*                 pColumnStyles;
89     ScRowStyles*                    pRowStyles;
90     ScFormatRangeStyles*                pCellStyles;
91     ScRowFormatRanges*                  pRowFormatRanges;
92     std::vector<rtl::OUString>          aTableStyles;
93     com::sun::star::table::CellRangeAddress aRowHeaderRange;
94     ScMyOpenCloseColumnRowGroup*        pGroupColumns;
95     ScMyOpenCloseColumnRowGroup*        pGroupRows;
96     ScMyDefaultStyles*                  pDefaults;
97     ScChartListener*                    pChartListener;
98     const ScMyCell*                     pCurrentCell;
99 
100     ScMyMergedRangesContainer*  pMergedRangesContainer;
101     ScMyValidationsContainer*   pValidationsContainer;
102     ScMyNotEmptyCellsIterator*  pCellsItr;
103     ScChangeTrackingExportHelper*   pChangeTrackingExportHelper;
104     const rtl::OUString         sLayerID;
105     const rtl::OUString         sCaptionShape;
106     rtl::OUString               sExternalRefTabStyleName;
107     rtl::OUString               sAttrName;
108     rtl::OUString               sAttrStyleName;
109     rtl::OUString               sAttrColumnsRepeated;
110     rtl::OUString               sAttrFormula;
111     rtl::OUString               sAttrValueType;
112     rtl::OUString               sAttrStringValue;
113     rtl::OUString               sElemCell;
114     rtl::OUString               sElemCoveredCell;
115     rtl::OUString               sElemCol;
116     rtl::OUString               sElemRow;
117     rtl::OUString               sElemTab;
118     rtl::OUString               sElemP;
119     sal_Int32                   nOpenRow;
120     sal_Int32                   nProgressCount;
121     sal_uInt16                  nCurrentTable;
122     sal_Bool                    bHasRowHeader;
123     sal_Bool                    bRowHeaderOpen;
124     sal_Bool                    mbShowProgress;
125 
126     sal_Int32       GetNumberFormatStyleIndex(sal_Int32 nNumFmt) const;
127     sal_Bool        HasDrawPages(com::sun::star::uno::Reference <com::sun::star::sheet::XSpreadsheetDocument>& xDoc);
128     void            CollectSharedData(sal_Int32& nTableCount, sal_Int32& nShapesCount, const sal_Int32 nCellCount);
129     void            CollectShapesAutoStyles(const sal_Int32 nTableCount);
130     void            WriteTablesView(const com::sun::star::uno::Any& aTableView);
131     void            WriteView(const com::sun::star::uno::Any& aView);
132     virtual void _ExportFontDecls();
133     virtual void _ExportStyles( sal_Bool bUsed );
134     virtual void _ExportAutoStyles();
135     virtual void _ExportMasterStyles();
136     virtual void SetBodyAttributes();
137     virtual void _ExportContent();
138     virtual void _ExportMeta();
139 
140     void CollectInternalShape( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape );
141 
142     com::sun::star::table::CellRangeAddress GetEndAddress(const com::sun::star::uno::Reference<com::sun::star::sheet::XSpreadsheet>& xTable,
143                                                         const sal_Int32 nTable);
144 //  ScMyEmptyDatabaseRangesContainer GetEmptyDatabaseRanges();
145     void GetAreaLinks( com::sun::star::uno::Reference< com::sun::star::sheet::XSpreadsheetDocument>& xSpreadDoc, ScMyAreaLinksContainer& rAreaLinks );
146     void GetDetectiveOpList( ScMyDetectiveOpContainer& rDetOp );
147     void WriteSingleColumn(const sal_Int32 nRepeatColumns, const sal_Int32 nStyleIndex,
148         const sal_Int32 nIndex, const sal_Bool bIsAutoStyle, const sal_Bool bIsVisible);
149     void WriteColumn(const sal_Int32 nColumn, const sal_Int32 nRepeatColumns,
150         const sal_Int32 nStyleIndex, const sal_Bool bIsVisible);
151     void OpenHeaderColumn();
152     void CloseHeaderColumn();
153     void ExportColumns(const sal_Int32 nTable, const com::sun::star::table::CellRangeAddress& aColumnHeaderRange, const sal_Bool bHasColumnHeader);
154     void ExportExternalRefCacheStyles();
155     void ExportFormatRanges(const sal_Int32 nStartCol, const sal_Int32 nStartRow,
156         const sal_Int32 nEndCol, const sal_Int32 nEndRow, const sal_Int32 nSheet);
157     void WriteRowContent();
158     void WriteRowStartTag(sal_Int32 nRow, const sal_Int32 nIndex, const sal_Int8 nFlag, const sal_Int32 nEmptyRows);
159     void OpenHeaderRows();
160     void CloseHeaderRows();
161     void OpenNewRow(const sal_Int32 nIndex, const sal_Int8 nFlag, const sal_Int32 nStartRow, const sal_Int32 nEmptyRows);
162     void OpenAndCloseRow(const sal_Int32 nIndex, const sal_Int8 nFlag,
163         const sal_Int32 nStartRow, const sal_Int32 nEmptyRows);
164     void OpenRow(const sal_Int32 nTable, const sal_Int32 nStartRow, const sal_Int32 nRepeatRow);
165     void CloseRow(const sal_Int32 nRow);
166     void GetColumnRowHeader(sal_Bool& bHasColumnHeader, com::sun::star::table::CellRangeAddress& aColumnHeaderRange,
167         sal_Bool& bHasRowHeader, com::sun::star::table::CellRangeAddress& aRowHeaderRange,
168         rtl::OUString& rPrintRanges) const;
169     void FillFieldGroup(ScOutlineArray* pFields, ScMyOpenCloseColumnRowGroup* pGroups);
170     void FillColumnRowGroups();
171 
172 //UNUSED2008-05  sal_Bool GetMerge (const com::sun::star::uno::Reference <com::sun::star::sheet::XSpreadsheet>& xTable,
173 //UNUSED2008-05                     sal_Int32 nCol, sal_Int32 nRow,
174 //UNUSED2008-05                     com::sun::star::table::CellRangeAddress& aCellAddress);
175 
176     sal_Bool GetMerged (const com::sun::star::table::CellRangeAddress* pCellRange,
177         const com::sun::star::uno::Reference <com::sun::star::sheet::XSpreadsheet>& xTable);
178 
179     sal_Bool GetCellText (ScMyCell& rMyCell, const ScAddress& aPos) const;
180 
181     void WriteCell(ScMyCell& aCell, sal_Int32 nEqualCellCount);
182     void WriteAreaLink(const ScMyCell& rMyCell);
183     void WriteAnnotation(ScMyCell& rMyCell);
184     void WriteDetective(const ScMyCell& rMyCell);
185     void ExportShape(const com::sun::star::uno::Reference < com::sun::star::drawing::XShape >& xShape, com::sun::star::awt::Point* pPoint);
186     void WriteShapes(const ScMyCell& rMyCell);
187     void WriteTableShapes();
188     void SetRepeatAttribute(sal_Int32 nEqualCellCount, bool bIncProgress);
189 
190     sal_Bool IsCellTypeEqual (const ScMyCell& aCell1, const ScMyCell& aCell2) const;
191     sal_Bool IsEditCell(const com::sun::star::table::CellAddress& aAddress, ScMyCell* pMyCell = NULL) const;
192 //UNUSED2008-05  sal_Bool IsEditCell(const com::sun::star::uno::Reference <com::sun::star::table::XCell>& xCell) const;
193     sal_Bool IsEditCell(ScMyCell& rCell) const;
194     sal_Bool IsMultiLineFormulaCell(ScMyCell& rCell) const;
195 //UNUSED2008-05  sal_Bool IsAnnotationEqual(const com::sun::star::uno::Reference<com::sun::star::table::XCell>& xCell1,
196 //UNUSED2008-05                             const com::sun::star::uno::Reference<com::sun::star::table::XCell>& xCell2);
197     sal_Bool IsCellEqual (ScMyCell& aCell1, ScMyCell& aCell2);
198 
199     void WriteCalculationSettings(const com::sun::star::uno::Reference <com::sun::star::sheet::XSpreadsheetDocument>& xSpreadDoc);
200     void WriteTableSource();
201     void WriteScenario();   // core implementation
202     void WriteTheLabelRanges(const com::sun::star::uno::Reference< com::sun::star::sheet::XSpreadsheetDocument >& xSpreadDoc);
203     void WriteLabelRanges( const com::sun::star::uno::Reference< com::sun::star::container::XIndexAccess >& xRangesIAccess, sal_Bool bColumn );
204     void WriteNamedExpressions(const com::sun::star::uno::Reference <com::sun::star::sheet::XSpreadsheetDocument>& xSpreadDoc, sal_Int16 nWhichTable);
205     void WriteExternalRefCaches();
206     void WriteConsolidation();  // core implementation
207 
208     void CollectUserDefinedNamespaces(const SfxItemPool* pPool, sal_uInt16 nAttrib);
209 
210     void AddStyleFromCells(
211         const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet >& xProperties,
212         const com::sun::star::uno::Reference< com::sun::star::sheet::XSpreadsheet >& xTable,
213         sal_Int32 nTable, const rtl::OUString* pOldName );
214     void AddStyleFromColumn(
215         const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet >& xColumnProperties,
216         const rtl::OUString* pOldName, sal_Int32& rIndex, sal_Bool& rIsVisible );
217     void AddStyleFromRow(
218         const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet >& xRowProperties,
219         const rtl::OUString* pOldName, sal_Int32& rIndex );
220 
221     void IncrementProgressBar(sal_Bool bEditCell, sal_Int32 nInc = 1);
222 
223     void CopySourceStream( sal_Int32 nStartOffset, sal_Int32 nEndOffset, sal_Int32& rNewStart, sal_Int32& rNewEnd );
224 
225 protected:
226     virtual SvXMLAutoStylePoolP* CreateAutoStylePool();
227     virtual XMLPageExport* CreatePageExport();
228     virtual XMLShapeExport* CreateShapeExport();
229     virtual XMLFontAutoStylePool* CreateFontAutoStylePool();
230 public:
231     // #110680#
232     ScXMLExport(
233         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
234         const sal_uInt16 nExportFlag);
235 
236     virtual ~ScXMLExport();
237 
238     static sal_Int16 GetFieldUnit();
GetDocument()239     inline ScDocument*          GetDocument()           { return pDoc; }
GetDocument() const240     inline const ScDocument*    GetDocument() const     { return pDoc; }
241 //UNUSED2008-05  sal_Bool IsMatrix (const com::sun::star::uno::Reference <com::sun::star::table::XCellRange>& xCellRange,
242 //UNUSED2008-05                     const com::sun::star::uno::Reference <com::sun::star::sheet::XSpreadsheet>& xTable,
243 //UNUSED2008-05                     const sal_Int32 nCol, const sal_Int32 nRow,
244 //UNUSED2008-05                     com::sun::star::table::CellRangeAddress& aCellAddress, sal_Bool& bIsFirst) const;
245     sal_Bool IsMatrix (const ScAddress& aCell,
246         com::sun::star::table::CellRangeAddress& aCellAddress, sal_Bool& bIsFirst) const;
247 
GetCellStylesPropertySetMapper()248     UniReference < XMLPropertySetMapper > GetCellStylesPropertySetMapper() { return xCellStylesPropertySetMapper; }
GetTableStylesPropertySetMapper()249     UniReference < XMLPropertySetMapper > GetTableStylesPropertySetMapper() { return xTableStylesPropertySetMapper; }
250 
251     void SetSourceStream( const com::sun::star::uno::Reference<com::sun::star::io::XInputStream>& xNewStream );
252 
253     void GetChangeTrackViewSettings(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& rProps);
254     virtual void GetViewSettings(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& rProps);
255     virtual void GetConfigurationSettings(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& rProps);
256 
257     virtual void exportAnnotationMeta( const com::sun::star::uno::Reference < com::sun::star::drawing::XShape >& xShape);
258 
259     void CreateSharedData(const sal_Int32 nTableCount);
SetSharedData(ScMySharedData * pTemp)260     void SetSharedData(ScMySharedData* pTemp) { pSharedData = pTemp; }
GetSharedData()261     ScMySharedData* GetSharedData() { return pSharedData; }
262     XMLNumberFormatAttributesExportHelper* GetNumberFormatAttributesExportHelper();
263 
264     // Export the document.
265     virtual sal_uInt32 exportDoc( enum ::xmloff::token::XMLTokenEnum eClass = ::xmloff::token::XML_TOKEN_INVALID );
266 
267     // XExporter
268     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);
269 
270     // XFilter
271     virtual sal_Bool SAL_CALL filter( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) throw(::com::sun::star::uno::RuntimeException);
272     virtual void SAL_CALL cancel() throw(::com::sun::star::uno::RuntimeException);
273 
274     // XInitialization
275     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);
276 
277     // XServiceInfo
278     virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
279     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
280     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);
281 
282     // XUnoTunnel
283     virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);
284 
285     virtual void DisposingModel();
286 };
287 
288 #endif
289 
290