Update git submodules
[LibreOffice.git] / sc / source / filter / xml / xmlimprt.hxx
blob74958aa1398fe915eb209b51dea0ae823cb84cb6
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 #pragma once
22 #include <xmloff/xmlimp.hxx>
23 #include <xmloff/xmlprmap.hxx>
24 #include "xmlsubti.hxx"
25 #include <formula/grammar.hxx>
26 #include <vcl/svapp.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;
53 class ScModelObj;
55 namespace sc {
56 struct ImportPostProcessData;
57 struct PivotTableSources;
58 class ScDrawObjData;
62 class SvXMLTokenMap;
63 class XMLShapeImportHelper;
64 class ScXMLChangeTrackingImportHelper;
66 struct ScMyNamedExpression
68 OUString sName;
69 OUString sContent;
70 OUString sContentNmsp;
71 OUString sBaseCellAddress;
72 OUString sRangeType;
73 formula::FormulaGrammar::Grammar eGrammar;
74 bool bIsExpression;
77 typedef ::std::list<ScMyNamedExpression> ScMyNamedExpressions;
79 struct ScMyLabelRange
81 OUString sLabelRangeStr;
82 OUString sDataRangeStr;
83 bool bColumnOrientation;
86 typedef std::list<ScMyLabelRange> ScMyLabelRanges;
88 struct ScMyImportValidation
90 OUString sName;
91 OUString sInputTitle;
92 OUString sInputMessage;
93 OUString sErrorTitle;
94 OUString sErrorMessage;
95 OUString sFormula1;
96 OUString sFormula2;
97 OUString sFormulaNmsp1;
98 OUString sFormulaNmsp2;
99 OUString sBaseCellAddress; // string is used directly
100 css::sheet::ValidationAlertStyle aAlertStyle;
101 css::sheet::ValidationType aValidationType;
102 css::sheet::ConditionOperator aOperator;
103 formula::FormulaGrammar::Grammar eGrammar1;
104 formula::FormulaGrammar::Grammar eGrammar2;
105 sal_Int16 nShowList;
106 bool bShowErrorMessage;
107 bool bShowInputMessage;
108 bool bIgnoreBlanks;
109 bool bCaseSensitive;
112 typedef std::vector<ScMyImportValidation> ScMyImportValidations;
113 class ScMyStylesImportHelper;
114 class ScXMLEditAttributeMap;
115 class ScCellRangesObj;
117 class ScXMLImport: public SvXMLImport
119 ScXMLImport(const ScXMLImport&) = delete;
120 const ScXMLImport& operator=(const ScXMLImport&) = delete;
122 typedef ::std::map<SCTAB, ScMyNamedExpressions> SheetNamedExpMap;
124 ScDocument* mpDoc;
125 std::unique_ptr<ScDocumentImport> mpDocImport;
126 std::unique_ptr<ScCompiler> mpComp; // For error-checking of cached string cell values.
127 std::unique_ptr<ScEditEngineDefaulter> mpEditEngine;
128 std::unique_ptr<sc::PivotTableSources> mpPivotSources;
130 mutable std::unique_ptr<ScXMLEditAttributeMap> mpEditAttrMap;
131 std::unique_ptr<ScXMLChangeTrackingImportHelper> pChangeTrackingImportHelper;
132 std::unique_ptr<ScMyStylesImportHelper> pStylesImportHelper;
134 rtl::Reference < XMLPropertyHandlerFactory > xScPropHdlFactory;
135 rtl::Reference < XMLPropertySetMapper > xCellStylesPropertySetMapper;
136 rtl::Reference < XMLPropertySetMapper > xColumnStylesPropertySetMapper;
137 rtl::Reference < XMLPropertySetMapper > xRowStylesPropertySetMapper;
138 rtl::Reference < XMLPropertySetMapper > xTableStylesPropertySetMapper;
140 sc::ImportPostProcessData* mpPostProcessData; /// Lift cycle managed elsewhere, no need to delete.
142 ScMyTables aTables;
144 std::vector<ScDocRowHeightUpdater::TabRanges> maRecalcRowRanges;
146 ScMyNamedExpressions m_aMyNamedExpressions;
147 SheetNamedExpMap m_SheetNamedExpressions;
149 ScMyLabelRanges maMyLabelRanges;
150 ScMyImportValidations maValidations;
151 std::unique_ptr<ScMyImpDetectiveOpArray> pDetectiveOpArray;
152 std::optional<SolarMutexGuard> moSolarMutexGuard;
154 std::unique_ptr<XMLNumberFormatAttributesExportHelper> pNumberFormatAttributesExportHelper;
155 std::unique_ptr<ScMyStyleNumberFormats> pStyleNumberFormats;
156 css::uno::Reference <css::util::XNumberFormats> xNumberFormats;
157 css::uno::Reference <css::util::XNumberFormatTypes> xNumberFormatTypes;
159 rtl::Reference<ScCellRangesObj> mxSheetCellRanges; // css::sheet::XSheetCellRangeContainer
161 OUString sPrevStyleName;
162 OUString sPrevCurrency;
163 sal_uInt32 nSolarMutexLocked;
164 sal_Int32 nProgressCount;
165 sal_Int16 nPrevCellType;
166 bool bLoadDoc; // Load doc or styles only
167 bool bNullDateSetted;
168 bool bSelfImportingXMLSet;
169 bool mbLockSolarMutex;
170 bool mbImportStyles;
171 bool mbHasNewCondFormatData;
173 protected:
175 // This method is called after the namespace map has been updated, but
176 // before a context for the current element has been pushed.
177 virtual SvXMLImportContext *CreateFastContext( sal_Int32 nElement,
178 const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList >& xAttrList ) override;
180 virtual XMLShapeImportHelper* CreateShapeImport() override;
182 public:
183 ScXMLImport(
184 const css::uno::Reference< css::uno::XComponentContext >& rContext,
185 OUString const & implementationName, SvXMLImportFlags nImportFlag,
186 const css::uno::Sequence< OUString > & sSupportedServiceNames = {});
188 virtual ~ScXMLImport() noexcept override;
190 // XInitialization
191 virtual void SAL_CALL initialize( const css::uno::Sequence<css::uno::Any>& aArguments ) override;
193 // namespace office
194 // NB: in contrast to other CreateFooContexts, this particular one handles
195 // the root element (i.e. office:document-meta)
196 SvXMLImportContext *CreateMetaContext( sal_Int32 nElement );
197 SvXMLImportContext *CreateFontDeclsContext();
198 SvXMLImportContext *CreateScriptContext();
199 SvXMLImportContext *CreateStylesContext( bool bAutoStyles );
201 SvXMLImportContext *CreateBodyContext(
202 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList );
204 virtual void SetStatistics( const css::uno::Sequence< css::beans::NamedValue> & i_rStats) override;
206 ScDocumentImport& GetDoc();
208 SAL_RET_MAYBENULL ScDocument* GetDocument() { return mpDoc; }
209 SAL_RET_MAYBENULL const ScDocument* GetDocument() const { return mpDoc; }
211 ScModelObj* GetScModel() const;
213 ScMyTables& GetTables() { return aTables; }
215 std::vector<ScDocRowHeightUpdater::TabRanges>& GetRecalcRowRanges() { return maRecalcRowRanges; }
217 bool IsStylesOnlyMode() const { return !bLoadDoc; }
219 static sal_Int16 GetCellType(const char* rStrValue, const sal_Int32 nStrLength);
221 const rtl::Reference < XMLPropertySetMapper >& GetCellStylesPropertySetMapper() const { return xCellStylesPropertySetMapper; }
222 const rtl::Reference < XMLPropertySetMapper >& GetColumnStylesPropertySetMapper() const { return xColumnStylesPropertySetMapper; }
223 const rtl::Reference < XMLPropertySetMapper >& GetRowStylesPropertySetMapper() const { return xRowStylesPropertySetMapper; }
224 const rtl::Reference < XMLPropertySetMapper >& GetTableStylesPropertySetMapper() const { return xTableStylesPropertySetMapper; }
226 void SetPostProcessData( sc::ImportPostProcessData* p );
227 sc::ImportPostProcessData* GetPostProcessData() { return mpPostProcessData;}
229 sc::PivotTableSources& GetPivotTableSources();
231 void AddNamedExpression(ScMyNamedExpression aMyNamedExpression)
233 m_aMyNamedExpressions.push_back(std::move(aMyNamedExpression));
236 void AddNamedExpression(SCTAB nTab, ScMyNamedExpression aNamedExp);
238 void AddLabelRange(ScMyLabelRange aMyLabelRange)
240 maMyLabelRanges.push_back(std::move(aMyLabelRange));
243 void AddValidation(const ScMyImportValidation& rValidation) { maValidations.push_back(rValidation); }
244 bool GetValidation(const OUString& sName, ScMyImportValidation& aValidation);
246 ScMyImpDetectiveOpArray* GetDetectiveOpArray();
248 ScXMLChangeTrackingImportHelper* GetChangeTrackingImportHelper();
249 void InsertStyles();
251 void SetChangeTrackingViewSettings(const css::uno::Sequence<css::beans::PropertyValue>& rChangeProps);
252 virtual void SetViewSettings(const css::uno::Sequence<css::beans::PropertyValue>& aViewProps) override;
253 virtual void SetConfigurationSettings(const css::uno::Sequence<css::beans::PropertyValue>& aConfigProps) override;
255 ScMyStylesImportHelper* GetStylesImportHelper() { return pStylesImportHelper.get(); }
256 sal_Int32 SetCurrencySymbol(const sal_Int32 nKey, std::u16string_view rCurrency);
257 bool IsCurrencySymbol(const sal_Int32 nNumberFormat, std::u16string_view sCurrencySymbol, std::u16string_view sBankSymbol);
258 void SetType(const css::uno::Reference <css::beans::XPropertySet>& rProperties,
259 sal_Int32& rNumberFormat,
260 const sal_Int16 nCellType,
261 std::u16string_view rCurrency);
263 void ProgressBarIncrement();
265 void SetNewCondFormatData() { mbHasNewCondFormatData = true; }
266 bool HasNewCondFormatData() const { return mbHasNewCondFormatData; }
268 private:
269 void SetStyleToRanges();
271 void ExamineDefaultStyle();
272 public:
273 void SetStyleToRanges(const ScRangeList& rRanges, const OUString* pStyleName,
274 const sal_Int16 nCellType, const OUString* pCurrency);
275 bool SetNullDateOnUnitConverter();
276 XMLNumberFormatAttributesExportHelper* GetNumberFormatAttributesExportHelper();
277 ScMyStyleNumberFormats* GetStyleNumberFormats();
279 void SetStylesToRangesFinished();
281 // XImporter
282 virtual void SAL_CALL setTargetDocument( const css::uno::Reference< css::lang::XComponent >& xDoc ) override;
284 virtual void SAL_CALL startDocument() override;
285 virtual void SAL_CALL endDocument() override;
287 virtual void DisposingModel() override;
290 * Use this class to manage solar mutex locking instead of calling
291 * LockSolarMutex() and UnlockSolarMutex() directly.
293 class MutexGuard
295 public:
296 explicit MutexGuard(ScXMLImport& rImport);
297 ~MutexGuard();
298 private:
299 ScXMLImport& mrImport;
301 void LockSolarMutex();
302 void UnlockSolarMutex();
304 sal_Int64 GetByteOffset() const;
306 void SetRangeOverflowType(ErrCode nType);
308 static sal_Int32 GetRangeType(std::u16string_view sRangeType);
309 void SetNamedRanges();
310 void SetSheetNamedRanges();
311 void SetLabelRanges();
312 void SetStringRefSyntaxIfMissing();
314 /** Extracts the formula string, the formula grammar namespace URL, and a
315 grammar enum value from the passed formula attribute value.
317 @param rFormula
318 (out-parameter) Returns the plain formula string with the leading
319 equality sign if existing.
321 @param rFormulaNmsp
322 (out-parameter) Returns the URL of the formula grammar namespace if
323 the attribute value contains the prefix of an unknown namespace.
325 @param reGrammar
326 (out-parameter) Returns the exact formula grammar if the formula
327 is in a supported ODF format (e.g. FormulaGrammar::GRAM_PODF for
328 ODF 1.0/1.1 formulas, or FormulaGrammar::GRAM_ODFF for ODF 1.2
329 formulas a.k.a. OpenFormula). Returns the default storage grammar,
330 if the attribute value does not contain a namespace prefix. Returns
331 the special value FormulaGrammar::GRAM_EXTERNAL, if an unknown
332 namespace could be extracted from the formula which will be
333 contained in the parameter rFormulaNmsp then.
335 @param rAttrValue
336 The value of the processed formula attribute.
338 @param bRestrictToExternalNmsp
339 If set to true, only namespaces of external formula grammars will
340 be recognized. Internal namespace prefixes (e.g. 'oooc:' or 'of:'
341 will be considered to be part of the formula, e.g. an expression
342 with range operator.
344 void ExtractFormulaNamespaceGrammar(
345 OUString& rFormula,
346 OUString& rFormulaNmsp,
347 ::formula::FormulaGrammar::Grammar& reGrammar,
348 const OUString& rAttrValue,
349 bool bRestrictToExternalNmsp = false ) const;
351 FormulaError GetFormulaErrorConstant( const OUString& rStr ) const;
353 ScEditEngineDefaulter* GetEditEngine();
354 const ScXMLEditAttributeMap& GetEditAttributeMap() const;
355 virtual void NotifyContainsEmbeddedFont() override;
358 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */