1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
24 #include <rtl/ustrbuf.hxx>
25 #include <rtl/ustring.hxx>
29 class SwTableSortBoxes
;
33 class SwTableFormulaUpdate
;
39 const SwTableBox
* m_pLastTableBox
;
40 sal_uInt16 m_nStackCount
, m_nMaxSize
;
43 SwRootFrame
const*const m_pLayout
; ///< layout to access text field results
44 std::unique_ptr
<SwTableSortBoxes
> m_pBoxStack
; ///< stack for recognizing recursion
45 SwCalc
& m_rCalc
; ///< current Calculator
46 const SwTable
* m_pTable
; ///< current table
48 SwTableCalcPara(SwCalc
& rCalculator
, const SwTable
& rTable
, SwRootFrame
const* pLayout
);
51 bool CalcWithStackOverflow();
52 bool IsStackOverflow() const { return m_nMaxSize
== m_nStackCount
; }
53 bool IncStackCnt() { return m_nMaxSize
== ++m_nStackCount
; }
54 void DecStackCnt() { if( m_nStackCount
) --m_nStackCount
; }
55 void SetLastTableBox( const SwTableBox
* pBox
) { m_pLastTableBox
= pBox
; }
58 class SAL_DLLPUBLIC_RTTI SwTableFormula
60 typedef void (SwTableFormula::*FnScanFormula
)( const SwTable
&, OUStringBuffer
&,
61 OUString
&, OUString
*, void* ) const;
63 void BoxNmsToPtr( const SwTable
&, OUStringBuffer
&, OUString
&, OUString
*,
65 void PtrToBoxNms( const SwTable
&, OUStringBuffer
&, OUString
&, OUString
*,
67 void RelNmsToBoxNms( const SwTable
&, OUStringBuffer
&, OUString
&, OUString
*,
69 void RelBoxNmsToPtr( const SwTable
&, OUStringBuffer
&, OUString
&, OUString
*,
71 void BoxNmsToRelNm( const SwTable
&, OUStringBuffer
&, OUString
&, OUString
*,
73 void MakeFormula_( const SwTable
&, OUStringBuffer
&, OUString
&, OUString
*,
75 void GetFormulaBoxes( const SwTable
&, OUStringBuffer
&, OUString
&, OUString
*,
77 void HasValidBoxes_( const SwTable
&, OUStringBuffer
&, OUString
&, OUString
*,
79 void SplitMergeBoxNm_( const SwTable
&, OUStringBuffer
&, OUString
&, OUString
*,
82 static void GetBoxes( const SwTableBox
& rStt
, const SwTableBox
& rEnd
,
84 OUString
ScanString( FnScanFormula fnFormula
, const SwTable
& rTable
,
87 static const SwTable
* FindTable( SwDoc
& rDoc
, const OUString
& rNm
);
90 enum NameType
{ EXTRNL_NAME
, INTRNL_NAME
, REL_NAME
};
92 OUString m_sFormula
; ///< current formula
93 NameType m_eNmType
; ///< current display method
94 bool m_bValidValue
; ///< true: recalculate formula
96 // find the node in which the formula is located
97 // TextField -> TextNode,
98 // BoxAttribut -> BoxStartNode
99 // !!! every derived class must override this !!!
100 virtual const SwNode
* GetNodeOfFormula() const = 0;
102 SwTableFormula( const OUString
& rFormula
);
104 OUString
MakeFormula( SwTableCalcPara
& rCalcPara
) const
106 return ScanString( &SwTableFormula::MakeFormula_
,
107 *rCalcPara
.m_pTable
, &rCalcPara
);
110 static sal_uInt16
GetLnPosInTable( const SwTable
& rTable
, const SwTableBox
* pBox
);
114 virtual ~SwTableFormula();
116 SwTableFormula(SwTableFormula
const &) = default;
117 SwTableFormula(SwTableFormula
&&) = default;
118 SwTableFormula
& operator =(SwTableFormula
const &) = default;
119 SwTableFormula
& operator =(SwTableFormula
&&) = default;
121 /// create from the internal formula (for CORE) the external formula (for UI)
122 SW_DLLPUBLIC
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
)
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;
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */