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
26 #include <rtl/ustrbuf.hxx>
27 #include <rtl/ustring.hxx>
31 class SwTableSortBoxes
;
35 class SwTableFormulaUpdate
;
41 const SwTableBox
* m_pLastTableBox
;
42 sal_uInt16 m_nStackCount
, m_nMaxSize
;
45 SwRootFrame
const*const m_pLayout
; ///< layout to access text field results
46 std::unique_ptr
<SwTableSortBoxes
> m_pBoxStack
; ///< stack for recognizing recursion
47 SwCalc
& m_rCalc
; ///< current Calculator
48 const SwTable
* m_pTable
; ///< current table
50 SwTableCalcPara(SwCalc
& rCalculator
, const SwTable
& rTable
, SwRootFrame
const* pLayout
);
53 bool CalcWithStackOverflow();
54 bool IsStackOverflow() const { return m_nMaxSize
== m_nStackCount
; }
55 bool IncStackCnt() { return m_nMaxSize
== ++m_nStackCount
; }
56 void DecStackCnt() { if( m_nStackCount
) --m_nStackCount
; }
57 void SetLastTableBox( const SwTableBox
* pBox
) { m_pLastTableBox
= pBox
; }
60 class SW_DLLPUBLIC SwTableFormula
62 typedef void (SwTableFormula::*FnScanFormula
)( const SwTable
&, OUStringBuffer
&,
63 OUString
&, OUString
*, void* ) const;
65 void BoxNmsToPtr( const SwTable
&, OUStringBuffer
&, OUString
&, OUString
*,
67 void PtrToBoxNms( const SwTable
&, OUStringBuffer
&, OUString
&, OUString
*,
69 void RelNmsToBoxNms( const SwTable
&, OUStringBuffer
&, OUString
&, OUString
*,
71 void RelBoxNmsToPtr( const SwTable
&, OUStringBuffer
&, OUString
&, OUString
*,
73 void BoxNmsToRelNm( const SwTable
&, OUStringBuffer
&, OUString
&, OUString
*,
75 void MakeFormula_( const SwTable
&, OUStringBuffer
&, OUString
&, OUString
*,
77 void GetFormulaBoxes( const SwTable
&, OUStringBuffer
&, OUString
&, OUString
*,
79 void HasValidBoxes_( const SwTable
&, OUStringBuffer
&, OUString
&, OUString
*,
81 void SplitMergeBoxNm_( const SwTable
&, OUStringBuffer
&, OUString
&, OUString
*,
84 static void GetBoxes( const SwTableBox
& rStt
, const SwTableBox
& rEnd
,
86 OUString
ScanString( FnScanFormula fnFormula
, const SwTable
& rTable
,
89 static const SwTable
* FindTable( SwDoc
& rDoc
, std::u16string_view rNm
);
92 enum NameType
{ EXTRNL_NAME
, INTRNL_NAME
, REL_NAME
};
94 OUString m_sFormula
; ///< current formula
95 NameType m_eNmType
; ///< current display method
96 bool m_bValidValue
; ///< true: recalculate formula
98 // find the node in which the formula is located
99 // TextField -> TextNode,
100 // BoxAttribut -> BoxStartNode
101 // !!! every derived class must override this !!!
102 virtual const SwNode
* GetNodeOfFormula() const = 0;
104 SwTableFormula( OUString aFormula
);
106 OUString
MakeFormula( SwTableCalcPara
& rCalcPara
) const
108 return ScanString( &SwTableFormula::MakeFormula_
,
109 *rCalcPara
.m_pTable
, &rCalcPara
);
115 virtual ~SwTableFormula();
117 SwTableFormula(SwTableFormula
const &) = default;
118 SwTableFormula(SwTableFormula
&&) = default;
119 SwTableFormula
& operator =(SwTableFormula
const &) = default;
120 SwTableFormula
& operator =(SwTableFormula
&&) = default;
122 /// create from the internal formula (for CORE) the external formula (for UI)
123 void PtrToBoxNm( const SwTable
* pTable
);
124 /// create from the external formula the internal
125 void BoxNmToPtr( const SwTable
* pTable
);
126 /// create from the external/internal formula the relative formula
127 void ToRelBoxNm( const SwTable
* pTable
);
128 /// gets called before/after merging/splitting of tables
129 void ToSplitMergeBoxNm( SwTableFormulaUpdate
& rTableUpd
);
131 bool IsIntrnlName() const { return m_eNmType
== INTRNL_NAME
; }
132 NameType
GetNameType() const { return m_eNmType
; }
134 bool IsValid() const { return m_bValidValue
; }
135 void ChgValid( bool bNew
) { m_bValidValue
= bNew
; }
137 const OUString
& GetFormula() const { return m_sFormula
; }
138 void SetFormula( const OUString
& rNew
)
141 m_eNmType
= EXTRNL_NAME
;
142 m_bValidValue
= false;
145 void GetBoxesOfFormula(const SwTable
& rTable
, SwSelBoxes
& rBoxes
);
146 // are all boxes valid which this formula relies on?
147 bool HasValidBoxes() const;
148 static sal_uInt16
GetLnPosInTable( const SwTable
& rTable
, const SwTableBox
* pBox
);
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */