nss: upgrade to release 3.73
[LibreOffice.git] / sc / source / filter / xml / xmlimprt.hxx
blob910617027beb5036ced2c20781511555db5bb2b1
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 #ifndef INCLUDED_SC_SOURCE_FILTER_XML_XMLIMPRT_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_XML_XMLIMPRT_HXX
23 #include <xmloff/xmlimp.hxx>
24 #include <xmloff/xmlprmap.hxx>
25 #include "xmlsubti.hxx"
26 #include <formula/grammar.hxx>
27 #include <dociter.hxx>
29 #include <com/sun/star/sheet/ValidationAlertStyle.hpp>
30 #include <com/sun/star/sheet/ValidationType.hpp>
31 #include <com/sun/star/sheet/ConditionOperator.hpp>
33 #include <memory>
34 #include <map>
35 #include <vector>
36 #include <list>
38 namespace com::sun::star::beans { class XPropertySet; }
39 namespace com::sun::star::sheet { class XSheetCellRangeContainer; }
40 namespace com::sun::star::table { struct CellRangeAddress; }
41 namespace com::sun::star::util { class XNumberFormatTypes; }
42 namespace com::sun::star::util { class XNumberFormats; }
43 namespace sax_fastparser { class FastAttributeList; }
45 class ScCompiler;
46 class ErrCode;
47 class ScMyStyleNumberFormats;
48 class XMLNumberFormatAttributesExportHelper;
49 class ScEditEngineDefaulter;
50 class ScDocumentImport;
51 class ScMyImpDetectiveOpArray;
52 class SdrPage;
54 namespace sc {
55 struct ImportPostProcessData;
56 struct PivotTableSources;
57 class ScDrawObjData;
61 enum ScXMLTableTokens
63 XML_TOK_TABLE_NAMED_EXPRESSIONS,
64 XML_TOK_TABLE_COL_GROUP,
65 XML_TOK_TABLE_HEADER_COLS,
66 XML_TOK_TABLE_COLS,
67 XML_TOK_TABLE_COL,
68 XML_TOK_TABLE_ROW_GROUP,
69 XML_TOK_TABLE_HEADER_ROWS,
70 XML_TOK_TABLE_PROTECTION,
71 XML_TOK_TABLE_PROTECTION_EXT,
72 XML_TOK_TABLE_ROWS,
73 XML_TOK_TABLE_ROW,
74 XML_TOK_TABLE_SOURCE,
75 XML_TOK_TABLE_SCENARIO,
76 XML_TOK_TABLE_SHAPES,
77 XML_TOK_TABLE_FORMS,
78 XML_TOK_TABLE_EVENT_LISTENERS,
79 XML_TOK_TABLE_EVENT_LISTENERS_EXT,
80 XML_TOK_TABLE_CONDFORMATS
83 enum ScXMLTableRowsTokens
85 XML_TOK_TABLE_ROWS_ROW_GROUP,
86 XML_TOK_TABLE_ROWS_HEADER_ROWS,
87 XML_TOK_TABLE_ROWS_ROWS,
88 XML_TOK_TABLE_ROWS_ROW
91 enum ScXMLTableRowTokens
93 XML_TOK_TABLE_ROW_CELL,
94 XML_TOK_TABLE_ROW_COVERED_CELL
97 enum ScXMLTableRowAttrTokens
99 XML_TOK_TABLE_ROW_ATTR_STYLE_NAME,
100 XML_TOK_TABLE_ROW_ATTR_VISIBILITY,
101 XML_TOK_TABLE_ROW_ATTR_REPEATED,
102 XML_TOK_TABLE_ROW_ATTR_DEFAULT_CELL_STYLE_NAME
103 // XML_TOK_TABLE_ROW_ATTR_USE_OPTIMAL_HEIGHT
106 enum ScXMLTableRowCellTokens
108 XML_TOK_TABLE_ROW_CELL_P,
109 XML_TOK_TABLE_ROW_CELL_TABLE,
110 XML_TOK_TABLE_ROW_CELL_ANNOTATION,
111 XML_TOK_TABLE_ROW_CELL_DETECTIVE,
112 XML_TOK_TABLE_ROW_CELL_CELL_RANGE_SOURCE
115 enum ScXMLTableRowCellAttrTokens
117 XML_TOK_TABLE_ROW_CELL_ATTR_STYLE_NAME,
118 XML_TOK_TABLE_ROW_CELL_ATTR_CONTENT_VALIDATION_NAME,
119 XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_ROWS,
120 XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_COLS,
121 XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_MATRIX_COLS,
122 XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_MATRIX_ROWS,
123 XML_TOK_TABLE_ROW_CELL_ATTR_REPEATED,
124 XML_TOK_TABLE_ROW_CELL_ATTR_VALUE_TYPE,
125 XML_TOK_TABLE_ROW_CELL_ATTR_NEW_VALUE_TYPE,
126 XML_TOK_TABLE_ROW_CELL_ATTR_VALUE,
127 XML_TOK_TABLE_ROW_CELL_ATTR_DATE_VALUE,
128 XML_TOK_TABLE_ROW_CELL_ATTR_TIME_VALUE,
129 XML_TOK_TABLE_ROW_CELL_ATTR_STRING_VALUE,
130 XML_TOK_TABLE_ROW_CELL_ATTR_BOOLEAN_VALUE,
131 XML_TOK_TABLE_ROW_CELL_ATTR_FORMULA,
132 XML_TOK_TABLE_ROW_CELL_ATTR_CURRENCY
135 enum ScXMLAnnotationAttrTokens
137 XML_TOK_TABLE_ANNOTATION_ATTR_AUTHOR,
138 XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE,
139 XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE_STRING,
140 XML_TOK_TABLE_ANNOTATION_ATTR_DISPLAY,
141 XML_TOK_TABLE_ANNOTATION_ATTR_X,
142 XML_TOK_TABLE_ANNOTATION_ATTR_Y
145 class SvXMLTokenMap;
146 class XMLShapeImportHelper;
147 class ScXMLChangeTrackingImportHelper;
148 class SolarMutexGuard;
150 struct ScMyNamedExpression
152 OUString sName;
153 OUString sContent;
154 OUString sContentNmsp;
155 OUString sBaseCellAddress;
156 OUString sRangeType;
157 formula::FormulaGrammar::Grammar eGrammar;
158 bool bIsExpression;
161 typedef ::std::list<std::unique_ptr<ScMyNamedExpression>> ScMyNamedExpressions;
163 struct ScMyLabelRange
165 OUString sLabelRangeStr;
166 OUString sDataRangeStr;
167 bool bColumnOrientation;
170 typedef std::list< std::unique_ptr<const ScMyLabelRange> > ScMyLabelRanges;
172 struct ScMyImportValidation
174 OUString sName;
175 OUString sInputTitle;
176 OUString sInputMessage;
177 OUString sErrorTitle;
178 OUString sErrorMessage;
179 OUString sFormula1;
180 OUString sFormula2;
181 OUString sFormulaNmsp1;
182 OUString sFormulaNmsp2;
183 OUString sBaseCellAddress; // string is used directly
184 css::sheet::ValidationAlertStyle aAlertStyle;
185 css::sheet::ValidationType aValidationType;
186 css::sheet::ConditionOperator aOperator;
187 formula::FormulaGrammar::Grammar eGrammar1;
188 formula::FormulaGrammar::Grammar eGrammar2;
189 sal_Int16 nShowList;
190 bool bShowErrorMessage;
191 bool bShowInputMessage;
192 bool bIgnoreBlanks;
195 typedef std::vector<ScMyImportValidation> ScMyImportValidations;
196 class ScMyStylesImportHelper;
197 class ScXMLEditAttributeMap;
199 class ScXMLImport: public SvXMLImport
201 ScXMLImport(const ScXMLImport&) = delete;
202 const ScXMLImport& operator=(const ScXMLImport&) = delete;
204 typedef ::std::map<SCTAB, std::unique_ptr<ScMyNamedExpressions>> SheetNamedExpMap;
206 ScDocument* pDoc;
207 std::unique_ptr<ScDocumentImport> mpDocImport;
208 std::unique_ptr<ScCompiler> mpComp; // For error-checking of cached string cell values.
209 std::unique_ptr<ScEditEngineDefaulter> mpEditEngine;
210 std::unique_ptr<sc::PivotTableSources> mpPivotSources;
212 mutable std::unique_ptr<ScXMLEditAttributeMap> mpEditAttrMap;
213 std::unique_ptr<ScXMLChangeTrackingImportHelper> pChangeTrackingImportHelper;
214 std::unique_ptr<ScMyStylesImportHelper> pStylesImportHelper;
216 rtl::Reference < XMLPropertyHandlerFactory > xScPropHdlFactory;
217 rtl::Reference < XMLPropertySetMapper > xCellStylesPropertySetMapper;
218 rtl::Reference < XMLPropertySetMapper > xColumnStylesPropertySetMapper;
219 rtl::Reference < XMLPropertySetMapper > xRowStylesPropertySetMapper;
220 rtl::Reference < XMLPropertySetMapper > xTableStylesPropertySetMapper;
222 std::unique_ptr<SvXMLTokenMap> pTableElemTokenMap;
223 std::unique_ptr<SvXMLTokenMap> pTableRowsElemTokenMap;
224 std::unique_ptr<SvXMLTokenMap> pTableRowElemTokenMap;
225 std::unique_ptr<SvXMLTokenMap> pTableRowAttrTokenMap;
226 std::unique_ptr<SvXMLTokenMap> pTableRowCellElemTokenMap;
227 std::unique_ptr<SvXMLTokenMap> pTableRowCellAttrTokenMap;
228 std::unique_ptr<SvXMLTokenMap> pTableAnnotationAttrTokenMap;
230 sc::ImportPostProcessData* mpPostProcessData; /// Lift cycle managed elsewhere, no need to delete.
232 ScMyTables aTables;
234 std::vector<ScDocRowHeightUpdater::TabRanges> maRecalcRowRanges;
236 std::unique_ptr<ScMyNamedExpressions> m_pMyNamedExpressions;
237 SheetNamedExpMap m_SheetNamedExpressions;
239 std::unique_ptr<ScMyLabelRanges> pMyLabelRanges;
240 std::unique_ptr<ScMyImportValidations> pValidations;
241 std::unique_ptr<ScMyImpDetectiveOpArray> pDetectiveOpArray;
242 std::unique_ptr<SolarMutexGuard> pSolarMutexGuard;
244 std::unique_ptr<XMLNumberFormatAttributesExportHelper> pNumberFormatAttributesExportHelper;
245 std::unique_ptr<ScMyStyleNumberFormats> pStyleNumberFormats;
246 css::uno::Reference <css::util::XNumberFormats> xNumberFormats;
247 css::uno::Reference <css::util::XNumberFormatTypes> xNumberFormatTypes;
249 css::uno::Reference <css::sheet::XSheetCellRangeContainer> xSheetCellRanges;
251 OUString sPrevStyleName;
252 OUString sPrevCurrency;
253 sal_uInt32 nSolarMutexLocked;
254 sal_Int32 nProgressCount;
255 sal_Int16 nPrevCellType;
256 bool bLoadDoc; // Load doc or styles only
257 bool bNullDateSetted;
258 bool bSelfImportingXMLSet;
259 bool mbLockSolarMutex;
260 bool mbImportStyles;
261 bool mbHasNewCondFormatData;
263 protected:
265 // This method is called after the namespace map has been updated, but
266 // before a context for the current element has been pushed.
267 virtual SvXMLImportContext *CreateFastContext( sal_Int32 nElement,
268 const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList >& xAttrList ) override;
270 virtual XMLShapeImportHelper* CreateShapeImport() override;
272 public:
273 ScXMLImport(
274 const css::uno::Reference< css::uno::XComponentContext >& rContext,
275 OUString const & implementationName, SvXMLImportFlags nImportFlag,
276 const css::uno::Sequence< OUString > & sSupportedServiceNames = {});
278 virtual ~ScXMLImport() throw() override;
280 // XInitialization
281 virtual void SAL_CALL initialize( const css::uno::Sequence<css::uno::Any>& aArguments ) override;
283 // namespace office
284 // NB: in contrast to other CreateFooContexts, this particular one handles
285 // the root element (i.e. office:document-meta)
286 SvXMLImportContext *CreateMetaContext( sal_Int32 nElement );
287 SvXMLImportContext *CreateFontDeclsContext();
288 SvXMLImportContext *CreateScriptContext();
289 SvXMLImportContext *CreateStylesContext( bool bAutoStyles );
291 SvXMLImportContext *CreateBodyContext(
292 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList );
294 virtual void SetStatistics( const css::uno::Sequence< css::beans::NamedValue> & i_rStats) override;
296 ScDocumentImport& GetDoc();
298 ScDocument* GetDocument() { return pDoc; }
299 const ScDocument* GetDocument() const { return pDoc; }
301 ScMyTables& GetTables() { return aTables; }
303 std::vector<ScDocRowHeightUpdater::TabRanges>& GetRecalcRowRanges() { return maRecalcRowRanges; }
305 bool IsStylesOnlyMode() const { return !bLoadDoc; }
307 static sal_Int16 GetCellType(const char* rStrValue, const sal_Int32 nStrLength);
309 const rtl::Reference < XMLPropertySetMapper >& GetCellStylesPropertySetMapper() const { return xCellStylesPropertySetMapper; }
310 const rtl::Reference < XMLPropertySetMapper >& GetColumnStylesPropertySetMapper() const { return xColumnStylesPropertySetMapper; }
311 const rtl::Reference < XMLPropertySetMapper >& GetRowStylesPropertySetMapper() const { return xRowStylesPropertySetMapper; }
312 const rtl::Reference < XMLPropertySetMapper >& GetTableStylesPropertySetMapper() const { return xTableStylesPropertySetMapper; }
314 const SvXMLTokenMap& GetTableElemTokenMap();
315 const SvXMLTokenMap& GetTableRowsElemTokenMap();
316 const SvXMLTokenMap& GetTableRowElemTokenMap();
317 const SvXMLTokenMap& GetTableRowAttrTokenMap();
318 const SvXMLTokenMap& GetTableRowCellElemTokenMap();
319 const SvXMLTokenMap& GetTableRowCellAttrTokenMap();
320 const SvXMLTokenMap& GetTableAnnotationAttrTokenMap();
322 void SetPostProcessData( sc::ImportPostProcessData* p );
323 sc::ImportPostProcessData* GetPostProcessData() { return mpPostProcessData;}
325 sc::PivotTableSources& GetPivotTableSources();
327 void AddNamedExpression(ScMyNamedExpression* pMyNamedExpression)
329 if (!m_pMyNamedExpressions)
330 m_pMyNamedExpressions.reset(new ScMyNamedExpressions);
331 m_pMyNamedExpressions->push_back(std::unique_ptr<ScMyNamedExpression>(pMyNamedExpression));
334 void AddNamedExpression(SCTAB nTab, ScMyNamedExpression* pNamedExp);
336 void AddLabelRange(std::unique_ptr<const ScMyLabelRange> pMyLabelRange) {
337 if (!pMyLabelRanges)
338 pMyLabelRanges.reset(new ScMyLabelRanges);
339 pMyLabelRanges->push_back(std::move(pMyLabelRange)); }
341 void AddValidation(const ScMyImportValidation& rValidation) {
342 if (!pValidations)
343 pValidations.reset(new ScMyImportValidations);
344 pValidations->push_back(rValidation); }
345 bool GetValidation(const OUString& sName, ScMyImportValidation& aValidation);
347 ScMyImpDetectiveOpArray* GetDetectiveOpArray();
349 ScXMLChangeTrackingImportHelper* GetChangeTrackingImportHelper();
350 void InsertStyles();
352 void SetChangeTrackingViewSettings(const css::uno::Sequence<css::beans::PropertyValue>& rChangeProps);
353 virtual void SetViewSettings(const css::uno::Sequence<css::beans::PropertyValue>& aViewProps) override;
354 virtual void SetConfigurationSettings(const css::uno::Sequence<css::beans::PropertyValue>& aConfigProps) override;
356 ScMyStylesImportHelper* GetStylesImportHelper() { return pStylesImportHelper.get(); }
357 sal_Int32 SetCurrencySymbol(const sal_Int32 nKey, const OUString& rCurrency);
358 bool IsCurrencySymbol(const sal_Int32 nNumberFormat, const OUString& sCurrencySymbol, const OUString& sBankSymbol);
359 void SetType(const css::uno::Reference <css::beans::XPropertySet>& rProperties,
360 sal_Int32& rNumberFormat,
361 const sal_Int16 nCellType,
362 const OUString& rCurrency);
364 void ProgressBarIncrement();
366 void SetNewCondFormatData() { mbHasNewCondFormatData = true; }
367 bool HasNewCondFormatData() const { return mbHasNewCondFormatData; }
369 private:
370 void SetStyleToRanges();
372 void ExamineDefaultStyle();
373 public:
374 void SetStyleToRanges(const ScRangeList& rRanges, const OUString* pStyleName,
375 const sal_Int16 nCellType, const OUString* pCurrency);
376 bool SetNullDateOnUnitConverter();
377 XMLNumberFormatAttributesExportHelper* GetNumberFormatAttributesExportHelper();
378 ScMyStyleNumberFormats* GetStyleNumberFormats();
380 void SetStylesToRangesFinished();
382 // XImporter
383 virtual void SAL_CALL setTargetDocument( const css::uno::Reference< css::lang::XComponent >& xDoc ) override;
385 virtual void SAL_CALL startDocument() override;
386 virtual void SAL_CALL endDocument() override;
388 virtual void DisposingModel() override;
391 * Use this class to manage solar mutex locking instead of calling
392 * LockSolarMutex() and UnlockSolarMutex() directly.
394 class MutexGuard
396 public:
397 explicit MutexGuard(ScXMLImport& rImport);
398 ~MutexGuard();
399 private:
400 ScXMLImport& mrImport;
402 void LockSolarMutex();
403 void UnlockSolarMutex();
405 sal_Int32 GetByteOffset() const;
407 void SetRangeOverflowType(ErrCode nType);
409 static sal_Int32 GetRangeType(const OUString& sRangeType);
410 void SetNamedRanges();
411 void SetSheetNamedRanges();
412 void SetLabelRanges();
413 void SetStringRefSyntaxIfMissing();
415 /** Extracts the formula string, the formula grammar namespace URL, and a
416 grammar enum value from the passed formula attribute value.
418 @param rFormula
419 (out-parameter) Returns the plain formula string with the leading
420 equality sign if existing.
422 @param rFormulaNmsp
423 (out-parameter) Returns the URL of the formula grammar namespace if
424 the attribute value contains the prefix of an unknown namespace.
426 @param reGrammar
427 (out-parameter) Returns the exact formula grammar if the formula
428 is in a supported ODF format (e.g. FormulaGrammar::GRAM_PODF for
429 ODF 1.0/1.1 formulas, or FormulaGrammar::GRAM_ODFF for ODF 1.2
430 formulas a.k.a. OpenFormula). Returns the default storage grammar,
431 if the attribute value does not contain a namespace prefix. Returns
432 the special value FormulaGrammar::GRAM_EXTERNAL, if an unknown
433 namespace could be extracted from the formula which will be
434 contained in the parameter rFormulaNmsp then.
436 @param rAttrValue
437 The value of the processed formula attribute.
439 @param bRestrictToExternalNmsp
440 If set to true, only namespaces of external formula grammars will
441 be recognized. Internal namespace prefixes (e.g. 'oooc:' or 'of:'
442 will be considered to be part of the formula, e.g. an expression
443 with range operator.
445 void ExtractFormulaNamespaceGrammar(
446 OUString& rFormula,
447 OUString& rFormulaNmsp,
448 ::formula::FormulaGrammar::Grammar& reGrammar,
449 const OUString& rAttrValue,
450 bool bRestrictToExternalNmsp = false ) const;
452 FormulaError GetFormulaErrorConstant( const OUString& rStr ) const;
454 ScEditEngineDefaulter* GetEditEngine();
455 const ScXMLEditAttributeMap& GetEditAttributeMap() const;
456 virtual void NotifyContainsEmbeddedFont() override;
459 #endif
461 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */