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: conditio.hxx,v $
10 * $Revision: 1.13.32.4 $
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 ************************************************************************/
31 #ifndef SC_CONDITIO_HXX
32 #define SC_CONDITIO_HXX
35 #include "address.hxx"
36 #include "formula/grammar.hxx"
37 #include <svtools/svarray.hxx>
46 #define SC_COND_GROW 16
49 #define SC_COND_NOBLANKS 1
52 // Reihenfolge von ScConditionMode wie ScQueryOp,
53 // damit einmal zusammengefasst werden kann:
69 enum ScConditionValType
76 class SC_DLLPUBLIC ScConditionEntry
78 // gespeicherte Daten:
81 double nVal1
; // eingegeben oder berechnet
83 String aStrVal1
; // eingegeben oder berechnet
85 String aStrNmsp1
; // namespace to be used on (re)compilation, e.g. in XML import
86 String aStrNmsp2
; // namespace to be used on (re)compilation, e.g. in XML import
87 formula::FormulaGrammar::Grammar eTempGrammar1
; // grammar to be used on (re)compilation, e.g. in XML import
88 formula::FormulaGrammar::Grammar eTempGrammar2
; // grammar to be used on (re)compilation, e.g. in XML import
89 BOOL bIsStr1
; // um auch leere Strings zu erkennen
91 ScTokenArray
* pFormula1
; // eingegebene Formel
92 ScTokenArray
* pFormula2
;
93 ScAddress aSrcPos
; // source position for formulas
95 String aSrcString
; // formula source position as text during XML import
96 ScFormulaCell
* pFCell1
;
97 ScFormulaCell
* pFCell2
;
103 void MakeCells( const ScAddress
& rPos
);
104 void Compile( const String
& rExpr1
, const String
& rExpr2
,
105 const String
& rExprNmsp1
, const String
& rExprNmsp2
,
106 formula::FormulaGrammar::Grammar eGrammar1
,
107 formula::FormulaGrammar::Grammar eGrammar2
,
109 void Interpret( const ScAddress
& rPos
);
111 BOOL
IsValid( double nArg
) const;
112 BOOL
IsValidStr( const String
& rArg
) const;
115 ScConditionEntry( ScConditionMode eOper
,
116 const String
& rExpr1
, const String
& rExpr2
,
117 ScDocument
* pDocument
, const ScAddress
& rPos
,
118 const String
& rExprNmsp1
, const String
& rExprNmsp2
,
119 formula::FormulaGrammar::Grammar eGrammar1
,
120 formula::FormulaGrammar::Grammar eGrammar2
);
121 ScConditionEntry( ScConditionMode eOper
,
122 const ScTokenArray
* pArr1
, const ScTokenArray
* pArr2
,
123 ScDocument
* pDocument
, const ScAddress
& rPos
);
124 ScConditionEntry( const ScConditionEntry
& r
); // flache Kopie der Formeln
125 // echte Kopie der Formeln (fuer Ref-Undo):
126 ScConditionEntry( ScDocument
* pDocument
, const ScConditionEntry
& r
);
127 virtual ~ScConditionEntry();
129 int operator== ( const ScConditionEntry
& r
) const;
131 BOOL
IsCellValid( ScBaseCell
* pCell
, const ScAddress
& rPos
) const;
133 ScConditionMode
GetOperation() const { return eOp
; }
134 BOOL
IsIgnoreBlank() const { return ( nOptions
& SC_COND_NOBLANKS
) == 0; }
135 void SetIgnoreBlank(BOOL bSet
);
136 ScAddress
GetSrcPos() const { return aSrcPos
; }
138 ScAddress
GetValidSrcPos() const; // adjusted to allow textual representation of expressions
140 void SetSrcString( const String
& rNew
); // for XML import
142 void SetFormula1( const ScTokenArray
& rArray
);
143 void SetFormula2( const ScTokenArray
& rArray
);
145 String
GetExpression( const ScAddress
& rCursor
, USHORT nPos
, ULONG nNumFmt
= 0,
146 const formula::FormulaGrammar::Grammar eGrammar
= formula::FormulaGrammar::GRAM_DEFAULT
) const;
148 ScTokenArray
* CreateTokenArry( USHORT nPos
) const;
152 void UpdateReference( UpdateRefMode eUpdateRefMode
,
153 const ScRange
& rRange
, SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
);
154 void UpdateMoveTab( SCTAB nOldPos
, SCTAB nNewPos
);
156 void SourceChanged( const ScAddress
& rChanged
);
158 bool MarkUsedExternalReferences() const;
161 virtual void DataChanged( const ScRange
* pModified
) const;
162 ScDocument
* GetDocument() const { return pDoc
; }
166 // einzelner Eintrag fuer bedingte Formatierung
169 class ScConditionalFormat
;
171 class SC_DLLPUBLIC ScCondFormatEntry
: public ScConditionEntry
174 ScConditionalFormat
* pParent
;
176 using ScConditionEntry::operator==;
179 ScCondFormatEntry( ScConditionMode eOper
,
180 const String
& rExpr1
, const String
& rExpr2
,
181 ScDocument
* pDocument
, const ScAddress
& rPos
,
182 const String
& rStyle
,
183 const String
& rExprNmsp1
= EMPTY_STRING
,
184 const String
& rExprNmsp2
= EMPTY_STRING
,
185 formula::FormulaGrammar::Grammar eGrammar1
= formula::FormulaGrammar::GRAM_DEFAULT
,
186 formula::FormulaGrammar::Grammar eGrammar2
= formula::FormulaGrammar::GRAM_DEFAULT
);
187 ScCondFormatEntry( ScConditionMode eOper
,
188 const ScTokenArray
* pArr1
, const ScTokenArray
* pArr2
,
189 ScDocument
* pDocument
, const ScAddress
& rPos
,
190 const String
& rStyle
);
191 ScCondFormatEntry( const ScCondFormatEntry
& r
);
192 ScCondFormatEntry( ScDocument
* pDocument
, const ScCondFormatEntry
& r
);
193 virtual ~ScCondFormatEntry();
195 void SetParent( ScConditionalFormat
* pNew
) { pParent
= pNew
; }
197 int operator== ( const ScCondFormatEntry
& r
) const;
199 const String
& GetStyle() const { return aStyleName
; }
200 void UpdateStyleName(const String
& rNew
) { aStyleName
=rNew
; }
203 virtual void DataChanged( const ScRange
* pModified
) const;
207 // komplette bedingte Formatierung
210 class SC_DLLPUBLIC ScConditionalFormat
213 ScRangeList
* pAreas
; // Bereiche fuer Paint
214 sal_uInt32 nKey
; // Index in Attributen
215 ScCondFormatEntry
** ppEntries
;
217 BOOL bIsUsed
; // temporaer beim Speichern
220 ScConditionalFormat(sal_uInt32 nNewKey
, ScDocument
* pDocument
);
221 ScConditionalFormat(const ScConditionalFormat
& r
);
222 ~ScConditionalFormat();
224 // echte Kopie der Formeln (fuer Ref-Undo / zwischen Dokumenten)
225 ScConditionalFormat
* Clone(ScDocument
* pNewDoc
= NULL
) const;
227 void AddEntry( const ScCondFormatEntry
& rNew
);
229 BOOL
IsEmpty() const { return (nEntryCount
== 0); }
230 USHORT
Count() const { return nEntryCount
; }
234 void UpdateReference( UpdateRefMode eUpdateRefMode
,
235 const ScRange
& rRange
, SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
);
236 void UpdateMoveTab( SCTAB nOldPos
, SCTAB nNewPos
);
237 void RenameCellStyle( const String
& rOld
, const String
& rNew
);
239 void SourceChanged( const ScAddress
& rAddr
);
241 const ScCondFormatEntry
* GetEntry( USHORT nPos
) const;
243 const String
& GetCellStyle( ScBaseCell
* pCell
, const ScAddress
& rPos
) const;
245 BOOL
EqualEntries( const ScConditionalFormat
& r
) const;
247 void DoRepaint( const ScRange
* pModified
);
248 void InvalidateArea();
250 sal_uInt32
GetKey() const { return nKey
; }
251 void SetKey(sal_uInt32 nNew
) { nKey
= nNew
; } // nur wenn nicht eingefuegt!
253 void SetUsed(BOOL bSet
) { bIsUsed
= bSet
; }
254 BOOL
IsUsed() const { return bIsUsed
; }
256 bool MarkUsedExternalReferences() const;
258 // sortiert (per PTRARR) nach Index
259 // operator== nur fuer die Sortierung
260 BOOL
operator ==( const ScConditionalFormat
& r
) const { return nKey
== r
.nKey
; }
261 BOOL
operator < ( const ScConditionalFormat
& r
) const { return nKey
< r
.nKey
; }
265 // Liste der Bereiche und Formate:
268 typedef ScConditionalFormat
* ScConditionalFormatPtr
;
270 SV_DECL_PTRARR_SORT(ScConditionalFormats_Impl
, ScConditionalFormatPtr
,
271 SC_COND_GROW
, SC_COND_GROW
)
273 class ScConditionalFormatList
: public ScConditionalFormats_Impl
276 ScConditionalFormatList() {}
277 ScConditionalFormatList(const ScConditionalFormatList
& rList
);
278 ScConditionalFormatList(ScDocument
* pNewDoc
, const ScConditionalFormatList
& rList
);
279 ~ScConditionalFormatList() {}
281 void InsertNew( ScConditionalFormat
* pNew
)
282 { if (!Insert(pNew
)) delete pNew
; }
284 ScConditionalFormat
* GetFormat( sal_uInt32 nKey
);
288 void UpdateReference( UpdateRefMode eUpdateRefMode
,
289 const ScRange
& rRange
, SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
);
290 void RenameCellStyle( const String
& rOld
, const String
& rNew
);
291 void UpdateMoveTab( SCTAB nOldPos
, SCTAB nNewPos
);
293 void SourceChanged( const ScAddress
& rAddr
);
295 /** Temporarily during save, returns RefManager's decision whether ALL
296 * references are marked now. */
297 bool MarkUsedExternalReferences() const;
299 BOOL
operator==( const ScConditionalFormatList
& r
) const; // fuer Ref-Undo