Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / inc / cellvalue.hxx
blobc2606b511e72338889bab54b1404815e26a48231
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #ifndef SC_CELLVALUE_HXX
11 #define SC_CELLVALUE_HXX
13 #include "global.hxx"
15 class ScDocument;
16 class ScFormulaCell;
17 class EditTextObject;
18 class ScColumn;
19 struct ScRefCellValue;
21 namespace svl {
23 class SharedString;
27 /**
28 * Store arbitrary cell value of any kind. It only stores cell value and
29 * nothing else. It creates a copy of the original cell value, and manages
30 * the life cycle of the copied value.
32 struct SC_DLLPUBLIC ScCellValue
34 CellType meType;
35 union {
36 double mfValue;
37 svl::SharedString* mpString;
38 EditTextObject* mpEditText;
39 ScFormulaCell* mpFormula;
42 ScCellValue();
43 ScCellValue( const ScRefCellValue& rCell );
44 ScCellValue( double fValue );
45 ScCellValue( const svl::SharedString& rString );
46 ScCellValue( const EditTextObject& rEditText );
47 ScCellValue( const ScFormulaCell& rFormula );
48 ScCellValue( const ScCellValue& r );
49 ~ScCellValue();
51 void clear();
53 void set( double fValue );
54 void set( const svl::SharedString& rStr );
55 void set( const EditTextObject& rEditText );
56 void set( const ScFormulaCell& rFormula );
57 void set( ScFormulaCell* pFormula );
59 /**
60 * Take cell value from specified position in specified document.
62 void assign( const ScDocument& rDoc, const ScAddress& rPos );
64 void assign( const ScCellValue& rOther, ScDocument& rDestDoc, int nCloneFlags = SC_CLONECELL_DEFAULT );
66 /**
67 * Set cell value at specified position in specified document.
69 void commit( ScDocument& rDoc, const ScAddress& rPos ) const;
71 void commit( ScColumn& rColumn, SCROW nRow ) const;
73 /**
74 * Set cell value at specified position in specified document. But unlike
75 * commit(), this method sets the original value to the document without
76 * copying. After this call, the value gets cleared.
78 void release( ScDocument& rDoc, const ScAddress& rPos );
80 void release( ScColumn& rColumn, SCROW nRow );
82 bool hasString() const;
84 bool hasNumeric() const;
86 bool isEmpty() const;
88 bool equalsWithoutFormat( const ScCellValue& r ) const;
90 ScCellValue& operator= ( const ScCellValue& r );
91 ScCellValue& operator= ( const ScRefCellValue& r );
93 void swap( ScCellValue& r );
96 /**
97 * This is very similar to ScCellValue, except that it references the
98 * original value instead of copying it. As such, don't hold an instance of
99 * this class any longer than necessary, and absolutely not after the
100 * original cell has been destroyed.
102 struct SC_DLLPUBLIC ScRefCellValue
104 CellType meType;
105 union {
106 double mfValue;
107 const svl::SharedString* mpString;
108 const EditTextObject* mpEditText;
109 ScFormulaCell* mpFormula;
112 ScRefCellValue();
113 ScRefCellValue( double fValue );
114 ScRefCellValue( const svl::SharedString* pString );
115 ScRefCellValue( const EditTextObject* pEditText );
116 ScRefCellValue( ScFormulaCell* pFormula );
117 ScRefCellValue( const ScRefCellValue& r );
118 ~ScRefCellValue();
120 void clear();
123 * Take cell value from specified position in specified document.
125 void assign( ScDocument& rDoc, const ScAddress& rPos );
128 * Set cell value at specified position in specified document.
130 void commit( ScDocument& rDoc, const ScAddress& rPos ) const;
132 void commit( ScColumn& rColumn, SCROW nRow ) const;
134 bool hasString() const;
136 bool hasNumeric() const;
138 double getValue();
140 /** Retrieve string value.
142 @param pDoc
143 Needed to resolve EditCells' field contents, obtain a
144 ScFieldEditEngine from that document. May be NULL if there is
145 no ScDocument in the calling context but then the document
146 specific fields can not be resolved. See
147 ScEditUtil::GetString().
149 OUString getString( const ScDocument* pDoc );
151 bool isEmpty() const;
153 bool hasEmptyValue();
155 bool equalsWithoutFormat( const ScRefCellValue& r ) const;
157 ScRefCellValue& operator= ( const ScRefCellValue& r );
159 void swap( ScRefCellValue& r );
162 #endif
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */