Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / sc / source / filter / xml / xmlimprt.hxx
blob4481b5ebdb406c7832c5edbfce60df260e63d936
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 <dociter.hxx>
28 #include <com/sun/star/sheet/ValidationAlertStyle.hpp>
29 #include <com/sun/star/sheet/ValidationType.hpp>
30 #include <com/sun/star/sheet/ConditionOperator.hpp>
32 #include <memory>
33 #include <map>
34 #include <vector>
35 #include <list>
37 namespace com::sun::star::beans { class XPropertySet; }
38 namespace com::sun::star::sheet { class XSheetCellRangeContainer; }
39 namespace com::sun::star::table { struct CellRangeAddress; }
40 namespace com::sun::star::util { class XNumberFormatTypes; }
41 namespace com::sun::star::util { class XNumberFormats; }
42 namespace sax_fastparser { class FastAttributeList; }
44 class ScCompiler;
45 class ErrCode;
46 class ScMyStyleNumberFormats;
47 class XMLNumberFormatAttributesExportHelper;
48 class ScEditEngineDefaulter;
49 class ScDocumentImport;
50 class ScMyImpDetectiveOpArray;
51 class SdrPage;
53 namespace sc {
54 struct ImportPostProcessData;
55 struct PivotTableSources;
56 class ScDrawObjData;
60 class SvXMLTokenMap;
61 class XMLShapeImportHelper;
62 class ScXMLChangeTrackingImportHelper;
63 class SolarMutexGuard;
65 struct ScMyNamedExpression
67 OUString sName;
68 OUString sContent;
69 OUString sContentNmsp;
70 OUString sBaseCellAddress;
71 OUString sRangeType;
72 formula::FormulaGrammar::Grammar eGrammar;
73 bool bIsExpression;
76 typedef ::std::list<ScMyNamedExpression> ScMyNamedExpressions;
78 struct ScMyLabelRange
80 OUString sLabelRangeStr;
81 OUString sDataRangeStr;
82 bool bColumnOrientation;
85 typedef std::list<ScMyLabelRange> ScMyLabelRanges;
87 struct ScMyImportValidation
89 OUString sName;
90 OUString sInputTitle;
91 OUString sInputMessage;
92 OUString sErrorTitle;
93 OUString sErrorMessage;
94 OUString sFormula1;
95 OUString sFormula2;
96 OUString sFormulaNmsp1;
97 OUString sFormulaNmsp2;
98 OUString sBaseCellAddress; // string is used directly
99 css::sheet::ValidationAlertStyle aAlertStyle;
100 css::sheet::ValidationType aValidationType;
101 css::sheet::ConditionOperator aOperator;
102 formula::FormulaGrammar::Grammar eGrammar1;
103 formula::FormulaGrammar::Grammar eGrammar2;
104 sal_Int16 nShowList;
105 bool bShowErrorMessage;
106 bool bShowInputMessage;
107 bool bIgnoreBlanks;
110 typedef std::vector<ScMyImportValidation> ScMyImportValidations;
111 class ScMyStylesImportHelper;
112 class ScXMLEditAttributeMap;
114 class ScXMLImport: public SvXMLImport
116 ScXMLImport(const ScXMLImport&) = delete;
117 const ScXMLImport& operator=(const ScXMLImport&) = delete;
119 typedef ::std::map<SCTAB, ScMyNamedExpressions> SheetNamedExpMap;
121 ScDocument* pDoc;
122 std::unique_ptr<ScDocumentImport> mpDocImport;
123 std::unique_ptr<ScCompiler> mpComp; // For error-checking of cached string cell values.
124 std::unique_ptr<ScEditEngineDefaulter> mpEditEngine;
125 std::unique_ptr<sc::PivotTableSources> mpPivotSources;
127 mutable std::unique_ptr<ScXMLEditAttributeMap> mpEditAttrMap;
128 std::unique_ptr<ScXMLChangeTrackingImportHelper> pChangeTrackingImportHelper;
129 std::unique_ptr<ScMyStylesImportHelper> pStylesImportHelper;
131 rtl::Reference < XMLPropertyHandlerFactory > xScPropHdlFactory;
132 rtl::Reference < XMLPropertySetMapper > xCellStylesPropertySetMapper;
133 rtl::Reference < XMLPropertySetMapper > xColumnStylesPropertySetMapper;
134 rtl::Reference < XMLPropertySetMapper > xRowStylesPropertySetMapper;
135 rtl::Reference < XMLPropertySetMapper > xTableStylesPropertySetMapper;
137 sc::ImportPostProcessData* mpPostProcessData; /// Lift cycle managed elsewhere, no need to delete.
139 ScMyTables aTables;
141 std::vector<ScDocRowHeightUpdater::TabRanges> maRecalcRowRanges;
143 ScMyNamedExpressions m_aMyNamedExpressions;
144 SheetNamedExpMap m_SheetNamedExpressions;
146 ScMyLabelRanges maMyLabelRanges;
147 ScMyImportValidations maValidations;
148 std::unique_ptr<ScMyImpDetectiveOpArray> pDetectiveOpArray;
149 std::unique_ptr<SolarMutexGuard> pSolarMutexGuard;
151 std::unique_ptr<XMLNumberFormatAttributesExportHelper> pNumberFormatAttributesExportHelper;
152 std::unique_ptr<ScMyStyleNumberFormats> pStyleNumberFormats;
153 css::uno::Reference <css::util::XNumberFormats> xNumberFormats;
154 css::uno::Reference <css::util::XNumberFormatTypes> xNumberFormatTypes;
156 css::uno::Reference <css::sheet::XSheetCellRangeContainer> xSheetCellRanges;
158 OUString sPrevStyleName;
159 OUString sPrevCurrency;
160 sal_uInt32 nSolarMutexLocked;
161 sal_Int32 nProgressCount;
162 sal_Int16 nPrevCellType;
163 bool bLoadDoc; // Load doc or styles only
164 bool bNullDateSetted;
165 bool bSelfImportingXMLSet;
166 bool mbLockSolarMutex;
167 bool mbImportStyles;
168 bool mbHasNewCondFormatData;
170 protected:
172 // This method is called after the namespace map has been updated, but
173 // before a context for the current element has been pushed.
174 virtual SvXMLImportContext *CreateFastContext( sal_Int32 nElement,
175 const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList >& xAttrList ) override;
177 virtual XMLShapeImportHelper* CreateShapeImport() override;
179 public:
180 ScXMLImport(
181 const css::uno::Reference< css::uno::XComponentContext >& rContext,
182 OUString const & implementationName, SvXMLImportFlags nImportFlag,
183 const css::uno::Sequence< OUString > & sSupportedServiceNames = {});
185 virtual ~ScXMLImport() noexcept override;
187 // XInitialization
188 virtual void SAL_CALL initialize( const css::uno::Sequence<css::uno::Any>& aArguments ) override;
190 // namespace office
191 // NB: in contrast to other CreateFooContexts, this particular one handles
192 // the root element (i.e. office:document-meta)
193 SvXMLImportContext *CreateMetaContext( sal_Int32 nElement );
194 SvXMLImportContext *CreateFontDeclsContext();
195 SvXMLImportContext *CreateScriptContext();
196 SvXMLImportContext *CreateStylesContext( bool bAutoStyles );
198 SvXMLImportContext *CreateBodyContext(
199 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList );
201 virtual void SetStatistics( const css::uno::Sequence< css::beans::NamedValue> & i_rStats) override;
203 ScDocumentImport& GetDoc();
205 ScDocument* GetDocument() { return pDoc; }
206 const ScDocument* GetDocument() const { return pDoc; }
208 ScMyTables& GetTables() { return aTables; }
210 std::vector<ScDocRowHeightUpdater::TabRanges>& GetRecalcRowRanges() { return maRecalcRowRanges; }
212 bool IsStylesOnlyMode() const { return !bLoadDoc; }
214 static sal_Int16 GetCellType(const char* rStrValue, const sal_Int32 nStrLength);
216 const rtl::Reference < XMLPropertySetMapper >& GetCellStylesPropertySetMapper() const { return xCellStylesPropertySetMapper; }
217 const rtl::Reference < XMLPropertySetMapper >& GetColumnStylesPropertySetMapper() const { return xColumnStylesPropertySetMapper; }
218 const rtl::Reference < XMLPropertySetMapper >& GetRowStylesPropertySetMapper() const { return xRowStylesPropertySetMapper; }
219 const rtl::Reference < XMLPropertySetMapper >& GetTableStylesPropertySetMapper() const { return xTableStylesPropertySetMapper; }
221 void SetPostProcessData( sc::ImportPostProcessData* p );
222 sc::ImportPostProcessData* GetPostProcessData() { return mpPostProcessData;}
224 sc::PivotTableSources& GetPivotTableSources();
226 void AddNamedExpression(ScMyNamedExpression aMyNamedExpression)
228 m_aMyNamedExpressions.push_back(std::move(aMyNamedExpression));
231 void AddNamedExpression(SCTAB nTab, ScMyNamedExpression aNamedExp);
233 void AddLabelRange(ScMyLabelRange aMyLabelRange)
235 maMyLabelRanges.push_back(std::move(aMyLabelRange));
238 void AddValidation(const ScMyImportValidation& rValidation) { maValidations.push_back(rValidation); }
239 bool GetValidation(const OUString& sName, ScMyImportValidation& aValidation);
241 ScMyImpDetectiveOpArray* GetDetectiveOpArray();
243 ScXMLChangeTrackingImportHelper* GetChangeTrackingImportHelper();
244 void InsertStyles();
246 void SetChangeTrackingViewSettings(const css::uno::Sequence<css::beans::PropertyValue>& rChangeProps);
247 virtual void SetViewSettings(const css::uno::Sequence<css::beans::PropertyValue>& aViewProps) override;
248 virtual void SetConfigurationSettings(const css::uno::Sequence<css::beans::PropertyValue>& aConfigProps) override;
250 ScMyStylesImportHelper* GetStylesImportHelper() { return pStylesImportHelper.get(); }
251 sal_Int32 SetCurrencySymbol(const sal_Int32 nKey, std::u16string_view rCurrency);
252 bool IsCurrencySymbol(const sal_Int32 nNumberFormat, std::u16string_view sCurrencySymbol, std::u16string_view sBankSymbol);
253 void SetType(const css::uno::Reference <css::beans::XPropertySet>& rProperties,
254 sal_Int32& rNumberFormat,
255 const sal_Int16 nCellType,
256 std::u16string_view rCurrency);
258 void ProgressBarIncrement();
260 void SetNewCondFormatData() { mbHasNewCondFormatData = true; }
261 bool HasNewCondFormatData() const { return mbHasNewCondFormatData; }
263 private:
264 void SetStyleToRanges();
266 void ExamineDefaultStyle();
267 public:
268 void SetStyleToRanges(const ScRangeList& rRanges, const OUString* pStyleName,
269 const sal_Int16 nCellType, const OUString* pCurrency);
270 bool SetNullDateOnUnitConverter();
271 XMLNumberFormatAttributesExportHelper* GetNumberFormatAttributesExportHelper();
272 ScMyStyleNumberFormats* GetStyleNumberFormats();
274 void SetStylesToRangesFinished();
276 // XImporter
277 virtual void SAL_CALL setTargetDocument( const css::uno::Reference< css::lang::XComponent >& xDoc ) override;
279 virtual void SAL_CALL startDocument() override;
280 virtual void SAL_CALL endDocument() override;
282 virtual void DisposingModel() override;
285 * Use this class to manage solar mutex locking instead of calling
286 * LockSolarMutex() and UnlockSolarMutex() directly.
288 class MutexGuard
290 public:
291 explicit MutexGuard(ScXMLImport& rImport);
292 ~MutexGuard();
293 private:
294 ScXMLImport& mrImport;
296 void LockSolarMutex();
297 void UnlockSolarMutex();
299 sal_Int32 GetByteOffset() const;
301 void SetRangeOverflowType(ErrCode nType);
303 static sal_Int32 GetRangeType(std::u16string_view sRangeType);
304 void SetNamedRanges();
305 void SetSheetNamedRanges();
306 void SetLabelRanges();
307 void SetStringRefSyntaxIfMissing();
309 /** Extracts the formula string, the formula grammar namespace URL, and a
310 grammar enum value from the passed formula attribute value.
312 @param rFormula
313 (out-parameter) Returns the plain formula string with the leading
314 equality sign if existing.
316 @param rFormulaNmsp
317 (out-parameter) Returns the URL of the formula grammar namespace if
318 the attribute value contains the prefix of an unknown namespace.
320 @param reGrammar
321 (out-parameter) Returns the exact formula grammar if the formula
322 is in a supported ODF format (e.g. FormulaGrammar::GRAM_PODF for
323 ODF 1.0/1.1 formulas, or FormulaGrammar::GRAM_ODFF for ODF 1.2
324 formulas a.k.a. OpenFormula). Returns the default storage grammar,
325 if the attribute value does not contain a namespace prefix. Returns
326 the special value FormulaGrammar::GRAM_EXTERNAL, if an unknown
327 namespace could be extracted from the formula which will be
328 contained in the parameter rFormulaNmsp then.
330 @param rAttrValue
331 The value of the processed formula attribute.
333 @param bRestrictToExternalNmsp
334 If set to true, only namespaces of external formula grammars will
335 be recognized. Internal namespace prefixes (e.g. 'oooc:' or 'of:'
336 will be considered to be part of the formula, e.g. an expression
337 with range operator.
339 void ExtractFormulaNamespaceGrammar(
340 OUString& rFormula,
341 OUString& rFormulaNmsp,
342 ::formula::FormulaGrammar::Grammar& reGrammar,
343 const OUString& rAttrValue,
344 bool bRestrictToExternalNmsp = false ) const;
346 FormulaError GetFormulaErrorConstant( const OUString& rStr ) const;
348 ScEditEngineDefaulter* GetEditEngine();
349 const ScXMLEditAttributeMap& GetEditAttributeMap() const;
350 virtual void NotifyContainsEmbeddedFont() override;
353 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */