xref: /AOO41X/main/sc/inc/cell.hxx (revision b4df81e395f7fffe8aec37c1b771710de256f09c)
138d50f7bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
338d50f7bSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
438d50f7bSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
538d50f7bSAndrew Rist  * distributed with this work for additional information
638d50f7bSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
738d50f7bSAndrew Rist  * to you under the Apache License, Version 2.0 (the
838d50f7bSAndrew Rist  * "License"); you may not use this file except in compliance
938d50f7bSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
1138d50f7bSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
1338d50f7bSAndrew Rist  * Unless required by applicable law or agreed to in writing,
1438d50f7bSAndrew Rist  * software distributed under the License is distributed on an
1538d50f7bSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1638d50f7bSAndrew Rist  * KIND, either express or implied.  See the License for the
1738d50f7bSAndrew Rist  * specific language governing permissions and limitations
1838d50f7bSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
2038d50f7bSAndrew Rist  *************************************************************/
2138d50f7bSAndrew Rist 
2238d50f7bSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef SC_CELL_HXX
25cdf0e10cSrcweir #define SC_CELL_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <stddef.h>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <set>
30cdf0e10cSrcweir #include <tools/mempool.hxx>
31cdf0e10cSrcweir #include <svl/listener.hxx>
32cdf0e10cSrcweir #include "global.hxx"
33cdf0e10cSrcweir #include "rangenam.hxx"
34cdf0e10cSrcweir #include "formula/grammar.hxx"
35cdf0e10cSrcweir #include "tokenarray.hxx"
36cdf0e10cSrcweir #include "formularesult.hxx"
37cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
38cdf0e10cSrcweir #include <unotools/fontcvt.hxx>
39cdf0e10cSrcweir #include "scdllapi.h"
40cdf0e10cSrcweir 
41*b4df81e3SWang Lei #include <cellform.hxx>
42*b4df81e3SWang Lei 
43cdf0e10cSrcweir #define USE_MEMPOOL
44cdf0e10cSrcweir #define TEXTWIDTH_DIRTY		0xffff
45cdf0e10cSrcweir 
46cdf0e10cSrcweir // in addition to SCRIPTTYPE_... flags from scripttypeitem.hxx:
47cdf0e10cSrcweir // set (in nScriptType) if type has not been determined yet
48cdf0e10cSrcweir #define SC_SCRIPTTYPE_UNKNOWN	0x08
49cdf0e10cSrcweir 
50cdf0e10cSrcweir class ScDocument;
51cdf0e10cSrcweir class EditTextObject;
52cdf0e10cSrcweir class ScMatrix;
53cdf0e10cSrcweir class SvtBroadcaster;
54cdf0e10cSrcweir class ScCodeArray;
55cdf0e10cSrcweir class ScProgress;
56cdf0e10cSrcweir class ScPostIt;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir // ============================================================================
59cdf0e10cSrcweir 
60cdf0e10cSrcweir /** Default cell clone flags: do not start listening, do not adjust 3D refs to
61cdf0e10cSrcweir     old position, clone note captions of cell notes. */
62cdf0e10cSrcweir const int SC_CLONECELL_DEFAULT          = 0x0000;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir /** If set, cloned formula cells will start to listen to the document. */
65cdf0e10cSrcweir const int SC_CLONECELL_STARTLISTENING   = 0x0001;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir /** If set, relative 3D references of cloned formula cells will be adjusted to
68cdf0e10cSrcweir     old position (used while swapping cells for sorting a cell range). */
69cdf0e10cSrcweir const int SC_CLONECELL_ADJUST3DREL      = 0x0002;
70cdf0e10cSrcweir 
71cdf0e10cSrcweir /** If set, the caption object of a cell note will not be cloned (used while
72cdf0e10cSrcweir     copying cells to undo document, where captions are handled in drawing undo). */
73cdf0e10cSrcweir const int SC_CLONECELL_NOCAPTION        = 0x0004;
74cdf0e10cSrcweir 
75cdf0e10cSrcweir // ============================================================================
76cdf0e10cSrcweir 
77cdf0e10cSrcweir class SC_DLLPUBLIC ScBaseCell
78cdf0e10cSrcweir {
79cdf0e10cSrcweir protected:
80cdf0e10cSrcweir 					~ScBaseCell();	// nicht virtuell -> darf nicht direkt aufgerufen werden
81cdf0e10cSrcweir 
82cdf0e10cSrcweir public:
83cdf0e10cSrcweir     explicit        ScBaseCell( CellType eNewType );
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     /** Base copy constructor. Does NOT clone cell note or broadcaster! */
86cdf0e10cSrcweir                     ScBaseCell( const ScBaseCell& rCell );
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     /** Returns a clone of this cell at the same position, cell note and
89cdf0e10cSrcweir         broadcaster will not be cloned. */
90cdf0e10cSrcweir     ScBaseCell*     CloneWithoutNote( ScDocument& rDestDoc, int nCloneFlags = SC_CLONECELL_DEFAULT ) const;
91cdf0e10cSrcweir 
92cdf0e10cSrcweir     /** Returns a clone of this cell for the passed document position, cell
93cdf0e10cSrcweir         note and broadcaster will not be cloned. */
94cdf0e10cSrcweir     ScBaseCell*     CloneWithoutNote( ScDocument& rDestDoc, const ScAddress& rDestPos, int nCloneFlags = SC_CLONECELL_DEFAULT ) const;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     /** Returns a clone of this cell, clones cell note and caption object too
97cdf0e10cSrcweir         (unless SC_CLONECELL_NOCAPTION flag is set). Broadcaster will not be cloned. */
98cdf0e10cSrcweir     ScBaseCell*     CloneWithNote( const ScAddress& rOwnPos, ScDocument& rDestDoc, const ScAddress& rDestPos, int nCloneFlags = SC_CLONECELL_DEFAULT ) const;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     /** Due to the fact that ScBaseCell does not have a vtable, this function
101cdf0e10cSrcweir         deletes the cell by calling the appropriate d'tor of the derived class. */
102cdf0e10cSrcweir     void            Delete();
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     inline CellType GetCellType() const	{ return (CellType)eCellType; }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir     /** Returns true, if the cell is empty (neither value nor formula nor cell note).
107cdf0e10cSrcweir         Returns false for formula cells returning nothing, use HasEmptyData() for that. */
108cdf0e10cSrcweir     bool            IsBlank( bool bIgnoreNotes = false ) const;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir // fuer Idle-Berechnung
111cdf0e10cSrcweir     inline sal_uInt16   GetTextWidth() const { return nTextWidth; }
112cdf0e10cSrcweir     inline void     SetTextWidth( sal_uInt16 nNew ) { nTextWidth = nNew; }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir     inline sal_uInt8     GetScriptType() const { return nScriptType; }
115cdf0e10cSrcweir     inline void     SetScriptType( sal_uInt8 nNew ) { nScriptType = nNew; }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     /** Returns true, if the cell contains a note. */
118cdf0e10cSrcweir     inline bool     HasNote() const { return mpNote != 0; }
119cdf0e10cSrcweir     /** Returns the pointer to a cell note object (read-only). */
120cdf0e10cSrcweir     inline const ScPostIt* GetNote() const { return mpNote; }
121cdf0e10cSrcweir     /** Returns the pointer to a cell note object. */
122cdf0e10cSrcweir     inline ScPostIt* GetNote() { return mpNote; }
123cdf0e10cSrcweir     /** Takes ownership of the passed cell note object. */
124cdf0e10cSrcweir     void            TakeNote( ScPostIt* pNote );
125cdf0e10cSrcweir     /** Returns and forgets the own cell note object. Caller takes ownership! */
126cdf0e10cSrcweir     ScPostIt*       ReleaseNote();
127cdf0e10cSrcweir     /** Deletes the own cell note object. */
128cdf0e10cSrcweir     void            DeleteNote();
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     /** Returns true, if the cell contains a broadcaster. */
131cdf0e10cSrcweir     inline bool     HasBroadcaster() const { return mpBroadcaster != 0; }
132cdf0e10cSrcweir     /** Returns the pointer to the cell broadcaster. */
133cdf0e10cSrcweir     inline SvtBroadcaster* GetBroadcaster() const { return mpBroadcaster; }
134cdf0e10cSrcweir     /** Takes ownership of the passed cell broadcaster. */
135cdf0e10cSrcweir     void            TakeBroadcaster( SvtBroadcaster* pBroadcaster );
136cdf0e10cSrcweir     /** Returns and forgets the own cell broadcaster. Caller takes ownership! */
137cdf0e10cSrcweir     SvtBroadcaster* ReleaseBroadcaster();
138cdf0e10cSrcweir     /** Deletes the own cell broadcaster. */
139cdf0e10cSrcweir     void            DeleteBroadcaster();
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 						// String- oder EditCell
142cdf0e10cSrcweir 	static ScBaseCell* CreateTextCell( const String& rString, ScDocument* );
143cdf0e10cSrcweir 
144cdf0e10cSrcweir     // nOnlyNames may be one or more of SC_LISTENING_NAMES_*
145cdf0e10cSrcweir 	void			StartListeningTo( ScDocument* pDoc );
146cdf0e10cSrcweir 	void			EndListeningTo( ScDocument* pDoc,
147cdf0e10cSrcweir 									ScTokenArray* pArr = NULL,
148cdf0e10cSrcweir 									ScAddress aPos = ScAddress() );
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     /** Error code if ScFormulaCell, else 0. */
151cdf0e10cSrcweir     sal_uInt16          GetErrorCode() const;
152cdf0e10cSrcweir     /** ScFormulaCell with formula::svEmptyCell result, or ScNoteCell (may have been
153cdf0e10cSrcweir         created due to reference to empty cell). */
154cdf0e10cSrcweir 	sal_Bool			HasEmptyData() const;
155cdf0e10cSrcweir 	sal_Bool			HasValueData() const;
156cdf0e10cSrcweir 	sal_Bool			HasStringData() const;
157cdf0e10cSrcweir 	String			GetStringData() const;			// nur echte Strings
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 	static sal_Bool		CellEqual( const ScBaseCell* pCell1, const ScBaseCell* pCell2 );
160cdf0e10cSrcweir 
161cdf0e10cSrcweir private:
162cdf0e10cSrcweir     ScBaseCell&     operator=( const ScBaseCell& );
163cdf0e10cSrcweir 
164cdf0e10cSrcweir private:
165cdf0e10cSrcweir     ScPostIt*       mpNote;         /// The cell note. Cell takes ownership!
166cdf0e10cSrcweir     SvtBroadcaster* mpBroadcaster;  /// Broadcaster for changed values. Cell takes ownership!
167cdf0e10cSrcweir 
168cdf0e10cSrcweir protected:
169cdf0e10cSrcweir     sal_uInt16          nTextWidth;
170cdf0e10cSrcweir     sal_uInt8            eCellType;      // enum CellType - sal_uInt8 spart Speicher
171cdf0e10cSrcweir     sal_uInt8            nScriptType;
172cdf0e10cSrcweir };
173cdf0e10cSrcweir 
174cdf0e10cSrcweir // ============================================================================
175cdf0e10cSrcweir 
176cdf0e10cSrcweir class SC_DLLPUBLIC ScNoteCell : public ScBaseCell
177cdf0e10cSrcweir {
178cdf0e10cSrcweir public:
179cdf0e10cSrcweir #ifdef USE_MEMPOOL
180cdf0e10cSrcweir 	DECL_FIXEDMEMPOOL_NEWDEL( ScNoteCell )
181cdf0e10cSrcweir #endif
182cdf0e10cSrcweir 
183cdf0e10cSrcweir     /** Cell takes ownership of the passed broadcaster. */
184cdf0e10cSrcweir     explicit        ScNoteCell( SvtBroadcaster* pBC = 0 );
185cdf0e10cSrcweir     /** Cell takes ownership of the passed note and broadcaster. */
186cdf0e10cSrcweir     explicit        ScNoteCell( ScPostIt* pNote, SvtBroadcaster* pBC = 0 );
187cdf0e10cSrcweir 
188cdf0e10cSrcweir #ifdef DBG_UTIL
189cdf0e10cSrcweir 					~ScNoteCell();
190cdf0e10cSrcweir #endif
191cdf0e10cSrcweir 
192cdf0e10cSrcweir private:
193cdf0e10cSrcweir                     ScNoteCell( const ScNoteCell& );
194cdf0e10cSrcweir };
195cdf0e10cSrcweir 
196cdf0e10cSrcweir // ============================================================================
197cdf0e10cSrcweir 
198cdf0e10cSrcweir class SC_DLLPUBLIC ScValueCell : public ScBaseCell
199cdf0e10cSrcweir {
200cdf0e10cSrcweir public:
201cdf0e10cSrcweir #ifdef USE_MEMPOOL
202cdf0e10cSrcweir 	DECL_FIXEDMEMPOOL_NEWDEL( ScValueCell )
203cdf0e10cSrcweir #endif
204cdf0e10cSrcweir 					ScValueCell();
205cdf0e10cSrcweir     explicit		ScValueCell( double fValue );
206cdf0e10cSrcweir 
207cdf0e10cSrcweir #ifdef DBG_UTIL
208cdf0e10cSrcweir 					~ScValueCell();
209cdf0e10cSrcweir #endif
210cdf0e10cSrcweir 
211cdf0e10cSrcweir     inline void     SetValue( double fValue ) { mfValue = fValue; }
212cdf0e10cSrcweir     inline double   GetValue() const { return mfValue; }
213cdf0e10cSrcweir 
214cdf0e10cSrcweir private:
215cdf0e10cSrcweir 	double		    mfValue;
216cdf0e10cSrcweir };
217cdf0e10cSrcweir 
218cdf0e10cSrcweir // ============================================================================
219cdf0e10cSrcweir 
220cdf0e10cSrcweir class SC_DLLPUBLIC ScStringCell : public ScBaseCell
221cdf0e10cSrcweir {
222cdf0e10cSrcweir public:
223cdf0e10cSrcweir #ifdef USE_MEMPOOL
224cdf0e10cSrcweir 	DECL_FIXEDMEMPOOL_NEWDEL( ScStringCell )
225cdf0e10cSrcweir #endif
226cdf0e10cSrcweir 
227cdf0e10cSrcweir 					ScStringCell();
228cdf0e10cSrcweir     explicit		ScStringCell( const String& rString );
229cdf0e10cSrcweir 
230cdf0e10cSrcweir #ifdef DBG_UTIL
231cdf0e10cSrcweir 					~ScStringCell();
232cdf0e10cSrcweir #endif
233cdf0e10cSrcweir 
234cdf0e10cSrcweir     inline void		SetString( const String& rString ) { maString = rString; }
235cdf0e10cSrcweir     inline void		GetString( String& rString ) const { rString = maString; }
236cdf0e10cSrcweir 	inline const String& GetString() const { return maString; }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir private:
239cdf0e10cSrcweir 	String		    maString;
240cdf0e10cSrcweir };
241cdf0e10cSrcweir 
242cdf0e10cSrcweir // ============================================================================
243cdf0e10cSrcweir 
244cdf0e10cSrcweir class SC_DLLPUBLIC ScEditCell : public ScBaseCell
245cdf0e10cSrcweir {
246cdf0e10cSrcweir private:
247cdf0e10cSrcweir 	EditTextObject*		pData;
248cdf0e10cSrcweir 	String*				pString;		// fuer schnelleren Zugriff von Formeln
249cdf0e10cSrcweir 	ScDocument*			pDoc;			// fuer EditEngine Zugriff mit Pool
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 	void			SetTextObject( const EditTextObject* pObject,
252cdf0e10cSrcweir 									const SfxItemPool* pFromPool );
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 					// not implemented
255cdf0e10cSrcweir 					ScEditCell( const ScEditCell& );
256cdf0e10cSrcweir 
257cdf0e10cSrcweir public:
258cdf0e10cSrcweir 
259cdf0e10cSrcweir #ifdef USE_MEMPOOL
260cdf0e10cSrcweir 	DECL_FIXEDMEMPOOL_NEWDEL( ScEditCell )
261cdf0e10cSrcweir #endif
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 					~ScEditCell();				// wegen pData immer!
264cdf0e10cSrcweir 
265cdf0e10cSrcweir 					ScEditCell( const EditTextObject* pObject, ScDocument*,
266cdf0e10cSrcweir 								const SfxItemPool* pFromPool /* = NULL */ );
267cdf0e10cSrcweir                     ScEditCell( const ScEditCell& rCell, ScDocument& rDoc );
268cdf0e10cSrcweir 					// fuer Zeilenumbrueche
269cdf0e10cSrcweir 					ScEditCell( const String& rString, ScDocument* );
270cdf0e10cSrcweir 
271cdf0e10cSrcweir 	void			SetData( const EditTextObject* pObject,
272cdf0e10cSrcweir 							const SfxItemPool* pFromPool /* = NULL */ );
273cdf0e10cSrcweir 	void			GetData( const EditTextObject*& rpObject ) const;
274cdf0e10cSrcweir 	void			GetString( String& rString ) const;
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 	const EditTextObject* GetData() const	{ return pData; }
277cdf0e10cSrcweir };
278cdf0e10cSrcweir 
279cdf0e10cSrcweir // ============================================================================
280cdf0e10cSrcweir 
281cdf0e10cSrcweir enum ScMatrixMode {
282cdf0e10cSrcweir     MM_NONE      = 0,                   // No matrix formula
283cdf0e10cSrcweir     MM_FORMULA   = 1,                   // Upper left matrix formula cell
284cdf0e10cSrcweir     MM_REFERENCE = 2,                   // Remaining cells, via ocMatRef reference token
285cdf0e10cSrcweir     MM_FAKE      = 3                    // Interpret "as-if" matrix formula (legacy)
286cdf0e10cSrcweir };
287cdf0e10cSrcweir 
288cdf0e10cSrcweir class SC_DLLPUBLIC ScFormulaCell : public ScBaseCell, public SvtListener
289cdf0e10cSrcweir {
290cdf0e10cSrcweir private:
291cdf0e10cSrcweir     ScFormulaResult aResult;
292cdf0e10cSrcweir     formula::FormulaGrammar::Grammar  eTempGrammar;   // used between string (creation) and (re)compilation
293cdf0e10cSrcweir     ScTokenArray*   pCode;              // The (new) token array
294cdf0e10cSrcweir     ScDocument*     pDocument;
295cdf0e10cSrcweir     ScFormulaCell*  pPrevious;
296cdf0e10cSrcweir     ScFormulaCell*  pNext;
297cdf0e10cSrcweir     ScFormulaCell*  pPreviousTrack;
298cdf0e10cSrcweir     ScFormulaCell*  pNextTrack;
299cdf0e10cSrcweir     sal_uLong           nFormatIndex;       // Number format set by calculation
300cdf0e10cSrcweir     short           nFormatType;        // Number format type set by calculation
301cdf0e10cSrcweir     sal_uInt16          nSeenInIteration;   // Iteration cycle in which the cell was last encountered
302cdf0e10cSrcweir     sal_uInt8            cMatrixFlag;        // One of ScMatrixMode
303cdf0e10cSrcweir     sal_Bool            bDirty         : 1; // Must be (re)calculated
304cdf0e10cSrcweir     sal_Bool            bChanged       : 1; // Whether something changed regarding display/representation
305cdf0e10cSrcweir     sal_Bool            bRunning       : 1; // Already interpreting right now
306cdf0e10cSrcweir     sal_Bool            bCompile       : 1; // Must be (re)compiled
307cdf0e10cSrcweir     sal_Bool            bSubTotal      : 1; // Cell is part of or contains a SubTotal
308cdf0e10cSrcweir     sal_Bool            bIsIterCell    : 1; // Cell is part of a circular reference
309cdf0e10cSrcweir     sal_Bool            bInChangeTrack : 1; // Cell is in ChangeTrack
310cdf0e10cSrcweir     sal_Bool            bTableOpDirty  : 1; // Dirty flag for TableOp
311cdf0e10cSrcweir     sal_Bool            bNeedListening : 1; // Listeners need to be re-established after UpdateReference
312cdf0e10cSrcweir 
313cdf0e10cSrcweir                     enum ScInterpretTailParameter
314cdf0e10cSrcweir                     {
315cdf0e10cSrcweir                         SCITP_NORMAL,
316cdf0e10cSrcweir                         SCITP_FROM_ITERATION,
317cdf0e10cSrcweir                         SCITP_CLOSE_ITERATION_CIRCLE
318cdf0e10cSrcweir                     };
319cdf0e10cSrcweir 	void			InterpretTail( ScInterpretTailParameter );
320cdf0e10cSrcweir 
321cdf0e10cSrcweir     ScFormulaCell( const ScFormulaCell& );
322cdf0e10cSrcweir 
323cdf0e10cSrcweir public:
324cdf0e10cSrcweir 
325cdf0e10cSrcweir #ifdef USE_MEMPOOL
326cdf0e10cSrcweir 	DECL_FIXEDMEMPOOL_NEWDEL( ScFormulaCell )
327cdf0e10cSrcweir #endif
328cdf0e10cSrcweir 
329cdf0e10cSrcweir 	ScAddress		aPos;
330cdf0e10cSrcweir 
331cdf0e10cSrcweir 					~ScFormulaCell();
332cdf0e10cSrcweir 					ScFormulaCell();
333cdf0e10cSrcweir 
334cdf0e10cSrcweir     /** Empty formula cell, or with a preconstructed token array. */
335cdf0e10cSrcweir     ScFormulaCell( ScDocument*, const ScAddress&, const ScTokenArray* = NULL,
336cdf0e10cSrcweir                     const formula::FormulaGrammar::Grammar = formula::FormulaGrammar::GRAM_DEFAULT,
337cdf0e10cSrcweir                     sal_uInt8 = MM_NONE );
338cdf0e10cSrcweir 
339cdf0e10cSrcweir     /** With formula string and grammar to compile with.
340cdf0e10cSrcweir        formula::FormulaGrammar::GRAM_DEFAULT effectively isformula::FormulaGrammar::GRAM_NATIVE_UI that
341cdf0e10cSrcweir         also includes formula::FormulaGrammar::CONV_UNSPECIFIED, therefor uses the address
342cdf0e10cSrcweir         convention associated with rPos::nTab by default. */
343cdf0e10cSrcweir     ScFormulaCell( ScDocument* pDoc, const ScAddress& rPos,
344cdf0e10cSrcweir                     const String& rFormula,
345cdf0e10cSrcweir                     const formula::FormulaGrammar::Grammar = formula::FormulaGrammar::GRAM_DEFAULT,
346cdf0e10cSrcweir                     sal_uInt8 cMatInd = MM_NONE );
347cdf0e10cSrcweir 
348cdf0e10cSrcweir     ScFormulaCell( const ScFormulaCell& rCell, ScDocument& rDoc, const ScAddress& rPos, int nCloneFlags = SC_CLONECELL_DEFAULT );
349cdf0e10cSrcweir 
350cdf0e10cSrcweir 	void			GetFormula( String& rFormula,
351cdf0e10cSrcweir 								const formula::FormulaGrammar::Grammar = formula::FormulaGrammar::GRAM_DEFAULT ) const;
352cdf0e10cSrcweir 	void			GetFormula( rtl::OUStringBuffer& rBuffer,
353cdf0e10cSrcweir 								const formula::FormulaGrammar::Grammar = formula::FormulaGrammar::GRAM_DEFAULT ) const;
354cdf0e10cSrcweir 
355cdf0e10cSrcweir 	void			SetDirty();
356cdf0e10cSrcweir 	inline void		SetDirtyVar() { bDirty = sal_True; }
357cdf0e10cSrcweir     // If setting entire document dirty after load, no broadcasts but still append to FormulaTree.
358cdf0e10cSrcweir     void            SetDirtyAfterLoad();
359cdf0e10cSrcweir 	inline void		ResetTableOpDirtyVar() { bTableOpDirty = sal_False; }
360cdf0e10cSrcweir 	void			SetTableOpDirty();
361cdf0e10cSrcweir 	sal_Bool			IsDirtyOrInTableOpDirty() const;
362cdf0e10cSrcweir 	sal_Bool			GetDirty() const { return bDirty; }
363cdf0e10cSrcweir     sal_Bool            NeedsListening() const { return bNeedListening; }
364cdf0e10cSrcweir     void            SetNeedsListening( sal_Bool bVar ) { bNeedListening = bVar; }
365cdf0e10cSrcweir 	void			Compile(const String& rFormula,
366cdf0e10cSrcweir 							sal_Bool bNoListening = sal_False,
367cdf0e10cSrcweir                             const formula::FormulaGrammar::Grammar = formula::FormulaGrammar::GRAM_DEFAULT );
368cdf0e10cSrcweir 	void			CompileTokenArray( sal_Bool bNoListening = sal_False );
369cdf0e10cSrcweir 	void			CompileXML( ScProgress& rProgress );		// compile temporary string tokens
370cdf0e10cSrcweir 	void			CalcAfterLoad();
371cdf0e10cSrcweir     bool            MarkUsedExternalReferences();
372cdf0e10cSrcweir 	void			Interpret();
373cdf0e10cSrcweir     inline sal_Bool     IsIterCell() const { return bIsIterCell; }
374cdf0e10cSrcweir     inline sal_uInt16   GetSeenInIteration() const { return nSeenInIteration; }
375cdf0e10cSrcweir 
376cdf0e10cSrcweir 	sal_Bool			HasOneReference( ScRange& r ) const;
377cdf0e10cSrcweir     /* Checks if the formula contains reference list that can be
378cdf0e10cSrcweir        expressed by one reference (like A1;A2;A3:A5 -> A1:A5). The
379cdf0e10cSrcweir        reference list is not required to be sorted (i.e. A3;A1;A2 is
380cdf0e10cSrcweir        still recognized as A1:A3), but no overlapping is allowed.
381cdf0e10cSrcweir        If one reference is recognized, the rRange is filled.
382cdf0e10cSrcweir 
383cdf0e10cSrcweir        It is similar to HasOneReference(), but more general.
384cdf0e10cSrcweir      */
385cdf0e10cSrcweir     bool HasRefListExpressibleAsOneReference(ScRange& rRange) const;
386cdf0e10cSrcweir 	sal_Bool			HasRelNameReference() const;
387cdf0e10cSrcweir 	sal_Bool			HasColRowName() const;
388cdf0e10cSrcweir 
389cdf0e10cSrcweir 	void			UpdateReference(UpdateRefMode eUpdateRefMode,
390cdf0e10cSrcweir 									const ScRange& r,
391cdf0e10cSrcweir 									SCsCOL nDx, SCsROW nDy, SCsTAB nDz,
392cdf0e10cSrcweir                                     ScDocument* pUndoDoc = NULL,
393cdf0e10cSrcweir                                     const ScAddress* pUndoCellPos = NULL );
394cdf0e10cSrcweir 
395cdf0e10cSrcweir 	void			TransposeReference();
396cdf0e10cSrcweir 	void			UpdateTranspose( const ScRange& rSource, const ScAddress& rDest,
397cdf0e10cSrcweir 										ScDocument* pUndoDoc );
398cdf0e10cSrcweir 
399cdf0e10cSrcweir 	void			UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY );
400cdf0e10cSrcweir 
401cdf0e10cSrcweir 	void			UpdateInsertTab(SCTAB nTable);
402cdf0e10cSrcweir 	void 			UpdateInsertTabAbs(SCTAB nTable);
403cdf0e10cSrcweir 	sal_Bool			UpdateDeleteTab(SCTAB nTable, sal_Bool bIsMove = sal_False);
404cdf0e10cSrcweir 	void			UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo);
405cdf0e10cSrcweir 	void			UpdateRenameTab(SCTAB nTable, const String& rName);
406cdf0e10cSrcweir 	sal_Bool 			TestTabRefAbs(SCTAB nTable);
407cdf0e10cSrcweir 	void			UpdateCompile( sal_Bool bForceIfNameInUse = sal_False );
408cdf0e10cSrcweir 	sal_Bool			IsRangeNameInUse(sal_uInt16 nIndex) const;
409cdf0e10cSrcweir     void            FindRangeNamesInUse(std::set<sal_uInt16>& rIndexes) const;
410cdf0e10cSrcweir 	void 			ReplaceRangeNamesInUse( const ScRangeData::IndexMap& rMap );
411cdf0e10cSrcweir 	sal_Bool			IsSubTotal() const 						{ return bSubTotal; }
412cdf0e10cSrcweir 	sal_Bool			IsChanged() const  						{ return bChanged; }
413cdf0e10cSrcweir 	void			ResetChanged()							{ bChanged = sal_False; }
414cdf0e10cSrcweir 	sal_Bool			IsEmpty();      // formula::svEmptyCell result
415cdf0e10cSrcweir                     // display as empty string if formula::svEmptyCell result
416cdf0e10cSrcweir 	sal_Bool			IsEmptyDisplayedAsString();
417cdf0e10cSrcweir 	sal_Bool			IsValue();      // also sal_True if formula::svEmptyCell
418cdf0e10cSrcweir 	double			GetValue();
419cdf0e10cSrcweir 	double			GetValueAlways();	// ignore errors
420cdf0e10cSrcweir 	void			GetString( String& rString );
421cdf0e10cSrcweir 	const ScMatrix* GetMatrix();
422cdf0e10cSrcweir 	sal_Bool			GetMatrixOrigin( ScAddress& rPos ) const;
423cdf0e10cSrcweir 	void			GetResultDimensions( SCSIZE& rCols, SCSIZE& rRows );
424cdf0e10cSrcweir 	sal_uInt16 			GetMatrixEdge( ScAddress& rOrgPos );
425cdf0e10cSrcweir 	sal_uInt16			GetErrCode();   // interpret first if necessary
426cdf0e10cSrcweir 	sal_uInt16			GetRawError();  // don't interpret, just return code or result error
427cdf0e10cSrcweir 	short			GetFormatType() const   				{ return nFormatType; }
428cdf0e10cSrcweir 	sal_uLong			GetFormatIndex() const					{ return nFormatIndex; }
429cdf0e10cSrcweir 	void			GetFormatInfo( short& nType, sal_uLong& nIndex ) const
430cdf0e10cSrcweir 						{ nType = nFormatType; nIndex = nFormatIndex; }
431cdf0e10cSrcweir 	sal_uInt8			GetMatrixFlag() const   				{ return cMatrixFlag; }
432cdf0e10cSrcweir 	ScTokenArray*   GetCode() const                         { return pCode; }
433cdf0e10cSrcweir 
434cdf0e10cSrcweir 	sal_Bool			IsRunning() const						{ return bRunning; }
435cdf0e10cSrcweir 	void			SetRunning( sal_Bool bVal )					{ bRunning = bVal; }
436cdf0e10cSrcweir 	void 			CompileDBFormula();
437cdf0e10cSrcweir 	void 			CompileDBFormula( sal_Bool bCreateFormulaString );
438cdf0e10cSrcweir 	void 			CompileNameFormula( sal_Bool bCreateFormulaString );
439cdf0e10cSrcweir 	void 			CompileColRowNameFormula();
440cdf0e10cSrcweir 	ScFormulaCell*	GetPrevious() const					{ return pPrevious; }
441cdf0e10cSrcweir 	ScFormulaCell*	GetNext() const						{ return pNext; }
442cdf0e10cSrcweir 	void			SetPrevious( ScFormulaCell* pF )	{ pPrevious = pF; }
443cdf0e10cSrcweir 	void			SetNext( ScFormulaCell* pF )		{ pNext = pF; }
444cdf0e10cSrcweir 	ScFormulaCell*	GetPreviousTrack() const				{ return pPreviousTrack; }
445cdf0e10cSrcweir 	ScFormulaCell*	GetNextTrack() const					{ return pNextTrack; }
446cdf0e10cSrcweir 	void			SetPreviousTrack( ScFormulaCell* pF )	{ pPreviousTrack = pF; }
447cdf0e10cSrcweir 	void			SetNextTrack( ScFormulaCell* pF )		{ pNextTrack = pF; }
448cdf0e10cSrcweir 
449cdf0e10cSrcweir 	virtual void    Notify( SvtBroadcaster& rBC, const SfxHint& rHint);
450cdf0e10cSrcweir 	void			SetCompile( sal_Bool bVal ) { bCompile = bVal; }
451cdf0e10cSrcweir 	ScDocument*		GetDocument() const		{ return pDocument; }
452cdf0e10cSrcweir 	void			SetMatColsRows( SCCOL nCols, SCROW nRows );
453cdf0e10cSrcweir 	void			GetMatColsRows( SCCOL& nCols, SCROW& nRows ) const;
454cdf0e10cSrcweir 
455cdf0e10cSrcweir 					// ob Zelle im ChangeTrack und nicht im echten Dokument ist
456cdf0e10cSrcweir 	void			SetInChangeTrack( sal_Bool bVal ) { bInChangeTrack = bVal; }
457cdf0e10cSrcweir 	sal_Bool			IsInChangeTrack() const { return bInChangeTrack; }
458cdf0e10cSrcweir 
459cdf0e10cSrcweir 					// Zu Typ und Format das entsprechende Standardformat.
460cdf0e10cSrcweir 					// Bei Format "Standard" evtl. das in die Formelzelle
461cdf0e10cSrcweir 					// uebernommene Format.
462cdf0e10cSrcweir 	sal_uLong			GetStandardFormat( SvNumberFormatter& rFormatter, sal_uLong nFormat ) const;
463cdf0e10cSrcweir 
464cdf0e10cSrcweir 	// For import filters!
465cdf0e10cSrcweir     void 			AddRecalcMode( formula::ScRecalcMode );
466cdf0e10cSrcweir     /** For import only: set a double result. */
467cdf0e10cSrcweir 	void			SetHybridDouble( double n )     { aResult.SetHybridDouble( n); }
468cdf0e10cSrcweir     /** For import only: set a string result.
469cdf0e10cSrcweir         If for whatever reason you have to use both, SetHybridDouble() and
470cdf0e10cSrcweir         SetHybridString() or SetHybridFormula(), use SetHybridDouble() first
471cdf0e10cSrcweir         for performance reasons.*/
472cdf0e10cSrcweir     void            SetHybridString( const String& r )
473cdf0e10cSrcweir                         { aResult.SetHybridString( r); }
474cdf0e10cSrcweir     /** For import only: set a temporary formula string to be compiled later.
475cdf0e10cSrcweir         If for whatever reason you have to use both, SetHybridDouble() and
476cdf0e10cSrcweir         SetHybridString() or SetHybridFormula(), use SetHybridDouble() first
477cdf0e10cSrcweir         for performance reasons.*/
478cdf0e10cSrcweir     void            SetHybridFormula( const String& r,
479cdf0e10cSrcweir                                     const formula::FormulaGrammar::Grammar eGrammar )
480cdf0e10cSrcweir                         { aResult.SetHybridFormula( r); eTempGrammar = eGrammar; }
481cdf0e10cSrcweir 	void			SetErrCode( sal_uInt16 n );
482cdf0e10cSrcweir 	inline sal_Bool		IsHyperLinkCell() const { return pCode && pCode->IsHyperLink(); }
483cdf0e10cSrcweir 	EditTextObject*		CreateURLObject() ;
484cdf0e10cSrcweir     void            GetURLResult( String& rURL, String& rCellText );
485cdf0e10cSrcweir 
486cdf0e10cSrcweir     /** Determines whether or not the result string contains more than one paragraph */
487cdf0e10cSrcweir     bool            IsMultilineResult();
488cdf0e10cSrcweir };
489cdf0e10cSrcweir 
490cdf0e10cSrcweir //			Iterator fuer Referenzen in einer Formelzelle
491cdf0e10cSrcweir class ScDetectiveRefIter
492cdf0e10cSrcweir {
493cdf0e10cSrcweir private:
494cdf0e10cSrcweir 	ScTokenArray* pCode;
495cdf0e10cSrcweir 	ScAddress aPos;
496cdf0e10cSrcweir public:
497cdf0e10cSrcweir 				ScDetectiveRefIter( ScFormulaCell* pCell );
498cdf0e10cSrcweir 	sal_Bool		GetNextRef( ScRange& rRange );
499cdf0e10cSrcweir };
500cdf0e10cSrcweir 
501cdf0e10cSrcweir // ============================================================================
502*b4df81e3SWang Lei inline double GetValueFromCell( const ScBaseCell * pCell )
503*b4df81e3SWang Lei {
504*b4df81e3SWang Lei     switch (pCell->GetCellType())
505*b4df81e3SWang Lei     {
506*b4df81e3SWang Lei     case CELLTYPE_VALUE:
507*b4df81e3SWang Lei         return ((ScValueCell*)pCell)->GetValue();
508*b4df81e3SWang Lei     case CELLTYPE_FORMULA:
509*b4df81e3SWang Lei         {
510*b4df81e3SWang Lei             if (((ScFormulaCell*)pCell)->IsValue())
511*b4df81e3SWang Lei                 return ((ScFormulaCell*)pCell)->GetValue();
512*b4df81e3SWang Lei             else
513*b4df81e3SWang Lei                 return 0.0;
514*b4df81e3SWang Lei         }
515*b4df81e3SWang Lei     default:
516*b4df81e3SWang Lei         return 0.0;
517*b4df81e3SWang Lei     }
518*b4df81e3SWang Lei }
519*b4df81e3SWang Lei // ============================================================================
520*b4df81e3SWang Lei 
521*b4df81e3SWang Lei 
522*b4df81e3SWang Lei inline String GetStringFromCell( const ScBaseCell * pCell, sal_uLong nFormat, SvNumberFormatter* pFormatter )
523*b4df81e3SWang Lei {
524*b4df81e3SWang Lei     if (pCell->GetCellType() != CELLTYPE_NOTE)
525*b4df81e3SWang Lei     {
526*b4df81e3SWang Lei         String strResult;
527*b4df81e3SWang Lei 	Color* pColor = NULL;
528*b4df81e3SWang Lei         ScCellFormat::GetString( const_cast<ScBaseCell*>(pCell), nFormat, strResult, &pColor, *(pFormatter) );
529*b4df81e3SWang Lei         return strResult;
530*b4df81e3SWang Lei     }
531*b4df81e3SWang Lei     else
532*b4df81e3SWang Lei         return String();
533*b4df81e3SWang Lei }
534cdf0e10cSrcweir 
535cdf0e10cSrcweir #endif
536cdf0e10cSrcweir 
537