xref: /aoo41x/main/sw/inc/cellfml.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _CELLFML_HXX
29 #define _CELLFML_HXX
30 
31 #include <tools/string.hxx>
32 
33 class SwTable;
34 class SwNode;
35 class SwTableSortBoxes;
36 class SwSelBoxes;
37 class SwCalc;
38 class SwTableBox;
39 class SwTableFmlUpdate;
40 class SwDoc;
41 class String;
42 
43 class SwTblCalcPara
44 {
45 	const SwTableBox* pLastTblBox;
46 	sal_uInt16 nStackCnt, nMaxSize;
47 
48 public:
49 	SwTableSortBoxes *pBoxStk;	// Stack fuers erkennen von Rekursionen !
50 	SwCalc& rCalc;				// akt. Calculator
51 	const SwTable* pTbl;        // akt. Tabelle
52 
53 	SwTblCalcPara( SwCalc& rCalculator, const SwTable& rTable );
54 	~SwTblCalcPara();
55 
56 	sal_Bool CalcWithStackOverflow();
57 	sal_Bool IsStackOverFlow() const 		{ return nMaxSize == nStackCnt; }
58 	sal_Bool IncStackCnt() 					{ return nMaxSize == ++nStackCnt; }
59 	void DecStackCnt() 					{ if( nStackCnt ) --nStackCnt; }
60 	void SetLastTblBox( const SwTableBox* pBox )	{ pLastTblBox = pBox; }
61 };
62 
63 
64 
65 class SwTableFormula
66 {
67 typedef void (SwTableFormula:: *FnScanFormel)( const SwTable&, String&,
68 											String&, String*, void* ) const;
69 
70 	void BoxNmsToPtr( const SwTable&, String&, String&, String* = 0,
71 						void* pPara = 0 ) const;
72 	void PtrToBoxNms( const SwTable&, String&, String&, String* = 0,
73 						void* pPara = 0 ) const;
74 	void RelNmsToBoxNms( const SwTable&, String&, String&, String* = 0,
75 						void* pPara = 0 ) const;
76 	void RelBoxNmsToPtr( const SwTable&, String&, String&, String* = 0,
77 						void* pPara = 0 ) const;
78 	void BoxNmsToRelNm( const SwTable&, String&, String&, String* = 0,
79 						void* pPara = 0 ) const;
80 	void _MakeFormel( const SwTable&, String&, String&, String* = 0,
81 						void* pPara = 0 ) const;
82 	void _GetFmlBoxes( const SwTable&, String&, String&, String* = 0,
83 						void* pPara = 0 ) const;
84 	void _HasValidBoxes( const SwTable&, String&, String&, String* = 0,
85 						void* pPara = 0 ) const;
86 	void _SplitMergeBoxNm( const SwTable&, String&, String&, String* = 0,
87 						void* pPara = 0 ) const;
88 
89 	void GetBoxes( const SwTableBox& rStt, const SwTableBox& rEnd,
90 					SwSelBoxes& rBoxes ) const;
91 	String ScanString( FnScanFormel fnFormel, const SwTable& rTbl,
92 						void* = 0 ) const;
93 
94 	const SwTable* FindTable( SwDoc& rDoc, const String& rNm ) const;
95 
96 protected:
97 	enum NameType { EXTRNL_NAME, INTRNL_NAME, REL_NAME };
98 
99 	String 		sFormel;			// akt. Formel
100 	NameType 	eNmType;			// akt. Darstellungs Art
101 	sal_Bool 		bValidValue;		// sal_True: Formel neu berechnen
102 
103 	// suche den Node, in dem die Formel steht:
104 	//	TextFeld	-> TextNode,
105 	//	BoxAttribut	-> BoxStartNode
106 	// !!! MUSS VON JEDER ABLEITUNG UEBERLADEN WERDEN !!!
107 	virtual const SwNode* GetNodeOfFormula() const = 0;
108 
109 	SwTableFormula( const String& rFormel );
110 
111 	String MakeFormel( SwTblCalcPara& rCalcPara ) const
112 	{
113 		return ScanString( &SwTableFormula::_MakeFormel,
114 							*rCalcPara.pTbl, &rCalcPara );
115 	}
116 
117 	static sal_uInt16 GetLnPosInTbl( const SwTable& rTbl, const SwTableBox* pBox );
118 
119 public:
120 
121 	SwTableFormula( const SwTableFormula& rCpy )	{ *this = rCpy; }
122 	virtual ~SwTableFormula();
123 	SwTableFormula& operator=( const SwTableFormula& rCpy )
124 		{
125 									sFormel = rCpy.sFormel;
126 									eNmType = rCpy.eNmType;
127 									bValidValue = rCpy.bValidValue;
128 									return *this;
129 		}
130 
131 	// erzeuge aus der internen (fuer CORE) die externe (fuer UI) Formel
132 	void PtrToBoxNm( const SwTable* pTbl );
133 	// erzeuge aus der externen (fuer UI) die interne (fuer CORE) Formel
134 	void BoxNmToPtr( const SwTable* pTbl );
135 	// erzeuge aus der externen/internen Formel die relative Formel
136 	void ToRelBoxNm( const SwTable* pTbl );
137 	// wird vorm/nach dem mergen/splitten von Tabellen rerufen
138 	void ToSplitMergeBoxNm( SwTableFmlUpdate& rTblUpd );
139 
140 	// ist gerade eine intern Darstellung aktiv
141 	sal_Bool IsIntrnlName() const			{ return eNmType == INTRNL_NAME; }
142 	// erfrage die akt. Darstellung der Formel
143 	NameType GetNameType() const		{ return eNmType; }
144 
145 	// erfrage/setze das Flag, ob der akt. Wert gueltig ist
146 	sal_Bool 		IsValid() const				{ return bValidValue; }
147 	inline void	ChgValid( sal_Bool bNew )		{ bValidValue = bNew; }
148 
149 	const String& GetFormula() const 		{ return sFormel; }
150 	void SetFormula( const String& rNew )
151 		{
152 			sFormel = rNew;
153 			bValidValue = sal_False;
154 			eNmType = EXTRNL_NAME;
155 		}
156 
157 	sal_uInt16 GetBoxesOfFormula( const SwTable& rTbl, SwSelBoxes& rBoxes );
158 	// sind alle Boxen gueltig, auf die sich die Formel bezieht?
159 	sal_Bool HasValidBoxes() const;
160 };
161 
162 
163 
164 #endif
165