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