1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cellfml.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
34 #include <tools/string.hxx>
38 class SwTableSortBoxes
;
42 class SwTableFmlUpdate
;
48 const SwTableBox
* pLastTblBox
;
49 USHORT nStackCnt
, nMaxSize
;
52 SwTableSortBoxes
*pBoxStk
; // Stack fuers erkennen von Rekursionen !
53 SwCalc
& rCalc
; // akt. Calculator
54 const SwTable
* pTbl
; // akt. Tabelle
56 SwTblCalcPara( SwCalc
& rCalculator
, const SwTable
& rTable
);
59 BOOL
CalcWithStackOverflow();
60 BOOL
IsStackOverFlow() const { return nMaxSize
== nStackCnt
; }
61 BOOL
IncStackCnt() { return nMaxSize
== ++nStackCnt
; }
62 void DecStackCnt() { if( nStackCnt
) --nStackCnt
; }
63 void SetLastTblBox( const SwTableBox
* pBox
) { pLastTblBox
= pBox
; }
70 typedef void (SwTableFormula:: *FnScanFormel
)( const SwTable
&, String
&,
71 String
&, String
*, void* ) const;
73 void BoxNmsToPtr( const SwTable
&, String
&, String
&, String
* = 0,
74 void* pPara
= 0 ) const;
75 void PtrToBoxNms( const SwTable
&, String
&, String
&, String
* = 0,
76 void* pPara
= 0 ) const;
77 void RelNmsToBoxNms( const SwTable
&, String
&, String
&, String
* = 0,
78 void* pPara
= 0 ) const;
79 void RelBoxNmsToPtr( const SwTable
&, String
&, String
&, String
* = 0,
80 void* pPara
= 0 ) const;
81 void BoxNmsToRelNm( const SwTable
&, String
&, String
&, String
* = 0,
82 void* pPara
= 0 ) const;
83 void _MakeFormel( const SwTable
&, String
&, String
&, String
* = 0,
84 void* pPara
= 0 ) const;
85 void _GetFmlBoxes( const SwTable
&, String
&, String
&, String
* = 0,
86 void* pPara
= 0 ) const;
87 void _HasValidBoxes( const SwTable
&, String
&, String
&, String
* = 0,
88 void* pPara
= 0 ) const;
89 void _SplitMergeBoxNm( const SwTable
&, String
&, String
&, String
* = 0,
90 void* pPara
= 0 ) const;
92 void GetBoxes( const SwTableBox
& rStt
, const SwTableBox
& rEnd
,
93 SwSelBoxes
& rBoxes
) const;
94 String
ScanString( FnScanFormel fnFormel
, const SwTable
& rTbl
,
97 const SwTable
* FindTable( SwDoc
& rDoc
, const String
& rNm
) const;
100 enum NameType
{ EXTRNL_NAME
, INTRNL_NAME
, REL_NAME
};
102 String sFormel
; // akt. Formel
103 NameType eNmType
; // akt. Darstellungs Art
104 BOOL bValidValue
; // TRUE: Formel neu berechnen
106 // suche den Node, in dem die Formel steht:
107 // TextFeld -> TextNode,
108 // BoxAttribut -> BoxStartNode
109 // !!! MUSS VON JEDER ABLEITUNG UEBERLADEN WERDEN !!!
110 virtual const SwNode
* GetNodeOfFormula() const = 0;
112 SwTableFormula( const String
& rFormel
);
114 String
MakeFormel( SwTblCalcPara
& rCalcPara
) const
116 return ScanString( &SwTableFormula::_MakeFormel
,
117 *rCalcPara
.pTbl
, &rCalcPara
);
120 static USHORT
GetLnPosInTbl( const SwTable
& rTbl
, const SwTableBox
* pBox
);
124 SwTableFormula( const SwTableFormula
& rCpy
) { *this = rCpy
; }
125 virtual ~SwTableFormula();
126 SwTableFormula
& operator=( const SwTableFormula
& rCpy
)
128 sFormel
= rCpy
.sFormel
;
129 eNmType
= rCpy
.eNmType
;
130 bValidValue
= rCpy
.bValidValue
;
134 // erzeuge aus der internen (fuer CORE) die externe (fuer UI) Formel
135 void PtrToBoxNm( const SwTable
* pTbl
);
136 // erzeuge aus der externen (fuer UI) die interne (fuer CORE) Formel
137 void BoxNmToPtr( const SwTable
* pTbl
);
138 // erzeuge aus der externen/internen Formel die relative Formel
139 void ToRelBoxNm( const SwTable
* pTbl
);
140 // wird vorm/nach dem mergen/splitten von Tabellen rerufen
141 void ToSplitMergeBoxNm( SwTableFmlUpdate
& rTblUpd
);
143 // ist gerade eine intern Darstellung aktiv
144 BOOL
IsIntrnlName() const { return eNmType
== INTRNL_NAME
; }
145 // erfrage die akt. Darstellung der Formel
146 NameType
GetNameType() const { return eNmType
; }
148 // erfrage/setze das Flag, ob der akt. Wert gueltig ist
149 BOOL
IsValid() const { return bValidValue
; }
150 inline void ChgValid( BOOL bNew
) { bValidValue
= bNew
; }
152 const String
& GetFormula() const { return sFormel
; }
153 void SetFormula( const String
& rNew
)
157 eNmType
= EXTRNL_NAME
;
160 USHORT
GetBoxesOfFormula( const SwTable
& rTbl
, SwSelBoxes
& rBoxes
);
161 // sind alle Boxen gueltig, auf die sich die Formel bezieht?
162 BOOL
HasValidBoxes() const;