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
23 #include <rtl/ustring.hxx>
27 class SwTableSortBoxes
;
31 class SwTableFormulaUpdate
;
36 const SwTableBox
* pLastTableBox
;
37 sal_uInt16 nStackCnt
, nMaxSize
;
40 SwTableSortBoxes
*pBoxStk
; ///< stack for recognizing recursion
41 SwCalc
& rCalc
; ///< current Calculator
42 const SwTable
* pTable
; ///< current table
44 SwTableCalcPara( SwCalc
& rCalculator
, const SwTable
& rTable
);
47 bool CalcWithStackOverflow();
48 bool IsStackOverflow() const { return nMaxSize
== nStackCnt
; }
49 bool IncStackCnt() { return nMaxSize
== ++nStackCnt
; }
50 void DecStackCnt() { if( nStackCnt
) --nStackCnt
; }
51 void SetLastTableBox( const SwTableBox
* pBox
) { pLastTableBox
= pBox
; }
56 typedef void (SwTableFormula:: *FnScanFormula
)( const SwTable
&, OUString
&,
57 OUString
&, OUString
*, void* ) const;
59 void BoxNmsToPtr( const SwTable
&, OUString
&, OUString
&, OUString
* = 0,
60 void* pPara
= 0 ) const;
61 void PtrToBoxNms( const SwTable
&, OUString
&, OUString
&, OUString
* = 0,
62 void* pPara
= 0 ) const;
63 void RelNmsToBoxNms( const SwTable
&, OUString
&, OUString
&, OUString
* = 0,
64 void* pPara
= 0 ) const;
65 void RelBoxNmsToPtr( const SwTable
&, OUString
&, OUString
&, OUString
* = 0,
66 void* pPara
= 0 ) const;
67 void BoxNmsToRelNm( const SwTable
&, OUString
&, OUString
&, OUString
* = 0,
68 void* pPara
= 0 ) const;
69 void _MakeFormula( const SwTable
&, OUString
&, OUString
&, OUString
* = 0,
70 void* pPara
= 0 ) const;
71 void _GetFormulaBoxes( const SwTable
&, OUString
&, OUString
&, OUString
* = 0,
72 void* pPara
= 0 ) const;
73 void _HasValidBoxes( const SwTable
&, OUString
&, OUString
&, OUString
* = 0,
74 void* pPara
= 0 ) const;
75 void _SplitMergeBoxNm( const SwTable
&, OUString
&, OUString
&, OUString
* = 0,
76 void* pPara
= 0 ) const;
78 static void GetBoxes( const SwTableBox
& rStt
, const SwTableBox
& rEnd
,
80 OUString
ScanString( FnScanFormula fnFormula
, const SwTable
& rTable
,
83 static const SwTable
* FindTable( SwDoc
& rDoc
, const OUString
& rNm
);
86 enum NameType
{ EXTRNL_NAME
, INTRNL_NAME
, REL_NAME
};
88 OUString m_sFormula
; ///< current formula
89 NameType m_eNmType
; ///< current display method
90 bool m_bValidValue
; ///< true: recalculate formula
92 // find the node in which the formula is located
93 // TextFeld -> TextNode,
94 // BoxAttribut -> BoxStartNode
95 // !!! every derived class must override this !!!
96 virtual const SwNode
* GetNodeOfFormula() const = 0;
98 SwTableFormula( const OUString
& rFormula
);
100 OUString
MakeFormula( SwTableCalcPara
& rCalcPara
) const
102 return ScanString( &SwTableFormula::_MakeFormula
,
103 *rCalcPara
.pTable
, &rCalcPara
);
106 static sal_uInt16
GetLnPosInTable( const SwTable
& rTable
, const SwTableBox
* pBox
);
110 SwTableFormula( const SwTableFormula
& rCpy
) { *this = rCpy
; }
111 virtual ~SwTableFormula();
112 SwTableFormula
& operator=( const SwTableFormula
& rCpy
)
114 m_sFormula
= rCpy
.m_sFormula
;
115 m_eNmType
= rCpy
.m_eNmType
;
116 m_bValidValue
= rCpy
.m_bValidValue
;
120 /// create from the internal formula (for CORE) the external formula (for UI)
121 void PtrToBoxNm( const SwTable
* pTable
);
122 /// create from the external formula the internal
123 void BoxNmToPtr( const SwTable
* pTable
);
124 /// create from the external/internal formula the relative formula
125 void ToRelBoxNm( const SwTable
* pTable
);
126 /// gets called before/after merging/splitting of tables
127 void ToSplitMergeBoxNm( SwTableFormulaUpdate
& rTableUpd
);
129 bool IsIntrnlName() const { return m_eNmType
== INTRNL_NAME
; }
130 NameType
GetNameType() const { return m_eNmType
; }
132 bool IsValid() const { return m_bValidValue
; }
133 void ChgValid( bool bNew
) { m_bValidValue
= bNew
; }
135 OUString
GetFormula() const { return m_sFormula
; }
136 void SetFormula( const OUString
& rNew
)
139 m_eNmType
= EXTRNL_NAME
;
140 m_bValidValue
= false;
143 void GetBoxesOfFormula(const SwTable
& rTable
, SwSelBoxes
& rBoxes
);
144 // are all boxes valid which this formula relies on?
145 bool HasValidBoxes() const;
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */