bump product version to 4.1.6.2
[LibreOffice.git] / sc / inc / cell.hxx
blob597feb85719c735670ce969aaf24c0b92d0c3047
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef SC_CELL_HXX
21 #define SC_CELL_HXX
23 #include "scdllapi.h"
24 #include "global.hxx"
26 #include "tools/mempool.hxx"
28 #include <boost/shared_ptr.hpp>
30 #define USE_MEMPOOL
32 class ScDocument;
33 class EditTextObject;
34 class ScMatrix;
35 class SvtBroadcaster;
36 class ScProgress;
37 class ScPatternAttr;
39 class ScBaseCell
41 protected:
42 ~ScBaseCell(); // not virtual - not to be called directly.
44 public:
45 explicit ScBaseCell( CellType eNewType );
47 /** Base copy constructor. Does NOT clone cell note or broadcaster! */
48 ScBaseCell( const ScBaseCell& rCell );
50 /** Returns a clone of this cell at the same position,
51 broadcaster will not be cloned. */
52 ScBaseCell* Clone( ScDocument& rDestDoc, int nCloneFlags = SC_CLONECELL_DEFAULT ) const;
54 /** Returns a clone of this cell for the passed document position,
55 broadcaster will not be cloned. */
56 ScBaseCell* Clone( ScDocument& rDestDoc, const ScAddress& rDestPos, int nCloneFlags = SC_CLONECELL_DEFAULT ) const;
58 /** Due to the fact that ScBaseCell does not have a vtable, this function
59 deletes the cell by calling the appropriate d'tor of the derived class. */
60 void Delete();
62 inline CellType GetCellType() const { return (CellType)eCellType; }
64 /** ScFormulaCell with formula::svEmptyCell result, or ScNoteCell (may have been
65 created due to reference to empty cell). */
66 bool HasEmptyData() const;
67 bool HasValueData() const;
68 bool HasStringData() const;
69 OUString GetStringData() const; // only real strings
71 private:
72 ScBaseCell& operator=( const ScBaseCell& );
74 protected:
75 sal_uInt8 eCellType; // enum CellType - sal_uInt8 spart Speicher
78 class ScValueCell : public ScBaseCell
80 public:
81 #ifdef USE_MEMPOOL
82 DECL_FIXEDMEMPOOL_NEWDEL( ScValueCell )
83 #endif
85 explicit ScValueCell( double fValue );
87 #if OSL_DEBUG_LEVEL > 0
88 ~ScValueCell();
89 #endif
91 inline void SetValue( double fValue ) { mfValue = fValue; }
92 inline double GetValue() const { return mfValue; }
93 double* GetValuePtr() { return &mfValue; }
95 private:
96 double mfValue;
99 class ScStringCell : public ScBaseCell
101 public:
102 #ifdef USE_MEMPOOL
103 DECL_FIXEDMEMPOOL_NEWDEL( ScStringCell )
104 #endif
106 explicit ScStringCell(const OUString& rString);
108 #if OSL_DEBUG_LEVEL > 0
109 ~ScStringCell();
110 #endif
112 inline void SetString( const OUString& rString ) { maString = rString; }
113 inline const OUString& GetString() const { return maString; }
114 const OUString* GetStringPtr() const { return &maString; }
116 private:
117 OUString maString;
120 class ScEditCell : public ScBaseCell
122 EditTextObject* mpData;
123 mutable OUString* mpString; // for faster access to formulas
124 ScDocument* mpDoc; // for EditEngine access with Pool
126 void SetTextObject( const EditTextObject* pObject,
127 const SfxItemPool* pFromPool );
129 // not implemented
130 ScEditCell( const ScEditCell& );
132 public:
134 #ifdef USE_MEMPOOL
135 DECL_FIXEDMEMPOOL_NEWDEL( ScEditCell )
136 #endif
138 ~ScEditCell(); // always because of pData!
141 * Constructor that takes ownership of the passed EditTextObject instance
142 * which the caller must not delete afterward!
144 * <p>Also ensure that the passed edit text object <i>uses the SfxItemPool
145 * instance returned from ScDocument::GetEditPool()</i>. This is
146 * important.</p>
148 ScEditCell(EditTextObject* pObject, ScDocument* pDoc);
151 * Constructor. The caller is responsible for deleting the text object
152 * instance passed on to this constructor, since it creates a clone and
153 * stores it instead of the original.
155 * @param rObject text object to clone from.
156 * @param pDoc pointer to the document instance.
157 * @param pFromPool pointer to SfxItemPool instance that the new text
158 * object that is to be stored in the cell instance
159 * should use. If it's NULL, it uses the default pool
160 * for edit cells from the document instance (one
161 * returned from GetEditPool()).
163 ScEditCell(const EditTextObject& rObject, ScDocument* pDoc, const SfxItemPool* pFromPool);
164 ScEditCell(const ScEditCell& rCell, ScDocument& rDoc, const ScAddress& rDestPos);
166 // for line breaks
167 ScEditCell(const OUString& rString, ScDocument* pDoc);
170 * Remove the text data as well as string cache.
172 void ClearData();
175 * Set new text data. This method clones the passed text data and stores
176 * the clone; the caller is responsible for deleting the text data
177 * instance after the call.
179 * @param rObject text object to clone from.
180 * @param pFromPool pointer to SfxItemPool instance that the new text
181 * object that is to be stored in the cell instance
182 * should use. If it's NULL, it uses the default pool
183 * for edit cells from the document instance (one
184 * returned from GetEditPool()).
186 void SetData(const EditTextObject& rObject, const SfxItemPool* pFromPool);
189 * Set new text data. The passed text data instance will be owned by the
190 * cell. The caller must ensure that the text data uses the SfxItemPool
191 * instance returned from ScDocument::GetEditPool().
193 void SetData(EditTextObject* pObject);
195 OUString GetString() const;
197 const EditTextObject* GetData() const;
199 /** Removes character attribute based on new pattern attributes. */
200 void RemoveCharAttribs( const ScPatternAttr& rAttr );
202 /** Update field items if any. */
203 void UpdateFields(SCTAB nTab);
206 class ScEditDataArray
208 public:
209 class Item
211 public:
212 explicit Item(SCTAB nTab, SCCOL nCol, SCROW nRow,
213 EditTextObject* pOldData, EditTextObject* pNewData);
214 ~Item();
216 const EditTextObject* GetOldData() const;
217 const EditTextObject* GetNewData() const;
218 SCTAB GetTab() const;
219 SCCOL GetCol() const;
220 SCROW GetRow() const;
222 private:
223 Item(); // disabled
225 private:
226 ::boost::shared_ptr<EditTextObject> mpOldData;
227 ::boost::shared_ptr<EditTextObject> mpNewData;
228 SCTAB mnTab;
229 SCCOL mnCol;
230 SCROW mnRow;
234 ScEditDataArray();
235 ~ScEditDataArray();
237 void AddItem(SCTAB nTab, SCCOL nCol, SCROW nRow,
238 EditTextObject* pOldData, EditTextObject* pNewData);
240 const Item* First();
241 const Item* Next();
243 private:
244 ::std::vector<Item>::const_iterator maIter;
245 ::std::vector<Item> maArray;
248 #endif
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */