Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / sw / inc / cellfml.hxx
blob6492095e7c06ad3a6b2324573ed2b6a60a896971
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_SW_INC_CELLFML_HXX
21 #define INCLUDED_SW_INC_CELLFML_HXX
23 #include <memory>
24 #include <rtl/ustring.hxx>
26 class SwTable;
27 class SwNode;
28 class SwTableSortBoxes;
29 class SwSelBoxes;
30 class SwCalc;
31 class SwTableBox;
32 class SwTableFormulaUpdate;
33 class SwDoc;
35 class SwTableCalcPara
37 const SwTableBox* pLastTableBox;
38 sal_uInt16 nStackCnt, nMaxSize;
40 public:
41 std::unique_ptr<SwTableSortBoxes> pBoxStack; ///< stack for recognizing recursion
42 SwCalc& rCalc; ///< current Calculator
43 const SwTable* pTable; ///< current table
45 SwTableCalcPara( SwCalc& rCalculator, const SwTable& rTable );
46 ~SwTableCalcPara();
48 bool CalcWithStackOverflow();
49 bool IsStackOverflow() const { return nMaxSize == nStackCnt; }
50 bool IncStackCnt() { return nMaxSize == ++nStackCnt; }
51 void DecStackCnt() { if( nStackCnt ) --nStackCnt; }
52 void SetLastTableBox( const SwTableBox* pBox ) { pLastTableBox = pBox; }
55 class SwTableFormula
57 typedef void (SwTableFormula:: *FnScanFormula)( const SwTable&, OUString&,
58 OUString&, OUString*, void* ) const;
60 void BoxNmsToPtr( const SwTable&, OUString&, OUString&, OUString*,
61 void* pPara = nullptr ) const;
62 void PtrToBoxNms( const SwTable&, OUString&, OUString&, OUString*,
63 void* pPara = nullptr ) const;
64 void RelNmsToBoxNms( const SwTable&, OUString&, OUString&, OUString*,
65 void* pPara = nullptr ) const;
66 void RelBoxNmsToPtr( const SwTable&, OUString&, OUString&, OUString*,
67 void* pPara = nullptr ) const;
68 void BoxNmsToRelNm( const SwTable&, OUString&, OUString&, OUString*,
69 void* pPara = nullptr ) const;
70 void MakeFormula_( const SwTable&, OUString&, OUString&, OUString*,
71 void* pPara = nullptr ) const;
72 void GetFormulaBoxes( const SwTable&, OUString&, OUString&, OUString*,
73 void* pPara = nullptr ) const;
74 void HasValidBoxes_( const SwTable&, OUString&, OUString&, OUString*,
75 void* pPara = nullptr ) const;
76 void SplitMergeBoxNm_( const SwTable&, OUString&, OUString&, OUString*,
77 void* pPara = nullptr ) const;
79 static void GetBoxes( const SwTableBox& rStt, const SwTableBox& rEnd,
80 SwSelBoxes& rBoxes );
81 OUString ScanString( FnScanFormula fnFormula, const SwTable& rTable,
82 void*) const;
84 static const SwTable* FindTable( SwDoc& rDoc, const OUString& rNm );
86 protected:
87 enum NameType { EXTRNL_NAME, INTRNL_NAME, REL_NAME };
89 OUString m_sFormula; ///< current formula
90 NameType m_eNmType; ///< current display method
91 bool m_bValidValue; ///< true: recalculate formula
93 // find the node in which the formula is located
94 // TextFeld -> TextNode,
95 // BoxAttribut -> BoxStartNode
96 // !!! every derived class must override this !!!
97 virtual const SwNode* GetNodeOfFormula() const = 0;
99 SwTableFormula( const OUString& rFormula );
101 OUString MakeFormula( SwTableCalcPara& rCalcPara ) const
103 return ScanString( &SwTableFormula::MakeFormula_,
104 *rCalcPara.pTable, &rCalcPara );
107 static sal_uInt16 GetLnPosInTable( const SwTable& rTable, const SwTableBox* pBox );
109 public:
111 SwTableFormula( const SwTableFormula& rCpy ) { *this = rCpy; }
112 virtual ~SwTableFormula();
113 SwTableFormula& operator=( const SwTableFormula& rCpy )
115 m_sFormula = rCpy.m_sFormula;
116 m_eNmType = rCpy.m_eNmType;
117 m_bValidValue = rCpy.m_bValidValue;
118 return *this;
121 /// create from the internal formula (for CORE) the external formula (for UI)
122 void PtrToBoxNm( const SwTable* pTable );
123 /// create from the external formula the internal
124 void BoxNmToPtr( const SwTable* pTable );
125 /// create from the external/internal formula the relative formula
126 void ToRelBoxNm( const SwTable* pTable );
127 /// gets called before/after merging/splitting of tables
128 void ToSplitMergeBoxNm( SwTableFormulaUpdate& rTableUpd );
130 bool IsIntrnlName() const { return m_eNmType == INTRNL_NAME; }
131 NameType GetNameType() const { return m_eNmType; }
133 bool IsValid() const { return m_bValidValue; }
134 void ChgValid( bool bNew ) { m_bValidValue = bNew; }
136 const OUString& GetFormula() const { return m_sFormula; }
137 void SetFormula( const OUString& rNew )
139 m_sFormula = rNew;
140 m_eNmType = EXTRNL_NAME;
141 m_bValidValue = false;
144 void GetBoxesOfFormula(const SwTable& rTable, SwSelBoxes& rBoxes);
145 // are all boxes valid which this formula relies on?
146 bool HasValidBoxes() const;
149 #endif
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */