fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / core / data / clipcontext.cxx
blob9988a483c3fe6b6568f178383e9b52ec68d436c4
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 #include "clipcontext.hxx"
11 #include "document.hxx"
12 #include "mtvelements.hxx"
13 #include <column.hxx>
14 #include <scitems.hxx>
15 #include <tokenarray.hxx>
16 #include <editutil.hxx>
17 #include <clipparam.hxx>
19 #include <svl/intitem.hxx>
21 namespace sc {
23 ClipContextBase::ClipContextBase(ScDocument& rDoc) :
24 mpSet(new ColumnBlockPositionSet(rDoc)) {}
26 ClipContextBase::~ClipContextBase() {}
28 ColumnBlockPosition* ClipContextBase::getBlockPosition(SCTAB nTab, SCCOL nCol)
30 return mpSet->getBlockPosition(nTab, nCol);
33 CopyFromClipContext::CopyFromClipContext(ScDocument& rDoc,
34 ScDocument* pRefUndoDoc, ScDocument* pClipDoc, InsertDeleteFlags nInsertFlag,
35 bool bAsLink, bool bSkipAttrForEmptyCells) :
36 ClipContextBase(rDoc),
37 mnDestCol1(-1), mnDestCol2(-1),
38 mnDestRow1(-1), mnDestRow2(-1),
39 mnTabStart(-1), mnTabEnd(-1),
40 mrDestDoc(rDoc),
41 mpRefUndoDoc(pRefUndoDoc), mpClipDoc(pClipDoc),
42 mnInsertFlag(nInsertFlag), mnDeleteFlag(IDF_NONE),
43 mpCondFormatList(NULL),
44 mbAsLink(bAsLink), mbSkipAttrForEmptyCells(bSkipAttrForEmptyCells),
45 mbCloneNotes (mnInsertFlag & (IDF_NOTE|IDF_ADDNOTES)),
46 mbTableProtected(false)
50 CopyFromClipContext::~CopyFromClipContext()
54 void CopyFromClipContext::setTabRange(SCTAB nStart, SCTAB nEnd)
56 mnTabStart = nStart;
57 mnTabEnd = nEnd;
60 SCTAB CopyFromClipContext::getTabStart() const
62 return mnTabStart;
65 SCTAB CopyFromClipContext::getTabEnd() const
67 return mnTabEnd;
70 void CopyFromClipContext::setDestRange( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
72 mnDestCol1 = nCol1;
73 mnDestRow1 = nRow1;
74 mnDestCol2 = nCol2;
75 mnDestRow2 = nRow2;
78 CopyFromClipContext::Range CopyFromClipContext::getDestRange() const
80 Range aRet;
81 aRet.mnCol1 = mnDestCol1;
82 aRet.mnCol2 = mnDestCol2;
83 aRet.mnRow1 = mnDestRow1;
84 aRet.mnRow2 = mnDestRow2;
85 return aRet;
88 ScDocument* CopyFromClipContext::getUndoDoc()
90 return mpRefUndoDoc;
93 ScDocument* CopyFromClipContext::getClipDoc()
95 return mpClipDoc;
98 InsertDeleteFlags CopyFromClipContext::getInsertFlag() const
100 return mnInsertFlag;
103 void CopyFromClipContext::setDeleteFlag( InsertDeleteFlags nFlag )
105 mnDeleteFlag = nFlag;
108 InsertDeleteFlags CopyFromClipContext::getDeleteFlag() const
110 return mnDeleteFlag;
113 void CopyFromClipContext::setSingleCellColumnSize( size_t nSize )
115 maSingleCells.resize(nSize);
116 maSingleCellAttrs.resize(nSize);
117 maSinglePatterns.resize(nSize, NULL);
118 maSingleNotes.resize(nSize, NULL);
121 ScCellValue& CopyFromClipContext::getSingleCell( size_t nColOffset )
123 assert(nColOffset < maSingleCells.size());
124 return maSingleCells[nColOffset];
127 sc::CellTextAttr& CopyFromClipContext::getSingleCellAttr( size_t nColOffset )
129 assert(nColOffset < maSingleCellAttrs.size());
130 return maSingleCellAttrs[nColOffset];
133 void CopyFromClipContext::setSingleCell( const ScAddress& rSrcPos, const ScColumn& rSrcCol )
135 SCCOL nColOffset = rSrcPos.Col() - mpClipDoc->GetClipParam().getWholeRange().aStart.Col();
136 ScCellValue& rSrcCell = getSingleCell(nColOffset);
138 const sc::CellTextAttr* pAttr = rSrcCol.GetCellTextAttr(rSrcPos.Row());
140 if (pAttr)
142 sc::CellTextAttr& rAttr = getSingleCellAttr(nColOffset);
143 rAttr = *pAttr;
146 if (mbAsLink)
148 ScSingleRefData aRef;
149 aRef.InitAddress(rSrcPos);
150 aRef.SetFlag3D(true);
152 ScTokenArray aArr;
153 aArr.AddSingleReference(aRef);
154 rSrcCell.set(new ScFormulaCell(mpClipDoc, rSrcPos, aArr));
155 return;
158 rSrcCell.assign(*mpClipDoc, rSrcPos);
160 // Check the paste flag to see whether we want to paste this cell. If the
161 // flag says we don't want to paste this cell, we'll return with true.
162 InsertDeleteFlags nFlags = getInsertFlag();
163 bool bNumeric = (nFlags & IDF_VALUE) != IDF_NONE;
164 bool bDateTime = (nFlags & IDF_DATETIME) != IDF_NONE;
165 bool bString = (nFlags & IDF_STRING) != IDF_NONE;
166 bool bBoolean = (nFlags & IDF_SPECIAL_BOOLEAN) != IDF_NONE;
167 bool bFormula = (nFlags & IDF_FORMULA) != IDF_NONE;
169 switch (rSrcCell.meType)
171 case CELLTYPE_VALUE:
173 bool bPaste = isDateCell(rSrcCol, rSrcPos.Row()) ? bDateTime : bNumeric;
174 if (!bPaste)
175 // Don't paste this.
176 rSrcCell.clear();
178 break;
179 case CELLTYPE_STRING:
180 case CELLTYPE_EDIT:
182 if (!bString)
183 // Skip pasting.
184 rSrcCell.clear();
186 break;
187 case CELLTYPE_FORMULA:
189 if (bBoolean)
191 // Check if this formula cell is a boolean cell, and if so, go ahead and paste it.
192 ScTokenArray* pCode = rSrcCell.mpFormula->GetCode();
193 if (pCode && pCode->GetLen() == 1)
195 const formula::FormulaToken* p = pCode->First();
196 if (p->GetOpCode() == ocTrue || p->GetOpCode() == ocFalse)
197 // This is a boolean formula. Good.
198 break;
202 if (bFormula)
203 // Good.
204 break;
206 sal_uInt16 nErr = rSrcCell.mpFormula->GetErrCode();
207 if (nErr)
209 // error codes are cloned with values
210 if (!bNumeric)
211 // Error code is treated as numeric value. Don't paste it.
212 rSrcCell.clear();
214 else if (rSrcCell.mpFormula->IsValue())
216 bool bPaste = isDateCell(rSrcCol, rSrcPos.Row()) ? bDateTime : bNumeric;
217 if (!bPaste)
219 // Don't paste this.
220 rSrcCell.clear();
221 break;
224 // Turn this into a numeric cell.
225 rSrcCell.set(rSrcCell.mpFormula->GetValue());
227 else if (bString)
229 svl::SharedString aStr = rSrcCell.mpFormula->GetString();
230 if (aStr.isEmpty())
232 // do not clone empty string
233 rSrcCell.clear();
234 break;
237 // Turn this into a string or edit cell.
238 if (rSrcCell.mpFormula->IsMultilineResult())
240 // TODO : Add shared string support to the edit engine to
241 // make this process simpler.
242 ScFieldEditEngine& rEngine = mrDestDoc.GetEditEngine();
243 rEngine.SetText(rSrcCell.mpFormula->GetString().getString());
244 boost::scoped_ptr<EditTextObject> pObj(rEngine.CreateTextObject());
245 pObj->NormalizeString(mrDestDoc.GetSharedStringPool());
246 rSrcCell.set(*pObj);
248 else
249 rSrcCell.set(rSrcCell.mpFormula->GetString());
251 else
252 // We don't want to paste this.
253 rSrcCell.clear();
255 break;
256 case CELLTYPE_NONE:
257 default:
258 // There is nothing to paste.
259 rSrcCell.clear();
263 const ScPatternAttr* CopyFromClipContext::getSingleCellPattern( size_t nColOffset ) const
265 assert(nColOffset < maSinglePatterns.size());
266 return maSinglePatterns[nColOffset];
269 void CopyFromClipContext::setSingleCellPattern( size_t nColOffset, const ScPatternAttr* pAttr )
271 assert(nColOffset < maSinglePatterns.size());
272 maSinglePatterns[nColOffset] = pAttr;
275 const ScPostIt* CopyFromClipContext::getSingleCellNote( size_t nColOffset ) const
277 assert(nColOffset < maSingleNotes.size());
278 return maSingleNotes[nColOffset];
281 void CopyFromClipContext::setSingleCellNote( size_t nColOffset, const ScPostIt* pNote )
283 assert(nColOffset < maSingleNotes.size());
284 maSingleNotes[nColOffset] = pNote;
287 void CopyFromClipContext::setCondFormatList( ScConditionalFormatList* pCondFormatList )
289 mpCondFormatList = pCondFormatList;
292 ScConditionalFormatList* CopyFromClipContext::getCondFormatList()
294 return mpCondFormatList;
297 void CopyFromClipContext::setTableProtected( bool b )
299 mbTableProtected = b;
302 bool CopyFromClipContext::isTableProtected() const
304 return mbTableProtected;
307 bool CopyFromClipContext::isAsLink() const
309 return mbAsLink;
312 bool CopyFromClipContext::isSkipAttrForEmptyCells() const
314 return mbSkipAttrForEmptyCells;
317 bool CopyFromClipContext::isCloneNotes() const
319 return mbCloneNotes;
322 bool CopyFromClipContext::isDateCell( const ScColumn& rCol, SCROW nRow ) const
324 sal_uLong nNumIndex = static_cast<const SfxUInt32Item*>(rCol.GetAttr(nRow, ATTR_VALUE_FORMAT))->GetValue();
325 short nType = mpClipDoc->GetFormatTable()->GetType(nNumIndex);
326 return (nType == css::util::NumberFormat::DATE) || (nType == css::util::NumberFormat::TIME) || (nType == css::util::NumberFormat::DATETIME);
329 CopyToClipContext::CopyToClipContext(
330 ScDocument& rDoc, bool bKeepScenarioFlags, bool bCloneNotes) :
331 ClipContextBase(rDoc), mbKeepScenarioFlags(bKeepScenarioFlags), mbCloneNotes(bCloneNotes) {}
333 CopyToClipContext::~CopyToClipContext() {}
335 bool CopyToClipContext::isKeepScenarioFlags() const
337 return mbKeepScenarioFlags;
340 bool CopyToClipContext::isCloneNotes() const
342 return mbCloneNotes;
345 CopyToDocContext::CopyToDocContext(ScDocument& rDoc) :
346 ClipContextBase(rDoc), mbStartListening(true) {}
348 CopyToDocContext::~CopyToDocContext() {}
350 void CopyToDocContext::setStartListening( bool b )
352 mbStartListening = b;
355 bool CopyToDocContext::isStartListening() const
357 return mbStartListening;
360 MixDocContext::MixDocContext(ScDocument& rDoc) : ClipContextBase(rDoc) {}
361 MixDocContext::~MixDocContext() {}
365 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */