update credits
[LibreOffice.git] / sw / inc / cellfml.hxx
blob301c9082210089e5d8bb500e45f487e656c63376
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 _CELLFML_HXX
21 #define _CELLFML_HXX
23 #include <tools/string.hxx>
25 class SwTable;
26 class SwNode;
27 class SwTableSortBoxes;
28 class SwSelBoxes;
29 class SwCalc;
30 class SwTableBox;
31 class SwTableFmlUpdate;
32 class SwDoc;
33 class String;
35 class SwTblCalcPara
37 const SwTableBox* pLastTblBox;
38 sal_uInt16 nStackCnt, nMaxSize;
40 public:
41 SwTableSortBoxes *pBoxStk; ///< stack for recognizing recursion
42 SwCalc& rCalc; ///< current Calculator
43 const SwTable* pTbl; ///< current table
45 SwTblCalcPara( SwCalc& rCalculator, const SwTable& rTable );
46 ~SwTblCalcPara();
48 sal_Bool CalcWithStackOverflow();
49 sal_Bool IsStackOverFlow() const { return nMaxSize == nStackCnt; }
50 sal_Bool IncStackCnt() { return nMaxSize == ++nStackCnt; }
51 void DecStackCnt() { if( nStackCnt ) --nStackCnt; }
52 void SetLastTblBox( const SwTableBox* pBox ) { pLastTblBox = pBox; }
57 class SwTableFormula
59 typedef void (SwTableFormula:: *FnScanFormel)( const SwTable&, String&,
60 String&, String*, void* ) const;
62 void BoxNmsToPtr( const SwTable&, String&, String&, String* = 0,
63 void* pPara = 0 ) const;
64 void PtrToBoxNms( const SwTable&, String&, String&, String* = 0,
65 void* pPara = 0 ) const;
66 void RelNmsToBoxNms( const SwTable&, String&, String&, String* = 0,
67 void* pPara = 0 ) const;
68 void RelBoxNmsToPtr( const SwTable&, String&, String&, String* = 0,
69 void* pPara = 0 ) const;
70 void BoxNmsToRelNm( const SwTable&, String&, String&, String* = 0,
71 void* pPara = 0 ) const;
72 void _MakeFormula( const SwTable&, String&, String&, String* = 0,
73 void* pPara = 0 ) const;
74 void _GetFmlBoxes( const SwTable&, String&, String&, String* = 0,
75 void* pPara = 0 ) const;
76 void _HasValidBoxes( const SwTable&, String&, String&, String* = 0,
77 void* pPara = 0 ) const;
78 void _SplitMergeBoxNm( const SwTable&, String&, String&, String* = 0,
79 void* pPara = 0 ) const;
81 void GetBoxes( const SwTableBox& rStt, const SwTableBox& rEnd,
82 SwSelBoxes& rBoxes ) const;
83 String ScanString( FnScanFormel fnFormel, const SwTable& rTbl,
84 void* = 0 ) const;
86 const SwTable* FindTable( SwDoc& rDoc, const String& rNm ) const;
88 protected:
89 enum NameType { EXTRNL_NAME, INTRNL_NAME, REL_NAME };
91 String sFormel; ///< current formula
92 NameType eNmType; ///< current display method
93 bool bValidValue; ///< true: recalculate formula
95 // find the node in which the formula is located
96 // TextFeld -> TextNode,
97 // BoxAttribut -> BoxStartNode
98 // !!! has to be overloaded by every derivation !!!
99 virtual const SwNode* GetNodeOfFormula() const = 0;
101 SwTableFormula( const String& rFormel );
103 String MakeFormula( SwTblCalcPara& rCalcPara ) const
105 return ScanString( &SwTableFormula::_MakeFormula,
106 *rCalcPara.pTbl, &rCalcPara );
109 static sal_uInt16 GetLnPosInTbl( const SwTable& rTbl, const SwTableBox* pBox );
111 public:
113 SwTableFormula( const SwTableFormula& rCpy ) { *this = rCpy; }
114 virtual ~SwTableFormula();
115 SwTableFormula& operator=( const SwTableFormula& rCpy )
117 sFormel = rCpy.sFormel;
118 eNmType = rCpy.eNmType;
119 bValidValue = rCpy.bValidValue;
120 return *this;
123 /// create from the internal formula (for CORE) the external formula (for UI)
124 void PtrToBoxNm( const SwTable* pTbl );
125 /// create from the external formula the internal
126 void BoxNmToPtr( const SwTable* pTbl );
127 /// create from the external/internal formula the relative formula
128 void ToRelBoxNm( const SwTable* pTbl );
129 /// gets called before/after merging/splitting of tables
130 void ToSplitMergeBoxNm( SwTableFmlUpdate& rTblUpd );
132 bool IsIntrnlName() const { return eNmType == INTRNL_NAME; }
133 NameType GetNameType() const { return eNmType; }
135 bool IsValid() const { return bValidValue; }
136 inline void ChgValid( bool bNew ) { bValidValue = bNew; }
138 const String& GetFormula() const { return sFormel; }
139 void SetFormula( const String& rNew )
141 sFormel = rNew;
142 bValidValue = false;
143 eNmType = EXTRNL_NAME;
146 void GetBoxesOfFormula(const SwTable& rTbl, SwSelBoxes& rBoxes);
147 // are all boxes valid which this formula relies on?
148 bool HasValidBoxes() const;
153 #endif
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */