LibreOffice Module sc (master)  1
column4.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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  */
9 
10 #include <column.hxx>
11 #include <clipparam.hxx>
12 #include <cellvalue.hxx>
13 #include <attarray.hxx>
14 #include <document.hxx>
15 #include <cellvalues.hxx>
16 #include <columnspanset.hxx>
17 #include <columniterator.hxx>
18 #include <mtvcellfunc.hxx>
19 #include <clipcontext.hxx>
20 #include <attrib.hxx>
21 #include <patattr.hxx>
22 #include <docpool.hxx>
23 #include <conditio.hxx>
24 #include <formulagroup.hxx>
25 #include <tokenarray.hxx>
26 #include <scitems.hxx>
27 #include <cellform.hxx>
28 #include <sharedformula.hxx>
29 #include <drwlayer.hxx>
30 #include <compiler.hxx>
31 #include <recursionhelper.hxx>
32 
33 #include <o3tl/safeint.hxx>
34 #include <svl/sharedstringpool.hxx>
35 #include <sal/log.hxx>
36 #include <tools/stream.hxx>
37 
38 #include <numeric>
39 #include <vector>
40 #include <cassert>
41 
42 bool ScColumn::IsMerged( SCROW nRow ) const
43 {
44  return pAttrArray->IsMerged(nRow);
45 }
46 
48  SCROW nRow1, SCROW nRow2, SCROW* pRow1 ) const
49 {
50  sc::CellStoreType::const_position_type aPos = maCells.position(nRow1);
51  sc::CellStoreType::const_iterator it = aPos.first;
52  size_t nOffset = aPos.second;
53  SCROW nRow = nRow1;
54  bool bHasOne = false; // whether or not we have found a non-empty block of size one.
55 
56  for (; it != maCells.end() && nRow <= nRow2; ++it)
57  {
58  if (it->type != sc::element_type_empty)
59  {
60  // non-empty block found.
61  assert(it->size > 0); // mtv should never contain a block of zero length.
62  size_t nSize = it->size - nOffset;
63 
64  SCROW nLastRow = nRow + nSize - 1;
65  if (nLastRow > nRow2)
66  // shrink the size to avoid exceeding the specified last row position.
67  nSize -= nLastRow - nRow2;
68 
69  if (nSize == 1)
70  {
71  // this block is of size one.
72  if (bHasOne)
74 
75  bHasOne = true;
76  if (pRow1)
77  *pRow1 = nRow;
78  }
79  else
80  {
81  // size of this block is greater than one.
82  if (pRow1)
83  *pRow1 = nRow;
85  }
86  }
87 
88  nRow += it->size - nOffset;
89  nOffset = 0;
90  }
91 
93 }
94 
96  sc::CopyFromClipContext& rCxt, const ScColumn& rClipCol, sc::ColumnSpanSet& rBroadcastSpans )
97 {
98  ScDocument& rDocument = GetDoc();
100  if (!rDocument.ValidRow(aRange.mnRow1) || !rDocument.ValidRow(aRange.mnRow2))
101  return;
102 
103  ScRange aClipRange = rCxt.getClipDoc()->GetClipParam().getWholeRange();
104  SCROW nClipRow1 = aClipRange.aStart.Row();
105  SCROW nClipRow2 = aClipRange.aEnd.Row();
106  SCROW nClipRowLen = nClipRow2 - nClipRow1 + 1;
107 
108  // Check for non-empty cell ranges in the clip column.
109  sc::SingleColumnSpanSet aSpanSet(GetDoc().GetSheetLimits());
110  aSpanSet.scan(rClipCol, nClipRow1, nClipRow2);
112  aSpanSet.getSpans(aSpans);
113 
114  if (aSpans.empty())
115  // All cells in the range in the clip are empty. Nothing to delete.
116  return;
117 
118  // Translate the clip column spans into the destination column, and repeat as needed.
119  std::vector<sc::RowSpan> aDestSpans;
120  SCROW nDestOffset = aRange.mnRow1 - nClipRow1;
121  bool bContinue = true;
122  while (bContinue)
123  {
124  for (const sc::RowSpan& r : aSpans)
125  {
126  SCROW nDestRow1 = r.mnRow1 + nDestOffset;
127  SCROW nDestRow2 = r.mnRow2 + nDestOffset;
128 
129  if (nDestRow1 > aRange.mnRow2)
130  {
131  // We're done.
132  bContinue = false;
133  break;
134  }
135 
136  if (nDestRow2 > aRange.mnRow2)
137  {
138  // Truncate this range, and set it as the last span.
139  nDestRow2 = aRange.mnRow2;
140  bContinue = false;
141  }
142 
143  aDestSpans.emplace_back(nDestRow1, nDestRow2);
144 
145  if (!bContinue)
146  break;
147  }
148 
149  nDestOffset += nClipRowLen;
150  }
151 
152  InsertDeleteFlags nDelFlag = rCxt.getDeleteFlag();
153  sc::ColumnBlockPosition aBlockPos;
154  InitBlockPosition(aBlockPos);
155 
156  for (const auto& rDestSpan : aDestSpans)
157  {
158  SCROW nRow1 = rDestSpan.mnRow1;
159  SCROW nRow2 = rDestSpan.mnRow2;
160 
161  if (nDelFlag & InsertDeleteFlags::CONTENTS)
162  {
163  sc::SingleColumnSpanSet aDeletedRows(GetDoc().GetSheetLimits());
164  DeleteCells(aBlockPos, nRow1, nRow2, nDelFlag, aDeletedRows);
165  rBroadcastSpans.set(GetDoc(), nTab, nCol, aDeletedRows, true);
166  }
167 
168  if (nDelFlag & InsertDeleteFlags::NOTE)
169  DeleteCellNotes(aBlockPos, nRow1, nRow2, false);
170 
171  if (nDelFlag & InsertDeleteFlags::EDITATTR)
172  RemoveEditAttribs(nRow1, nRow2);
173 
174  // Delete attributes just now
175  if (nDelFlag & InsertDeleteFlags::ATTRIB)
176  {
177  pAttrArray->DeleteArea(nRow1, nRow2);
178 
179  if (rCxt.isTableProtected())
180  {
181  ScPatternAttr aPattern(rDocument.GetPool());
182  aPattern.GetItemSet().Put(ScProtectionAttr(false));
183  ApplyPatternArea(nRow1, nRow2, aPattern);
184  }
185 
186  ScConditionalFormatList* pCondList = rCxt.getCondFormatList();
187  if (pCondList)
188  pCondList->DeleteArea(nCol, nRow1, nCol, nRow2);
189  }
190  else if ((nDelFlag & InsertDeleteFlags::HARDATTR) == InsertDeleteFlags::HARDATTR)
191  pAttrArray->DeleteHardAttr(nRow1, nRow2);
192  }
193 }
194 
195 void ScColumn::CopyOneCellFromClip( sc::CopyFromClipContext& rCxt, SCROW nRow1, SCROW nRow2, size_t nColOffset )
196 {
197  assert(nRow1 <= nRow2);
198 
199  size_t nDestSize = nRow2 - nRow1 + 1;
201  if (!pBlockPos)
202  return;
203 
204  ScDocument& rDocument = GetDoc();
205  bool bSameDocPool = (rCxt.getClipDoc()->GetPool() == rDocument.GetPool());
206 
207  ScCellValue& rSrcCell = rCxt.getSingleCell(nColOffset);
208  sc::CellTextAttr& rSrcAttr = rCxt.getSingleCellAttr(nColOffset);
209 
210  InsertDeleteFlags nFlags = rCxt.getInsertFlag();
211 
213  {
214  if (!rCxt.isSkipAttrForEmptyCells() || rSrcCell.meType != CELLTYPE_NONE)
215  {
216  const ScPatternAttr* pAttr = (bSameDocPool ? rCxt.getSingleCellPattern(nColOffset) :
217  rCxt.getSingleCellPattern(nColOffset)->PutInPool( &rDocument, rCxt.getClipDoc()));
218 
219  auto pNewPattern = std::make_unique<ScPatternAttr>(*pAttr);
220  sal_uInt16 pItems[2];
221  pItems[0] = ATTR_CONDITIONAL;
222  pItems[1] = 0;
223  pNewPattern->ClearItems(pItems);
224  pAttrArray->SetPatternArea(nRow1, nRow2, std::move(pNewPattern), true);
225  }
226  }
227 
229  {
230  std::vector<sc::CellTextAttr> aTextAttrs(nDestSize, rSrcAttr);
231 
232  switch (rSrcCell.meType)
233  {
234  case CELLTYPE_VALUE:
235  {
236  std::vector<double> aVals(nDestSize, rSrcCell.mfValue);
237  pBlockPos->miCellPos =
238  maCells.set(pBlockPos->miCellPos, nRow1, aVals.begin(), aVals.end());
239  pBlockPos->miCellTextAttrPos =
240  maCellTextAttrs.set(pBlockPos->miCellTextAttrPos, nRow1, aTextAttrs.begin(), aTextAttrs.end());
242  }
243  break;
244  case CELLTYPE_STRING:
245  {
246  // Compare the ScDocumentPool* to determine if we are copying within the
247  // same document. If not, re-intern shared strings.
248  svl::SharedStringPool* pSharedStringPool = (bSameDocPool ? nullptr : &rDocument.GetSharedStringPool());
249  svl::SharedString aStr = (pSharedStringPool ?
250  pSharedStringPool->intern( rSrcCell.mpString->getString()) :
251  *rSrcCell.mpString);
252 
253  std::vector<svl::SharedString> aStrs(nDestSize, aStr);
254  pBlockPos->miCellPos =
255  maCells.set(pBlockPos->miCellPos, nRow1, aStrs.begin(), aStrs.end());
256  pBlockPos->miCellTextAttrPos =
257  maCellTextAttrs.set(pBlockPos->miCellTextAttrPos, nRow1, aTextAttrs.begin(), aTextAttrs.end());
259  }
260  break;
261  case CELLTYPE_EDIT:
262  {
263  std::vector<EditTextObject*> aStrs;
264  aStrs.reserve(nDestSize);
265  for (size_t i = 0; i < nDestSize; ++i)
266  aStrs.push_back(rSrcCell.mpEditText->Clone().release());
267 
268  pBlockPos->miCellPos =
269  maCells.set(pBlockPos->miCellPos, nRow1, aStrs.begin(), aStrs.end());
270  pBlockPos->miCellTextAttrPos =
271  maCellTextAttrs.set(pBlockPos->miCellTextAttrPos, nRow1, aTextAttrs.begin(), aTextAttrs.end());
273  }
274  break;
275  case CELLTYPE_FORMULA:
276  {
277  std::vector<sc::RowSpan> aRanges;
278  aRanges.reserve(1);
279  aRanges.emplace_back(nRow1, nRow2);
280  CloneFormulaCell(*rSrcCell.mpFormula, rSrcAttr, aRanges);
281  }
282  break;
283  default:
284  ;
285  }
286  }
287 
288  const ScPostIt* pNote = rCxt.getSingleCellNote(nColOffset);
290  return;
291 
292  // Duplicate the cell note over the whole pasted range.
293 
294  ScDocument* pClipDoc = rCxt.getClipDoc();
295  const ScAddress aSrcPos = pClipDoc->GetClipParam().getWholeRange().aStart;
296  std::vector<ScPostIt*> aNotes;
297  ScAddress aDestPos(nCol, nRow1, nTab);
298  aNotes.reserve(nDestSize);
299  for (size_t i = 0; i < nDestSize; ++i)
300  {
301  bool bCloneCaption = (nFlags & InsertDeleteFlags::NOCAPTIONS) == InsertDeleteFlags::NONE;
302  aNotes.push_back(pNote->Clone(aSrcPos, rDocument, aDestPos, bCloneCaption).release());
303  aDestPos.IncRow();
304  }
305 
306  pBlockPos->miCellNotePos =
307  maCellNotes.set(
308  pBlockPos->miCellNotePos, nRow1, aNotes.begin(), aNotes.end());
309 }
310 
311 void ScColumn::SetValues( const SCROW nRow, const std::vector<double>& rVals )
312 {
313  if (!GetDoc().ValidRow(nRow))
314  return;
315 
316  SCROW nLastRow = nRow + rVals.size() - 1;
317  if (nLastRow > GetDoc().MaxRow())
318  // Out of bound. Do nothing.
319  return;
320 
321  sc::CellStoreType::position_type aPos = maCells.position(nRow);
322  std::vector<SCROW> aNewSharedRows;
323  DetachFormulaCells(aPos, rVals.size(), &aNewSharedRows);
324 
325  maCells.set(nRow, rVals.begin(), rVals.end());
326  std::vector<sc::CellTextAttr> aDefaults(rVals.size());
327  maCellTextAttrs.set(nRow, aDefaults.begin(), aDefaults.end());
328 
330 
331  StartListeningUnshared( aNewSharedRows);
332 
333  std::vector<SCROW> aRows;
334  aRows.reserve(rVals.size());
335  for (SCROW i = nRow; i <= nLastRow; ++i)
336  aRows.push_back(i);
337 
338  BroadcastCells(aRows, SfxHintId::ScDataChanged);
339 }
340 
341 void ScColumn::TransferCellValuesTo( SCROW nRow, size_t nLen, sc::CellValues& rDest )
342 {
343  if (!GetDoc().ValidRow(nRow))
344  return;
345 
346  SCROW nLastRow = nRow + nLen - 1;
347  if (nLastRow > GetDoc().MaxRow())
348  // Out of bound. Do nothing.
349  return;
350 
351  sc::CellStoreType::position_type aPos = maCells.position(nRow);
352  DetachFormulaCells(aPos, nLen, nullptr);
353 
354  rDest.transferFrom(*this, nRow, nLen);
355 
357 
358  std::vector<SCROW> aRows;
359  aRows.reserve(nLen);
360  for (SCROW i = nRow; i <= nLastRow; ++i)
361  aRows.push_back(i);
362 
363  BroadcastCells(aRows, SfxHintId::ScDataChanged);
364 }
365 
367 {
368  if (!GetDoc().ValidRow(nRow))
369  return;
370 
371  SCROW nLastRow = nRow + rSrc.size() - 1;
372  if (nLastRow > GetDoc().MaxRow())
373  // Out of bound. Do nothing
374  return;
375 
376  sc::CellStoreType::position_type aPos = maCells.position(nRow);
377  DetachFormulaCells(aPos, rSrc.size(), nullptr);
378 
379  rSrc.copyTo(*this, nRow);
380 
382 
383  std::vector<SCROW> aRows;
384  aRows.reserve(rSrc.size());
385  for (SCROW i = nRow; i <= nLastRow; ++i)
386  aRows.push_back(i);
387 
388  BroadcastCells(aRows, SfxHintId::ScDataChanged);
389 }
390 
391 namespace {
392 
393 class ConvertFormulaToValueHandler
394 {
395  sc::CellValues maResValues;
396  bool mbModified;
397 
398 public:
399  ConvertFormulaToValueHandler(ScSheetLimits const & rSheetLimits) :
400  mbModified(false)
401  {
402  maResValues.reset(rSheetLimits.GetMaxRowCount());
403  }
404 
405  void operator() ( size_t nRow, const ScFormulaCell* pCell )
406  {
407  sc::FormulaResultValue aRes = pCell->GetResult();
408  switch (aRes.meType)
409  {
411  maResValues.setValue(nRow, aRes.mfValue);
412  break;
414  maResValues.setValue(nRow, aRes.maString);
415  break;
418  default:
419  maResValues.setValue(nRow, svl::SharedString::getEmptyString());
420  }
421 
422  mbModified = true;
423  }
424 
425  bool isModified() const { return mbModified; }
426 
427  sc::CellValues& getResValues() { return maResValues; }
428 };
429 
430 }
431 
433  sc::EndListeningContext& rCxt, SCROW nRow1, SCROW nRow2, sc::TableValues* pUndo )
434 {
435  if (!GetDoc().ValidRow(nRow1) || !GetDoc().ValidRow(nRow2) || nRow1 > nRow2)
436  return;
437 
438  std::vector<SCROW> aBounds;
439  aBounds.push_back(nRow1);
440  if (nRow2 < GetDoc().MaxRow()-1)
441  aBounds.push_back(nRow2+1);
442 
443  // Split formula cell groups at top and bottom boundaries (if applicable).
445 
446  // Parse all formulas within the range and store their results into temporary storage.
447  ConvertFormulaToValueHandler aFunc(GetDoc().GetSheetLimits());
448  sc::ParseFormula(maCells.begin(), maCells, nRow1, nRow2, aFunc);
449  if (!aFunc.isModified())
450  // No formula cells encountered.
451  return;
452 
453  DetachFormulaCells(rCxt, nRow1, nRow2, nullptr);
454 
455  // Undo storage to hold static values which will get swapped to the cell storage later.
456  sc::CellValues aUndoCells;
457  aFunc.getResValues().swap(aUndoCells);
458  aUndoCells.swapNonEmpty(*this);
459  if (pUndo)
460  pUndo->swap(nTab, nCol, aUndoCells);
461 }
462 
463 namespace {
464 
465 class StartListeningHandler
466 {
468 
469 public:
470  explicit StartListeningHandler( sc::StartListeningContext& rCxt ) :
471  mrCxt(rCxt) {}
472 
473  void operator() (size_t /*nRow*/, ScFormulaCell* pCell)
474  {
475  pCell->StartListeningTo(mrCxt);
476  }
477 };
478 
479 class EndListeningHandler
480 {
482 
483 public:
484  explicit EndListeningHandler( sc::EndListeningContext& rCxt ) :
485  mrCxt(rCxt) {}
486 
487  void operator() (size_t /*nRow*/, ScFormulaCell* pCell)
488  {
489  pCell->EndListeningTo(mrCxt);
490  }
491 };
492 
493 }
494 
496  sc::TableValues& rValues, sc::StartListeningContext& rStartCxt, sc::EndListeningContext& rEndCxt )
497 {
498  const ScRange& rRange = rValues.getRange();
499  std::vector<SCROW> aBounds;
500  aBounds.push_back(rRange.aStart.Row());
501  if (rRange.aEnd.Row() < GetDoc().MaxRow()-1)
502  aBounds.push_back(rRange.aEnd.Row()+1);
503 
504  // Split formula cell groups at top and bottom boundaries (if applicable).
506  std::vector<sc::CellValueSpan> aSpans = rValues.getNonEmptySpans(nTab, nCol);
507 
508  // Detach formula cells within the spans (if any).
509  EndListeningHandler aEndLisFunc(rEndCxt);
510  sc::CellStoreType::iterator itPos = maCells.begin();
511  for (const auto& rSpan : aSpans)
512  {
513  SCROW nRow1 = rSpan.mnRow1;
514  SCROW nRow2 = rSpan.mnRow2;
515  itPos = sc::ProcessFormula(itPos, maCells, nRow1, nRow2, aEndLisFunc);
516  }
517 
518  rValues.swapNonEmpty(nTab, nCol, *this);
520 
521  // Attach formula cells within the spans (if any).
522  StartListeningHandler aStartLisFunc(rStartCxt);
523  itPos = maCells.begin();
524  for (const auto& rSpan : aSpans)
525  {
526  SCROW nRow1 = rSpan.mnRow1;
527  SCROW nRow2 = rSpan.mnRow2;
528  itPos = sc::ProcessFormula(itPos, maCells, nRow1, nRow2, aStartLisFunc);
529  }
530 
532 }
533 
534 void ScColumn::DeleteRanges( const std::vector<sc::RowSpan>& rRanges, InsertDeleteFlags nDelFlag )
535 {
536  for (const auto& rSpan : rRanges)
537  DeleteArea(rSpan.mnRow1, rSpan.mnRow2, nDelFlag, false/*bBroadcast*/);
538 }
539 
541  const ScFormulaCell& rSrc, const sc::CellTextAttr& rAttr,
542  const std::vector<sc::RowSpan>& rRanges )
543 {
544  sc::CellStoreType::iterator itPos = maCells.begin();
545  sc::CellTextAttrStoreType::iterator itAttrPos = maCellTextAttrs.begin();
546 
547  SCCOL nMatrixCols = 0;
548  SCROW nMatrixRows = 0;
549  ScMatrixMode nMatrixFlag = rSrc.GetMatrixFlag();
550  if (nMatrixFlag == ScMatrixMode::Formula)
551  {
552  rSrc.GetMatColsRows( nMatrixCols, nMatrixRows);
553  SAL_WARN_IF( nMatrixCols != 1 || nMatrixRows != 1, "sc.core",
554  "ScColumn::CloneFormulaCell - cloning array/matrix with not exactly one column or row as single cell");
555  }
556 
557  ScDocument& rDocument = GetDoc();
558  std::vector<ScFormulaCell*> aFormulas;
559  for (const auto& rSpan : rRanges)
560  {
561  SCROW nRow1 = rSpan.mnRow1, nRow2 = rSpan.mnRow2;
562  size_t nLen = nRow2 - nRow1 + 1;
563  assert(nLen > 0);
564  aFormulas.clear();
565  aFormulas.reserve(nLen);
566 
567  ScAddress aPos(nCol, nRow1, nTab);
568 
569  if (nLen == 1)
570  {
571  // Single, ungrouped formula cell.
572  ScFormulaCell* pCell = new ScFormulaCell(rSrc, rDocument, aPos);
573  aFormulas.push_back(pCell);
574  }
575  else
576  {
577  // Create a group of formula cells.
579  xGroup->setCode(*rSrc.GetCode());
580  xGroup->compileCode(rDocument, aPos, rDocument.GetGrammar());
581  for (size_t i = 0; i < nLen; ++i, aPos.IncRow())
582  {
583  ScFormulaCell* pCell = new ScFormulaCell(rDocument, aPos, xGroup, rDocument.GetGrammar(), nMatrixFlag);
584  if (nMatrixFlag == ScMatrixMode::Formula)
585  pCell->SetMatColsRows( nMatrixCols, nMatrixRows);
586  if (i == 0)
587  {
588  xGroup->mpTopCell = pCell;
589  xGroup->mnLength = nLen;
590  }
591  aFormulas.push_back(pCell);
592  }
593  }
594 
595  itPos = maCells.set(itPos, nRow1, aFormulas.begin(), aFormulas.end());
596 
597  // Join the top and bottom of the pasted formula cells as needed.
598  sc::CellStoreType::position_type aPosObj = maCells.position(itPos, nRow1);
599 
600  assert(aPosObj.first->type == sc::element_type_formula);
601  ScFormulaCell* pCell = sc::formula_block::at(*aPosObj.first->data, aPosObj.second);
602  JoinNewFormulaCell(aPosObj, *pCell);
603 
604  aPosObj = maCells.position(aPosObj.first, nRow2);
605  assert(aPosObj.first->type == sc::element_type_formula);
606  pCell = sc::formula_block::at(*aPosObj.first->data, aPosObj.second);
607  JoinNewFormulaCell(aPosObj, *pCell);
608 
609  std::vector<sc::CellTextAttr> aTextAttrs(nLen, rAttr);
610  itAttrPos = maCellTextAttrs.set(itAttrPos, nRow1, aTextAttrs.begin(), aTextAttrs.end());
611  }
612 
614 }
615 
616 std::unique_ptr<ScPostIt> ScColumn::ReleaseNote( SCROW nRow )
617 {
618  if (!GetDoc().ValidRow(nRow))
619  return nullptr;
620 
621  ScPostIt* p = nullptr;
622  maCellNotes.release(nRow, p);
623  return std::unique_ptr<ScPostIt>(p);
624 }
625 
627 {
628  return std::accumulate(maCellNotes.begin(), maCellNotes.end(), size_t(0),
629  [](const size_t& rCount, const auto& rCellNote) {
630  if (rCellNote.type != sc::element_type_cellnote)
631  return rCount;
632  return rCount + rCellNote.size;
633  });
634 }
635 
636 namespace {
637 
638 class NoteCaptionCreator
639 {
640  ScAddress maPos;
641 public:
642  NoteCaptionCreator( SCTAB nTab, SCCOL nCol ) : maPos(nCol,0,nTab) {}
643 
644  void operator() ( size_t nRow, const ScPostIt* p )
645  {
646  maPos.SetRow(nRow);
647  p->GetOrCreateCaption(maPos);
648  }
649 };
650 
651 class NoteCaptionCleaner
652 {
653  bool mbPreserveData;
654 public:
655  explicit NoteCaptionCleaner( bool bPreserveData ) : mbPreserveData(bPreserveData) {}
656 
657  void operator() ( size_t /*nRow*/, ScPostIt* p )
658  {
659  p->ForgetCaption(mbPreserveData);
660  }
661 };
662 
663 }
664 
666 {
667  NoteCaptionCreator aFunc(nTab, nCol);
669 }
670 
671 void ScColumn::ForgetNoteCaptions( SCROW nRow1, SCROW nRow2, bool bPreserveData )
672 {
673  if (maCellNotes.empty())
674  return;
675 
676  if (!GetDoc().ValidRow(nRow1) || !GetDoc().ValidRow(nRow2))
677  return;
678 
679  NoteCaptionCleaner aFunc(bPreserveData);
680  sc::CellNoteStoreType::iterator it = maCellNotes.begin();
681  sc::ProcessNote(it, maCellNotes, nRow1, nRow2, aFunc);
682 }
683 
684 SCROW ScColumn::GetNotePosition( size_t nIndex ) const
685 {
686  // Return the row position of the nth note in the column.
687 
688  size_t nCount = 0; // Number of notes encountered so far.
689  for (const auto& rCellNote : maCellNotes)
690  {
691  if (rCellNote.type != sc::element_type_cellnote)
692  // Skip the empty blocks.
693  continue;
694 
695  if (nIndex < nCount + rCellNote.size)
696  {
697  // Index falls within this block.
698  size_t nOffset = nIndex - nCount;
699  return rCellNote.position + nOffset;
700  }
701 
702  nCount += rCellNote.size;
703  }
704 
705  return -1;
706 }
707 
708 namespace {
709 
710 class NoteEntryCollector
711 {
712  std::vector<sc::NoteEntry>& mrNotes;
713  SCTAB mnTab;
714  SCCOL mnCol;
715  SCROW mnStartRow;
716  SCROW mnEndRow;
717 public:
718  NoteEntryCollector( std::vector<sc::NoteEntry>& rNotes, SCTAB nTab, SCCOL nCol,
719  SCROW nStartRow, SCROW nEndRow) :
720  mrNotes(rNotes), mnTab(nTab), mnCol(nCol),
721  mnStartRow(nStartRow), mnEndRow(nEndRow) {}
722 
723  void operator() (const sc::CellNoteStoreType::value_type& node) const
724  {
725  if (node.type != sc::element_type_cellnote)
726  return;
727 
728  size_t nTopRow = node.position;
729  sc::cellnote_block::const_iterator it = sc::cellnote_block::begin(*node.data);
730  sc::cellnote_block::const_iterator itEnd = sc::cellnote_block::end(*node.data);
731  size_t nOffset = 0;
732  if(nTopRow < o3tl::make_unsigned(mnStartRow))
733  {
734  std::advance(it, mnStartRow - nTopRow);
735  nOffset = mnStartRow - nTopRow;
736  }
737 
738  for (; it != itEnd && nTopRow + nOffset <= o3tl::make_unsigned(mnEndRow);
739  ++it, ++nOffset)
740  {
741  ScAddress aPos(mnCol, nTopRow + nOffset, mnTab);
742  mrNotes.emplace_back(aPos, *it);
743  }
744  }
745 };
746 
747 }
748 
749 void ScColumn::GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const
750 {
751  std::for_each(maCellNotes.begin(), maCellNotes.end(), NoteEntryCollector(rNotes, nTab, nCol, 0, GetDoc().MaxRow()));
752 }
753 
754 void ScColumn::GetNotesInRange(SCROW nStartRow, SCROW nEndRow,
755  std::vector<sc::NoteEntry>& rNotes ) const
756 {
757  std::pair<sc::CellNoteStoreType::const_iterator,size_t> aPos = maCellNotes.position(nStartRow);
758  sc::CellNoteStoreType::const_iterator it = aPos.first;
759  if (it == maCellNotes.end())
760  // Invalid row number.
761  return;
762 
763  std::pair<sc::CellNoteStoreType::const_iterator,size_t> aEndPos =
764  maCellNotes.position(nEndRow);
765  sc::CellNoteStoreType::const_iterator itEnd = aEndPos.first;
766 
767  std::for_each(it, ++itEnd, NoteEntryCollector(rNotes, nTab, nCol, nStartRow, nEndRow));
768 }
769 
770 void ScColumn::GetUnprotectedCells( SCROW nStartRow, SCROW nEndRow, ScRangeList& rRangeList ) const
771 {
772  SCROW nTmpStartRow = nStartRow, nTmpEndRow = nEndRow;
773  const ScPatternAttr* pPattern = pAttrArray->GetPatternRange(nTmpStartRow, nTmpEndRow, nStartRow);
774  bool bProtection = pPattern->GetItem(ATTR_PROTECTION).GetProtection();
775  if (!bProtection)
776  {
777  // Limit the span to the range in question.
778  if (nTmpStartRow < nStartRow)
779  nTmpStartRow = nStartRow;
780  if (nTmpEndRow > nEndRow)
781  nTmpEndRow = nEndRow;
782  rRangeList.Join( ScRange( nCol, nTmpStartRow, nTab, nCol, nTmpEndRow, nTab));
783  }
784  while (nEndRow > nTmpEndRow)
785  {
786  nStartRow = nTmpEndRow + 1;
787  pPattern = pAttrArray->GetPatternRange(nTmpStartRow, nTmpEndRow, nStartRow);
788  bool bTmpProtection = pPattern->GetItem(ATTR_PROTECTION).GetProtection();
789  if (!bTmpProtection)
790  {
791  // Limit the span to the range in question.
792  // Only end row needs to be checked as we enter here only for spans
793  // below the original nStartRow.
794  if (nTmpEndRow > nEndRow)
795  nTmpEndRow = nEndRow;
796  rRangeList.Join( ScRange( nCol, nTmpStartRow, nTab, nCol, nTmpEndRow, nTab));
797  }
798  }
799 }
800 
801 namespace {
802 
803 class RecompileByOpcodeHandler
804 {
805  ScDocument* mpDoc;
806  const formula::unordered_opcode_set& mrOps;
807  sc::EndListeningContext& mrEndListenCxt;
808  sc::CompileFormulaContext& mrCompileFormulaCxt;
809 
810 public:
811  RecompileByOpcodeHandler(
812  ScDocument* pDoc, const formula::unordered_opcode_set& rOps,
813  sc::EndListeningContext& rEndListenCxt, sc::CompileFormulaContext& rCompileCxt ) :
814  mpDoc(pDoc),
815  mrOps(rOps),
816  mrEndListenCxt(rEndListenCxt),
817  mrCompileFormulaCxt(rCompileCxt) {}
818 
819  void operator() ( sc::FormulaGroupEntry& rEntry )
820  {
821  // Perform end listening, remove from formula tree, and set them up
822  // for re-compilation.
823 
824  ScFormulaCell* pTop = nullptr;
825 
826  if (rEntry.mbShared)
827  {
828  // Only inspect the code from the top cell.
829  pTop = *rEntry.mpCells;
830  }
831  else
832  pTop = rEntry.mpCell;
833 
834  ScTokenArray* pCode = pTop->GetCode();
835  bool bRecompile = pCode->HasOpCodes(mrOps);
836 
837  if (!bRecompile)
838  return;
839 
840  // Get the formula string.
841  OUString aFormula = pTop->GetFormula(mrCompileFormulaCxt);
842  sal_Int32 n = aFormula.getLength();
843  if (pTop->GetMatrixFlag() != ScMatrixMode::NONE && n > 0)
844  {
845  if (aFormula[0] == '{' && aFormula[n-1] == '}')
846  aFormula = aFormula.copy(1, n-2);
847  }
848 
849  if (rEntry.mbShared)
850  {
851  ScFormulaCell** pp = rEntry.mpCells;
852  ScFormulaCell** ppEnd = pp + rEntry.mnLength;
853  for (; pp != ppEnd; ++pp)
854  {
855  ScFormulaCell* p = *pp;
856  p->EndListeningTo(mrEndListenCxt);
857  mpDoc->RemoveFromFormulaTree(p);
858  }
859  }
860  else
861  {
862  rEntry.mpCell->EndListeningTo(mrEndListenCxt);
863  mpDoc->RemoveFromFormulaTree(rEntry.mpCell);
864  }
865 
866  pCode->Clear();
867  pTop->SetHybridFormula(aFormula, mpDoc->GetGrammar());
868  }
869 };
870 
871 class CompileHybridFormulaHandler
872 {
873  ScDocument& mrDoc;
874  sc::StartListeningContext& mrStartListenCxt;
875  sc::CompileFormulaContext& mrCompileFormulaCxt;
876 
877 public:
878  CompileHybridFormulaHandler(ScDocument& rDoc, sc::StartListeningContext& rStartListenCxt, sc::CompileFormulaContext& rCompileCxt ) :
879  mrDoc(rDoc),
880  mrStartListenCxt(rStartListenCxt),
881  mrCompileFormulaCxt(rCompileCxt) {}
882 
883  void operator() ( sc::FormulaGroupEntry& rEntry )
884  {
885  if (rEntry.mbShared)
886  {
887  ScFormulaCell* pTop = *rEntry.mpCells;
888  OUString aFormula = pTop->GetHybridFormula();
889 
890  if (!aFormula.isEmpty())
891  {
892  // Create a new token array from the hybrid formula string, and
893  // set it to the group.
894  ScCompiler aComp(mrCompileFormulaCxt, pTop->aPos);
895  std::unique_ptr<ScTokenArray> pNewCode = aComp.CompileString(aFormula);
896  ScFormulaCellGroupRef xGroup = pTop->GetCellGroup();
897  assert(xGroup);
898  xGroup->setCode(std::move(pNewCode));
899  xGroup->compileCode(mrDoc, pTop->aPos, mrDoc.GetGrammar());
900 
901  // Propagate the new token array to all formula cells in the group.
902  ScFormulaCell** pp = rEntry.mpCells;
903  ScFormulaCell** ppEnd = pp + rEntry.mnLength;
904  for (; pp != ppEnd; ++pp)
905  {
906  ScFormulaCell* p = *pp;
907  p->SyncSharedCode();
908  p->StartListeningTo(mrStartListenCxt);
909  p->SetDirty();
910  }
911  }
912  }
913  else
914  {
915  ScFormulaCell* pCell = rEntry.mpCell;
916  OUString aFormula = pCell->GetHybridFormula();
917 
918  if (!aFormula.isEmpty())
919  {
920  // Create token array from formula string.
921  ScCompiler aComp(mrCompileFormulaCxt, pCell->aPos);
922  std::unique_ptr<ScTokenArray> pNewCode = aComp.CompileString(aFormula);
923 
924  // Generate RPN tokens.
925  ScCompiler aComp2(mrDoc, pCell->aPos, *pNewCode, formula::FormulaGrammar::GRAM_UNSPECIFIED,
926  true, pCell->GetMatrixFlag() != ScMatrixMode::NONE);
927  aComp2.CompileTokenArray();
928 
929  pCell->SetCode(std::move(pNewCode));
930  pCell->StartListeningTo(mrStartListenCxt);
931  pCell->SetDirty();
932  }
933  }
934  }
935 };
936 
937 }
938 
940  sc::EndListeningContext& rEndListenCxt, sc::CompileFormulaContext& rCompileCxt )
941 {
942  // Collect all formula groups.
943  std::vector<sc::FormulaGroupEntry> aGroups = GetFormulaGroupEntries();
944 
946  aOps.insert(ocBad);
947  aOps.insert(ocColRowName);
948  aOps.insert(ocName);
949  RecompileByOpcodeHandler aFunc(&GetDoc(), aOps, rEndListenCxt, rCompileCxt);
950  std::for_each(aGroups.begin(), aGroups.end(), aFunc);
951 }
952 
954  sc::EndListeningContext& rEndListenCxt, sc::CompileFormulaContext& rCompileCxt )
955 {
956  // Collect all formula groups.
957  std::vector<sc::FormulaGroupEntry> aGroups = GetFormulaGroupEntries();
958 
960  aOps.insert(ocBad);
961  aOps.insert(ocColRowName);
962  aOps.insert(ocDBArea);
963  aOps.insert(ocTableRef);
964  RecompileByOpcodeHandler aFunc(&GetDoc(), aOps, rEndListenCxt, rCompileCxt);
965  std::for_each(aGroups.begin(), aGroups.end(), aFunc);
966 }
967 
969  sc::StartListeningContext& rStartListenCxt, sc::CompileFormulaContext& rCompileCxt )
970 {
971  // Collect all formula groups.
972  std::vector<sc::FormulaGroupEntry> aGroups = GetFormulaGroupEntries();
973 
974  CompileHybridFormulaHandler aFunc(GetDoc(), rStartListenCxt, rCompileCxt);
975  std::for_each(aGroups.begin(), aGroups.end(), aFunc);
976 }
977 
978 namespace {
979 
980 class ScriptTypeUpdater
981 {
982  ScColumn& mrCol;
983  sc::CellTextAttrStoreType& mrTextAttrs;
984  sc::CellTextAttrStoreType::iterator miPosAttr;
985  ScConditionalFormatList* mpCFList;
986  SvNumberFormatter* mpFormatter;
987  ScAddress maPos;
988  bool mbUpdated;
989 
990 private:
991  void updateScriptType( size_t nRow, ScRefCellValue& rCell )
992  {
993  sc::CellTextAttrStoreType::position_type aAttrPos = mrTextAttrs.position(miPosAttr, nRow);
994  miPosAttr = aAttrPos.first;
995 
996  if (aAttrPos.first->type != sc::element_type_celltextattr)
997  return;
998 
999  sc::CellTextAttr& rAttr = sc::celltextattr_block::at(*aAttrPos.first->data, aAttrPos.second);
1000  if (rAttr.mnScriptType != SvtScriptType::UNKNOWN)
1001  // Script type already determined. Skip it.
1002  return;
1003 
1004  const ScPatternAttr* pPat = mrCol.GetPattern(nRow);
1005  if (!pPat)
1006  // In theory this should never return NULL. But let's be safe.
1007  return;
1008 
1009  const SfxItemSet* pCondSet = nullptr;
1010  if (mpCFList)
1011  {
1012  maPos.SetRow(nRow);
1013  const ScCondFormatItem& rItem = pPat->GetItem(ATTR_CONDITIONAL);
1014  const ScCondFormatIndexes& rData = rItem.GetCondFormatData();
1015  pCondSet = mrCol.GetDoc().GetCondResult(rCell, maPos, *mpCFList, rData);
1016  }
1017 
1018  OUString aStr;
1019  const Color* pColor;
1020  sal_uInt32 nFormat = pPat->GetNumberFormat(mpFormatter, pCondSet);
1021  ScCellFormat::GetString(rCell, nFormat, aStr, &pColor, *mpFormatter, mrCol.GetDoc());
1022 
1023  rAttr.mnScriptType = mrCol.GetDoc().GetStringScriptType(aStr);
1024  mbUpdated = true;
1025  }
1026 
1027 public:
1028  explicit ScriptTypeUpdater( ScColumn& rCol ) :
1029  mrCol(rCol),
1030  mrTextAttrs(rCol.GetCellAttrStore()),
1031  miPosAttr(mrTextAttrs.begin()),
1032  mpCFList(rCol.GetDoc().GetCondFormList(rCol.GetTab())),
1033  mpFormatter(rCol.GetDoc().GetFormatTable()),
1034  maPos(rCol.GetCol(), 0, rCol.GetTab()),
1035  mbUpdated(false)
1036  {}
1037 
1038  void operator() ( size_t nRow, double fVal )
1039  {
1040  ScRefCellValue aCell(fVal);
1041  updateScriptType(nRow, aCell);
1042  }
1043 
1044  void operator() ( size_t nRow, const svl::SharedString& rStr )
1045  {
1046  ScRefCellValue aCell(&rStr);
1047  updateScriptType(nRow, aCell);
1048  }
1049 
1050  void operator() ( size_t nRow, const EditTextObject* pText )
1051  {
1052  ScRefCellValue aCell(pText);
1053  updateScriptType(nRow, aCell);
1054  }
1055 
1056  void operator() ( size_t nRow, const ScFormulaCell* pCell )
1057  {
1058  ScRefCellValue aCell(const_cast<ScFormulaCell*>(pCell));
1059  updateScriptType(nRow, aCell);
1060  }
1061 
1062  bool isUpdated() const { return mbUpdated; }
1063 };
1064 
1065 }
1066 
1068 {
1069  if (!GetDoc().ValidRow(nRow1) || !GetDoc().ValidRow(nRow2) || nRow1 > nRow2)
1070  return;
1071 
1072  ScriptTypeUpdater aFunc(*this);
1073  sc::ParseAllNonEmpty(maCells.begin(), maCells, nRow1, nRow2, aFunc);
1074  if (aFunc.isUpdated())
1076 }
1077 
1078 void ScColumn::Swap( ScColumn& rOther, SCROW nRow1, SCROW nRow2, bool bPattern )
1079 {
1080  maCells.swap(nRow1, nRow2, rOther.maCells, nRow1);
1081  maCellTextAttrs.swap(nRow1, nRow2, rOther.maCellTextAttrs, nRow1);
1082  maCellNotes.swap(nRow1, nRow2, rOther.maCellNotes, nRow1);
1083  maBroadcasters.swap(nRow1, nRow2, rOther.maBroadcasters, nRow1);
1084 
1085  // Update draw object anchors
1086  ScDrawLayer* pDrawLayer = GetDoc().GetDrawLayer();
1087  if (pDrawLayer)
1088  {
1089  std::map<SCROW, std::vector<SdrObject*>> aThisColRowDrawObjects
1090  = pDrawLayer->GetObjectsAnchoredToRange(GetTab(), GetCol(), nRow1, nRow2);
1091  std::map<SCROW, std::vector<SdrObject*>> aOtherColRowDrawObjects
1092  = pDrawLayer->GetObjectsAnchoredToRange(GetTab(), rOther.GetCol(), nRow1, nRow2);
1093  for (SCROW nRow = nRow1; nRow <= nRow2; ++nRow)
1094  {
1095  std::vector<SdrObject*>& rThisCellDrawObjects = aThisColRowDrawObjects[nRow];
1096  if (!rThisCellDrawObjects.empty())
1097  UpdateDrawObjectsForRow(rThisCellDrawObjects, rOther.GetCol(), nRow);
1098  std::vector<SdrObject*>& rOtherCellDrawObjects = aOtherColRowDrawObjects[nRow];
1099  if (!rOtherCellDrawObjects.empty())
1100  rOther.UpdateDrawObjectsForRow(rOtherCellDrawObjects, GetCol(), nRow);
1101  }
1102  }
1103 
1104  if (bPattern)
1105  {
1106  for (SCROW nRow = nRow1; nRow <= nRow2; ++nRow)
1107  {
1108  const ScPatternAttr* pPat1 = GetPattern(nRow);
1109  const ScPatternAttr* pPat2 = rOther.GetPattern(nRow);
1110  if (pPat1 != pPat2)
1111  {
1112  if (pPat1->GetRefCount() == 1)
1113  pPat1 = &rOther.GetDoc().GetPool()->Put(*pPat1);
1114  SetPattern(nRow, *pPat2);
1115  rOther.SetPattern(nRow, *pPat1);
1116  }
1117  }
1118  }
1119 
1121  rOther.CellStorageModified();
1122 }
1123 
1124 namespace {
1125 
1126 class FormulaColPosSetter
1127 {
1128  SCCOL mnCol;
1129  bool mbUpdateRefs;
1130 public:
1131  FormulaColPosSetter( SCCOL nCol, bool bUpdateRefs ) : mnCol(nCol), mbUpdateRefs(bUpdateRefs) {}
1132 
1133  void operator() ( size_t nRow, ScFormulaCell* pCell )
1134  {
1135  if (!pCell->IsShared() || pCell->IsSharedTop())
1136  {
1137  // Ensure that the references still point to the same locations
1138  // after the position change.
1139  ScAddress aOldPos = pCell->aPos;
1140  pCell->aPos.SetCol(mnCol);
1141  pCell->aPos.SetRow(nRow);
1142  if (mbUpdateRefs)
1143  pCell->GetCode()->AdjustReferenceOnMovedOrigin(aOldPos, pCell->aPos);
1144  else
1145  pCell->GetCode()->AdjustReferenceOnMovedOriginIfOtherSheet(aOldPos, pCell->aPos);
1146  }
1147  else
1148  {
1149  pCell->aPos.SetCol(mnCol);
1150  pCell->aPos.SetRow(nRow);
1151  }
1152  }
1153 };
1154 
1155 }
1156 
1157 void ScColumn::ResetFormulaCellPositions( SCROW nRow1, SCROW nRow2, bool bUpdateRefs )
1158 {
1159  FormulaColPosSetter aFunc(nCol, bUpdateRefs);
1160  sc::ProcessFormula(maCells.begin(), maCells, nRow1, nRow2, aFunc);
1161 }
1162 
1163 namespace {
1164 
1165 class RelativeRefBoundChecker
1166 {
1167  std::vector<SCROW> maBounds;
1168  ScRange maBoundRange;
1169 
1170 public:
1171  explicit RelativeRefBoundChecker( const ScRange& rBoundRange ) :
1172  maBoundRange(rBoundRange) {}
1173 
1174  void operator() ( size_t /*nRow*/, ScFormulaCell* pCell )
1175  {
1176  if (!pCell->IsSharedTop())
1177  return;
1178 
1180  pCell->aPos, pCell->GetSharedLength(), maBoundRange, maBounds);
1181  }
1182 
1183  void swapBounds( std::vector<SCROW>& rBounds )
1184  {
1185  rBounds.swap(maBounds);
1186  }
1187 };
1188 
1189 }
1190 
1192 {
1193  if (rBoundRange.aStart.Row() >= GetDoc().MaxRow())
1194  // Nothing to split.
1195  return;
1196 
1197  std::vector<SCROW> aBounds;
1198 
1199  // Cut at row boundaries first.
1200  aBounds.push_back(rBoundRange.aStart.Row());
1201  if (rBoundRange.aEnd.Row() < GetDoc().MaxRow())
1202  aBounds.push_back(rBoundRange.aEnd.Row()+1);
1204 
1205  RelativeRefBoundChecker aFunc(rBoundRange);
1207  maCells.begin(), maCells, rBoundRange.aStart.Row(), rBoundRange.aEnd.Row(), aFunc);
1208  aFunc.swapBounds(aBounds);
1210 }
1211 
1212 namespace {
1213 
1214 class ListenerCollector
1215 {
1216  std::vector<SvtListener*>& mrListeners;
1217 public:
1218  explicit ListenerCollector( std::vector<SvtListener*>& rListener ) :
1219  mrListeners(rListener) {}
1220 
1221  void operator() ( size_t /*nRow*/, SvtBroadcaster* p )
1222  {
1224  mrListeners.insert(mrListeners.end(), rLis.begin(), rLis.end());
1225  }
1226 };
1227 
1228 class FormulaCellCollector
1229 {
1230  std::vector<ScFormulaCell*>& mrCells;
1231 public:
1232  explicit FormulaCellCollector( std::vector<ScFormulaCell*>& rCells ) : mrCells(rCells) {}
1233 
1234  void operator() ( size_t /*nRow*/, ScFormulaCell* p )
1235  {
1236  mrCells.push_back(p);
1237  }
1238 };
1239 
1240 }
1241 
1242 void ScColumn::CollectListeners( std::vector<SvtListener*>& rListeners, SCROW nRow1, SCROW nRow2 )
1243 {
1244  if (nRow2 < nRow1 || !GetDoc().ValidRow(nRow1) || !GetDoc().ValidRow(nRow2))
1245  return;
1246 
1247  ListenerCollector aFunc(rListeners);
1248  sc::ProcessBroadcaster(maBroadcasters.begin(), maBroadcasters, nRow1, nRow2, aFunc);
1249 }
1250 
1251 void ScColumn::CollectFormulaCells( std::vector<ScFormulaCell*>& rCells, SCROW nRow1, SCROW nRow2 )
1252 {
1253  if (nRow2 < nRow1 || !GetDoc().ValidRow(nRow1) || !GetDoc().ValidRow(nRow2))
1254  return;
1255 
1256  FormulaCellCollector aFunc(rCells);
1257  sc::ProcessFormula(maCells.begin(), maCells, nRow1, nRow2, aFunc);
1258 }
1259 
1261 {
1262  return mnBlkCountFormula != 0;
1263 }
1264 
1265 namespace {
1266 
1267 struct FindAnyFormula
1268 {
1269  bool operator() ( size_t /*nRow*/, const ScFormulaCell* /*pCell*/ ) const
1270  {
1271  return true;
1272  }
1273 };
1274 
1275 }
1276 
1277 bool ScColumn::HasFormulaCell( SCROW nRow1, SCROW nRow2 ) const
1278 {
1279  if (!mnBlkCountFormula)
1280  return false;
1281 
1282  if (nRow2 < nRow1 || !GetDoc().ValidRow(nRow1) || !GetDoc().ValidRow(nRow2))
1283  return false;
1284 
1285  if (nRow1 == 0 && nRow2 == GetDoc().MaxRow())
1286  return HasFormulaCell();
1287 
1288  FindAnyFormula aFunc;
1289  std::pair<sc::CellStoreType::const_iterator, size_t> aRet =
1290  sc::FindFormula(maCells, nRow1, nRow2, aFunc);
1291 
1292  return aRet.first != maCells.end();
1293 }
1294 
1295 namespace {
1296 
1297 void endListening( sc::EndListeningContext& rCxt, ScFormulaCell** pp, ScFormulaCell** ppEnd )
1298 {
1299  for (; pp != ppEnd; ++pp)
1300  {
1301  ScFormulaCell& rFC = **pp;
1302  rFC.EndListeningTo(rCxt);
1303  }
1304 }
1305 
1306 class StartListeningFormulaCellsHandler
1307 {
1308  sc::StartListeningContext& mrStartCxt;
1309  sc::EndListeningContext& mrEndCxt;
1310  SCROW mnStartRow;
1311 
1312 public:
1313  StartListeningFormulaCellsHandler( sc::StartListeningContext& rStartCxt, sc::EndListeningContext& rEndCxt ) :
1314  mrStartCxt(rStartCxt), mrEndCxt(rEndCxt), mnStartRow(-1) {}
1315 
1316  void operator() ( const sc::CellStoreType::value_type& node, size_t nOffset, size_t nDataSize )
1317  {
1318  if (node.type != sc::element_type_formula)
1319  // We are only interested in formulas.
1320  return;
1321 
1322  mnStartRow = node.position + nOffset;
1323 
1324  ScFormulaCell** ppBeg = &sc::formula_block::at(*node.data, nOffset);
1325  ScFormulaCell** ppEnd = ppBeg + nDataSize;
1326 
1327  ScFormulaCell** pp = ppBeg;
1328 
1329  // If the first formula cell belongs to a group and it's not the top
1330  // cell, move up to the top cell of the group, and have all the extra
1331  // formula cells stop listening.
1332 
1333  ScFormulaCell* pFC = *pp;
1334  if (pFC->IsShared() && !pFC->IsSharedTop())
1335  {
1336  SCROW nBackTrackSize = pFC->aPos.Row() - pFC->GetSharedTopRow();
1337  if (nBackTrackSize > 0)
1338  {
1339  assert(o3tl::make_unsigned(nBackTrackSize) <= nOffset);
1340  for (SCROW i = 0; i < nBackTrackSize; ++i)
1341  --pp;
1342  endListening(mrEndCxt, pp, ppBeg);
1343  mnStartRow -= nBackTrackSize;
1344  }
1345  }
1346 
1347  for (; pp != ppEnd; ++pp)
1348  {
1349  pFC = *pp;
1350 
1351  if (!pFC->IsSharedTop())
1352  {
1353  assert(!pFC->IsShared());
1354  pFC->StartListeningTo(mrStartCxt);
1355  continue;
1356  }
1357 
1358  // If This is the last group in the range, see if the group
1359  // extends beyond the range, in which case have the excess
1360  // formula cells stop listening.
1361  size_t nEndGroupPos = (pp - ppBeg) + pFC->GetSharedLength();
1362  if (nEndGroupPos > nDataSize)
1363  {
1364  size_t nExcessSize = nEndGroupPos - nDataSize;
1365  ScFormulaCell** ppGrpEnd = pp + pFC->GetSharedLength();
1366  ScFormulaCell** ppGrp = ppGrpEnd - nExcessSize;
1367  endListening(mrEndCxt, ppGrp, ppGrpEnd);
1368 
1369  // Register formula cells as a group.
1371  pp = ppEnd - 1; // Move to the one before the end position.
1372  }
1373  else
1374  {
1375  // Register formula cells as a group.
1377  pp += pFC->GetSharedLength() - 1; // Move to the last one in the group.
1378  }
1379  }
1380  }
1381 
1382 };
1383 
1384 class EndListeningFormulaCellsHandler
1385 {
1386  sc::EndListeningContext& mrEndCxt;
1387  SCROW mnStartRow;
1388  SCROW mnEndRow;
1389 
1390 public:
1391  explicit EndListeningFormulaCellsHandler( sc::EndListeningContext& rEndCxt ) :
1392  mrEndCxt(rEndCxt), mnStartRow(-1), mnEndRow(-1) {}
1393 
1394  void operator() ( const sc::CellStoreType::value_type& node, size_t nOffset, size_t nDataSize )
1395  {
1396  if (node.type != sc::element_type_formula)
1397  // We are only interested in formulas.
1398  return;
1399 
1400  mnStartRow = node.position + nOffset;
1401 
1402  ScFormulaCell** ppBeg = &sc::formula_block::at(*node.data, nOffset);
1403  ScFormulaCell** ppEnd = ppBeg + nDataSize;
1404 
1405  ScFormulaCell** pp = ppBeg;
1406 
1407  // If the first formula cell belongs to a group and it's not the top
1408  // cell, move up to the top cell of the group.
1409 
1410  ScFormulaCell* pFC = *pp;
1411  if (pFC->IsShared() && !pFC->IsSharedTop())
1412  {
1413  SCROW nBackTrackSize = pFC->aPos.Row() - pFC->GetSharedTopRow();
1414  if (nBackTrackSize > 0)
1415  {
1416  assert(o3tl::make_unsigned(nBackTrackSize) <= nOffset);
1417  for (SCROW i = 0; i < nBackTrackSize; ++i)
1418  --pp;
1419  mnStartRow -= nBackTrackSize;
1420  }
1421  }
1422 
1423  for (; pp != ppEnd; ++pp)
1424  {
1425  pFC = *pp;
1426 
1427  if (!pFC->IsSharedTop())
1428  {
1429  assert(!pFC->IsShared());
1430  pFC->EndListeningTo(mrEndCxt);
1431  continue;
1432  }
1433 
1434  size_t nEndGroupPos = (pp - ppBeg) + pFC->GetSharedLength();
1435  mnEndRow = node.position + nOffset + nEndGroupPos - 1; // absolute row position of the last one in the group.
1436 
1437  ScFormulaCell** ppGrpEnd = pp + pFC->GetSharedLength();
1438  endListening(mrEndCxt, pp, ppGrpEnd);
1439 
1440  if (nEndGroupPos > nDataSize)
1441  {
1442  // The group goes beyond the specified end row. Move to the
1443  // one before the end position to finish the loop.
1444  pp = ppEnd - 1;
1445  }
1446  else
1447  {
1448  // Move to the last one in the group.
1449  pp += pFC->GetSharedLength() - 1;
1450  }
1451  }
1452  }
1453 
1454  SCROW getStartRow() const
1455  {
1456  return mnStartRow;
1457  }
1458 
1459  SCROW getEndRow() const
1460  {
1461  return mnEndRow;
1462  }
1463 };
1464 
1465 }
1466 
1469  SCROW nRow1, SCROW nRow2 )
1470 {
1471  if (!HasFormulaCell())
1472  return;
1473 
1474  StartListeningFormulaCellsHandler aFunc(rStartCxt, rEndCxt);
1475  sc::ProcessBlock(maCells.begin(), maCells, aFunc, nRow1, nRow2);
1476 }
1477 
1479  sc::EndListeningContext& rCxt, SCROW nRow1, SCROW nRow2,
1480  SCROW* pStartRow, SCROW* pEndRow )
1481 {
1482  if (!HasFormulaCell())
1483  return;
1484 
1485  EndListeningFormulaCellsHandler aFunc(rCxt);
1486  sc::ProcessBlock(maCells.begin(), maCells, aFunc, nRow1, nRow2);
1487 
1488  if (pStartRow)
1489  *pStartRow = aFunc.getStartRow();
1490 
1491  if (pEndRow)
1492  *pEndRow = aFunc.getEndRow();
1493 }
1494 
1496  sc::EndListeningContext& rCxt, SCROW nRow, std::vector<ScAddress>* pGroupPos )
1497 {
1498  if (!GetDoc().ValidRow(nRow))
1499  return;
1500 
1501  sc::CellStoreType::position_type aPos = maCells.position(nRow);
1502  sc::CellStoreType::iterator it = aPos.first;
1503  if (it->type != sc::element_type_formula)
1504  // Only interested in a formula block.
1505  return;
1506 
1507  ScFormulaCell* pFC = sc::formula_block::at(*it->data, aPos.second);
1508  ScFormulaCellGroupRef xGroup = pFC->GetCellGroup();
1509  if (!xGroup)
1510  // Not a formula group.
1511  return;
1512 
1513  // End listening.
1514  pFC->EndListeningTo(rCxt);
1515 
1516  if (pGroupPos)
1517  {
1518  if (!pFC->IsSharedTop())
1519  // Record the position of the top cell of the group.
1520  pGroupPos->push_back(xGroup->mpTopCell->aPos);
1521 
1522  SCROW nGrpLastRow = pFC->GetSharedTopRow() + pFC->GetSharedLength() - 1;
1523  if (nRow < nGrpLastRow)
1524  // Record the last position of the group.
1525  pGroupPos->push_back(ScAddress(nCol, nGrpLastRow, nTab));
1526  }
1527 }
1528 
1530  sc::EndListeningContext& rCxt, SCROW nRow1, SCROW nRow2, std::vector<ScAddress>* pGroupPos )
1531 {
1532  // Only end the intersected group.
1533  sc::CellStoreType::position_type aPos = maCells.position(nRow1);
1534  sc::CellStoreType::iterator it = aPos.first;
1535  if (it->type == sc::element_type_formula)
1536  {
1537  ScFormulaCell* pFC = sc::formula_block::at(*it->data, aPos.second);
1538  ScFormulaCellGroupRef xGroup = pFC->GetCellGroup();
1539  if (xGroup)
1540  {
1541  if (!pFC->IsSharedTop())
1542  // End listening.
1543  pFC->EndListeningTo(rCxt);
1544 
1545  if (pGroupPos)
1546  // Record the position of the top cell of the group.
1547  pGroupPos->push_back(xGroup->mpTopCell->aPos);
1548  }
1549  }
1550 
1551  aPos = maCells.position(it, nRow2);
1552  it = aPos.first;
1553  if (it->type != sc::element_type_formula)
1554  return;
1555 
1556  ScFormulaCell* pFC = sc::formula_block::at(*it->data, aPos.second);
1557  ScFormulaCellGroupRef xGroup = pFC->GetCellGroup();
1558  if (!xGroup)
1559  return;
1560 
1561  if (!pFC->IsSharedTop())
1562  // End listening.
1563  pFC->EndListeningTo(rCxt);
1564 
1565  if (pGroupPos)
1566  {
1567  // Record the position of the bottom cell of the group.
1568  ScAddress aPosLast = xGroup->mpTopCell->aPos;
1569  aPosLast.IncRow(xGroup->mnLength-1);
1570  pGroupPos->push_back(aPosLast);
1571  }
1572 }
1573 
1575 {
1576  sc::CellStoreType::position_type aPos = maCells.position(nRow);
1577  if (aPos.first->type != sc::element_type_formula)
1578  // not a formula cell.
1579  return;
1580 
1581  ScFormulaCell** pp = &sc::formula_block::at(*aPos.first->data, aPos.second);
1582 
1583  ScFormulaCellGroupRef xGroup = (*pp)->GetCellGroup();
1584  if (!xGroup)
1585  {
1586  // not a formula group.
1587  (*pp)->EndListeningTo(rCxt);
1588  return;
1589  }
1590 
1591  // Move back to the top cell.
1592  SCROW nTopDelta = (*pp)->aPos.Row() - xGroup->mpTopCell->aPos.Row();
1593  assert(nTopDelta >= 0);
1594  if (nTopDelta > 0)
1595  pp -= nTopDelta;
1596 
1597  // Set the needs listening flag to all cells in the group.
1598  assert(*pp == xGroup->mpTopCell);
1599  ScFormulaCell** ppEnd = pp + xGroup->mnLength;
1600  for (; pp != ppEnd; ++pp)
1601  (*pp)->EndListeningTo(rCxt);
1602 }
1603 
1605 {
1606  sc::CellStoreType::position_type aPos = maCells.position(nRow);
1607  if (aPos.first->type != sc::element_type_formula)
1608  // not a formula cell.
1609  return;
1610 
1611  ScFormulaCell** pp = &sc::formula_block::at(*aPos.first->data, aPos.second);
1612 
1613  ScFormulaCellGroupRef xGroup = (*pp)->GetCellGroup();
1614  if (!xGroup)
1615  {
1616  // not a formula group.
1617  (*pp)->SetNeedsListening(true);
1618  return;
1619  }
1620 
1621  // Move back to the top cell.
1622  SCROW nTopDelta = (*pp)->aPos.Row() - xGroup->mpTopCell->aPos.Row();
1623  assert(nTopDelta >= 0);
1624  if (nTopDelta > 0)
1625  pp -= nTopDelta;
1626 
1627  // Set the needs listening flag to all cells in the group.
1628  assert(*pp == xGroup->mpTopCell);
1629  ScFormulaCell** ppEnd = pp + xGroup->mnLength;
1630  for (; pp != ppEnd; ++pp)
1631  (*pp)->SetNeedsListening(true);
1632 }
1633 
1634 std::unique_ptr<sc::ColumnIterator> ScColumn::GetColumnIterator( SCROW nRow1, SCROW nRow2 ) const
1635 {
1636  if (!GetDoc().ValidRow(nRow1) || !GetDoc().ValidRow(nRow2) || nRow1 > nRow2)
1637  return std::unique_ptr<sc::ColumnIterator>();
1638 
1639  return std::make_unique<sc::ColumnIterator>(maCells, nRow1, nRow2);
1640 }
1641 
1642 static bool lcl_InterpretSpan(sc::formula_block::const_iterator& rSpanIter, SCROW nStartOffset, SCROW nEndOffset,
1643  const ScFormulaCellGroupRef& mxParentGroup, bool& bAllowThreading, ScDocument& rDoc)
1644 {
1645  bAllowThreading = true;
1646  ScFormulaCell* pCellStart = nullptr;
1647  SCROW nSpanStart = -1;
1648  SCROW nSpanEnd = -1;
1649  sc::formula_block::const_iterator itSpanStart;
1650  bool bAnyDirty = false;
1651  for (SCROW nFGOffset = nStartOffset; nFGOffset <= nEndOffset; ++rSpanIter, ++nFGOffset)
1652  {
1653  bool bThisDirty = (*rSpanIter)->NeedsInterpret();
1654  if (!pCellStart && bThisDirty)
1655  {
1656  pCellStart = *rSpanIter;
1657  itSpanStart = rSpanIter;
1658  nSpanStart = nFGOffset;
1659  bAnyDirty = true;
1660  }
1661 
1662  if (pCellStart && (!bThisDirty || nFGOffset == nEndOffset))
1663  {
1664  nSpanEnd = bThisDirty ? nFGOffset : nFGOffset - 1;
1665  assert(nSpanStart >= nStartOffset && nSpanStart <= nSpanEnd && nSpanEnd <= nEndOffset);
1666 
1667  // Found a completely dirty sub span [nSpanStart, nSpanEnd] inside the required span [nStartOffset, nEndOffset]
1668  bool bGroupInterpreted = pCellStart->Interpret(nSpanStart, nSpanEnd);
1669 
1670  if (bGroupInterpreted)
1671  for (SCROW nIdx = nSpanStart; nIdx <= nSpanEnd; ++nIdx, ++itSpanStart)
1672  assert(!(*itSpanStart)->NeedsInterpret());
1673 
1674  ScRecursionHelper& rRecursionHelper = rDoc.GetRecursionHelper();
1675  // child cell's Interpret could result in calling dependency calc
1676  // and that could detect a cycle involving mxGroup
1677  // and do early exit in that case.
1678  // OR
1679  // this call resulted from a dependency calculation for a multi-formula-group-threading and
1680  // if intergroup dependency is found, return early.
1681  if ((mxParentGroup && mxParentGroup->mbPartOfCycle) || !rRecursionHelper.AreGroupsIndependent())
1682  {
1683  bAllowThreading = false;
1684  return bAnyDirty;
1685  }
1686 
1687  if (!bGroupInterpreted)
1688  {
1689  // Evaluate from second cell in non-grouped style (no point in trying group-interpret again).
1690  ++itSpanStart;
1691  for (SCROW nIdx = nSpanStart+1; nIdx <= nSpanEnd; ++nIdx, ++itSpanStart)
1692  {
1693  (*itSpanStart)->Interpret(); // We know for sure that this cell is dirty so directly call Interpret().
1694  if ((*itSpanStart)->NeedsInterpret())
1695  {
1696  SAL_WARN("sc.core.formulagroup", "Internal error, cell " << (*itSpanStart)->aPos
1697  << " failed running Interpret(), not allowing threading");
1698  bAllowThreading = false;
1699  return bAnyDirty;
1700  }
1701 
1702  // Allow early exit like above.
1703  if ((mxParentGroup && mxParentGroup->mbPartOfCycle) || !rRecursionHelper.AreGroupsIndependent())
1704  {
1705  // Set this cell as dirty as this may be interpreted in InterpretTail()
1706  pCellStart->SetDirtyVar();
1707  bAllowThreading = false;
1708  return bAnyDirty;
1709  }
1710  }
1711  }
1712 
1713  pCellStart = nullptr; // For next sub span start detection.
1714  }
1715  }
1716 
1717  return bAnyDirty;
1718 }
1719 
1720 static void lcl_EvalDirty(sc::CellStoreType& rCells, SCROW nRow1, SCROW nRow2, ScDocument& rDoc,
1721  const ScFormulaCellGroupRef& mxGroup, bool bThreadingDepEval, bool bSkipRunning,
1722  bool& bIsDirty, bool& bAllowThreading)
1723 {
1724  ScRecursionHelper& rRecursionHelper = rDoc.GetRecursionHelper();
1725  std::pair<sc::CellStoreType::const_iterator,size_t> aPos = rCells.position(nRow1);
1726  sc::CellStoreType::const_iterator it = aPos.first;
1727  size_t nOffset = aPos.second;
1728  SCROW nRow = nRow1;
1729 
1730  bIsDirty = false;
1731 
1732  for (;it != rCells.end() && nRow <= nRow2; ++it, nOffset = 0)
1733  {
1734  switch( it->type )
1735  {
1737  // These require EditEngine (in ScEditUtils::GetString()), which is probably
1738  // too complex for use in threads.
1739  if (bThreadingDepEval)
1740  {
1741  bAllowThreading = false;
1742  return;
1743  }
1744  break;
1746  {
1747  size_t nRowsToRead = nRow2 - nRow + 1;
1748  const size_t nEnd = std::min(it->size, nOffset+nRowsToRead); // last row + 1
1749  sc::formula_block::const_iterator itCell = sc::formula_block::begin(*it->data);
1750  std::advance(itCell, nOffset);
1751 
1752  // Loop inside the formula block.
1753  size_t nCellIdx = nOffset;
1754  while (nCellIdx < nEnd)
1755  {
1756  const ScFormulaCellGroupRef& mxGroupChild = (*itCell)->GetCellGroup();
1757  ScFormulaCell* pChildTopCell = mxGroupChild ? mxGroupChild->mpTopCell : *itCell;
1758 
1759  // Check if itCell is already in path.
1760  // If yes use a cycle guard to mark all elements of the cycle
1761  // and return false
1762  if (bThreadingDepEval && pChildTopCell->GetSeenInPath())
1763  {
1764  ScFormulaGroupCycleCheckGuard aCycleCheckGuard(rRecursionHelper, pChildTopCell);
1765  bAllowThreading = false;
1766  return;
1767  }
1768 
1769  if (bSkipRunning && (*itCell)->IsRunning())
1770  {
1771  ++itCell;
1772  nCellIdx += 1;
1773  nRow += 1;
1774  nRowsToRead -= 1;
1775  continue;
1776  }
1777 
1778  if (mxGroupChild)
1779  {
1780  // It is a Formula-group, evaluate the necessary parts of it (spans).
1781  const SCROW nFGStartOffset = (*itCell)->aPos.Row() - pChildTopCell->aPos.Row();
1782  const SCROW nFGEndOffset = std::min(nFGStartOffset + static_cast<SCROW>(nRowsToRead) - 1, mxGroupChild->mnLength - 1);
1783  assert(nFGEndOffset >= nFGStartOffset);
1784  const SCROW nSpanLen = nFGEndOffset - nFGStartOffset + 1;
1785  // The (main) span required to be evaluated is [nFGStartOffset, nFGEndOffset], but this span may contain
1786  // non-dirty cells, so split this into sets of completely-dirty spans and try evaluate each of them in grouped-style.
1787 
1788  bool bAnyDirtyInSpan = lcl_InterpretSpan(itCell, nFGStartOffset, nFGEndOffset, mxGroup, bAllowThreading, rDoc);
1789  if (!bAllowThreading)
1790  return;
1791  // itCell will now point to cell just after the end of span [nFGStartOffset, nFGEndOffset].
1792  bIsDirty = bIsDirty || bAnyDirtyInSpan;
1793 
1794  // update the counters by nSpanLen.
1795  // itCell already got updated.
1796  nCellIdx += nSpanLen;
1797  nRow += nSpanLen;
1798  nRowsToRead -= nSpanLen;
1799  }
1800  else
1801  {
1802  // No formula-group here.
1803  bool bDirtyFlag = false;
1804  if( (*itCell)->NeedsInterpret())
1805  {
1806  bDirtyFlag = true;
1807  (*itCell)->Interpret();
1808  if ((*itCell)->NeedsInterpret())
1809  {
1810  SAL_WARN("sc.core.formulagroup", "Internal error, cell " << (*itCell)->aPos
1811  << " failed running Interpret(), not allowing threading");
1812  bAllowThreading = false;
1813  return;
1814  }
1815  }
1816  bIsDirty = bIsDirty || bDirtyFlag;
1817 
1818  // child cell's Interpret could result in calling dependency calc
1819  // and that could detect a cycle involving mxGroup
1820  // and do early exit in that case.
1821  // OR
1822  // we are trying multi-formula-group-threading, but found intergroup dependency.
1823  if (bThreadingDepEval && mxGroup &&
1824  (mxGroup->mbPartOfCycle || !rRecursionHelper.AreGroupsIndependent()))
1825  {
1826  // Set itCell as dirty as itCell may be interpreted in InterpretTail()
1827  (*itCell)->SetDirtyVar();
1828  bAllowThreading = false;
1829  return;
1830  }
1831 
1832  // update the counters by 1.
1833  nCellIdx += 1;
1834  nRow += 1;
1835  nRowsToRead -= 1;
1836  ++itCell;
1837  }
1838  }
1839  break;
1840  }
1841  default:
1842  // Skip this block.
1843  nRow += it->size - nOffset;
1844  continue;
1845  }
1846  }
1847 
1848  if (bThreadingDepEval)
1849  bAllowThreading = true;
1850 
1851 }
1852 
1853 // Returns true if at least one FC is dirty.
1854 bool ScColumn::EnsureFormulaCellResults( SCROW nRow1, SCROW nRow2, bool bSkipRunning )
1855 {
1856  if (!GetDoc().ValidRow(nRow1) || !GetDoc().ValidRow(nRow2) || nRow1 > nRow2)
1857  return false;
1858 
1859  if (!HasFormulaCell(nRow1, nRow2))
1860  return false;
1861 
1862  bool bAnyDirty = false, bTmp = false;
1863  lcl_EvalDirty(maCells, nRow1, nRow2, GetDoc(), nullptr, false, bSkipRunning, bAnyDirty, bTmp);
1864  return bAnyDirty;
1865 }
1866 
1868 {
1869  if (nRow1 > nRow2)
1870  return false;
1871 
1872  bool bAllowThreading = true, bTmp = false;
1873  lcl_EvalDirty(maCells, nRow1, nRow2, GetDoc(), mxGroup, true, false, bTmp, bAllowThreading);
1874 
1875  return bAllowThreading;
1876 }
1877 
1878 namespace {
1879 
1880 class StoreToCacheFunc
1881 {
1882  SvStream& mrStrm;
1883 public:
1884 
1885  StoreToCacheFunc(SvStream& rStrm):
1886  mrStrm(rStrm)
1887  {
1888  }
1889 
1890  void operator() ( const sc::CellStoreType::value_type& node, size_t nOffset, size_t nDataSize )
1891  {
1892  SCROW nStartRow = node.position + nOffset;
1893  mrStrm.WriteUInt64(nStartRow);
1894  mrStrm.WriteUInt64(nDataSize);
1895  switch (node.type)
1896  {
1898  {
1899  mrStrm.WriteUChar(0);
1900  }
1901  break;
1903  {
1904  mrStrm.WriteUChar(1);
1905  sc::numeric_block::const_iterator it = sc::numeric_block::begin(*node.data);
1906  std::advance(it, nOffset);
1907  sc::numeric_block::const_iterator itEnd = it;
1908  std::advance(itEnd, nDataSize);
1909 
1910  for (; it != itEnd; ++it)
1911  {
1912  mrStrm.WriteDouble(*it);
1913  }
1914  }
1915  break;
1917  {
1918  mrStrm.WriteUChar(2);
1919  sc::string_block::const_iterator it = sc::string_block::begin(*node.data);
1920  std::advance(it, nOffset);
1921  sc::string_block::const_iterator itEnd = it;
1922  std::advance(itEnd, nDataSize);
1923 
1924  for (; it != itEnd; ++it)
1925  {
1926  OString aStr = OUStringToOString(it->getString(), RTL_TEXTENCODING_UTF8);
1927  sal_Int32 nStrLength = aStr.getLength();
1928  mrStrm.WriteInt32(nStrLength);
1929  mrStrm.WriteOString(aStr);
1930  }
1931  }
1932  break;
1934  {
1935  mrStrm.WriteUChar(3);
1936  sc::formula_block::const_iterator it = sc::formula_block::begin(*node.data);
1937  std::advance(it, nOffset);
1938  sc::formula_block::const_iterator itEnd = it;
1939  std::advance(itEnd, nDataSize);
1940 
1941  for (; it != itEnd; /* incrementing through std::advance*/)
1942  {
1943  const ScFormulaCell* pCell = *it;
1944  OUString aFormula;
1946  const auto& xCellGroup = pCell->GetCellGroup();
1947  sal_uInt64 nGroupLength = 0;
1948  if (xCellGroup)
1949  {
1950  nGroupLength = xCellGroup->mnLength;
1951  }
1952  else
1953  {
1954  nGroupLength = 1;
1955  }
1956  mrStrm.WriteUInt64(nGroupLength);
1957  mrStrm.WriteInt32(aFormula.getLength());
1958  mrStrm.WriteOString(OUStringToOString(aFormula, RTL_TEXTENCODING_UTF8));
1959 
1960  // incrementing the iterator
1961  std::advance(it, nGroupLength);
1962  }
1963  }
1964  break;
1965  }
1966  }
1967 };
1968 
1969 }
1970 
1972 {
1973  rStrm.WriteUInt64(nCol);
1974  SCROW nLastRow = GetLastDataPos();
1975  rStrm.WriteUInt64(nLastRow + 1); // the rows are zero based
1976 
1977  StoreToCacheFunc aFunc(rStrm);
1978  sc::ParseBlock(maCells.begin(), maCells, aFunc, SCROW(0), nLastRow);
1979 }
1980 
1982 {
1983  sal_uInt64 nStoredCol = 0;
1984  rStrm.ReadUInt64(nStoredCol);
1985  if (nStoredCol != static_cast<sal_uInt64>(nCol))
1986  throw std::exception();
1987 
1988  sal_uInt64 nLastRow = 0;
1989  rStrm.ReadUInt64(nLastRow);
1990  sal_uInt64 nReadRow = 0;
1991  ScDocument& rDocument = GetDoc();
1992  while (nReadRow < nLastRow)
1993  {
1994  sal_uInt64 nStartRow = 0;
1995  sal_uInt64 nDataSize = 0;
1996  rStrm.ReadUInt64(nStartRow);
1997  rStrm.ReadUInt64(nDataSize);
1998  sal_uInt8 nType = 0;
1999  rStrm.ReadUChar(nType);
2000  switch (nType)
2001  {
2002  case 0:
2003  // nothing to do
2004  maCells.set_empty(nStartRow, nDataSize);
2005  break;
2006  case 1:
2007  {
2008  // nDataSize double values
2009  std::vector<double> aValues(nDataSize);
2010  for (auto& rValue : aValues)
2011  {
2012  rStrm.ReadDouble(rValue);
2013  }
2014  maCells.set(nStartRow, aValues.begin(), aValues.end());
2015  }
2016  break;
2017  case 2:
2018  {
2019  std::vector<svl::SharedString> aStrings(nDataSize);
2020  svl::SharedStringPool& rPool = rDocument.GetSharedStringPool();
2021  for (auto& rString : aStrings)
2022  {
2023  sal_Int32 nStrLength = 0;
2024  rStrm.ReadInt32(nStrLength);
2025  std::unique_ptr<char[]> pStr(new char[nStrLength]);
2026  rStrm.ReadBytes(pStr.get(), nStrLength);
2027  OString aOStr(pStr.get(), nStrLength);
2028  OUString aStr = OStringToOUString(aOStr, RTL_TEXTENCODING_UTF8);
2029  rString = rPool.intern(aStr);
2030  }
2031  maCells.set(nStartRow, aStrings.begin(), aStrings.end());
2032 
2033  }
2034  break;
2035  case 3:
2036  {
2037  std::vector<ScFormulaCell*> aFormulaCells(nDataSize);
2038 
2039  ScAddress aAddr(nCol, nStartRow, nTab);
2041  for (SCROW nRow = 0; nRow < static_cast<SCROW>(nDataSize);)
2042  {
2043  sal_uInt64 nFormulaGroupSize = 0;
2044  rStrm.ReadUInt64(nFormulaGroupSize);
2045  sal_Int32 nStrLength = 0;
2046  rStrm.ReadInt32(nStrLength);
2047  std::unique_ptr<char[]> pStr(new char[nStrLength]);
2048  rStrm.ReadBytes(pStr.get(), nStrLength);
2049  OString aOStr(pStr.get(), nStrLength);
2050  OUString aStr = OStringToOUString(aOStr, RTL_TEXTENCODING_UTF8);
2051  for (sal_uInt64 i = 0; i < nFormulaGroupSize; ++i)
2052  {
2053  aFormulaCells[nRow + i] = new ScFormulaCell(rDocument, aAddr, aStr, eGrammar);
2054  aAddr.IncRow();
2055  }
2056 
2057  nRow += nFormulaGroupSize;
2058  }
2059 
2060  maCells.set(nStartRow, aFormulaCells.begin(), aFormulaCells.end());
2061  }
2062  break;
2063  }
2064 
2065  nReadRow += nDataSize;
2066  }
2067 }
2068 
2069 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void reset(size_t nSize)
Definition: cellvalues.cxx:127
void AdjustReferenceOnMovedOrigin(const ScAddress &rOldPos, const ScAddress &rNewPos)
Adjust all internal references on base position change.
Definition: token.cxx:4360
std::map< SCROW, std::vector< SdrObject * > > GetObjectsAnchoredToRange(SCTAB nTab, SCCOL nCol, SCROW nStartRow, SCROW nEndRow)
Definition: drwlayer.cxx:2192
void CellStorageModified()
Called whenever the state of cell array gets modified i.e.
Definition: column2.cxx:1596
std::unordered_set< OpCode, std::hash< std::underlying_type< OpCode >::type > > unordered_opcode_set
SCROW GetNotePosition(size_t nIndex) const
Definition: column4.cxx:684
svl::SharedString maString
::boost::intrusive_ptr< ScFormulaCellGroup > ScFormulaCellGroupRef
Definition: types.hxx:44
bool GetSeenInPath() const
SvStream & WriteUInt64(sal_uInt64 nuInt64)
void SplitFormulaGroupByRelativeRef(const ScRange &rBoundRange)
Definition: column4.cxx:1191
CellType meType
Definition: cellvalue.hxx:38
OUString getString() const
ScAddress aStart
Definition: address.hxx:500
SharedString intern(const OUString &rStr)
SC_DLLPUBLIC svl::SharedStringPool & GetSharedStringPool()
Definition: documen2.cxx:563
void DeleteArea(SCROW nStartRow, SCROW nEndRow, InsertDeleteFlags nDelFlag, bool bBroadcast=true, sc::ColumnSpanSet *pBroadcastSpans=nullptr)
Definition: column3.cxx:988
void GetAllNoteEntries(std::vector< sc::NoteEntry > &rNotes) const
Definition: column4.cxx:749
std::unique_ptr< ScAttrArray > pAttrArray
Definition: column.hxx:131
ScDocument & GetDoc() const
Definition: column.hxx:182
const ScPatternAttr * GetPattern(SCROW nRow) const
Definition: column.cxx:369
void StoreToCache(SvStream &rStrm) const
Definition: column4.cxx:1971
bool NeedsInterpret() const
ocName
void swap(SCTAB nTab, SCCOL nCol, CellValues &rColValue)
Swap the entire column.
Definition: cellvalues.cxx:322
Sheet / outlining (grouping) information.
SCROW Row() const
Definition: address.hxx:262
void RestoreFromCache(SvStream &rStrm)
Definition: column4.cxx:1981
static SharedString getEmptyString()
SvStream & WriteInt32(sal_Int32 nInt32)
void ForgetCaption(bool bPreserveData=false)
Forgets the pointer to the note caption object.
Definition: postit.cxx:956
void SwapNonEmpty(sc::TableValues &rValues, sc::StartListeningContext &rStartCxt, sc::EndListeningContext &rEndCxt)
Definition: column4.cxx:495
CellTextAttrStoreType::iterator miCellTextAttrPos
const mdds::mtv::element_t element_type_celltextattr
Definition: mtvelements.hxx:46
SCROW GetSharedTopRow() const
sal_uInt32 GetRefCount() const
Think of this as a mini-ScColumn like storage that only stores cell values in a column.
Definition: cellvalues.hxx:42
void GetFormula(OUString &rFormula, const formula::FormulaGrammar::Grammar=formula::FormulaGrammar::GRAM_DEFAULT, const ScInterpreterContext *pContext=nullptr) const
SCTAB nTab
Definition: column.hxx:136
ScTokenArray * GetCode()
std::unique_ptr< ScPostIt > ReleaseNote(SCROW nRow)
Definition: column4.cxx:616
StoreT::const_iterator ParseBlock(const typename StoreT::const_iterator &itPos, const StoreT &rStore, Func &rFunc, typename StoreT::size_type nStart, typename StoreT::size_type nEnd)
Generic algorithm to parse blocks of multi_type_vector either partially or fully. ...
sal_Int64 n
ListenersType & GetAllListeners()
sal_Int32 mnCol
Store position data for column array storage.
const SfxItemSet & GetItemSet() const
void TransferCellValuesTo(SCROW nRow, size_t nLen, sc::CellValues &rDest)
Definition: column4.cxx:341
const ContentProperties & rData
InsertDeleteFlags getInsertFlag() const
Stores cell values for multiple tables.
Definition: cellvalues.hxx:87
double mfValue
Definition: cellvalue.hxx:40
void transferFrom(ScColumn &rCol, SCROW nRow, size_t nLen)
Transfer values from specified column.
Definition: cellvalues.cxx:52
bool isSkipAttrForEmptyCells() const
ScAddress aEnd
Definition: address.hxx:501
CellStoreType::const_iterator ParseAllNonEmpty(const typename CellStoreType::const_iterator &itPos, const CellStoreType &rCells, SCROW nRow1, SCROW nRow2, Func &rFunc)
Definition: mtvcellfunc.hxx:96
static void startListeningAsGroup(StartListeningContext &rCxt, ScFormulaCell **ppSharedTop)
Have all formula cells belonging to a group start listening to their references.
SvStream & WriteOString(const OString &rStr)
void ApplyPatternArea(SCROW nStartRow, SCROW nEndRow, const ScPatternAttr &rPatAttr, ScEditDataArray *pDataArray=nullptr, bool *const pIsChanged=nullptr)
Definition: column.cxx:515
void CompileHybridFormula(sc::StartListeningContext &rStartListenCxt, sc::CompileFormulaContext &rCompileCxt)
Definition: column4.cxx:968
void Swap(ScColumn &rOther, SCROW nRow1, SCROW nRow2, bool bPattern)
Definition: column4.cxx:1078
bool isTableProtected() const
This is very similar to ScCellValue, except that it references the original value instead of copying ...
Definition: cellvalue.hxx:104
constexpr TypedWhichId< ScProtectionAttr > ATTR_PROTECTION(149)
SC_DLLPUBLIC formula::FormulaGrammar::Grammar GetGrammar() const
Definition: document.hxx:985
SCROW GetMaxRowCount() const
Definition: sheetlimits.hxx:61
mdds::multi_type_vector< CellFunc, CellStoreEvent > CellStoreType
SvStream & ReadUInt64(sal_uInt64 &rUInt64)
void DeleteRanges(const std::vector< sc::RowSpan > &rRanges, InsertDeleteFlags nDelFlag)
Definition: column4.cxx:534
StoreT::iterator ProcessBlock(const typename StoreT::iterator &itPos, StoreT &rStore, Func &rFunc, typename StoreT::size_type nStart, typename StoreT::size_type nEnd)
Non-const variant of the above function.
SC_DLLPUBLIC SvtScriptType GetStringScriptType(const OUString &rString)
Definition: documen6.cxx:76
void UpdateDrawObjectsForRow(std::vector< SdrObject * > &pObjects, SCCOL nTargetCol, SCROW nTargetRow)
Definition: column.cxx:1940
Internal use only (d&d undo): do not delete caption objects of cell notes.
SC_DLLPUBLIC ScDocumentPool * GetPool()
Definition: document.cxx:6061
const mdds::mtv::element_t element_type_cellnote
Definition: mtvelements.hxx:52
void ParseFormula(const CellStoreType &rStore, Func &rFunc)
Definition: mtvcellfunc.hxx:64
css::uno::Any const & rValue
Store arbitrary cell value of any kind.
Definition: cellvalue.hxx:36
const ScFormulaCellGroupRef & GetCellGroup() const
void PreprocessRangeNameUpdate(sc::EndListeningContext &rEndListenCxt, sc::CompileFormulaContext &rCompileCxt)
Definition: column4.cxx:939
void PreprocessDBDataUpdate(sc::EndListeningContext &rEndListenCxt, sc::CompileFormulaContext &rCompileCxt)
Definition: column4.cxx:953
virtual void Clear() override
Definition: token.cxx:1913
const mdds::mtv::element_t element_type_formula
Definition: mtvelements.hxx:50
bool HasFormulaCell() const
Definition: column4.cxx:1260
void StartListeningFormulaCells(sc::StartListeningContext &rStartCxt, sc::EndListeningContext &rEndCxt, SCROW nRow1, SCROW nRow2)
Definition: column4.cxx:1467
ScClipParam & GetClipParam()
Definition: document.cxx:2549
Keep track of spans in a single column only.
std::vector< SvtListener * > ListenersType
enumrange< T >::Iterator begin(enumrange< T >)
ScFormulaCell * mpFormula
Definition: cellvalue.hxx:43
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:873
void ForgetNoteCaptions(SCROW nRow1, SCROW nRow2, bool bPreserveData)
Definition: column4.cxx:671
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
Additional class containing cell annotation data.
Definition: postit.hxx:160
void StartListeningTo(ScDocument &rDoc)
ScConditionalFormatList * getCondFormatList()
void CreateAllNoteCaptions()
Definition: column4.cxx:665
void EndListeningFormulaCells(sc::EndListeningContext &rCxt, SCROW nRow1, SCROW nRow2, SCROW *pStartRow, SCROW *pEndRow)
Definition: column4.cxx:1478
int nCount
sc::CellStoreType maCells
Definition: column.hxx:129
void ResetFormulaCellPositions(SCROW nRow1, SCROW nRow2, bool bUpdateRefs)
Reset column position of formula cells within specified row range.
Definition: column4.cxx:1157
void set(const ScDocument &rDoc, SCTAB nTab, SCCOL nCol, SCROW nRow, bool bVal)
void SetRow(SCROW nRowP)
Definition: address.hxx:275
SCROW GetLastDataPos() const
Definition: column2.cxx:1337
void SetCode(std::unique_ptr< ScTokenArray > pNew)
ScAddress aPos
void CheckRelativeReferenceBounds(const sc::RefUpdateContext &rCxt, const ScAddress &rPos, SCROW nGroupLen, std::vector< SCROW > &rBounds) const
Definition: token.cxx:4628
void SetNeedsListening(bool bVar)
void SetCol(SCCOL nColP)
Definition: address.hxx:279
size_t mnBlkCountFormula
Definition: column.hxx:133
void swapNonEmpty(ScColumn &rCol)
Definition: cellvalues.cxx:67
void setValue(size_t nRow, double fVal)
Definition: cellvalues.cxx:138
void SetDirty(bool bDirtyFlag=true)
const SfxPoolItem & GetItem(sal_uInt16 nWhichP) const
Definition: patattr.hxx:70
void AdjustReferenceOnMovedOriginIfOtherSheet(const ScAddress &rOldPos, const ScAddress &rNewPos)
Adjust all internal references on base position change if they point to a sheet other than the one of...
Definition: token.cxx:4398
SCROW GetSharedLength() const
bool IsShared() const
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
Definition: document.hxx:1059
SCCOL nCol
Definition: column.hxx:135
void getSpans(SpansType &rSpans) const
ScRecursionHelper & GetRecursionHelper()
Definition: document.cxx:6806
void InitBlockPosition(sc::ColumnBlockPosition &rBlockPos)
Definition: column3.cxx:1043
int i
void SetValues(const SCROW nRow, const std::vector< double > &rVals)
Definition: column4.cxx:311
sal_Int16 SCCOL
Definition: types.hxx:22
InsertDeleteFlags
Definition: global.hxx:159
void RegroupFormulaCells(std::vector< ScAddress > *pGroupPos=nullptr)
Regroup formula cells for the entire column.
Definition: column3.cxx:3510
sc::MultiDataCellState::StateType HasDataCellsInRange(SCROW nRow1, SCROW nRow2, SCROW *pRow1) const
Definition: column4.cxx:47
size_t size() const
Definition: cellvalues.cxx:121
SvtScriptType mnScriptType
svl::SharedString * mpString
Definition: cellvalue.hxx:41
sc::CellTextAttrStoreType maCellTextAttrs
Definition: column.hxx:118
std::unique_ptr< ScPostIt > Clone(const ScAddress &rOwnPos, ScDocument &rDestDoc, const ScAddress &rDestPos, bool bCloneCaption) const
Clones this note and its caption object, if specified.
Definition: postit.cxx:876
const ScPatternAttr * SetPattern(SCROW nRow, std::unique_ptr< ScPatternAttr >)
Definition: column.cxx:698
bool Interpret(SCROW nStartOffset=-1, SCROW nEndOffset=-1)
static void JoinNewFormulaCell(const sc::CellStoreType::position_type &aPos, ScFormulaCell &rCell)
Definition: column3.cxx:270
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
const mdds::mtv::element_t element_type_empty
Definition: mtvelements.hxx:56
void IncRow(SCROW nDelta=1)
Definition: address.hxx:300
void EndListeningGroup(sc::EndListeningContext &rCxt, SCROW nRow)
Definition: column4.cxx:1574
Structure that stores segments of boolean flags per column, and perform custom action on those segmen...
ocBad
void GetUnprotectedCells(SCROW nStartRow, SCROW nEndRow, ScRangeList &rRangeList) const
Definition: column4.cxx:770
const mdds::mtv::element_t element_type_numeric
Mapped standard element types (for convenience).
Definition: mtvelements.hxx:55
SdrCaptionObj * GetOrCreateCaption(const ScAddress &rPos) const
Returns the caption object of this note.
Definition: postit.cxx:950
const ScRange & getRange() const
Definition: cellvalues.cxx:317
bool IsSharedTop() const
void EndListeningIntersectedGroups(sc::EndListeningContext &rCxt, SCROW nRow1, SCROW nRow2, std::vector< ScAddress > *pGroupPos)
Definition: column4.cxx:1529
void ProcessNote(CellNoteStoreType &rStore, Func &rFunc)
sal_uInt32 GetNumberFormat(SvNumberFormatter *) const
Definition: patattr.cxx:1257
bool EnsureFormulaCellResults(SCROW nRow1, SCROW nRow2, bool bSkipRunning=false)
Definition: column4.cxx:1854
void SetMatColsRows(SCCOL nCols, SCROW nRows)
SvStream & ReadUChar(unsigned char &rChar)
CellStoreType::iterator ProcessFormula(const CellStoreType::iterator &it, CellStoreType &rStore, SCROW nRow1, SCROW nRow2, std::function< void(size_t, ScFormulaCell *)> aFuncElem)
Process formula cells found within specified row range.
Definition: mtvcellfunc.cxx:12
void UpdateScriptTypes(SCROW nRow1, SCROW nRow2)
Definition: column4.cxx:1067
static bool lcl_InterpretSpan(sc::formula_block::const_iterator &rSpanIter, SCROW nStartOffset, SCROW nEndOffset, const ScFormulaCellGroupRef &mxParentGroup, bool &bAllowThreading, ScDocument &rDoc)
Definition: column4.cxx:1642
void DetachFormulaCells(const sc::CellStoreType::position_type &aPos, size_t nLength, std::vector< SCROW > *pNewSharedRows)
Definition: column3.cxx:401
SC_DLLPUBLIC const SfxItemSet * GetCondResult(SCCOL nCol, SCROW nRow, SCTAB nTab, ScRefCellValue *pCell=nullptr) const
Definition: documen4.cxx:788
SvStream & ReadDouble(double &rDouble)
void CollectFormulaCells(std::vector< ScFormulaCell * > &rCells, SCROW nRow1, SCROW nRow2)
Definition: column4.cxx:1251
const ScPatternAttr * getSingleCellPattern(size_t nColOffset) const
ScCellValue & getSingleCell(size_t nColOffset)
CellStoreType::iterator miCellPos
std::vector< CellValueSpan > getNonEmptySpans(SCTAB nTab, SCCOL nCol) const
Definition: cellvalues.cxx:340
SvStream & ReadInt32(sal_Int32 &rInt32)
Internal use only (undo etc.): do not copy/delete caption objects of cell notes.
std::size_t ReadBytes(void *pData, std::size_t nSize)
void SyncSharedCode()
OString OUStringToOString(const OUString &str, ConnectionSettings const *settings)
void copyTo(ScColumn &rCol, SCROW nRow) const
Definition: cellvalues.cxx:61
const ScPostIt * getSingleCellNote(size_t nColOffset) const
void DeleteCellNotes(sc::ColumnBlockPosition &rBlockPos, SCROW nRow1, SCROW nRow2, bool bForgetCaptionOwnership)
Definition: column2.cxx:2002
void SetHybridFormula(const OUString &r, const formula::FormulaGrammar::Grammar eGrammar)
For import only: set a temporary formula string to be compiled later.
A class to wrap ScRecursionHelper::PushFormulaGroup(), ScRecursionHelper::PopFormulaGroup() and make ...
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_Int32 SCROW
Definition: types.hxx:18
ScRange getWholeRange() const
Return a single range that encompasses all individual ranges.
Definition: clipparam.cxx:103
sc::BroadcasterStoreType maBroadcasters
Definition: column.hxx:124
void CollectListeners(std::vector< SvtListener * > &rListeners, SCROW nRow1, SCROW nRow2)
Definition: column4.cxx:1242
bool ValidRow(SCROW nRow) const
Definition: document.hxx:876
bool IsMerged(SCROW nRow) const
Definition: column4.cxx:42
sc::CellNoteStoreType maCellNotes
Definition: column.hxx:121
void CopyCellValuesFrom(SCROW nRow, const sc::CellValues &rSrc)
Definition: column4.cxx:366
#define SAL_WARN_IF(condition, area, stream)
void Join(const ScRange &, bool bIsInList=false)
Definition: rangelst.cxx:166
SCCOL GetCol() const
Definition: column.hxx:184
unsigned char sal_uInt8
ScPatternAttr * PutInPool(ScDocument *pDestDoc, ScDocument *pSrcDoc) const
Definition: patattr.cxx:1032
ScFormulaCell ** mpCells
void GetMatColsRows(SCCOL &nCols, SCROW &nRows) const
ScFormulaCell * mpCell
const mdds::mtv::element_t element_type_edittext
Definition: mtvelements.hxx:49
sc::CellTextAttr & getSingleCellAttr(size_t nColOffset)
SvStream & WriteUChar(unsigned char nChar)
void RemoveEditAttribs(SCROW nStartRow, SCROW nEndRow)
Definition: column2.cxx:1182
std::unique_ptr< sc::ColumnIterator > GetColumnIterator(SCROW nRow1, SCROW nRow2) const
Definition: column4.cxx:1634
CellNoteStoreType::iterator miCellNotePos
void CopyOneCellFromClip(sc::CopyFromClipContext &rCxt, SCROW nRow1, SCROW nRow2, size_t nColOffset)
Definition: column4.cxx:195
const T & Put(std::unique_ptr< T > xItem, sal_uInt16 nWhich=0)
ocTableRef
ocColRowName
static bool splitFormulaCellGroups(const ScDocument &rDoc, CellStoreType &rCells, std::vector< SCROW > &rBounds)
Split existing shared formula ranges at specified row positions.
constexpr TypedWhichId< ScCondFormatItem > ATTR_CONDITIONAL(154)
ScDocument * getClipDoc()
Definition: clipcontext.cxx:96
void * p
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:401
std::vector< RowSpan > SpansType
std::vector< sc::FormulaGroupEntry > GetFormulaGroupEntries()
Get all non-grouped formula cells and formula cell groups in the whole column.
Definition: column.cxx:2542
sc::FormulaResultValue GetResult()
ScMatrixMode
const ScCondFormatIndexes & GetCondFormatData() const
Definition: attrib.hxx:280
EditTextObject * mpEditText
Definition: cellvalue.hxx:42
size_t GetNoteCount() const
Definition: column4.cxx:626
InsertDeleteFlags getDeleteFlag() const
void ConvertFormulaToValue(sc::EndListeningContext &rCxt, SCROW nRow1, SCROW nRow2, sc::TableValues *pUndo)
Definition: column4.cxx:432
void scan(const ScColumn &rColumn)
Scan an entire column and tag all non-empty cell positions.
const OUString & GetHybridFormula() const
void BroadcastCells(const std::vector< SCROW > &rRows, SfxHintId nHint)
Definition: column3.cxx:72
bool ValidRow(SCROW nRow, SCROW nMaxRow)
Definition: address.hxx:99
bool HandleRefArrayForParallelism(SCROW nRow1, SCROW nRow2, const ScFormulaCellGroupRef &mxGroup)
Definition: column4.cxx:1867
SCTAB GetTab() const
Definition: column.hxx:183
Range getDestRange() const
Definition: clipcontext.cxx:81
std::pair< CellStoreType::const_iterator, size_t > FindFormula(const CellStoreType &rStore, SCROW nRow1, SCROW nRow2, Func &rFunc)
#define SAL_WARN(area, stream)
static void GetString(const ScRefCellValue &rCell, sal_uInt32 nFormat, OUString &rString, const Color **ppColor, SvNumberFormatter &rFormatter, const ScDocument &rDoc, bool bNullVals=true, bool bFormula=false, bool bUseStarFormat=false)
Definition: cellform.cxx:33
SvStream & WriteDouble(const double &rDouble)
void RemoveFromFormulaTree(ScFormulaCell *pCell)
Definition: documen7.cxx:274
void DeleteCells(sc::ColumnBlockPosition &rBlockPos, SCROW nRow1, SCROW nRow2, InsertDeleteFlags nDelFlag, sc::SingleColumnSpanSet &rDeleted)
Definition: column3.cxx:967
void DeleteBeforeCopyFromClip(sc::CopyFromClipContext &rCxt, const ScColumn &rClipCol, sc::ColumnSpanSet &rBroadcastSpans)
Definition: column4.cxx:95
std::unique_ptr< EditTextObject > Clone() const
ScMatrixMode GetMatrixFlag() const
void EndListeningIntersectedGroup(sc::EndListeningContext &rCxt, SCROW nRow, std::vector< ScAddress > *pGroupPos)
Definition: column4.cxx:1495
void SetNeedsListeningGroup(SCROW nRow)
Definition: column4.cxx:1604
const mdds::mtv::element_t element_type_string
Definition: mtvelements.hxx:48
mdds::multi_type_vector< CTAttrFunc > CellTextAttrStoreType
void EndListeningTo(ScDocument &rDoc, ScTokenArray *pArr=nullptr, ScAddress aPos=ScAddress())
void CloneFormulaCell(const ScFormulaCell &rSrc, const sc::CellTextAttr &rAttr, const std::vector< sc::RowSpan > &rRanges)
Definition: column4.cxx:540
aStr
bool HasOpCodes(const unordered_opcode_set &rOpCodes) const
void GetNotesInRange(SCROW nStartRow, SCROW nEndRow, std::vector< sc::NoteEntry > &rNotes) const
Definition: column4.cxx:754
Strings (and string results if InsertDeleteFlags::FORMULA is not set).
::basegfx::B2DRectangle maBounds
ocDBArea
void StartListeningUnshared(const std::vector< SCROW > &rNewSharedRows)
Re-establish listeners on unshared formula groups.
Definition: column3.cxx:343
sal_Int16 SCTAB
Definition: types.hxx:23
ColumnBlockPosition * getBlockPosition(SCTAB nTab, SCCOL nCol)
Definition: clipcontext.cxx:31
static void lcl_EvalDirty(sc::CellStoreType &rCells, SCROW nRow1, SCROW nRow2, ScDocument &rDoc, const ScFormulaCellGroupRef &mxGroup, bool bThreadingDepEval, bool bSkipRunning, bool &bIsDirty, bool &bAllowThreading)
Definition: column4.cxx:1720
void swapNonEmpty(SCTAB nTab, SCCOL nCol, ScColumn &rCol)
Swap non-empty blocks with the column storage.
Definition: cellvalues.cxx:331
void DeleteArea(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
Definition: conditio.cxx:2189
BroadcasterStoreType::iterator ProcessBroadcaster(const BroadcasterStoreType::iterator &it, BroadcasterStoreType &rStore, SCROW nRow1, SCROW nRow2, FuncElem &rFuncElem)