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