tdf#48459 sw inline heading: don't apply inside frames or over 120 chars
[LibreOffice.git] / sc / inc / cellvalue.hxx
blobbfbe228a857537ad7c2d4fd5b09644bfb45fa5ef
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 #pragma once
12 #include "global.hxx"
13 #include <svl/sharedstring.hxx>
14 #include <variant>
16 class ScDocument;
17 class ScFormulaCell;
18 class EditTextObject;
19 class ScColumn;
20 struct ScRefCellValue;
22 namespace sc {
23 struct ColumnBlockPosition;
25 namespace svl { class SharedStringPool; }
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 ScCellValue
34 private:
35 /// std::monostate is there to indicate CellType::NONE
36 std::variant<std::monostate, double, svl::SharedString, EditTextObject*, ScFormulaCell*> maData;
38 void reset_to_empty();
39 public:
41 SC_DLLPUBLIC ScCellValue();
42 ScCellValue( const ScRefCellValue& rCell );
43 ScCellValue( double fValue );
44 ScCellValue( const svl::SharedString& rString );
45 ScCellValue( std::unique_ptr<EditTextObject> );
46 ScCellValue( const ScCellValue& r );
47 ScCellValue(ScCellValue&& r) noexcept;
48 SC_DLLPUBLIC ~ScCellValue();
50 SC_DLLPUBLIC void clear() noexcept;
52 SC_DLLPUBLIC void set( double fValue );
53 SC_DLLPUBLIC void set( const svl::SharedString& rStr );
54 void set( const EditTextObject& rEditText );
55 SC_DLLPUBLIC void set( std::unique_ptr<EditTextObject> );
56 SC_DLLPUBLIC void set( ScFormulaCell* pFormula );
58 SC_DLLPUBLIC CellType getType() const;
59 double getDouble() const { return std::get<double>(maData); }
60 ScFormulaCell* getFormula() const { return std::get<ScFormulaCell*>(maData); }
61 const svl::SharedString* getSharedString() const { return &std::get<svl::SharedString>(maData); }
62 EditTextObject* getEditText() const { return std::get<EditTextObject*>(maData); }
63 EditTextObject* releaseEditText() { auto p = getEditText(); maData = static_cast<EditTextObject*>(nullptr); return p; }
64 ScFormulaCell* releaseFormula() { auto p = getFormula(); maData = static_cast<ScFormulaCell*>(nullptr); return p; }
66 /**
67 * Take cell value from specified position in specified document.
69 void assign( const ScDocument& rDoc, const ScAddress& rPos );
71 void assign(const ScCellValue& rOther, ScDocument& rDestDoc, ScCloneFlags nCloneFlags = ScCloneFlags::Default);
73 /**
74 * Set cell value at specified position in specified document.
76 void commit( ScDocument& rDoc, const ScAddress& rPos ) const;
78 void commit( ScColumn& rColumn, SCROW nRow ) const;
80 /**
81 * Set cell value at specified position in specified document. But unlike
82 * commit(), this method sets the original value to the document without
83 * copying. After this call, the value gets cleared.
85 void release( ScDocument& rDoc, const ScAddress& rPos );
87 void release( ScColumn& rColumn, SCROW nRow, sc::StartListeningType eListenType = sc::SingleCellListening );
89 OUString getString( const ScDocument& rDoc ) const;
91 SC_DLLPUBLIC bool isEmpty() const;
93 bool equalsWithoutFormat( const ScCellValue& r ) const;
95 ScCellValue& operator= ( const ScCellValue& r );
96 ScCellValue& operator=(ScCellValue&& r) noexcept;
97 ScCellValue& operator= ( const ScRefCellValue& r );
99 void swap( ScCellValue& r );
103 * This is very similar to ScCellValue, except that it references the
104 * original value instead of copying it. As such, don't hold an instance of
105 * this class any longer than necessary, and absolutely not after the
106 * original cell has been destroyed.
108 struct SAL_DLLPUBLIC_RTTI ScRefCellValue
110 private:
111 CellType meType;
112 union {
113 double mfValue;
114 const svl::SharedString* mpString;
115 const EditTextObject* mpEditText;
116 ScFormulaCell* mpFormula;
118 public:
120 SC_DLLPUBLIC ScRefCellValue();
121 SC_DLLPUBLIC ScRefCellValue( double fValue );
122 ScRefCellValue( const svl::SharedString* pString );
123 ScRefCellValue( const EditTextObject* pEditText );
124 ScRefCellValue( ScFormulaCell* pFormula );
127 * Take cell value from specified position in specified document.
129 SC_DLLPUBLIC ScRefCellValue( ScDocument& rDoc, const ScAddress& rPos );
130 SC_DLLPUBLIC ScRefCellValue( ScDocument& rDoc, const ScAddress& rPos, sc::ColumnBlockPosition& rBlockPos );
132 bool operator==(const ScRefCellValue&) const;
134 void clear();
136 CellType getType() const { return meType; }
137 double getDouble() const { assert(meType == CELLTYPE_VALUE); return mfValue; }
138 const svl::SharedString* getSharedString() const { assert(meType == CELLTYPE_STRING); return mpString; }
139 const EditTextObject* getEditText() const { assert(meType == CELLTYPE_EDIT); return mpEditText; }
140 ScFormulaCell* getFormula() const { assert(meType == CELLTYPE_FORMULA); return mpFormula; }
143 * Take cell value from specified position in specified document.
145 SC_DLLPUBLIC void assign( ScDocument& rDoc, const ScAddress& rPos );
146 void assign( ScDocument& rDoc, const ScAddress& rPos, sc::ColumnBlockPosition& rBlockPos );
149 * Set cell value at specified position in specified document.
151 void commit( ScDocument& rDoc, const ScAddress& rPos ) const;
153 bool hasString() const;
155 SC_DLLPUBLIC bool hasNumeric() const;
157 bool hasError() const;
159 double getValue();
162 * Retrieve a numeric value without modifying the states of any objects in
163 * the referenced document store.
165 double getRawValue() const;
168 * Retrieve string value.
170 * Note that this method is NOT thread-safe.
172 * @param pDoc
173 * Needed to resolve EditCells' field contents, obtain a
174 * ScFieldEditEngine from that document. May be NULL if there is
175 * no ScDocument in the calling context but then the document
176 * specific fields can not be resolved. See
177 * ScEditUtil::GetString().
179 SC_DLLPUBLIC OUString getString( const ScDocument* pDoc ) const;
180 SC_DLLPUBLIC svl::SharedString getSharedString( const ScDocument* pDoc, svl::SharedStringPool& rStrPool ) const;
183 * Retrieve a string value without modifying the states of any objects in
184 * the referenced document store.
186 * This method is thread-safe.
188 OUString getRawString( const ScDocument& rDoc ) const;
190 SC_DLLPUBLIC bool isEmpty() const;
192 bool hasEmptyValue();
194 bool equalsWithoutFormat( const ScRefCellValue& r ) const;
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */