1*38d50f7bSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*38d50f7bSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*38d50f7bSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*38d50f7bSAndrew Rist * distributed with this work for additional information 6*38d50f7bSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*38d50f7bSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*38d50f7bSAndrew Rist * "License"); you may not use this file except in compliance 9*38d50f7bSAndrew Rist * with the License. You may obtain a copy of the License at 10*38d50f7bSAndrew Rist * 11*38d50f7bSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*38d50f7bSAndrew Rist * 13*38d50f7bSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*38d50f7bSAndrew Rist * software distributed under the License is distributed on an 15*38d50f7bSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*38d50f7bSAndrew Rist * KIND, either express or implied. See the License for the 17*38d50f7bSAndrew Rist * specific language governing permissions and limitations 18*38d50f7bSAndrew Rist * under the License. 19*38d50f7bSAndrew Rist * 20*38d50f7bSAndrew Rist *************************************************************/ 21*38d50f7bSAndrew Rist 22*38d50f7bSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef SC_CONDITIO_HXX 25cdf0e10cSrcweir #define SC_CONDITIO_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "global.hxx" 28cdf0e10cSrcweir #include "address.hxx" 29cdf0e10cSrcweir #include "formula/grammar.hxx" 30cdf0e10cSrcweir #include <svl/svarray.hxx> 31cdf0e10cSrcweir #include "scdllapi.h" 32cdf0e10cSrcweir 33cdf0e10cSrcweir class ScBaseCell; 34cdf0e10cSrcweir class ScFormulaCell; 35cdf0e10cSrcweir class ScTokenArray; 36cdf0e10cSrcweir class ScRangeList; 37cdf0e10cSrcweir 38cdf0e10cSrcweir 39cdf0e10cSrcweir #define SC_COND_GROW 16 40cdf0e10cSrcweir 41cdf0e10cSrcweir // nOptions Flags 42cdf0e10cSrcweir #define SC_COND_NOBLANKS 1 43cdf0e10cSrcweir 44cdf0e10cSrcweir 45cdf0e10cSrcweir // Reihenfolge von ScConditionMode wie ScQueryOp, 46cdf0e10cSrcweir // damit einmal zusammengefasst werden kann: 47cdf0e10cSrcweir 48cdf0e10cSrcweir enum ScConditionMode 49cdf0e10cSrcweir { 50cdf0e10cSrcweir SC_COND_EQUAL, 51cdf0e10cSrcweir SC_COND_LESS, 52cdf0e10cSrcweir SC_COND_GREATER, 53cdf0e10cSrcweir SC_COND_EQLESS, 54cdf0e10cSrcweir SC_COND_EQGREATER, 55cdf0e10cSrcweir SC_COND_NOTEQUAL, 56cdf0e10cSrcweir SC_COND_BETWEEN, 57cdf0e10cSrcweir SC_COND_NOTBETWEEN, 58cdf0e10cSrcweir SC_COND_DIRECT, 59cdf0e10cSrcweir SC_COND_NONE 60cdf0e10cSrcweir }; 61cdf0e10cSrcweir 62cdf0e10cSrcweir enum ScConditionValType 63cdf0e10cSrcweir { 64cdf0e10cSrcweir SC_VAL_VALUE, 65cdf0e10cSrcweir SC_VAL_STRING, 66cdf0e10cSrcweir SC_VAL_FORMULA 67cdf0e10cSrcweir }; 68cdf0e10cSrcweir 69cdf0e10cSrcweir class SC_DLLPUBLIC ScConditionEntry 70cdf0e10cSrcweir { 71cdf0e10cSrcweir // gespeicherte Daten: 72cdf0e10cSrcweir ScConditionMode eOp; 73cdf0e10cSrcweir sal_uInt16 nOptions; 74cdf0e10cSrcweir double nVal1; // eingegeben oder berechnet 75cdf0e10cSrcweir double nVal2; 76cdf0e10cSrcweir String aStrVal1; // eingegeben oder berechnet 77cdf0e10cSrcweir String aStrVal2; 78cdf0e10cSrcweir String aStrNmsp1; // namespace to be used on (re)compilation, e.g. in XML import 79cdf0e10cSrcweir String aStrNmsp2; // namespace to be used on (re)compilation, e.g. in XML import 80cdf0e10cSrcweir formula::FormulaGrammar::Grammar eTempGrammar1; // grammar to be used on (re)compilation, e.g. in XML import 81cdf0e10cSrcweir formula::FormulaGrammar::Grammar eTempGrammar2; // grammar to be used on (re)compilation, e.g. in XML import 82cdf0e10cSrcweir sal_Bool bIsStr1; // um auch leere Strings zu erkennen 83cdf0e10cSrcweir sal_Bool bIsStr2; 84cdf0e10cSrcweir ScTokenArray* pFormula1; // eingegebene Formel 85cdf0e10cSrcweir ScTokenArray* pFormula2; 86cdf0e10cSrcweir ScAddress aSrcPos; // source position for formulas 87cdf0e10cSrcweir // temporary data: 88cdf0e10cSrcweir String aSrcString; // formula source position as text during XML import 89cdf0e10cSrcweir ScFormulaCell* pFCell1; 90cdf0e10cSrcweir ScFormulaCell* pFCell2; 91cdf0e10cSrcweir ScDocument* pDoc; 92cdf0e10cSrcweir sal_Bool bRelRef1; 93cdf0e10cSrcweir sal_Bool bRelRef2; 94cdf0e10cSrcweir sal_Bool bFirstRun; 95cdf0e10cSrcweir 96cdf0e10cSrcweir void MakeCells( const ScAddress& rPos ); 97cdf0e10cSrcweir void Compile( const String& rExpr1, const String& rExpr2, 98cdf0e10cSrcweir const String& rExprNmsp1, const String& rExprNmsp2, 99cdf0e10cSrcweir formula::FormulaGrammar::Grammar eGrammar1, 100cdf0e10cSrcweir formula::FormulaGrammar::Grammar eGrammar2, 101cdf0e10cSrcweir sal_Bool bTextToReal ); 102cdf0e10cSrcweir void Interpret( const ScAddress& rPos ); 103cdf0e10cSrcweir 104cdf0e10cSrcweir sal_Bool IsValid( double nArg ) const; 105cdf0e10cSrcweir sal_Bool IsValidStr( const String& rArg ) const; 106cdf0e10cSrcweir 107cdf0e10cSrcweir public: 108cdf0e10cSrcweir ScConditionEntry( ScConditionMode eOper, 109cdf0e10cSrcweir const String& rExpr1, const String& rExpr2, 110cdf0e10cSrcweir ScDocument* pDocument, const ScAddress& rPos, 111cdf0e10cSrcweir const String& rExprNmsp1, const String& rExprNmsp2, 112cdf0e10cSrcweir formula::FormulaGrammar::Grammar eGrammar1, 113cdf0e10cSrcweir formula::FormulaGrammar::Grammar eGrammar2 ); 114cdf0e10cSrcweir ScConditionEntry( ScConditionMode eOper, 115cdf0e10cSrcweir const ScTokenArray* pArr1, const ScTokenArray* pArr2, 116cdf0e10cSrcweir ScDocument* pDocument, const ScAddress& rPos ); 117cdf0e10cSrcweir ScConditionEntry( const ScConditionEntry& r ); // flache Kopie der Formeln 118cdf0e10cSrcweir // echte Kopie der Formeln (fuer Ref-Undo): 119cdf0e10cSrcweir ScConditionEntry( ScDocument* pDocument, const ScConditionEntry& r ); 120cdf0e10cSrcweir virtual ~ScConditionEntry(); 121cdf0e10cSrcweir 122cdf0e10cSrcweir int operator== ( const ScConditionEntry& r ) const; 123cdf0e10cSrcweir 124cdf0e10cSrcweir sal_Bool IsCellValid( ScBaseCell* pCell, const ScAddress& rPos ) const; 125cdf0e10cSrcweir GetOperation() const126cdf0e10cSrcweir ScConditionMode GetOperation() const { return eOp; } IsIgnoreBlank() const127cdf0e10cSrcweir sal_Bool IsIgnoreBlank() const { return ( nOptions & SC_COND_NOBLANKS ) == 0; } 128cdf0e10cSrcweir void SetIgnoreBlank(sal_Bool bSet); GetSrcPos() const129cdf0e10cSrcweir ScAddress GetSrcPos() const { return aSrcPos; } 130cdf0e10cSrcweir 131cdf0e10cSrcweir ScAddress GetValidSrcPos() const; // adjusted to allow textual representation of expressions 132cdf0e10cSrcweir 133cdf0e10cSrcweir void SetSrcString( const String& rNew ); // for XML import 134cdf0e10cSrcweir 135cdf0e10cSrcweir void SetFormula1( const ScTokenArray& rArray ); 136cdf0e10cSrcweir void SetFormula2( const ScTokenArray& rArray ); 137cdf0e10cSrcweir 138cdf0e10cSrcweir String GetExpression( const ScAddress& rCursor, sal_uInt16 nPos, sal_uLong nNumFmt = 0, 139cdf0e10cSrcweir const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT ) const; 140cdf0e10cSrcweir 141cdf0e10cSrcweir ScTokenArray* CreateTokenArry( sal_uInt16 nPos ) const; 142cdf0e10cSrcweir 143cdf0e10cSrcweir void CompileAll(); 144cdf0e10cSrcweir void CompileXML(); 145cdf0e10cSrcweir void UpdateReference( UpdateRefMode eUpdateRefMode, 146cdf0e10cSrcweir const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz ); 147cdf0e10cSrcweir void UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos ); 148cdf0e10cSrcweir 149cdf0e10cSrcweir void SourceChanged( const ScAddress& rChanged ); 150cdf0e10cSrcweir 151cdf0e10cSrcweir bool MarkUsedExternalReferences() const; 152cdf0e10cSrcweir 153cdf0e10cSrcweir protected: 154cdf0e10cSrcweir virtual void DataChanged( const ScRange* pModified ) const; GetDocument() const155cdf0e10cSrcweir ScDocument* GetDocument() const { return pDoc; } 156cdf0e10cSrcweir }; 157cdf0e10cSrcweir 158cdf0e10cSrcweir // 159cdf0e10cSrcweir // einzelner Eintrag fuer bedingte Formatierung 160cdf0e10cSrcweir // 161cdf0e10cSrcweir 162cdf0e10cSrcweir class ScConditionalFormat; 163cdf0e10cSrcweir 164cdf0e10cSrcweir class SC_DLLPUBLIC ScCondFormatEntry : public ScConditionEntry 165cdf0e10cSrcweir { 166cdf0e10cSrcweir String aStyleName; 167cdf0e10cSrcweir ScConditionalFormat* pParent; 168cdf0e10cSrcweir 169cdf0e10cSrcweir using ScConditionEntry::operator==; 170cdf0e10cSrcweir 171cdf0e10cSrcweir public: 172cdf0e10cSrcweir ScCondFormatEntry( ScConditionMode eOper, 173cdf0e10cSrcweir const String& rExpr1, const String& rExpr2, 174cdf0e10cSrcweir ScDocument* pDocument, const ScAddress& rPos, 175cdf0e10cSrcweir const String& rStyle, 176cdf0e10cSrcweir const String& rExprNmsp1 = EMPTY_STRING, 177cdf0e10cSrcweir const String& rExprNmsp2 = EMPTY_STRING, 178cdf0e10cSrcweir formula::FormulaGrammar::Grammar eGrammar1 = formula::FormulaGrammar::GRAM_DEFAULT, 179cdf0e10cSrcweir formula::FormulaGrammar::Grammar eGrammar2 = formula::FormulaGrammar::GRAM_DEFAULT ); 180cdf0e10cSrcweir ScCondFormatEntry( ScConditionMode eOper, 181cdf0e10cSrcweir const ScTokenArray* pArr1, const ScTokenArray* pArr2, 182cdf0e10cSrcweir ScDocument* pDocument, const ScAddress& rPos, 183cdf0e10cSrcweir const String& rStyle ); 184cdf0e10cSrcweir ScCondFormatEntry( const ScCondFormatEntry& r ); 185cdf0e10cSrcweir ScCondFormatEntry( ScDocument* pDocument, const ScCondFormatEntry& r ); 186cdf0e10cSrcweir virtual ~ScCondFormatEntry(); 187cdf0e10cSrcweir SetParent(ScConditionalFormat * pNew)188cdf0e10cSrcweir void SetParent( ScConditionalFormat* pNew ) { pParent = pNew; } 189cdf0e10cSrcweir 190cdf0e10cSrcweir int operator== ( const ScCondFormatEntry& r ) const; 191cdf0e10cSrcweir GetStyle() const192cdf0e10cSrcweir const String& GetStyle() const { return aStyleName; } UpdateStyleName(const String & rNew)193cdf0e10cSrcweir void UpdateStyleName(const String& rNew) { aStyleName=rNew; } 194cdf0e10cSrcweir 195cdf0e10cSrcweir protected: 196cdf0e10cSrcweir virtual void DataChanged( const ScRange* pModified ) const; 197cdf0e10cSrcweir }; 198cdf0e10cSrcweir 199cdf0e10cSrcweir // 200cdf0e10cSrcweir // komplette bedingte Formatierung 201cdf0e10cSrcweir // 202cdf0e10cSrcweir 203cdf0e10cSrcweir class SC_DLLPUBLIC ScConditionalFormat 204cdf0e10cSrcweir { 205cdf0e10cSrcweir ScDocument* pDoc; 206cdf0e10cSrcweir ScRangeList* pAreas; // Bereiche fuer Paint 207cdf0e10cSrcweir sal_uInt32 nKey; // Index in Attributen 208cdf0e10cSrcweir ScCondFormatEntry** ppEntries; 209cdf0e10cSrcweir sal_uInt16 nEntryCount; 210cdf0e10cSrcweir sal_Bool bIsUsed; // temporaer beim Speichern 211cdf0e10cSrcweir 212cdf0e10cSrcweir public: 213cdf0e10cSrcweir ScConditionalFormat(sal_uInt32 nNewKey, ScDocument* pDocument); 214cdf0e10cSrcweir ScConditionalFormat(const ScConditionalFormat& r); 215cdf0e10cSrcweir ~ScConditionalFormat(); 216cdf0e10cSrcweir 217cdf0e10cSrcweir // echte Kopie der Formeln (fuer Ref-Undo / zwischen Dokumenten) 218cdf0e10cSrcweir ScConditionalFormat* Clone(ScDocument* pNewDoc = NULL) const; 219cdf0e10cSrcweir 220cdf0e10cSrcweir void AddEntry( const ScCondFormatEntry& rNew ); 221cdf0e10cSrcweir IsEmpty() const222cdf0e10cSrcweir sal_Bool IsEmpty() const { return (nEntryCount == 0); } Count() const223cdf0e10cSrcweir sal_uInt16 Count() const { return nEntryCount; } 224cdf0e10cSrcweir 225cdf0e10cSrcweir void CompileAll(); 226cdf0e10cSrcweir void CompileXML(); 227cdf0e10cSrcweir void UpdateReference( UpdateRefMode eUpdateRefMode, 228cdf0e10cSrcweir const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz ); 229cdf0e10cSrcweir void UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos ); 230cdf0e10cSrcweir void RenameCellStyle( const String& rOld, const String& rNew ); 231cdf0e10cSrcweir 232cdf0e10cSrcweir void SourceChanged( const ScAddress& rAddr ); 233cdf0e10cSrcweir 234cdf0e10cSrcweir const ScCondFormatEntry* GetEntry( sal_uInt16 nPos ) const; 235cdf0e10cSrcweir 236cdf0e10cSrcweir const String& GetCellStyle( ScBaseCell* pCell, const ScAddress& rPos ) const; 237cdf0e10cSrcweir 238cdf0e10cSrcweir sal_Bool EqualEntries( const ScConditionalFormat& r ) const; 239cdf0e10cSrcweir 240cdf0e10cSrcweir void DoRepaint( const ScRange* pModified ); 241cdf0e10cSrcweir void InvalidateArea(); 242cdf0e10cSrcweir GetKey() const243cdf0e10cSrcweir sal_uInt32 GetKey() const { return nKey; } SetKey(sal_uInt32 nNew)244cdf0e10cSrcweir void SetKey(sal_uInt32 nNew) { nKey = nNew; } // nur wenn nicht eingefuegt! 245cdf0e10cSrcweir SetUsed(sal_Bool bSet)246cdf0e10cSrcweir void SetUsed(sal_Bool bSet) { bIsUsed = bSet; } IsUsed() const247cdf0e10cSrcweir sal_Bool IsUsed() const { return bIsUsed; } 248cdf0e10cSrcweir 249cdf0e10cSrcweir bool MarkUsedExternalReferences() const; 250cdf0e10cSrcweir 251cdf0e10cSrcweir // sortiert (per PTRARR) nach Index 252cdf0e10cSrcweir // operator== nur fuer die Sortierung operator ==(const ScConditionalFormat & r) const253cdf0e10cSrcweir sal_Bool operator ==( const ScConditionalFormat& r ) const { return nKey == r.nKey; } operator <(const ScConditionalFormat & r) const254cdf0e10cSrcweir sal_Bool operator < ( const ScConditionalFormat& r ) const { return nKey < r.nKey; } 255cdf0e10cSrcweir }; 256cdf0e10cSrcweir 257cdf0e10cSrcweir // 258cdf0e10cSrcweir // Liste der Bereiche und Formate: 259cdf0e10cSrcweir // 260cdf0e10cSrcweir 261cdf0e10cSrcweir typedef ScConditionalFormat* ScConditionalFormatPtr; 262cdf0e10cSrcweir 263cdf0e10cSrcweir SV_DECL_PTRARR_SORT(ScConditionalFormats_Impl, ScConditionalFormatPtr, 264cdf0e10cSrcweir SC_COND_GROW, SC_COND_GROW) 265cdf0e10cSrcweir 266cdf0e10cSrcweir class ScConditionalFormatList : public ScConditionalFormats_Impl 267cdf0e10cSrcweir { 268cdf0e10cSrcweir public: ScConditionalFormatList()269cdf0e10cSrcweir ScConditionalFormatList() {} 270cdf0e10cSrcweir ScConditionalFormatList(const ScConditionalFormatList& rList); 271cdf0e10cSrcweir ScConditionalFormatList(ScDocument* pNewDoc, const ScConditionalFormatList& rList); ~ScConditionalFormatList()272cdf0e10cSrcweir ~ScConditionalFormatList() {} 273cdf0e10cSrcweir InsertNew(ScConditionalFormat * pNew)274cdf0e10cSrcweir void InsertNew( ScConditionalFormat* pNew ) 275cdf0e10cSrcweir { if (!Insert(pNew)) delete pNew; } 276cdf0e10cSrcweir 277cdf0e10cSrcweir ScConditionalFormat* GetFormat( sal_uInt32 nKey ); 278cdf0e10cSrcweir 279cdf0e10cSrcweir void CompileAll(); 280cdf0e10cSrcweir void CompileXML(); 281cdf0e10cSrcweir void UpdateReference( UpdateRefMode eUpdateRefMode, 282cdf0e10cSrcweir const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz ); 283cdf0e10cSrcweir void RenameCellStyle( const String& rOld, const String& rNew ); 284cdf0e10cSrcweir void UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos ); 285cdf0e10cSrcweir 286cdf0e10cSrcweir void SourceChanged( const ScAddress& rAddr ); 287cdf0e10cSrcweir 288cdf0e10cSrcweir /** Temporarily during save, returns RefManager's decision whether ALL 289cdf0e10cSrcweir * references are marked now. */ 290cdf0e10cSrcweir bool MarkUsedExternalReferences() const; 291cdf0e10cSrcweir 292cdf0e10cSrcweir sal_Bool operator==( const ScConditionalFormatList& r ) const; // fuer Ref-Undo 293cdf0e10cSrcweir }; 294cdf0e10cSrcweir 295cdf0e10cSrcweir #endif 296cdf0e10cSrcweir 297cdf0e10cSrcweir 298