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