xref: /aoo41x/main/sw/inc/cellfml.hxx (revision 1d2dbeb0)
1*1d2dbeb0SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*1d2dbeb0SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*1d2dbeb0SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*1d2dbeb0SAndrew Rist  * distributed with this work for additional information
6*1d2dbeb0SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*1d2dbeb0SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*1d2dbeb0SAndrew Rist  * "License"); you may not use this file except in compliance
9*1d2dbeb0SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*1d2dbeb0SAndrew Rist  *
11*1d2dbeb0SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*1d2dbeb0SAndrew Rist  *
13*1d2dbeb0SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*1d2dbeb0SAndrew Rist  * software distributed under the License is distributed on an
15*1d2dbeb0SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*1d2dbeb0SAndrew Rist  * KIND, either express or implied.  See the License for the
17*1d2dbeb0SAndrew Rist  * specific language governing permissions and limitations
18*1d2dbeb0SAndrew Rist  * under the License.
19*1d2dbeb0SAndrew Rist  *
20*1d2dbeb0SAndrew Rist  *************************************************************/
21*1d2dbeb0SAndrew Rist 
22*1d2dbeb0SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _CELLFML_HXX
25cdf0e10cSrcweir #define _CELLFML_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <tools/string.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir class SwTable;
30cdf0e10cSrcweir class SwNode;
31cdf0e10cSrcweir class SwTableSortBoxes;
32cdf0e10cSrcweir class SwSelBoxes;
33cdf0e10cSrcweir class SwCalc;
34cdf0e10cSrcweir class SwTableBox;
35cdf0e10cSrcweir class SwTableFmlUpdate;
36cdf0e10cSrcweir class SwDoc;
37cdf0e10cSrcweir class String;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir class SwTblCalcPara
40cdf0e10cSrcweir {
41cdf0e10cSrcweir 	const SwTableBox* pLastTblBox;
42cdf0e10cSrcweir 	sal_uInt16 nStackCnt, nMaxSize;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir public:
45cdf0e10cSrcweir 	SwTableSortBoxes *pBoxStk;	// Stack fuers erkennen von Rekursionen !
46cdf0e10cSrcweir 	SwCalc& rCalc;				// akt. Calculator
47cdf0e10cSrcweir 	const SwTable* pTbl;        // akt. Tabelle
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 	SwTblCalcPara( SwCalc& rCalculator, const SwTable& rTable );
50cdf0e10cSrcweir 	~SwTblCalcPara();
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 	sal_Bool CalcWithStackOverflow();
IsStackOverFlow() const53cdf0e10cSrcweir 	sal_Bool IsStackOverFlow() const 		{ return nMaxSize == nStackCnt; }
IncStackCnt()54cdf0e10cSrcweir 	sal_Bool IncStackCnt() 					{ return nMaxSize == ++nStackCnt; }
DecStackCnt()55cdf0e10cSrcweir 	void DecStackCnt() 					{ if( nStackCnt ) --nStackCnt; }
SetLastTblBox(const SwTableBox * pBox)56cdf0e10cSrcweir 	void SetLastTblBox( const SwTableBox* pBox )	{ pLastTblBox = pBox; }
57cdf0e10cSrcweir };
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 
61cdf0e10cSrcweir class SwTableFormula
62cdf0e10cSrcweir {
63cdf0e10cSrcweir typedef void (SwTableFormula:: *FnScanFormel)( const SwTable&, String&,
64cdf0e10cSrcweir 											String&, String*, void* ) const;
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 	void BoxNmsToPtr( const SwTable&, String&, String&, String* = 0,
67cdf0e10cSrcweir 						void* pPara = 0 ) const;
68cdf0e10cSrcweir 	void PtrToBoxNms( const SwTable&, String&, String&, String* = 0,
69cdf0e10cSrcweir 						void* pPara = 0 ) const;
70cdf0e10cSrcweir 	void RelNmsToBoxNms( const SwTable&, String&, String&, String* = 0,
71cdf0e10cSrcweir 						void* pPara = 0 ) const;
72cdf0e10cSrcweir 	void RelBoxNmsToPtr( const SwTable&, String&, String&, String* = 0,
73cdf0e10cSrcweir 						void* pPara = 0 ) const;
74cdf0e10cSrcweir 	void BoxNmsToRelNm( const SwTable&, String&, String&, String* = 0,
75cdf0e10cSrcweir 						void* pPara = 0 ) const;
76cdf0e10cSrcweir 	void _MakeFormel( const SwTable&, String&, String&, String* = 0,
77cdf0e10cSrcweir 						void* pPara = 0 ) const;
78cdf0e10cSrcweir 	void _GetFmlBoxes( const SwTable&, String&, String&, String* = 0,
79cdf0e10cSrcweir 						void* pPara = 0 ) const;
80cdf0e10cSrcweir 	void _HasValidBoxes( const SwTable&, String&, String&, String* = 0,
81cdf0e10cSrcweir 						void* pPara = 0 ) const;
82cdf0e10cSrcweir 	void _SplitMergeBoxNm( const SwTable&, String&, String&, String* = 0,
83cdf0e10cSrcweir 						void* pPara = 0 ) const;
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 	void GetBoxes( const SwTableBox& rStt, const SwTableBox& rEnd,
86cdf0e10cSrcweir 					SwSelBoxes& rBoxes ) const;
87cdf0e10cSrcweir 	String ScanString( FnScanFormel fnFormel, const SwTable& rTbl,
88cdf0e10cSrcweir 						void* = 0 ) const;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 	const SwTable* FindTable( SwDoc& rDoc, const String& rNm ) const;
91cdf0e10cSrcweir 
92cdf0e10cSrcweir protected:
93cdf0e10cSrcweir 	enum NameType { EXTRNL_NAME, INTRNL_NAME, REL_NAME };
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 	String 		sFormel;			// akt. Formel
96cdf0e10cSrcweir 	NameType 	eNmType;			// akt. Darstellungs Art
97cdf0e10cSrcweir 	sal_Bool 		bValidValue;		// sal_True: Formel neu berechnen
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 	// suche den Node, in dem die Formel steht:
100cdf0e10cSrcweir 	//	TextFeld	-> TextNode,
101cdf0e10cSrcweir 	//	BoxAttribut	-> BoxStartNode
102cdf0e10cSrcweir 	// !!! MUSS VON JEDER ABLEITUNG UEBERLADEN WERDEN !!!
103cdf0e10cSrcweir 	virtual const SwNode* GetNodeOfFormula() const = 0;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 	SwTableFormula( const String& rFormel );
106cdf0e10cSrcweir 
MakeFormel(SwTblCalcPara & rCalcPara) const107cdf0e10cSrcweir 	String MakeFormel( SwTblCalcPara& rCalcPara ) const
108cdf0e10cSrcweir 	{
109cdf0e10cSrcweir 		return ScanString( &SwTableFormula::_MakeFormel,
110cdf0e10cSrcweir 							*rCalcPara.pTbl, &rCalcPara );
111cdf0e10cSrcweir 	}
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 	static sal_uInt16 GetLnPosInTbl( const SwTable& rTbl, const SwTableBox* pBox );
114cdf0e10cSrcweir 
115cdf0e10cSrcweir public:
116cdf0e10cSrcweir 
SwTableFormula(const SwTableFormula & rCpy)117cdf0e10cSrcweir 	SwTableFormula( const SwTableFormula& rCpy )	{ *this = rCpy; }
118cdf0e10cSrcweir 	virtual ~SwTableFormula();
operator =(const SwTableFormula & rCpy)119cdf0e10cSrcweir 	SwTableFormula& operator=( const SwTableFormula& rCpy )
120cdf0e10cSrcweir 		{
121cdf0e10cSrcweir 									sFormel = rCpy.sFormel;
122cdf0e10cSrcweir 									eNmType = rCpy.eNmType;
123cdf0e10cSrcweir 									bValidValue = rCpy.bValidValue;
124cdf0e10cSrcweir 									return *this;
125cdf0e10cSrcweir 		}
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	// erzeuge aus der internen (fuer CORE) die externe (fuer UI) Formel
128cdf0e10cSrcweir 	void PtrToBoxNm( const SwTable* pTbl );
129cdf0e10cSrcweir 	// erzeuge aus der externen (fuer UI) die interne (fuer CORE) Formel
130cdf0e10cSrcweir 	void BoxNmToPtr( const SwTable* pTbl );
131cdf0e10cSrcweir 	// erzeuge aus der externen/internen Formel die relative Formel
132cdf0e10cSrcweir 	void ToRelBoxNm( const SwTable* pTbl );
133cdf0e10cSrcweir 	// wird vorm/nach dem mergen/splitten von Tabellen rerufen
134cdf0e10cSrcweir 	void ToSplitMergeBoxNm( SwTableFmlUpdate& rTblUpd );
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 	// ist gerade eine intern Darstellung aktiv
IsIntrnlName() const137cdf0e10cSrcweir 	sal_Bool IsIntrnlName() const			{ return eNmType == INTRNL_NAME; }
138cdf0e10cSrcweir 	// erfrage die akt. Darstellung der Formel
GetNameType() const139cdf0e10cSrcweir 	NameType GetNameType() const		{ return eNmType; }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 	// erfrage/setze das Flag, ob der akt. Wert gueltig ist
IsValid() const142cdf0e10cSrcweir 	sal_Bool 		IsValid() const				{ return bValidValue; }
ChgValid(sal_Bool bNew)143cdf0e10cSrcweir 	inline void	ChgValid( sal_Bool bNew )		{ bValidValue = bNew; }
144cdf0e10cSrcweir 
GetFormula() const145cdf0e10cSrcweir 	const String& GetFormula() const 		{ return sFormel; }
SetFormula(const String & rNew)146cdf0e10cSrcweir 	void SetFormula( const String& rNew )
147cdf0e10cSrcweir 		{
148cdf0e10cSrcweir 			sFormel = rNew;
149cdf0e10cSrcweir 			bValidValue = sal_False;
150cdf0e10cSrcweir 			eNmType = EXTRNL_NAME;
151cdf0e10cSrcweir 		}
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 	sal_uInt16 GetBoxesOfFormula( const SwTable& rTbl, SwSelBoxes& rBoxes );
154cdf0e10cSrcweir 	// sind alle Boxen gueltig, auf die sich die Formel bezieht?
155cdf0e10cSrcweir 	sal_Bool HasValidBoxes() const;
156cdf0e10cSrcweir };
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 
160cdf0e10cSrcweir #endif
161