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