1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 #pragma once
20 
21 #include "XMLDetectiveContext.hxx"
22 #include "importcontext.hxx"
23 #include <formula/grammar.hxx>
24 #include <svl/itemset.hxx>
25 #include <editeng/editdata.hxx>
26 
27 #include <optional>
28 #include <memory>
29 #include <vector>
30 
31 class ScXMLImport;
32 class ScFormulaCell;
33 class ScEditEngineDefaulter;
34 class SvxFieldData;
35 struct ScXMLAnnotationData;
36 struct ScMyImpCellRangeSource;
37 
38 class ScXMLTableRowCellContext : public ScXMLImportContext
39 {
40     struct ParaFormat
41     {
42         SfxItemSet maItemSet;
43         ESelection maSelection;
44 
45         explicit ParaFormat(const ScEditEngineDefaulter& rEditEngine);
46     };
47 
48     struct Field
49     {
50         std::unique_ptr<SvxFieldData> mpData;
51         ESelection maSelection;
52 
53         Field(const Field&) = delete;
54         const Field& operator=(const Field&) = delete;
55 
56         explicit Field(std::unique_ptr<SvxFieldData> pData);
57         ~Field();
58     };
59 
60     typedef std::vector<std::unique_ptr<Field> > FieldsType;
61     typedef std::pair<OUString, OUString> FormulaWithNamespace;
62 
63     std::optional<FormulaWithNamespace> maFormula; /// table:formula attribute
64     std::optional<OUString> maStringValue;         /// office:string-value attribute
65     std::optional<OUString> maContentValidationName;
66     std::optional<OUString> maFirstParagraph; /// unformatted first paragraph, for better performance.
67 
68     ScEditEngineDefaulter* mpEditEngine;
69     OUStringBuffer maParagraph{32};
70     sal_Int32 mnCurParagraph;
71 
72     std::vector<std::unique_ptr<ParaFormat> > maFormats;
73     FieldsType maFields;
74 
75     std::unique_ptr< ScXMLAnnotationData > mxAnnotationData;
76     std::unique_ptr< ScMyImpDetectiveObjVec > pDetectiveObjVec;
77     std::unique_ptr< ScMyImpCellRangeSource > pCellRangeSource;
78     double      fValue;
79     SCROW       nMergedRows, nMatrixRows, nRepeatedRows;
80     SCCOL       nMergedCols, nMatrixCols, nColsRepeated;
81     ScXMLImport& rXMLImport;
82     formula::FormulaGrammar::Grammar  eGrammar;
83     sal_Int16   nCellType;
84     bool        bIsMerged;
85     bool        bIsMatrix;
86     bool        bIsCovered;
87     bool        bIsEmpty;
88     bool        mbNewValueType;
89     bool        mbErrorValue;
90     bool        bSolarMutexLocked;
91     bool        bFormulaTextResult;
92     bool mbPossibleErrorCell;
93     bool mbCheckWithCompilerForError;
94     bool mbEditEngineHasText;
95     bool mbHasFormatRuns;
96     bool mbHasStyle;
97     bool mbPossibleEmptyDisplay;
98 
99     void DoMerge(const ScAddress& rScCellPos, const SCCOL nCols, const SCROW nRows);
100 
101     void SetContentValidation( const ScRange& rScRange );
102     void SetContentValidation( const ScAddress& rScCellPos );
103 
104     void LockSolarMutex();
105 
106     bool CellsAreRepeated() const;
107 
108     void SetFormulaCell             ( ScFormulaCell* pFCell ) const;
109     void PutTextCell                ( const ScAddress& rScCurrentPos, const SCCOL nCurrentCol,
110                                       const ::std::optional< OUString >& pOUText );
111     void PutValueCell               ( const ScAddress& rScCurrentPos );
112     void AddTextAndValueCell       ( const ScAddress& rScCellPos,
113                                       const ::std::optional< OUString >& pOUText, ScAddress& rScCurrentPos );
114     void AddNonFormulaCell         ( const ScAddress& rScCellPos );
115     void PutFormulaCell             ( const ScAddress& rScCurrentPos );
116     void AddFormulaCell             ( const ScAddress& rScCellPos );
117 
118     void HasSpecialCaseFormulaText();
119 
120     bool IsPossibleErrorString() const;
121 
122     void PushParagraphField(std::unique_ptr<SvxFieldData> pData, const OUString& rStyleName);
123 
124     void PushFormat(sal_Int32 nBegin, sal_Int32 nEnd, const OUString& rStyleName);
125 
126     OUString GetFirstParagraph() const;
127 
128 public:
129 
130     ScXMLTableRowCellContext( ScXMLImport& rImport,
131                        const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
132                        const bool bIsCovered, const sal_Int32 nRepeatedRows );
133 
134     virtual ~ScXMLTableRowCellContext() override;
135 
136     virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
137         sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
138 
139     void PushParagraphSpan(const OUString& rSpan, const OUString& rStyleName);
140     void PushParagraphFieldDate(const OUString& rStyleName);
141     void PushParagraphFieldSheetName(const OUString& rStyleName);
142     void PushParagraphFieldDocTitle(const OUString& rStyleName);
143     void PushParagraphFieldURL(const OUString& rURL, const OUString& rRep, const OUString& rStyleName, const OUString& rTargetFrame);
144     void PushParagraphEnd();
145 
146     void SetAnnotation( const ScAddress& rPosition );
147     void SetDetectiveObj( const ScAddress& rPosition );
148     void SetCellRangeSource( const ScAddress& rPosition );
149 
150     virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
151 };
152 
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
154