Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _CELLFML_HXX
30 : : #define _CELLFML_HXX
31 : :
32 : : #include <tools/string.hxx>
33 : :
34 : : class SwTable;
35 : : class SwNode;
36 : : class SwTableSortBoxes;
37 : : class SwSelBoxes;
38 : : class SwCalc;
39 : : class SwTableBox;
40 : : class SwTableFmlUpdate;
41 : : class SwDoc;
42 : : class String;
43 : :
44 : : class SwTblCalcPara
45 : : {
46 : : const SwTableBox* pLastTblBox;
47 : : sal_uInt16 nStackCnt, nMaxSize;
48 : :
49 : : public:
50 : : SwTableSortBoxes *pBoxStk; ///< stack for recognizing recursion
51 : : SwCalc& rCalc; ///< current Calculator
52 : : const SwTable* pTbl; ///< current table
53 : :
54 : : SwTblCalcPara( SwCalc& rCalculator, const SwTable& rTable );
55 : : ~SwTblCalcPara();
56 : :
57 : : sal_Bool CalcWithStackOverflow();
58 : 0 : sal_Bool IsStackOverFlow() const { return nMaxSize == nStackCnt; }
59 : 0 : sal_Bool IncStackCnt() { return nMaxSize == ++nStackCnt; }
60 [ # # ]: 0 : void DecStackCnt() { if( nStackCnt ) --nStackCnt; }
61 : 0 : void SetLastTblBox( const SwTableBox* pBox ) { pLastTblBox = pBox; }
62 : : };
63 : :
64 : :
65 : :
66 : : class SwTableFormula
67 : : {
68 : : typedef void (SwTableFormula:: *FnScanFormel)( const SwTable&, String&,
69 : : String&, String*, void* ) const;
70 : :
71 : : void BoxNmsToPtr( const SwTable&, String&, String&, String* = 0,
72 : : void* pPara = 0 ) const;
73 : : void PtrToBoxNms( const SwTable&, String&, String&, String* = 0,
74 : : void* pPara = 0 ) const;
75 : : void RelNmsToBoxNms( const SwTable&, String&, String&, String* = 0,
76 : : void* pPara = 0 ) const;
77 : : void RelBoxNmsToPtr( const SwTable&, String&, String&, String* = 0,
78 : : void* pPara = 0 ) const;
79 : : void BoxNmsToRelNm( const SwTable&, String&, String&, String* = 0,
80 : : void* pPara = 0 ) const;
81 : : void _MakeFormula( const SwTable&, String&, String&, String* = 0,
82 : : void* pPara = 0 ) const;
83 : : void _GetFmlBoxes( const SwTable&, String&, String&, String* = 0,
84 : : void* pPara = 0 ) const;
85 : : void _HasValidBoxes( const SwTable&, String&, String&, String* = 0,
86 : : void* pPara = 0 ) const;
87 : : void _SplitMergeBoxNm( const SwTable&, String&, String&, String* = 0,
88 : : void* pPara = 0 ) const;
89 : :
90 : : void GetBoxes( const SwTableBox& rStt, const SwTableBox& rEnd,
91 : : SwSelBoxes& rBoxes ) const;
92 : : String ScanString( FnScanFormel fnFormel, const SwTable& rTbl,
93 : : void* = 0 ) const;
94 : :
95 : : const SwTable* FindTable( SwDoc& rDoc, const String& rNm ) const;
96 : :
97 : : protected:
98 : : enum NameType { EXTRNL_NAME, INTRNL_NAME, REL_NAME };
99 : :
100 : : String sFormel; ///< current formula
101 : : NameType eNmType; ///< current display method
102 : : sal_Bool bValidValue; ///< sal_True: recalculate formula
103 : :
104 : : // find the node in which the formula is located
105 : : // TextFeld -> TextNode,
106 : : // BoxAttribut -> BoxStartNode
107 : : // !!! has to be overloaded by every derivation !!!
108 : : virtual const SwNode* GetNodeOfFormula() const = 0;
109 : :
110 : : SwTableFormula( const String& rFormel );
111 : :
112 : 0 : String MakeFormula( SwTblCalcPara& rCalcPara ) const
113 : : {
114 : : return ScanString( &SwTableFormula::_MakeFormula,
115 : 0 : *rCalcPara.pTbl, &rCalcPara );
116 : : }
117 : :
118 : : static sal_uInt16 GetLnPosInTbl( const SwTable& rTbl, const SwTableBox* pBox );
119 : :
120 : : public:
121 : :
122 [ # # ]: 0 : SwTableFormula( const SwTableFormula& rCpy ) { *this = rCpy; }
123 : : virtual ~SwTableFormula();
124 : 0 : SwTableFormula& operator=( const SwTableFormula& rCpy )
125 : : {
126 : 0 : sFormel = rCpy.sFormel;
127 : 0 : eNmType = rCpy.eNmType;
128 : 0 : bValidValue = rCpy.bValidValue;
129 : 0 : return *this;
130 : : }
131 : :
132 : : /// create from the internal formula (for CORE) the external formula (for UI)
133 : : void PtrToBoxNm( const SwTable* pTbl );
134 : : /// create from the external formula the internal
135 : : void BoxNmToPtr( const SwTable* pTbl );
136 : : /// create from the external/internal formula the relative formula
137 : : void ToRelBoxNm( const SwTable* pTbl );
138 : : /// gets called before/after merging/splitting of tables
139 : : void ToSplitMergeBoxNm( SwTableFmlUpdate& rTblUpd );
140 : :
141 : 0 : bool IsIntrnlName() const { return eNmType == INTRNL_NAME; }
142 : 0 : NameType GetNameType() const { return eNmType; }
143 : :
144 : 0 : bool IsValid() const { return bValidValue; }
145 : 0 : inline void ChgValid( bool bNew ) { bValidValue = bNew; }
146 : :
147 : 0 : const String& GetFormula() const { return sFormel; }
148 : 0 : void SetFormula( const String& rNew )
149 : : {
150 : 0 : sFormel = rNew;
151 : 0 : bValidValue = false;
152 : 0 : eNmType = EXTRNL_NAME;
153 : 0 : }
154 : :
155 : : sal_uInt16 GetBoxesOfFormula( const SwTable& rTbl, SwSelBoxes& rBoxes );
156 : : // are all boxes valid which this formula relies on?
157 : : bool HasValidBoxes() const;
158 : : };
159 : :
160 : :
161 : :
162 : : #endif
163 : :
164 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|