LibreOffice Module sc (master)  1
document10.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 <memory>
11 #include <document.hxx>
12 #include <clipcontext.hxx>
13 #include <clipparam.hxx>
14 #include <table.hxx>
15 #include <tokenarray.hxx>
16 #include <listenercontext.hxx>
17 #include <tokenstringcontext.hxx>
18 #include <poolhelp.hxx>
19 #include <cellvalues.hxx>
20 #include <docpool.hxx>
21 #include <columniterator.hxx>
22 
23 #include <refupdatecontext.hxx>
24 #include <sal/log.hxx>
25 #include <editeng/colritem.hxx>
26 #include <scitems.hxx>
27 #include <datamapper.hxx>
28 #include <docsh.hxx>
29 
30 // Add totally brand-new methods to this source file.
31 
32 bool ScDocument::IsMerged( const ScAddress& rPos ) const
33 {
34  const ScTable* pTab = FetchTable(rPos.Tab());
35  if (!pTab)
36  return false;
37 
38  return pTab->IsMerged(rPos.Col(), rPos.Row());
39 }
40 
42 {
43  if (rRange.aStart.Tab() != rRange.aEnd.Tab())
44  // Currently we only support a single-sheet range.
45  return sc::MultiDataCellState();
46 
47  const ScTable* pTab = FetchTable(rRange.aStart.Tab());
48  if (!pTab)
50 
51  const ScAddress& s = rRange.aStart;
52  const ScAddress& e = rRange.aEnd;
53  return pTab->HasMultipleDataCells(s.Col(), s.Row(), e.Col(), e.Row());
54 }
55 
57  sc::CopyFromClipContext& rCxt, const ScMarkData& rMark, sc::ColumnSpanSet& rBroadcastSpans )
58 {
59  SCTAB nClipTab = 0;
60  const TableContainer& rClipTabs = rCxt.getClipDoc()->maTabs;
61  SCTAB nClipTabCount = rClipTabs.size();
62 
63  for (SCTAB nTab = rCxt.getTabStart(); nTab <= rCxt.getTabEnd(); ++nTab)
64  {
65  ScTable* pTab = FetchTable(nTab);
66  if (!pTab)
67  continue;
68 
69  if (!rMark.GetTableSelect(nTab))
70  continue;
71 
72  while (!rClipTabs[nClipTab])
73  nClipTab = (nClipTab+1) % nClipTabCount;
74 
75  pTab->DeleteBeforeCopyFromClip(rCxt, *rClipTabs[nClipTab], rBroadcastSpans);
76 
77  nClipTab = (nClipTab+1) % nClipTabCount;
78  }
79 }
80 
82  sc::CopyFromClipContext& rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
83 {
84  ScDocument* pClipDoc = rCxt.getClipDoc();
85  if (pClipDoc->GetClipParam().mbCutMode)
86  // We don't handle cut and paste or moving of cells here.
87  return false;
88 
89  ScRange aClipRange = pClipDoc->GetClipParam().getWholeRange();
90  if (aClipRange.aStart.Row() != aClipRange.aEnd.Row())
91  // The source is not really a single row. Bail out.
92  return false;
93 
94  SCCOL nSrcColSize = aClipRange.aEnd.Col() - aClipRange.aStart.Col() + 1;
95  SCCOL nDestColSize = nCol2 - nCol1 + 1;
96  if (nDestColSize < nSrcColSize)
97  return false;
98 
99  if (pClipDoc->maTabs.size() > 1)
100  // Copying from multiple source sheets is not handled here.
101  return false;
102 
103  ScAddress aSrcPos = aClipRange.aStart;
104 
105  for (SCCOL nCol = aClipRange.aStart.Col(); nCol <= aClipRange.aEnd.Col(); ++nCol)
106  {
107  ScAddress aTestPos = aSrcPos;
108  aTestPos.SetCol(nCol);
109  if (pClipDoc->IsMerged(aTestPos))
110  // We don't handle merged source cell for this.
111  return false;
112  }
113 
114  ScTable* pSrcTab = pClipDoc->FetchTable(aSrcPos.Tab());
115  if (!pSrcTab)
116  return false;
117 
118  rCxt.setSingleCellColumnSize(nSrcColSize);
119 
120  for (SCCOL nColOffset = 0; nColOffset < nSrcColSize; ++nColOffset, aSrcPos.IncCol())
121  {
122  const ScPatternAttr* pAttr = pClipDoc->GetPattern(aSrcPos);
123  rCxt.setSingleCellPattern(nColOffset, pAttr);
124 
126  rCxt.setSingleCellNote(nColOffset, pClipDoc->GetNote(aSrcPos));
127 
129  rCxt.setSingleSparkline(nColOffset, pClipDoc->GetSparkline(aSrcPos));
130 
131  ScColumn* pSrcCol = pSrcTab->FetchColumn(aSrcPos.Col());
132  assert(pSrcCol);
133  // Determine the script type of the copied single cell.
134  pSrcCol->UpdateScriptTypes(aSrcPos.Row(), aSrcPos.Row());
135  rCxt.setSingleCell(aSrcPos, *pSrcCol);
136  }
137 
138  // All good. Proceed with the pasting.
139 
140  SCTAB nTabEnd = rCxt.getTabEnd();
141  for (SCTAB i = rCxt.getTabStart(); i <= nTabEnd && i < static_cast<SCTAB>(maTabs.size()); ++i)
142  {
143  maTabs[i]->CopyOneCellFromClip(rCxt, nCol1, nRow1, nCol2, nRow2, aClipRange.aStart.Row(), pSrcTab);
144  }
145 
146  sc::RefUpdateContext aRefCxt(*this);
147  aRefCxt.maRange = ScRange(nCol1, nRow1, rCxt.getTabStart(), nCol2, nRow2, nTabEnd);
148  aRefCxt.mnColDelta = nCol1 - aSrcPos.Col();
149  aRefCxt.mnRowDelta = nRow1 - aSrcPos.Row();
150  aRefCxt.mnTabDelta = rCxt.getTabStart() - aSrcPos.Tab();
151  // Only Copy&Paste, for Cut&Paste we already bailed out early.
152  aRefCxt.meMode = URM_COPY;
153  UpdateReference(aRefCxt, rCxt.getUndoDoc(), false);
154 
155  return true;
156 }
157 
158 void ScDocument::SetValues( const ScAddress& rPos, const std::vector<double>& rVals )
159 {
160  ScTable* pTab = FetchTable(rPos.Tab());
161  if (!pTab)
162  return;
163 
164  pTab->SetValues(rPos.Col(), rPos.Row(), rVals);
165 }
166 
167 void ScDocument::TransferCellValuesTo( const ScAddress& rTopPos, size_t nLen, sc::CellValues& rDest )
168 {
169  ScTable* pTab = FetchTable(rTopPos.Tab());
170  if (!pTab)
171  return;
172 
173  pTab->TransferCellValuesTo(rTopPos.Col(), rTopPos.Row(), nLen, rDest);
174 }
175 
176 void ScDocument::CopyCellValuesFrom( const ScAddress& rTopPos, const sc::CellValues& rSrc )
177 {
178  ScTable* pTab = FetchTable(rTopPos.Tab());
179  if (!pTab)
180  return;
181 
182  pTab->CopyCellValuesFrom(rTopPos.Col(), rTopPos.Row(), rSrc);
183 }
184 
185 std::set<Color> ScDocument::GetDocColors()
186 {
187  std::set<Color> aDocColors;
188  ScDocumentPool *pPool = GetPool();
189  const sal_uInt16 pAttribs[] = {ATTR_BACKGROUND, ATTR_FONT_COLOR};
190  for (sal_uInt16 nAttrib : pAttribs)
191  {
192  for (const SfxPoolItem* pItem : pPool->GetItemSurrogates(nAttrib))
193  {
194  const SvxColorItem *pColorItem = static_cast<const SvxColorItem*>(pItem);
195  Color aColor( pColorItem->GetValue() );
196  if (COL_AUTO != aColor)
197  aDocColors.insert(aColor);
198  }
199  }
200  return aDocColors;
201 }
202 
204 {
206  maCalcConfig = rConfig;
207 }
208 
210 {
211  sc::EndListeningContext aCxt(*this);
212 
213  for (SCTAB nTab = rRange.aStart.Tab(); nTab <= rRange.aEnd.Tab(); ++nTab)
214  {
215  ScTable* pTab = FetchTable(nTab);
216  if (!pTab)
217  continue;
218 
219  pTab->ConvertFormulaToValue(
220  aCxt, rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row(),
221  pUndo);
222  }
223 
224  aCxt.purgeEmptyBroadcasters();
225 }
226 
228 {
229  const ScRange& rRange = rValues.getRange();
230  if (!rRange.IsValid())
231  return;
232 
233  auto pPosSet = std::make_shared<sc::ColumnBlockPositionSet>(*this);
234  sc::StartListeningContext aStartCxt(*this, pPosSet);
235  sc::EndListeningContext aEndCxt(*this, pPosSet);
236 
237  for (SCTAB nTab = rRange.aStart.Tab(); nTab <= rRange.aEnd.Tab(); ++nTab)
238  {
239  ScTable* pTab = FetchTable(nTab);
240  if (!pTab)
241  continue;
242 
243  pTab->SwapNonEmpty(rValues, aStartCxt, aEndCxt);
244  }
245 
246  aEndCxt.purgeEmptyBroadcasters();
247 }
248 
249 void ScDocument::PreprocessAllRangeNamesUpdate( const std::map<OUString, std::unique_ptr<ScRangeName>>& rRangeMap )
250 {
251  // Update all existing names with new names.
252  // The prerequisites are that the name dialog preserves ScRangeData index
253  // for changes and does not reuse free index slots for new names.
254  // ScDocument::SetAllRangeNames() hereafter then will replace the
255  // ScRangeName containers of ScRangeData instances with empty
256  // ScRangeData::maNewName.
257  std::map<OUString, ScRangeName*> aRangeNameMap;
258  GetRangeNameMap( aRangeNameMap);
259  for (const auto& itTab : aRangeNameMap)
260  {
261  ScRangeName* pOldRangeNames = itTab.second;
262  if (!pOldRangeNames)
263  continue;
264 
265  const auto& itNewTab( rRangeMap.find( itTab.first));
266  if (itNewTab == rRangeMap.end())
267  continue;
268 
269  const ScRangeName* pNewRangeNames = itNewTab->second.get();
270  if (!pNewRangeNames)
271  continue;
272 
273  for (const auto& rEntry : *pOldRangeNames)
274  {
275  ScRangeData* pOldData = rEntry.second.get();
276  if (!pOldData)
277  continue;
278 
279  const ScRangeData* pNewData = pNewRangeNames->findByIndex( pOldData->GetIndex());
280  if (pNewData)
281  pOldData->SetNewName( pNewData->GetName());
282  }
283  }
284 
285  sc::EndListeningContext aEndListenCxt(*this);
286  sc::CompileFormulaContext aCompileCxt(*this);
287 
288  for (const auto& rxTab : maTabs)
289  {
290  ScTable* p = rxTab.get();
291  p->PreprocessRangeNameUpdate(aEndListenCxt, aCompileCxt);
292  }
293 }
294 
296 {
297  sc::EndListeningContext aEndListenCxt(*this);
298  sc::CompileFormulaContext aCompileCxt(*this);
299 
300  for (const auto& rxTab : maTabs)
301  {
302  ScTable* p = rxTab.get();
303  p->PreprocessRangeNameUpdate(aEndListenCxt, aCompileCxt);
304  }
305 }
306 
308 {
309  sc::EndListeningContext aEndListenCxt(*this);
310  sc::CompileFormulaContext aCompileCxt(*this);
311 
312  for (const auto& rxTab : maTabs)
313  {
314  ScTable* p = rxTab.get();
315  p->PreprocessDBDataUpdate(aEndListenCxt, aCompileCxt);
316  }
317 }
318 
320 {
321  sc::StartListeningContext aStartListenCxt(*this);
322  sc::CompileFormulaContext aCompileCxt(*this);
323  for (const auto& rxTab : maTabs)
324  {
325  ScTable* p = rxTab.get();
326  p->CompileHybridFormula(aStartListenCxt, aCompileCxt);
327  }
328 }
329 
331 {
333  mxPoolHelper = pSrcDoc->mxPoolHelper;
335 }
336 
337 void ScDocument::UpdateScriptTypes( const ScAddress& rPos, SCCOL nColSize, SCROW nRowSize )
338 {
339  ScTable* pTab = FetchTable(rPos.Tab());
340  if (!pTab)
341  return;
342 
343  pTab->UpdateScriptTypes(rPos.Col(), rPos.Row(), rPos.Col()+nColSize-1, rPos.Row()+nRowSize-1);
344 }
345 
346 bool ScDocument::HasUniformRowHeight( SCTAB nTab, SCROW nRow1, SCROW nRow2 ) const
347 {
348  const ScTable* pTab = FetchTable(nTab);
349  if (!pTab)
350  return false;
351 
352  return pTab->HasUniformRowHeight(nRow1, nRow2);
353 }
354 
355 void ScDocument::UnshareFormulaCells( SCTAB nTab, SCCOL nCol, std::vector<SCROW>& rRows )
356 {
357  ScTable* pTab = FetchTable(nTab);
358  if (!pTab)
359  return;
360 
361  pTab->UnshareFormulaCells(nCol, rRows);
362 }
363 
365 {
366  ScTable* pTab = FetchTable(nTab);
367  if (!pTab)
368  return;
369 
370  pTab->RegroupFormulaCells(nCol);
371 }
372 
374 {
375  for( SCTAB tab = rRange.aStart.Tab(); tab <= rRange.aEnd.Tab(); ++tab )
376  for( SCCOL col = rRange.aStart.Col(); col <= rRange.aEnd.Col(); ++col )
377  RegroupFormulaCells( tab, col );
378 }
379 
381 {
382  if( delay )
383  {
386  }
387  else
388  {
391  pDelayedFormulaGrouping.reset();
392  }
393 }
394 
396 {
397  if( !pDelayedFormulaGrouping->Contains( cell->aPos ))
398  pDelayedFormulaGrouping->ExtendTo( cell->aPos );
399 }
400 
402 {
403  if( delay )
404  {
406  pDelayedStartListeningFormulaCells[ column ] = std::pair<SCROW, SCROW>( -1, -1 );
407  }
408  else
409  {
410  auto it = pDelayedStartListeningFormulaCells.find( column );
411  if( it != pDelayedStartListeningFormulaCells.end())
412  {
413  if( it->second.first != -1 )
414  {
415  auto pPosSet = std::make_shared<sc::ColumnBlockPositionSet>(*this);
416  sc::StartListeningContext aStartCxt(*this, pPosSet);
417  sc::EndListeningContext aEndCxt(*this, pPosSet);
418  column->StartListeningFormulaCells(aStartCxt, aEndCxt, it->second.first, it->second.second);
419  }
421  }
422  }
423 }
424 
426 {
428 }
429 
431 {
432  auto it = pDelayedStartListeningFormulaCells.find( column );
433  if( it == pDelayedStartListeningFormulaCells.end())
434  return false; // not enabled
435  if( it->second.first == -1 && it->second.second == -1 ) // uninitialized
436  pDelayedStartListeningFormulaCells[ column ] = std::make_pair( row1, row2 );
437  else
438  {
439  if( row1 > it->second.second + 1 || row2 < it->second.first - 1 )
440  { // two non-adjacent ranges, just bail out
441  return false;
442  }
443  it->second.first = std::min( it->second.first, row1 );
444  it->second.second = std::max( it->second.second, row2 );
445  }
446  return true;
447 }
448 
450 {
451  if( bDelayedDeletingBroadcasters == set )
452  return;
455  {
456  for (auto& rxTab : maTabs)
457  if (rxTab)
458  rxTab->DeleteEmptyBroadcasters();
459  }
460 }
461 
462 bool ScDocument::HasFormulaCell( const ScRange& rRange ) const
463 {
464  if (!rRange.IsValid())
465  return false;
466 
467  for (SCTAB nTab = rRange.aStart.Tab(); nTab <= rRange.aEnd.Tab(); ++nTab)
468  {
469  const ScTable* pTab = FetchTable(nTab);
470  if (!pTab)
471  continue;
472 
473  if (pTab->HasFormulaCell(rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row()))
474  return true;
475  }
476 
477  return false;
478 }
479 
481  sc::EndListeningContext& rCxt, const ScAddress& rPos, std::vector<ScAddress>* pGroupPos )
482 {
483  ScTable* pTab = FetchTable(rPos.Tab());
484  if (!pTab)
485  return;
486 
487  pTab->EndListeningIntersectedGroup(rCxt, rPos.Col(), rPos.Row(), pGroupPos);
488 }
489 
491  sc::EndListeningContext& rCxt, const ScRange& rRange, std::vector<ScAddress>* pGroupPos )
492 {
493  for (SCTAB nTab = rRange.aStart.Tab(); nTab <= rRange.aEnd.Tab(); ++nTab)
494  {
495  ScTable* pTab = FetchTable(nTab);
496  if (!pTab)
497  continue;
498 
500  rCxt, rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row(),
501  pGroupPos);
502  }
503 }
504 
505 void ScDocument::EndListeningGroups( const std::vector<ScAddress>& rPosArray )
506 {
507  sc::EndListeningContext aCxt(*this);
508  for (const ScAddress& rPos : rPosArray)
509  {
510  ScTable* pTab = FetchTable(rPos.Tab());
511  if (!pTab)
512  return;
513 
514  pTab->EndListeningGroup(aCxt, rPos.Col(), rPos.Row());
515  }
516 
517  aCxt.purgeEmptyBroadcasters();
518 }
519 
520 void ScDocument::SetNeedsListeningGroups( const std::vector<ScAddress>& rPosArray )
521 {
522  for (const ScAddress& rPos : rPosArray)
523  {
524  ScTable* pTab = FetchTable(rPos.Tab());
525  if (!pTab)
526  return;
527 
528  pTab->SetNeedsListeningGroup(rPos.Col(), rPos.Row());
529  }
530 }
531 
532 namespace {
533 
534 class StartNeededListenersHandler
535 {
536  std::shared_ptr<sc::StartListeningContext> mpCxt;
537 public:
538  explicit StartNeededListenersHandler( ScDocument& rDoc ) : mpCxt(std::make_shared<sc::StartListeningContext>(rDoc)) {}
539  explicit StartNeededListenersHandler( ScDocument& rDoc, const std::shared_ptr<const sc::ColumnSet>& rpColSet ) :
540  mpCxt(std::make_shared<sc::StartListeningContext>(rDoc))
541  {
542  mpCxt->setColumnSet( rpColSet);
543  }
544 
545  void operator() (const ScTableUniquePtr & p)
546  {
547  if (p)
548  p->StartListeners(*mpCxt, false);
549  }
550 };
551 
552 }
553 
555 {
556  std::for_each(maTabs.begin(), maTabs.end(), StartNeededListenersHandler(*this));
557 }
558 
559 void ScDocument::StartNeededListeners( const std::shared_ptr<const sc::ColumnSet>& rpColSet )
560 {
561  std::for_each(maTabs.begin(), maTabs.end(), StartNeededListenersHandler(*this, rpColSet));
562 }
563 
565 {
566  if (IsClipOrUndo() || GetNoListening())
567  return;
568 
569  auto pPosSet = std::make_shared<sc::ColumnBlockPositionSet>(*this);
570  sc::StartListeningContext aStartCxt(*this, pPosSet);
571  sc::EndListeningContext aEndCxt(*this, pPosSet);
572 
573  for (SCTAB nTab = rRange.aStart.Tab(); nTab <= rRange.aEnd.Tab(); ++nTab)
574  {
575  ScTable* pTab = FetchTable(nTab);
576  if (!pTab)
577  continue;
578 
580  aStartCxt, aEndCxt,
581  rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row());
582  }
583 }
584 
586 {
587  for (const auto& rxTab : maTabs)
588  {
589  ScTable* p = rxTab.get();
591  }
592 }
593 
595  SCTAB nTokenTab, const sal_uInt16 nTokenIndex,
596  SCTAB nGlobalRefTab, SCTAB nLocalRefTab, SCTAB nOldTokenTab, SCTAB nOldTokenTabReplacement,
597  bool bSameDoc, int nRecursion) const
598 {
599  if (nTokenTab < -1)
600  {
601  SAL_WARN("sc.core", "ScDocument::FindRangeNamesReferencingSheet - nTokenTab < -1 : " <<
602  nTokenTab << ", nTokenIndex " << nTokenIndex << " Fix the creator!");
603 #if OSL_DEBUG_LEVEL > 0
604  const ScRangeData* pData = FindRangeNameBySheetAndIndex( nTokenTab, nTokenIndex);
605  SAL_WARN_IF( pData, "sc.core", "ScDocument::FindRangeNamesReferencingSheet - named expression is: " << pData->GetName());
606 #endif
607  nTokenTab = -1;
608  }
609  SCTAB nRefTab = nGlobalRefTab;
610  if (nTokenTab == nOldTokenTab)
611  {
612  nTokenTab = nOldTokenTabReplacement;
613  nRefTab = nLocalRefTab;
614  }
615  else if (nTokenTab == nOldTokenTabReplacement)
616  {
617  nRefTab = nLocalRefTab;
618  }
619 
620  if (rIndexes.isNameUpdated( nTokenTab, nTokenIndex))
621  return true;
622 
623  ScRangeData* pData = FindRangeNameBySheetAndIndex( nTokenTab, nTokenIndex);
624  if (!pData)
625  return false;
626 
627  ScTokenArray* pCode = pData->GetCode();
628  if (!pCode)
629  return false;
630 
631  bool bRef = !bSameDoc; // include every name used when copying to other doc
632  if (nRecursion < 126) // whatever... 42*3
633  {
635  for (const formula::FormulaToken* p = aIter.First(); p; p = aIter.Next())
636  {
637  if (p->GetOpCode() == ocName)
638  {
639  bRef |= FindRangeNamesReferencingSheet( rIndexes, p->GetSheet(), p->GetIndex(),
640  nGlobalRefTab, nLocalRefTab, nOldTokenTab, nOldTokenTabReplacement, bSameDoc, nRecursion+1);
641  }
642  }
643  }
644 
645  if (!bRef)
646  {
647  SCTAB nPosTab = pData->GetPos().Tab();
648  if (nPosTab == nOldTokenTab)
649  nPosTab = nOldTokenTabReplacement;
650  bRef = pCode->ReferencesSheet( nRefTab, nPosTab);
651  }
652  if (bRef)
653  rIndexes.setUpdatedName( nTokenTab, nTokenIndex);
654 
655  return bRef;
656 }
657 
658 namespace {
659 
661 {
662  UNKNOWN,
663  NONE,
664  CODE,
665  NAME
666 };
667 
668 MightReferenceSheet mightRangeNameReferenceSheet( ScRangeData* pData, SCTAB nRefTab)
669 {
670  ScTokenArray* pCode = pData->GetCode();
671  if (!pCode)
673 
675  for (const formula::FormulaToken* p = aIter.First(); p; p = aIter.Next())
676  {
677  if (p->GetOpCode() == ocName)
678  return MightReferenceSheet::NAME;
679  }
680 
681  return pCode->ReferencesSheet( nRefTab, pData->GetPos().Tab()) ?
682  MightReferenceSheet::CODE : MightReferenceSheet::NONE;
683 }
684 
685 ScRangeData* copyRangeName( const ScRangeData* pOldRangeData, ScDocument& rNewDoc, const ScDocument& rOldDoc,
686  const ScAddress& rNewPos, const ScAddress& rOldPos, bool bGlobalNamesToLocal,
687  SCTAB nOldSheet, const SCTAB nNewSheet, bool bSameDoc)
688 {
689  ScAddress aRangePos( pOldRangeData->GetPos());
690  if (nNewSheet >= 0)
691  aRangePos.SetTab( nNewSheet);
692  ScRangeData* pRangeData = new ScRangeData(*pOldRangeData, &rNewDoc, &aRangePos);
693  pRangeData->SetIndex(0); // needed for insert to assign a new index
694  ScTokenArray* pRangeNameToken = pRangeData->GetCode();
695  if (bSameDoc && nNewSheet >= 0)
696  {
697  if (bGlobalNamesToLocal && nOldSheet < 0)
698  {
699  nOldSheet = rOldPos.Tab();
700  if (rNewPos.Tab() <= nOldSheet)
701  // Sheet was inserted before and references already updated.
702  ++nOldSheet;
703  }
704  pRangeNameToken->AdjustSheetLocalNameReferences( nOldSheet, nNewSheet);
705  }
706  if (!bSameDoc)
707  {
708  pRangeNameToken->ReadjustAbsolute3DReferences(rOldDoc, rNewDoc, pRangeData->GetPos(), true);
709  pRangeNameToken->AdjustAbsoluteRefs(rOldDoc, rOldPos, rNewPos, true);
710  }
711 
712  bool bInserted;
713  if (nNewSheet < 0)
714  bInserted = rNewDoc.GetRangeName()->insert(pRangeData);
715  else
716  bInserted = rNewDoc.GetRangeName(nNewSheet)->insert(pRangeData);
717 
718  return bInserted ? pRangeData : nullptr;
719 }
720 
721 struct SheetIndex
722 {
723  SCTAB mnSheet;
724  sal_uInt16 mnIndex;
725 
726  SheetIndex( SCTAB nSheet, sal_uInt16 nIndex ) : mnSheet(nSheet < -1 ? -1 : nSheet), mnIndex(nIndex) {}
727  bool operator<( const SheetIndex& r ) const
728  {
729  // Ascending order sheet, index
730  if (mnSheet < r.mnSheet)
731  return true;
732  if (mnSheet == r.mnSheet)
733  return mnIndex < r.mnIndex;
734  return false;
735  }
736 };
737 typedef std::map< SheetIndex, SheetIndex > SheetIndexMap;
738 
739 ScRangeData* copyRangeNames( SheetIndexMap& rSheetIndexMap, std::vector<ScRangeData*>& rRangeDataVec,
740  const sc::UpdatedRangeNames& rReferencingNames, SCTAB nTab,
741  const ScRangeData* pOldRangeData, ScDocument& rNewDoc, const ScDocument& rOldDoc,
742  const ScAddress& rNewPos, const ScAddress& rOldPos, bool bGlobalNamesToLocal,
743  const SCTAB nOldSheet, const SCTAB nNewSheet, bool bSameDoc)
744 {
745  ScRangeData* pRangeData = nullptr;
746  const ScRangeName* pOldRangeName = (nTab < 0 ? rOldDoc.GetRangeName() : rOldDoc.GetRangeName(nTab));
747  if (pOldRangeName)
748  {
749  const ScRangeName* pNewRangeName = (nNewSheet < 0 ? rNewDoc.GetRangeName() : rNewDoc.GetRangeName(nNewSheet));
750  sc::UpdatedRangeNames::NameIndicesType aSet( rReferencingNames.getUpdatedNames(nTab));
751  for (auto const & rIndex : aSet)
752  {
753  const ScRangeData* pCopyData = pOldRangeName->findByIndex(rIndex);
754  if (pCopyData)
755  {
756  // Match the original pOldRangeData to adapt the current
757  // token's values later. For that no check for an already
758  // copied name is needed as we only enter here if there was
759  // none.
760  if (pCopyData == pOldRangeData)
761  {
762  pRangeData = copyRangeName( pCopyData, rNewDoc, rOldDoc, rNewPos, rOldPos,
763  bGlobalNamesToLocal, nOldSheet, nNewSheet, bSameDoc);
764  if (pRangeData)
765  {
766  rRangeDataVec.push_back(pRangeData);
767  rSheetIndexMap.insert( std::make_pair( SheetIndex( nOldSheet, pCopyData->GetIndex()),
768  SheetIndex( nNewSheet, pRangeData->GetIndex())));
769  }
770  }
771  else
772  {
773  // First check if the name is already available as copy.
774  const ScRangeData* pFoundData = pNewRangeName->findByUpperName( pCopyData->GetUpperName());
775  if (pFoundData)
776  {
777  // Just add the resulting sheet/index mapping.
778  rSheetIndexMap.insert( std::make_pair( SheetIndex( nOldSheet, pCopyData->GetIndex()),
779  SheetIndex( nNewSheet, pFoundData->GetIndex())));
780  }
781  else
782  {
783  ScRangeData* pTmpData = copyRangeName( pCopyData, rNewDoc, rOldDoc, rNewPos, rOldPos,
784  bGlobalNamesToLocal, nOldSheet, nNewSheet, bSameDoc);
785  if (pTmpData)
786  {
787  rRangeDataVec.push_back(pTmpData);
788  rSheetIndexMap.insert( std::make_pair( SheetIndex( nOldSheet, pCopyData->GetIndex()),
789  SheetIndex( nNewSheet, pTmpData->GetIndex())));
790  }
791  }
792  }
793  }
794  }
795  }
796  return pRangeData;
797 }
798 
799 } // namespace
800 
801 bool ScDocument::CopyAdjustRangeName( SCTAB& rSheet, sal_uInt16& rIndex, ScRangeData*& rpRangeData,
802  ScDocument& rNewDoc, const ScAddress& rNewPos, const ScAddress& rOldPos, const bool bGlobalNamesToLocal,
803  const bool bUsedByFormula ) const
804 {
805  ScDocument* pThis = const_cast<ScDocument*>(this);
806  const bool bSameDoc = (rNewDoc.GetPool() == pThis->GetPool());
807  if (bSameDoc && ((rSheet < 0 && !bGlobalNamesToLocal) || (rSheet >= 0
808  && (rSheet != rOldPos.Tab() || (IsClipboard() && pThis->IsCutMode())))))
809  // Same doc and global name, if not copied to local name, or
810  // sheet-local name on other sheet stays the same. Sheet-local on
811  // same sheet also in a clipboard cut&paste / move operation.
812  return false;
813 
814  // Ensure we don't fiddle with the references until exit.
815  const SCTAB nOldSheet = rSheet;
816  const sal_uInt16 nOldIndex = rIndex;
817 
818  SAL_WARN_IF( !bSameDoc && nOldSheet >= 0 && nOldSheet != rOldPos.Tab(),
819  "sc.core", "adjustCopyRangeName - sheet-local name was on other sheet in other document");
820  /* TODO: can we do something about that? e.g. loop over sheets? */
821 
822  OUString aRangeName;
823  ScRangeData* pOldRangeData = nullptr;
824 
825  // XXX bGlobalNamesToLocal is also a synonym for copied sheet.
826  bool bInsertingBefore = (bGlobalNamesToLocal && bSameDoc && rNewPos.Tab() <= rOldPos.Tab());
827 
828  // The Tab where an old local name is to be found or that a global name
829  // references. May differ below from nOldSheet if a sheet was inserted
830  // before the old position. Global names and local names other than on the
831  // old sheet or new sheet are already updated, local names on the old sheet
832  // or inserted sheet will be updated later. Confusing stuff. Watch out.
833  SCTAB nOldTab = (nOldSheet < 0 ? rOldPos.Tab() : nOldSheet);
834  if (bInsertingBefore)
835  // Sheet was already inserted before old position.
836  ++nOldTab;
837 
838  // Search the name of the RangeName.
839  if (nOldSheet >= 0)
840  {
841  const ScRangeName* pNames = GetRangeName(nOldTab);
842  pOldRangeData = pNames ? pNames->findByIndex(nOldIndex) : nullptr;
843  if (!pOldRangeData)
844  return false; // might be an error in the formula array
845  aRangeName = pOldRangeData->GetUpperName();
846  }
847  else
848  {
849  pOldRangeData = GetRangeName()->findByIndex(nOldIndex);
850  if (!pOldRangeData)
851  return false; // might be an error in the formula array
852  aRangeName = pOldRangeData->GetUpperName();
853  }
854 
855  // Find corresponding range name in new document.
856  // First search for local range name then global range names.
857  SCTAB nNewSheet = rNewPos.Tab();
858  ScRangeName* pNewNames = rNewDoc.GetRangeName(nNewSheet);
859  // Search local range names.
860  if (pNewNames)
861  {
862  rpRangeData = pNewNames->findByUpperName(aRangeName);
863  }
864  // Search global range names.
865  if (!rpRangeData && !bGlobalNamesToLocal)
866  {
867  nNewSheet = -1;
868  pNewNames = rNewDoc.GetRangeName();
869  if (pNewNames)
870  rpRangeData = pNewNames->findByUpperName(aRangeName);
871  }
872  // If no range name was found copy it.
873  if (!rpRangeData)
874  {
875  // Do not copy global name if it doesn't reference sheet or is not used
876  // by a formula copied to another document.
877  bool bEarlyBailOut = (nOldSheet < 0 && (bSameDoc || !bUsedByFormula));
878  MightReferenceSheet eMightReference = mightRangeNameReferenceSheet( pOldRangeData, nOldTab);
879  if (bEarlyBailOut && eMightReference == MightReferenceSheet::NONE)
880  return false;
881 
882  if (eMightReference == MightReferenceSheet::NAME)
883  {
884  // Name these to clarify what is passed where.
885  const SCTAB nGlobalRefTab = nOldTab;
886  const SCTAB nLocalRefTab = (bInsertingBefore ? nOldTab-1 : nOldTab);
887  const SCTAB nOldTokenTab = (nOldSheet < 0 ? (bInsertingBefore ? nOldTab-1 : nOldTab) : nOldSheet);
888  const SCTAB nOldTokenTabReplacement = nOldTab;
889  sc::UpdatedRangeNames aReferencingNames;
890  FindRangeNamesReferencingSheet( aReferencingNames, nOldSheet, nOldIndex,
891  nGlobalRefTab, nLocalRefTab, nOldTokenTab, nOldTokenTabReplacement, bSameDoc, 0);
892  if (bEarlyBailOut && aReferencingNames.isEmpty(-1) && aReferencingNames.isEmpty(nOldTokenTabReplacement))
893  return false;
894 
895  SheetIndexMap aSheetIndexMap;
896  std::vector<ScRangeData*> aRangeDataVec;
897  if (!aReferencingNames.isEmpty(nOldTokenTabReplacement))
898  {
899  const SCTAB nTmpOldSheet = (nOldSheet < 0 ? nOldTab : nOldSheet);
900  nNewSheet = rNewPos.Tab();
901  rpRangeData = copyRangeNames( aSheetIndexMap, aRangeDataVec, aReferencingNames, nOldTab,
902  pOldRangeData, rNewDoc, *this, rNewPos, rOldPos,
903  bGlobalNamesToLocal, nTmpOldSheet, nNewSheet, bSameDoc);
904  }
905  if ((bGlobalNamesToLocal || !bSameDoc) && !aReferencingNames.isEmpty(-1))
906  {
907  const SCTAB nTmpOldSheet = -1;
908  const SCTAB nTmpNewSheet = (bGlobalNamesToLocal ? rNewPos.Tab() : -1);
909  ScRangeData* pTmpData = copyRangeNames( aSheetIndexMap, aRangeDataVec, aReferencingNames, -1,
910  pOldRangeData, rNewDoc, *this, rNewPos, rOldPos,
911  bGlobalNamesToLocal, nTmpOldSheet, nTmpNewSheet, bSameDoc);
912  if (!rpRangeData)
913  {
914  rpRangeData = pTmpData;
915  nNewSheet = nTmpNewSheet;
916  }
917  }
918 
919  // Adjust copied nested names to new sheet/index.
920  for (auto & iRD : aRangeDataVec)
921  {
922  ScTokenArray* pCode = iRD->GetCode();
923  if (pCode)
924  {
926  for (formula::FormulaToken* p = aIter.First(); p; p = aIter.Next())
927  {
928  if (p->GetOpCode() == ocName)
929  {
930  auto it = aSheetIndexMap.find( SheetIndex( p->GetSheet(), p->GetIndex()));
931  if (it != aSheetIndexMap.end())
932  {
933  p->SetSheet( it->second.mnSheet);
934  p->SetIndex( it->second.mnIndex);
935  }
936  else if (!bSameDoc)
937  {
938  SAL_WARN("sc.core","adjustCopyRangeName - mapping to new name in other doc missing");
939  p->SetIndex(0); // #NAME? error instead of arbitrary name.
940  }
941  }
942  }
943  }
944  }
945  }
946  else
947  {
948  nNewSheet = ((nOldSheet < 0 && !bGlobalNamesToLocal) ? -1 : rNewPos.Tab());
949  rpRangeData = copyRangeName( pOldRangeData, rNewDoc, *this, rNewPos, rOldPos, bGlobalNamesToLocal,
950  nOldSheet, nNewSheet, bSameDoc);
951  }
952 
953  if (rpRangeData && !rNewDoc.IsClipOrUndo())
954  {
955  ScDocShell* pDocSh = static_cast<ScDocShell*>(rNewDoc.GetDocumentShell());
956  if (pDocSh)
958  }
959  }
960 
961  rSheet = nNewSheet;
962  rIndex = rpRangeData ? rpRangeData->GetIndex() : 0; // 0 means not inserted
963  return true;
964 }
965 
967  sc::ColRowEditAction eAction, SCTAB nTab, SCCOLROW nStart, SCCOLROW nEnd ) const
968 {
969  const ScTable* pTab = FetchTable(nTab);
970  if (!pTab)
971  return false;
972 
973  return pTab->IsEditActionAllowed(eAction, nStart, nEnd);
974 }
975 
977  sc::ColRowEditAction eAction, const ScMarkData& rMark, SCCOLROW nStart, SCCOLROW nEnd ) const
978 {
979  return std::all_of(rMark.begin(), rMark.end(),
980  [this, &eAction, &nStart, &nEnd](const SCTAB& rTab) { return IsEditActionAllowed(eAction, rTab, nStart, nEnd); });
981 }
982 
983 std::optional<sc::ColumnIterator> ScDocument::GetColumnIterator( SCTAB nTab, SCCOL nCol, SCROW nRow1, SCROW nRow2 ) const
984 {
985  const ScTable* pTab = FetchTable(nTab);
986  if (!pTab)
987  return {};
988 
989  return pTab->GetColumnIterator(nCol, nRow1, nRow2);
990 }
991 
993 {
994  ScTable* pTab = FetchTable(nTab);
995  if (!pTab)
996  return;
997 
998  pTab->CreateColumnIfNotExists(nCol);
999 }
1000 
1001 bool ScDocument::EnsureFormulaCellResults( const ScRange& rRange, bool bSkipRunning )
1002 {
1003  bool bAnyDirty = false;
1004  for (SCTAB nTab = rRange.aStart.Tab(); nTab <= rRange.aEnd.Tab(); ++nTab)
1005  {
1006  ScTable* pTab = FetchTable(nTab);
1007  if (!pTab)
1008  continue;
1009 
1010  bool bRet = pTab->EnsureFormulaCellResults(
1011  rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row(), bSkipRunning);
1012  bAnyDirty = bAnyDirty || bRet;
1013  }
1014 
1015  return bAnyDirty;
1016 }
1017 
1019 {
1020  if (!mpDataMapper)
1021  mpDataMapper.reset(new sc::ExternalDataMapper(*this));
1022 
1023  return *mpDataMapper;
1024 }
1025 
1027 {
1028  const ScTable* pTab = FetchTable(nTab);
1029  if (!pTab)
1030  return;
1031 
1032  pTab->StoreToCache(rStrm);
1033 }
1034 
1036 {
1037  ScTable* pTab = FetchTable(nTab);
1038  if (!pTab)
1039  return;
1040 
1041  pTab->RestoreFromCache(rStrm);
1042 }
1043 
1044 OString ScDocument::dumpSheetGeomData(SCTAB nTab, bool bColumns, SheetGeomType eGeomType)
1045 {
1046  ScTable* pTab = FetchTable(nTab);
1047  if (!pTab)
1048  return "";
1049 
1050  return pTab->dumpSheetGeomData(bColumns, eGeomType);
1051 }
1052 
1054 {
1055  const ScTable* pTab = FetchTable(nTab);
1056  if (!pTab)
1057  return -1;
1058 
1059  return pTab->GetLOKFreezeCol();
1060 }
1062 {
1063  const ScTable* pTab = FetchTable(nTab);
1064  if (!pTab)
1065  return -1;
1066 
1067  return pTab->GetLOKFreezeRow();
1068 }
1069 
1071 {
1072  ScTable* pTab = FetchTable(nTab);
1073  if (!pTab)
1074  return false;
1075 
1076  return pTab->SetLOKFreezeCol(nFreezeCol);
1077 }
1078 
1080 {
1081  ScTable* pTab = FetchTable(nTab);
1082  if (!pTab)
1083  return false;
1084 
1085  return pTab->SetLOKFreezeRow(nFreezeRow);
1086 }
1087 
1089 {
1090  const ScTable* pTab = FetchTable(nTab);
1091  if (!pTab)
1092  return std::set<SCCOL>{};
1093 
1094  return pTab->QueryColumnsWithFormulaCells();
1095 }
1096 
1098 {
1099  const ScTable* pTab = FetchTable(nTab);
1100  if (!pTab)
1101  return;
1102 
1103  pTab->CheckIntegrity();
1104 }
1105 
1106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void AddDelayedFormulaGroupingCell(const ScFormulaCell *cell)
To be used only by SharedFormulaUtil::joinFormulaCells().
Definition: document10.cxx:395
void CheckIntegrity() const
Definition: table7.cxx:646
ScCalcConfig maCalcConfig
Definition: document.hxx:365
std::set< SCCOL > QueryColumnsWithFormulaCells() const
Definition: table7.cxx:633
SCROW mnRowDelta
Amount and direction of movement in the row direction.
ScAddress aStart
Definition: address.hxx:497
void TransferCellValuesTo(const SCCOL nCol, SCROW nRow, size_t nLen, sc::CellValues &rDest)
Definition: table7.cxx:189
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:42
std::optional< sc::ColumnIterator > GetColumnIterator(SCCOL nCol, SCROW nRow1, SCROW nRow2) const
Definition: table7.cxx:425
ocName
bool IsEnabledDelayStartListeningFormulaCells(ScColumn *column) const
Definition: document10.cxx:425
SCROW Row() const
Definition: address.hxx:274
SC_DLLPUBLIC ScRangeName * GetRangeName() const
Definition: documen3.cxx:176
void SetValues(const SCCOL nCol, const SCROW nRow, const std::vector< double > &rVals)
Definition: table7.cxx:181
void setSingleCell(const ScAddress &rSrcPos, const ScColumn &rSrcCol)
ScTable * FetchTable(SCTAB nTab)
Definition: document.cxx:2536
void RegroupFormulaCells(SCTAB nTab, SCCOL nCol)
Definition: document10.cxx:364
void UpdateScriptTypes(const SCCOL nCol1, SCROW nRow1, const SCCOL nCol2, SCROW nRow2)
Definition: table7.cxx:246
const OUString & GetUpperName() const
Definition: rangenam.hxx:112
ScColumn * FetchColumn(SCCOL nCol)
Definition: table2.cxx:1235
bool HasFormulaCell(const SCCOL nCol1, SCROW nRow1, const SCCOL nCol2, SCROW nRow2) const
Definition: table7.cxx:294
std::optional< sc::ColumnIterator > GetColumnIterator(SCTAB nTab, SCCOL nCol, SCROW nRow1, SCROW nRow2) const
Definition: document10.cxx:983
std::unique_ptr< sal_Int32[]> pData
Think of this as a mini-ScColumn like storage that only stores cell values in a column.
Definition: cellvalues.hxx:40
SCROW GetLOKFreezeRow(SCTAB nTab) const
sal_uInt16 GetIndex() const
Definition: rangenam.hxx:116
SC_DLLPUBLIC void CompileHybridFormula()
Call this immediately after updating named ranges.
Definition: document10.cxx:319
Context for reference update during shifting, moving or copying of cell ranges.
SC_DLLPUBLIC ScRangeName * GetRangeName(SCTAB nTab) const
Definition: documen3.cxx:168
constexpr::Color COL_AUTO(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
ScColumn & CreateColumnIfNotExists(const SCCOL nScCol)
Definition: table.hxx:289
MightReferenceSheet
Definition: document10.cxx:660
InsertDeleteFlags getInsertFlag() const
bool IsClipOrUndo() const
Definition: document.hxx:1587
void EndListeningIntersectedGroup(sc::EndListeningContext &rCxt, const ScAddress &rPos, std::vector< ScAddress > *pGroupPos)
Definition: document10.cxx:480
Stores cell values for multiple tables.
Definition: cellvalues.hxx:85
OString dumpSheetGeomData(SCTAB nTab, bool bColumns, SheetGeomType eGeomType)
Serializes the specified sheet's geometry data.
ScAddress aEnd
Definition: address.hxx:498
std::shared_ptr< T > make_shared(Args &&...args)
bool bDelayedDeletingBroadcasters
Definition: document.hxx:529
void ReadjustAbsolute3DReferences(const ScDocument &rOldDoc, ScDocument &rNewDoc, const ScAddress &rPos, bool bRangeName=false)
Make all absolute references external references pointing to the old document.
Definition: token.cxx:2544
void CompileHybridFormula(sc::StartListeningContext &rStartListenCxt, sc::CompileFormulaContext &rCompileCxt)
Definition: table7.cxx:239
void EndListeningGroups(const std::vector< ScAddress > &rPosArray)
Definition: document10.cxx:505
void RestoreFromCache(SvStream &rStrm)
Definition: table7.cxx:475
void PreprocessDBDataUpdate(sc::EndListeningContext &rEndListenCxt, sc::CompileFormulaContext &rCompileCxt)
Definition: table7.cxx:232
std::unordered_set< sal_uInt16 > NameIndicesType
void setUpdatedName(SCTAB nTab, sal_uInt16 nIndex)
SC_DLLPUBLIC ScDocumentPool * GetPool()
Definition: document.cxx:6156
NAME
bool IsEditActionAllowed(sc::ColRowEditAction eAction, SCCOLROW nStart, SCCOLROW nEnd) const
Definition: table7.cxx:344
SC_DLLPUBLIC ScPostIt * GetNote(const ScAddress &rPos)
Definition: document.cxx:6716
std::unordered_map< ScColumn *, std::pair< SCROW, SCROW > > pDelayedStartListeningFormulaCells
Definition: document.hxx:527
void StartListeningFormulaCells(sc::StartListeningContext &rStartCxt, sc::EndListeningContext &rEndCxt, SCROW nRow1, SCROW nRow2)
Definition: column4.cxx:1593
ScClipParam & GetClipParam()
Definition: document.cxx:2592
void UpdateReference(sc::RefUpdateContext &rCxt, ScDocument *pUndoDoc=nullptr, bool bIncludeDraw=true, bool bUpdateNoteCaptionPos=true)
Definition: documen3.cxx:1008
void finalizeOutlineImport()
Definition: table7.cxx:451
sal_Int32 SCCOLROW
a type capable of holding either SCCOL or SCROW
Definition: types.hxx:23
bool isEmpty(SCTAB nTab) const
bool CanDelayStartListeningFormulaCells(ScColumn *column, SCROW row1, SCROW row2)
If true is returned, ScColumn::StartListeningFormulaCells() for the given cells will be performed lat...
Definition: document10.cxx:430
SC_DLLPUBLIC void PreprocessAllRangeNamesUpdate(const std::map< OUString, std::unique_ptr< ScRangeName >> &rRangeMap)
Call this immediately before updating all named ranges.
Definition: document10.cxx:249
TableContainer maTabs
Definition: document.hxx:377
SC_DLLPUBLIC sc::ExternalDataMapper & GetExternalDataMapper()
void ConvertFormulaToValue(sc::EndListeningContext &rCxt, const SCCOL nCol1, const SCROW nRow1, const SCCOL nCol2, const SCROW nRow2, sc::TableValues *pUndo)
Definition: table7.cxx:205
void UpdateScriptTypes(const ScAddress &rPos, SCCOL nColSize, SCROW nRowSize)
Definition: document10.cxx:337
void PreprocessRangeNameUpdate(sc::EndListeningContext &rEndListenCxt, sc::CompileFormulaContext &rCompileCxt)
Definition: table7.cxx:225
SCTAB Tab() const
Definition: address.hxx:283
void EndListeningIntersectedGroups(sc::EndListeningContext &rCxt, const ScRange &rRange, std::vector< ScAddress > *pGroupPos)
Definition: document10.cxx:490
bool mbCutMode
Definition: clipparam.hxx:36
bool isNameUpdated(SCTAB nTab, sal_uInt16 nIndex) const
void CopyCellValuesFrom(const SCCOL nCol, SCROW nRow, const sc::CellValues &rSrc)
Definition: table7.cxx:197
void EndListeningIntersectedGroups(sc::EndListeningContext &rCxt, const SCCOL nCol1, SCROW nRow1, const SCCOL nCol2, SCROW nRow2, std::vector< ScAddress > *pGroupPos)
Definition: table7.cxx:317
bool HasUniformRowHeight(SCROW nRow1, SCROW nRow2) const
Definition: table7.cxx:257
ScAddress aPos
void GetName(OUString &rName) const
Definition: rangenam.hxx:110
void SetNeedsListeningGroup(SCCOL nCol, SCROW nRow)
Definition: table7.cxx:336
SC_DLLPUBLIC const ScPatternAttr * GetPattern(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: document.cxx:4799
void SetCol(SCCOL nColP)
Definition: address.hxx:291
UNKNOWN
SC_DLLPUBLIC bool CopyOneCellFromClip(sc::CopyFromClipContext &rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
Definition: document10.cxx:81
bool GetNoListening() const
Definition: document.hxx:2223
bool IsClipboard() const
Definition: document.hxx:1589
A pretty assertion that checks that the relevant bits in the are not set on the document at entry an...
Definition: document.hxx:2755
void AdjustAbsoluteRefs(const ScDocument &rOldDoc, const ScAddress &rOldPos, const ScAddress &rNewPos, bool bCheckCopyArea)
Make all absolute references pointing to the copied range if the range is copied too.
Definition: token.cxx:2596
void SwapNonEmpty(sc::TableValues &rValues)
Definition: document10.cxx:227
void SetTab(SCTAB nTabP)
Definition: address.hxx:295
SC_DLLPUBLIC ScRangeData * findByUpperName(const OUString &rName)
Definition: rangenam.cxx:704
void DelayFormulaGrouping(bool delay)
If set, joining cells into shared formula groups will be delayed until reset again (RegroupFormulaCel...
Definition: document10.cxx:380
Keep track of all named expressions that have been updated during reference update.
SC_DLLPUBLIC void GetRangeNameMap(std::map< OUString, ScRangeName * > &rRangeName)
Definition: documen3.cxx:146
int i
bool HasUniformRowHeight(SCTAB nTab, SCROW nRow1, SCROW nRow2) const
Definition: document10.cxx:346
UpdateRefMode meMode
update mode - insert/delete, copy, or move.
bool ReferencesSheet(SCTAB nTab, SCTAB nPosTab) const
Returns true if the sheet nTab is referenced in code.
Definition: token.cxx:2692
void IncCol(SCCOL nDelta=1)
Definition: address.hxx:316
void setSingleCellNote(size_t nColOffset, const ScPostIt *pNote)
SC_DLLPUBLIC void RestoreTabFromCache(SCTAB nTab, SvStream &rStream)
sal_Int16 SCCOL
Definition: types.hxx:21
std::unique_ptr< sc::ExternalDataMapper > mpDataMapper
Definition: document.hxx:402
void UnshareFormulaCells(SCCOL nCol, std::vector< SCROW > &rRows)
Definition: table7.cxx:278
void EnableDelayDeletingBroadcasters(bool set)
If set, cells will not delete their empty broadcasters, avoiding possible extensive mdds vector chang...
Definition: document10.cxx:449
CAUTION! The following defines must be in the same namespace as the respective type.
sc::MultiDataCellState HasMultipleDataCells(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const
Definition: table7.cxx:35
void DeleteBeforeCopyFromClip(sc::CopyFromClipContext &rCxt, const ScMarkData &rMark, sc::ColumnSpanSet &rBroadcastSpans)
Definition: document10.cxx:56
void SharePooledResources(const ScDocument *pSrcDoc)
Definition: document10.cxx:330
Structure that stores segments of boolean flags per column, and perform custom action on those segmen...
bool IsCutMode()
Definition: document.cxx:2052
void CopyCellValuesFrom(const ScAddress &rTopPos, const sc::CellValues &rSrc)
Definition: document10.cxx:176
const ScRange & getRange() const
Definition: cellvalues.cxx:317
void CreateColumnIfNotExists(SCTAB nTab, SCCOL nCol)
Definition: document10.cxx:992
void StartListeningFormulaCells(sc::StartListeningContext &rStartCxt, sc::EndListeningContext &rEndCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
Definition: table2.cxx:1298
exports com.sun.star.awt. tab
void UpdateScriptTypes(SCROW nRow1, SCROW nRow2)
Definition: column4.cxx:1193
SC_DLLPUBLIC ScRangeData * findByIndex(sal_uInt16 i) const
Definition: rangenam.cxx:716
void SetAreasChangedNeedBroadcast()
Definition: docsh.hxx:389
bool IsValid() const
Definition: address.hxx:544
SC_DLLPUBLIC void StoreTabToCache(SCTAB nTab, SvStream &rStrm) const
ScRange maRange
Range of cells that are about to be moved for insert/delete/move modes.
const_iterator end() const
Definition: markdata.hxx:164
void CheckIntegrity(SCTAB nTab) const
Check the integrity of the internal table state.
void setSingleCellPattern(size_t nColOffset, const ScPatternAttr *pAttr)
SCCOL Col() const
Definition: address.hxx:279
SheetGeomType
Represents the type of sheet geometry data.
Definition: document.hxx:275
void EndListeningGroup(sc::EndListeningContext &rCxt, const SCCOL nCol, SCROW nRow)
Definition: table7.cxx:328
Internal use only (undo etc.): do not copy/delete caption objects of cell notes.
bool IsEditActionAllowed(sc::ColRowEditAction eAction, SCTAB nTab, SCCOLROW nStart, SCCOLROW nEnd) const
Definition: document10.cxx:966
Configuration options for formula interpreter.
Definition: calcconfig.hxx:43
SCROW GetLOKFreezeRow() const
Definition: table7.cxx:594
SC_DLLPUBLIC std::shared_ptr< sc::Sparkline > GetSparkline(ScAddress const &rPosition)
Returns sparkline at the address if it exists.
Definition: document.cxx:6611
bool SetLOKFreezeCol(SCCOL nFreezeCol)
Definition: table7.cxx:599
NameIndicesType getUpdatedNames(SCTAB nTab) const
constexpr TypedWhichId< SvxBrushItem > ATTR_BACKGROUND(148)
void finalizeOutlineImport()
Definition: document10.cxx:585
SC_DLLPUBLIC bool EnsureFormulaCellResults(const ScRange &rRange, bool bSkipRunning=false)
Make sure all of the formula cells in the specified range have been fully calculated.
void SetNeedsListeningGroups(const std::vector< ScAddress > &rPosArray)
Definition: document10.cxx:520
sal_Int32 SCROW
Definition: types.hxx:17
ScRange getWholeRange() const
Return a single range that encompasses all individual ranges.
Definition: clipparam.cxx:109
bool operator<(const ScDPCollection::DBType &left, const ScDPCollection::DBType &right)
Definition: dpobject.cxx:3931
void SetIndex(sal_uInt16 nInd)
Definition: rangenam.hxx:115
void setSingleSparkline(size_t nColOffset, std::shared_ptr< sc::Sparkline > const &pSparkline)
void AdjustSheetLocalNameReferences(SCTAB nOldTab, SCTAB nNewTab)
When copying a sheet-local named expression, move sheet references that point to the originating shee...
Definition: token.cxx:2644
ColRowEditAction
Definition: global.hxx:424
SCCOL GetLOKFreezeCol(SCTAB nTab) const
const ScAddress & GetPos() const
Definition: rangenam.hxx:113
bool HasFormulaCell(const ScRange &rRange) const
Check if there is at least one formula cell in specified range.
Definition: document10.cxx:462
#define SAL_WARN_IF(condition, area, stream)
std::unique_ptr< ScTable, o3tl::default_delete< ScTable > > ScTableUniquePtr
Definition: document.hxx:319
SCTAB mnTabDelta
Amount and direction of movement in the sheet direction.
void UnshareFormulaCells(SCTAB nTab, SCCOL nCol, std::vector< SCROW > &rRows)
Make specified formula cells non-grouped.
Definition: document10.cxx:355
bool SetLOKFreezeRow(SCROW nFreezeRow, SCTAB nTab)
void EnableDelayStartListeningFormulaCells(ScColumn *column, bool delay)
If set, ScColumn::StartListeningFormulaCells() calls may be delayed using CanDelayStartListeningFormu...
Definition: document10.cxx:401
void SetNewName(const OUString &rNewName)
Does not change the name, but sets maNewName for formula update after dialog.
Definition: rangenam.hxx:118
std::set< Color > GetDocColors()
Definition: document10.cxx:185
FormulaToken ** GetCode() const
SCTAB getTabEnd() const
Definition: clipcontext.cxx:68
Item2Range GetItemSurrogates(sal_uInt16 nWhich) const
ScDocument * getUndoDoc()
Definition: clipcontext.cxx:91
SCTAB getTabStart() const
Definition: clipcontext.cxx:63
ScDocument * getClipDoc()
Definition: clipcontext.cxx:96
void * p
const_iterator begin() const
Definition: markdata.hxx:163
SC_DLLPUBLIC void PreprocessDBDataUpdate()
Definition: document10.cxx:307
bool IsMerged(const ScAddress &rPos) const
Definition: document10.cxx:32
std::vector< ScTableUniquePtr > TableContainer
Definition: document.hxx:346
bool SetLOKFreezeRow(SCROW nFreezeRow)
Definition: table7.cxx:616
void StartNeededListeners()
Definition: document10.cxx:554
std::shared_ptr< svl::SharedStringPool > mpCellStringPool
Definition: document.hxx:359
bool EnsureFormulaCellResults(const SCCOL nCol1, SCROW nRow1, const SCCOL nCol2, SCROW nRow2, bool bSkipRunning=false)
Definition: table7.cxx:433
void setSingleCellColumnSize(size_t nSize)
Set the column size of a "single cell" row, which is used when copying a single row of cells in a cli...
void RegroupFormulaCells(SCCOL nCol)
Definition: table7.cxx:286
rtl::Reference< ScPoolHelper > mxPoolHelper
Definition: document.hxx:357
void ConvertFormulaToValue(const ScRange &rRange, sc::TableValues *pUndo)
Definition: document10.cxx:209
SfxObjectShell * GetDocumentShell() const
Definition: document.hxx:1080
#define SAL_WARN(area, stream)
void StartAllListeners()
Definition: documen7.cxx:588
bool GetTableSelect(SCTAB nTab) const
Definition: markdata.cxx:169
void DeleteBeforeCopyFromClip(sc::CopyFromClipContext &rCxt, const ScTable &rClipTab, sc::ColumnSpanSet &rBroadcastSpans)
Definition: table7.cxx:98
bool CopyAdjustRangeName(SCTAB &rSheet, sal_uInt16 &rIndex, ScRangeData *&rpRangeData, ScDocument &rNewDoc, const ScAddress &rNewPos, const ScAddress &rOldPos, const bool bGlobalNamesToLocal, const bool bUsedByFormula) const
If necessary (name references sheet rOldPos.Tab()) copy and adjust named expression/range from sheet-...
Definition: document10.cxx:801
int mnIndex
void EndListeningIntersectedGroup(sc::EndListeningContext &rCxt, SCCOL nCol, SCROW nRow, std::vector< ScAddress > *pGroupPos)
Definition: table7.cxx:308
std::set< SCCOL > QueryColumnsWithFormulaCells(SCTAB nTab) const
ScRangeData * FindRangeNameBySheetAndIndex(SCTAB nTab, sal_uInt16 nIndex) const
Find a named expression / range name in either global or a local scope.
Definition: documen3.cxx:269
SCCOL mnColDelta
Amount and direction of movement in the column direction.
void SwapNonEmpty(sc::TableValues &rValues, sc::StartListeningContext &rStartCxt, sc::EndListeningContext &rEndCxt)
Definition: table7.cxx:216
void StoreToCache(SvStream &rStrm) const
Definition: table7.cxx:459
constexpr TypedWhichId< SvxColorItem > ATTR_FONT_COLOR(109)
bool SetLOKFreezeCol(SCCOL nFreezeCol, SCTAB nTab)
SC_DLLPUBLIC void SetCalcConfig(const ScCalcConfig &rConfig)
Definition: document10.cxx:203
SCCOL GetLOKFreezeCol() const
Definition: table7.cxx:589
void SetValues(const ScAddress &rPos, const std::vector< double > &rVals)
Definition: document10.cxx:158
ScTokenArray * GetCode()
Definition: rangenam.hxx:119
std::unique_ptr< ScRange > pDelayedFormulaGrouping
Definition: document.hxx:523
SC_DLLPUBLIC bool insert(ScRangeData *p, bool bReuseFreeIndex=true)
Insert object into set.
Definition: rangenam.cxx:802
Strings (and string results if InsertDeleteFlags::FORMULA is not set).
bool IsMerged(SCCOL nCol, SCROW nRow) const
Definition: table7.cxx:27
const Color & GetValue() const
SC_DLLPUBLIC void PreprocessRangeNameUpdate()
Definition: document10.cxx:295
sal_Int16 SCTAB
Definition: types.hxx:22
sc::MultiDataCellState HasMultipleDataCells(const ScRange &rRange) const
Check if the specified range contains either: 1) one non-empty cell, 2) more than one non-empty cells...
Definition: document10.cxx:41
bool FindRangeNamesReferencingSheet(sc::UpdatedRangeNames &rIndexes, SCTAB nTokenTab, const sal_uInt16 nTokenIndex, SCTAB nGlobalRefTab, SCTAB nLocalRefTab, SCTAB nOldTokenTab, SCTAB nOldTokenTabReplacement, bool bSameDoc, int nRecursion) const
Recursively find all named expressions that directly or indirectly (nested) reference a given sheet...
Definition: document10.cxx:594
OString dumpSheetGeomData(bool bColumns, SheetGeomType eGeomType)
Serializes the sheet's geometry data.
Definition: table7.cxx:485
void TransferCellValuesTo(const ScAddress &rTopPos, size_t nLen, sc::CellValues &rDest)
Transfer a series of contiguous cell values from specified position to the passed container...
Definition: document10.cxx:167
Sheet / outlining (grouping) information.