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 
128  ScColumn& rSrcCol = pSrcTab->aCol[aSrcPos.Col()];
129  // Determine the script type of the copied single cell.
130  rSrcCol.UpdateScriptTypes(aSrcPos.Row(), aSrcPos.Row());
131  rCxt.setSingleCell(aSrcPos, rSrcCol);
132  }
133 
134  // All good. Proceed with the pasting.
135 
136  SCTAB nTabEnd = rCxt.getTabEnd();
137  for (SCTAB i = rCxt.getTabStart(); i <= nTabEnd && i < static_cast<SCTAB>(maTabs.size()); ++i)
138  {
139  maTabs[i]->CopyOneCellFromClip(rCxt, nCol1, nRow1, nCol2, nRow2, aClipRange.aStart.Row(), pSrcTab);
140  }
141 
142  sc::RefUpdateContext aRefCxt(*this);
143  aRefCxt.maRange = ScRange(nCol1, nRow1, rCxt.getTabStart(), nCol2, nRow2, nTabEnd);
144  aRefCxt.mnColDelta = nCol1 - aSrcPos.Col();
145  aRefCxt.mnRowDelta = nRow1 - aSrcPos.Row();
146  aRefCxt.mnTabDelta = rCxt.getTabStart() - aSrcPos.Tab();
147  // Only Copy&Paste, for Cut&Paste we already bailed out early.
148  aRefCxt.meMode = URM_COPY;
149  UpdateReference(aRefCxt, rCxt.getUndoDoc(), false);
150 
151  return true;
152 }
153 
154 void ScDocument::SetValues( const ScAddress& rPos, const std::vector<double>& rVals )
155 {
156  ScTable* pTab = FetchTable(rPos.Tab());
157  if (!pTab)
158  return;
159 
160  pTab->SetValues(rPos.Col(), rPos.Row(), rVals);
161 }
162 
163 void ScDocument::TransferCellValuesTo( const ScAddress& rTopPos, size_t nLen, sc::CellValues& rDest )
164 {
165  ScTable* pTab = FetchTable(rTopPos.Tab());
166  if (!pTab)
167  return;
168 
169  pTab->TransferCellValuesTo(rTopPos.Col(), rTopPos.Row(), nLen, rDest);
170 }
171 
172 void ScDocument::CopyCellValuesFrom( const ScAddress& rTopPos, const sc::CellValues& rSrc )
173 {
174  ScTable* pTab = FetchTable(rTopPos.Tab());
175  if (!pTab)
176  return;
177 
178  pTab->CopyCellValuesFrom(rTopPos.Col(), rTopPos.Row(), rSrc);
179 }
180 
181 std::set<Color> ScDocument::GetDocColors()
182 {
183  std::set<Color> aDocColors;
184  ScDocumentPool *pPool = GetPool();
185  const sal_uInt16 pAttribs[] = {ATTR_BACKGROUND, ATTR_FONT_COLOR};
186  for (sal_uInt16 nAttrib : pAttribs)
187  {
188  for (const SfxPoolItem* pItem : pPool->GetItemSurrogates(nAttrib))
189  {
190  const SvxColorItem *pColorItem = static_cast<const SvxColorItem*>(pItem);
191  Color aColor( pColorItem->GetValue() );
192  if (COL_AUTO != aColor)
193  aDocColors.insert(aColor);
194  }
195  }
196  return aDocColors;
197 }
198 
200 {
202  maCalcConfig = rConfig;
203 }
204 
206 {
207  sc::EndListeningContext aCxt(*this);
208 
209  for (SCTAB nTab = rRange.aStart.Tab(); nTab <= rRange.aEnd.Tab(); ++nTab)
210  {
211  ScTable* pTab = FetchTable(nTab);
212  if (!pTab)
213  continue;
214 
215  pTab->ConvertFormulaToValue(
216  aCxt, rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row(),
217  pUndo);
218  }
219 
220  aCxt.purgeEmptyBroadcasters();
221 }
222 
224 {
225  const ScRange& rRange = rValues.getRange();
226  if (!rRange.IsValid())
227  return;
228 
229  auto pPosSet = std::make_shared<sc::ColumnBlockPositionSet>(*this);
230  sc::StartListeningContext aStartCxt(*this, pPosSet);
231  sc::EndListeningContext aEndCxt(*this, pPosSet);
232 
233  for (SCTAB nTab = rRange.aStart.Tab(); nTab <= rRange.aEnd.Tab(); ++nTab)
234  {
235  ScTable* pTab = FetchTable(nTab);
236  if (!pTab)
237  continue;
238 
239  pTab->SwapNonEmpty(rValues, aStartCxt, aEndCxt);
240  }
241 
242  aEndCxt.purgeEmptyBroadcasters();
243 }
244 
245 void ScDocument::PreprocessAllRangeNamesUpdate( const std::map<OUString, std::unique_ptr<ScRangeName>>& rRangeMap )
246 {
247  // Update all existing names with new names.
248  // The prerequisites are that the name dialog preserves ScRangeData index
249  // for changes and does not reuse free index slots for new names.
250  // ScDocument::SetAllRangeNames() hereafter then will replace the
251  // ScRangeName containers of ScRangeData instances with empty
252  // ScRangeData::maNewName.
253  std::map<OUString, ScRangeName*> aRangeNameMap;
254  GetRangeNameMap( aRangeNameMap);
255  for (const auto& itTab : aRangeNameMap)
256  {
257  ScRangeName* pOldRangeNames = itTab.second;
258  if (!pOldRangeNames)
259  continue;
260 
261  const auto& itNewTab( rRangeMap.find( itTab.first));
262  if (itNewTab == rRangeMap.end())
263  continue;
264 
265  const ScRangeName* pNewRangeNames = itNewTab->second.get();
266  if (!pNewRangeNames)
267  continue;
268 
269  for (const auto& rEntry : *pOldRangeNames)
270  {
271  ScRangeData* pOldData = rEntry.second.get();
272  if (!pOldData)
273  continue;
274 
275  const ScRangeData* pNewData = pNewRangeNames->findByIndex( pOldData->GetIndex());
276  if (pNewData)
277  pOldData->SetNewName( pNewData->GetName());
278  }
279  }
280 
281  sc::EndListeningContext aEndListenCxt(*this);
282  sc::CompileFormulaContext aCompileCxt(*this);
283 
284  for (const auto& rxTab : maTabs)
285  {
286  ScTable* p = rxTab.get();
287  p->PreprocessRangeNameUpdate(aEndListenCxt, aCompileCxt);
288  }
289 }
290 
292 {
293  sc::EndListeningContext aEndListenCxt(*this);
294  sc::CompileFormulaContext aCompileCxt(*this);
295 
296  for (const auto& rxTab : maTabs)
297  {
298  ScTable* p = rxTab.get();
299  p->PreprocessRangeNameUpdate(aEndListenCxt, aCompileCxt);
300  }
301 }
302 
304 {
305  sc::EndListeningContext aEndListenCxt(*this);
306  sc::CompileFormulaContext aCompileCxt(*this);
307 
308  for (const auto& rxTab : maTabs)
309  {
310  ScTable* p = rxTab.get();
311  p->PreprocessDBDataUpdate(aEndListenCxt, aCompileCxt);
312  }
313 }
314 
316 {
317  sc::StartListeningContext aStartListenCxt(*this);
318  sc::CompileFormulaContext aCompileCxt(*this);
319  for (const auto& rxTab : maTabs)
320  {
321  ScTable* p = rxTab.get();
322  p->CompileHybridFormula(aStartListenCxt, aCompileCxt);
323  }
324 }
325 
327 {
329  mxPoolHelper = pSrcDoc->mxPoolHelper;
331 }
332 
333 void ScDocument::UpdateScriptTypes( const ScAddress& rPos, SCCOL nColSize, SCROW nRowSize )
334 {
335  ScTable* pTab = FetchTable(rPos.Tab());
336  if (!pTab)
337  return;
338 
339  pTab->UpdateScriptTypes(rPos.Col(), rPos.Row(), rPos.Col()+nColSize-1, rPos.Row()+nRowSize-1);
340 }
341 
342 bool ScDocument::HasUniformRowHeight( SCTAB nTab, SCROW nRow1, SCROW nRow2 ) const
343 {
344  const ScTable* pTab = FetchTable(nTab);
345  if (!pTab)
346  return false;
347 
348  return pTab->HasUniformRowHeight(nRow1, nRow2);
349 }
350 
351 void ScDocument::UnshareFormulaCells( SCTAB nTab, SCCOL nCol, std::vector<SCROW>& rRows )
352 {
353  ScTable* pTab = FetchTable(nTab);
354  if (!pTab)
355  return;
356 
357  pTab->UnshareFormulaCells(nCol, rRows);
358 }
359 
361 {
362  ScTable* pTab = FetchTable(nTab);
363  if (!pTab)
364  return;
365 
366  pTab->RegroupFormulaCells(nCol);
367 }
368 
370 {
371  for( SCTAB tab = rRange.aStart.Tab(); tab <= rRange.aEnd.Tab(); ++tab )
372  for( SCCOL col = rRange.aStart.Col(); col <= rRange.aEnd.Col(); ++col )
373  RegroupFormulaCells( tab, col );
374 }
375 
377 {
378  if( delay )
379  {
382  }
383  else
384  {
387  pDelayedFormulaGrouping.reset();
388  }
389 }
390 
392 {
393  if( !pDelayedFormulaGrouping->In( cell->aPos ))
394  pDelayedFormulaGrouping->ExtendTo( cell->aPos );
395 }
396 
398 {
399  if( delay )
400  {
402  pDelayedStartListeningFormulaCells[ column ] = std::pair<SCROW, SCROW>( -1, -1 );
403  }
404  else
405  {
406  auto it = pDelayedStartListeningFormulaCells.find( column );
407  if( it != pDelayedStartListeningFormulaCells.end())
408  {
409  if( it->second.first != -1 )
410  {
411  auto pPosSet = std::make_shared<sc::ColumnBlockPositionSet>(*this);
412  sc::StartListeningContext aStartCxt(*this, pPosSet);
413  sc::EndListeningContext aEndCxt(*this, pPosSet);
414  column->StartListeningFormulaCells(aStartCxt, aEndCxt, it->second.first, it->second.second);
415  }
417  }
418  }
419 }
420 
422 {
424 }
425 
427 {
428  auto it = pDelayedStartListeningFormulaCells.find( column );
429  if( it == pDelayedStartListeningFormulaCells.end())
430  return false; // not enabled
431  if( it->second.first == -1 && it->second.second == -1 ) // uninitialized
432  pDelayedStartListeningFormulaCells[ column ] = std::make_pair( row1, row2 );
433  else
434  {
435  if( row1 > it->second.second + 1 || row2 < it->second.first - 1 )
436  { // two non-adjacent ranges, just bail out
437  return false;
438  }
439  it->second.first = std::min( it->second.first, row1 );
440  it->second.second = std::max( it->second.second, row2 );
441  }
442  return true;
443 }
444 
445 bool ScDocument::HasFormulaCell( const ScRange& rRange ) const
446 {
447  if (!rRange.IsValid())
448  return false;
449 
450  for (SCTAB nTab = rRange.aStart.Tab(); nTab <= rRange.aEnd.Tab(); ++nTab)
451  {
452  const ScTable* pTab = FetchTable(nTab);
453  if (!pTab)
454  continue;
455 
456  if (pTab->HasFormulaCell(rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row()))
457  return true;
458  }
459 
460  return false;
461 }
462 
464  sc::EndListeningContext& rCxt, const ScAddress& rPos, std::vector<ScAddress>* pGroupPos )
465 {
466  ScTable* pTab = FetchTable(rPos.Tab());
467  if (!pTab)
468  return;
469 
470  pTab->EndListeningIntersectedGroup(rCxt, rPos.Col(), rPos.Row(), pGroupPos);
471 }
472 
474  sc::EndListeningContext& rCxt, const ScRange& rRange, std::vector<ScAddress>* pGroupPos )
475 {
476  for (SCTAB nTab = rRange.aStart.Tab(); nTab <= rRange.aEnd.Tab(); ++nTab)
477  {
478  ScTable* pTab = FetchTable(nTab);
479  if (!pTab)
480  continue;
481 
483  rCxt, rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row(),
484  pGroupPos);
485  }
486 }
487 
488 void ScDocument::EndListeningGroups( const std::vector<ScAddress>& rPosArray )
489 {
490  sc::EndListeningContext aCxt(*this);
491  for (const ScAddress& rPos : rPosArray)
492  {
493  ScTable* pTab = FetchTable(rPos.Tab());
494  if (!pTab)
495  return;
496 
497  pTab->EndListeningGroup(aCxt, rPos.Col(), rPos.Row());
498  }
499 
500  aCxt.purgeEmptyBroadcasters();
501 }
502 
503 void ScDocument::SetNeedsListeningGroups( const std::vector<ScAddress>& rPosArray )
504 {
505  for (const ScAddress& rPos : rPosArray)
506  {
507  ScTable* pTab = FetchTable(rPos.Tab());
508  if (!pTab)
509  return;
510 
511  pTab->SetNeedsListeningGroup(rPos.Col(), rPos.Row());
512  }
513 }
514 
515 namespace {
516 
517 class StartNeededListenersHandler
518 {
519  std::shared_ptr<sc::StartListeningContext> mpCxt;
520 public:
521  explicit StartNeededListenersHandler( ScDocument& rDoc ) : mpCxt(std::make_shared<sc::StartListeningContext>(rDoc)) {}
522  explicit StartNeededListenersHandler( ScDocument& rDoc, const std::shared_ptr<const sc::ColumnSet>& rpColSet ) :
523  mpCxt(std::make_shared<sc::StartListeningContext>(rDoc))
524  {
525  mpCxt->setColumnSet( rpColSet);
526  }
527 
528  void operator() (const ScTableUniquePtr & p)
529  {
530  if (p)
531  p->StartListeners(*mpCxt, false);
532  }
533 };
534 
535 }
536 
538 {
539  std::for_each(maTabs.begin(), maTabs.end(), StartNeededListenersHandler(*this));
540 }
541 
542 void ScDocument::StartNeededListeners( const std::shared_ptr<const sc::ColumnSet>& rpColSet )
543 {
544  std::for_each(maTabs.begin(), maTabs.end(), StartNeededListenersHandler(*this, rpColSet));
545 }
546 
548 {
549  if (IsClipOrUndo() || GetNoListening())
550  return;
551 
552  auto pPosSet = std::make_shared<sc::ColumnBlockPositionSet>(*this);
553  sc::StartListeningContext aStartCxt(*this, pPosSet);
554  sc::EndListeningContext aEndCxt(*this, pPosSet);
555 
556  for (SCTAB nTab = rRange.aStart.Tab(); nTab <= rRange.aEnd.Tab(); ++nTab)
557  {
558  ScTable* pTab = FetchTable(nTab);
559  if (!pTab)
560  continue;
561 
563  aStartCxt, aEndCxt,
564  rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row());
565  }
566 }
567 
569 {
570  for (const auto& rxTab : maTabs)
571  {
572  ScTable* p = rxTab.get();
574  }
575 }
576 
578  SCTAB nTokenTab, const sal_uInt16 nTokenIndex,
579  SCTAB nGlobalRefTab, SCTAB nLocalRefTab, SCTAB nOldTokenTab, SCTAB nOldTokenTabReplacement,
580  bool bSameDoc, int nRecursion) const
581 {
582  if (nTokenTab < -1)
583  {
584  SAL_WARN("sc.core", "ScDocument::FindRangeNamesReferencingSheet - nTokenTab < -1 : " <<
585  nTokenTab << ", nTokenIndex " << nTokenIndex << " Fix the creator!");
586 #if OSL_DEBUG_LEVEL > 0
587  const ScRangeData* pData = FindRangeNameBySheetAndIndex( nTokenTab, nTokenIndex);
588  SAL_WARN_IF( pData, "sc.core", "ScDocument::FindRangeNamesReferencingSheet - named expression is: " << pData->GetName());
589 #endif
590  nTokenTab = -1;
591  }
592  SCTAB nRefTab = nGlobalRefTab;
593  if (nTokenTab == nOldTokenTab)
594  {
595  nTokenTab = nOldTokenTabReplacement;
596  nRefTab = nLocalRefTab;
597  }
598  else if (nTokenTab == nOldTokenTabReplacement)
599  {
600  nRefTab = nLocalRefTab;
601  }
602 
603  if (rIndexes.isNameUpdated( nTokenTab, nTokenIndex))
604  return true;
605 
606  ScRangeData* pData = FindRangeNameBySheetAndIndex( nTokenTab, nTokenIndex);
607  if (!pData)
608  return false;
609 
610  ScTokenArray* pCode = pData->GetCode();
611  if (!pCode)
612  return false;
613 
614  bool bRef = !bSameDoc; // include every name used when copying to other doc
615  if (nRecursion < 126) // whatever... 42*3
616  {
618  for (const formula::FormulaToken* p = aIter.First(); p; p = aIter.Next())
619  {
620  if (p->GetOpCode() == ocName)
621  {
622  bRef |= FindRangeNamesReferencingSheet( rIndexes, p->GetSheet(), p->GetIndex(),
623  nGlobalRefTab, nLocalRefTab, nOldTokenTab, nOldTokenTabReplacement, bSameDoc, nRecursion+1);
624  }
625  }
626  }
627 
628  if (!bRef)
629  {
630  SCTAB nPosTab = pData->GetPos().Tab();
631  if (nPosTab == nOldTokenTab)
632  nPosTab = nOldTokenTabReplacement;
633  bRef = pCode->ReferencesSheet( nRefTab, nPosTab);
634  }
635  if (bRef)
636  rIndexes.setUpdatedName( nTokenTab, nTokenIndex);
637 
638  return bRef;
639 }
640 
641 namespace {
642 
644 {
645  UNKNOWN,
646  NONE,
647  CODE,
648  NAME
649 };
650 
651 MightReferenceSheet mightRangeNameReferenceSheet( ScRangeData* pData, SCTAB nRefTab)
652 {
653  ScTokenArray* pCode = pData->GetCode();
654  if (!pCode)
656 
658  for (const formula::FormulaToken* p = aIter.First(); p; p = aIter.Next())
659  {
660  if (p->GetOpCode() == ocName)
661  return MightReferenceSheet::NAME;
662  }
663 
664  return pCode->ReferencesSheet( nRefTab, pData->GetPos().Tab()) ?
665  MightReferenceSheet::CODE : MightReferenceSheet::NONE;
666 }
667 
668 ScRangeData* copyRangeName( const ScRangeData* pOldRangeData, ScDocument& rNewDoc, const ScDocument& rOldDoc,
669  const ScAddress& rNewPos, const ScAddress& rOldPos, bool bGlobalNamesToLocal,
670  SCTAB nOldSheet, const SCTAB nNewSheet, bool bSameDoc)
671 {
672  ScAddress aRangePos( pOldRangeData->GetPos());
673  if (nNewSheet >= 0)
674  aRangePos.SetTab( nNewSheet);
675  ScRangeData* pRangeData = new ScRangeData(*pOldRangeData, &rNewDoc, &aRangePos);
676  pRangeData->SetIndex(0); // needed for insert to assign a new index
677  ScTokenArray* pRangeNameToken = pRangeData->GetCode();
678  if (bSameDoc && nNewSheet >= 0)
679  {
680  if (bGlobalNamesToLocal && nOldSheet < 0)
681  {
682  nOldSheet = rOldPos.Tab();
683  if (rNewPos.Tab() <= nOldSheet)
684  // Sheet was inserted before and references already updated.
685  ++nOldSheet;
686  }
687  pRangeNameToken->AdjustSheetLocalNameReferences( nOldSheet, nNewSheet);
688  }
689  if (!bSameDoc)
690  {
691  pRangeNameToken->ReadjustAbsolute3DReferences(rOldDoc, rNewDoc, pRangeData->GetPos(), true);
692  pRangeNameToken->AdjustAbsoluteRefs(rOldDoc, rOldPos, rNewPos, true);
693  }
694 
695  bool bInserted;
696  if (nNewSheet < 0)
697  bInserted = rNewDoc.GetRangeName()->insert(pRangeData);
698  else
699  bInserted = rNewDoc.GetRangeName(nNewSheet)->insert(pRangeData);
700 
701  return bInserted ? pRangeData : nullptr;
702 }
703 
704 struct SheetIndex
705 {
706  SCTAB mnSheet;
707  sal_uInt16 mnIndex;
708 
709  SheetIndex( SCTAB nSheet, sal_uInt16 nIndex ) : mnSheet(nSheet < -1 ? -1 : nSheet), mnIndex(nIndex) {}
710  bool operator<( const SheetIndex& r ) const
711  {
712  // Ascending order sheet, index
713  if (mnSheet < r.mnSheet)
714  return true;
715  if (mnSheet == r.mnSheet)
716  return mnIndex < r.mnIndex;
717  return false;
718  }
719 };
720 typedef std::map< SheetIndex, SheetIndex > SheetIndexMap;
721 
722 ScRangeData* copyRangeNames( SheetIndexMap& rSheetIndexMap, std::vector<ScRangeData*>& rRangeDataVec,
723  const sc::UpdatedRangeNames& rReferencingNames, SCTAB nTab,
724  const ScRangeData* pOldRangeData, ScDocument& rNewDoc, const ScDocument& rOldDoc,
725  const ScAddress& rNewPos, const ScAddress& rOldPos, bool bGlobalNamesToLocal,
726  const SCTAB nOldSheet, const SCTAB nNewSheet, bool bSameDoc)
727 {
728  ScRangeData* pRangeData = nullptr;
729  const ScRangeName* pOldRangeName = (nTab < 0 ? rOldDoc.GetRangeName() : rOldDoc.GetRangeName(nTab));
730  if (pOldRangeName)
731  {
732  const ScRangeName* pNewRangeName = (nNewSheet < 0 ? rNewDoc.GetRangeName() : rNewDoc.GetRangeName(nNewSheet));
733  sc::UpdatedRangeNames::NameIndicesType aSet( rReferencingNames.getUpdatedNames(nTab));
734  for (auto const & rIndex : aSet)
735  {
736  const ScRangeData* pCopyData = pOldRangeName->findByIndex(rIndex);
737  if (pCopyData)
738  {
739  // Match the original pOldRangeData to adapt the current
740  // token's values later. For that no check for an already
741  // copied name is needed as we only enter here if there was
742  // none.
743  if (pCopyData == pOldRangeData)
744  {
745  pRangeData = copyRangeName( pCopyData, rNewDoc, rOldDoc, rNewPos, rOldPos,
746  bGlobalNamesToLocal, nOldSheet, nNewSheet, bSameDoc);
747  if (pRangeData)
748  {
749  rRangeDataVec.push_back(pRangeData);
750  rSheetIndexMap.insert( std::make_pair( SheetIndex( nOldSheet, pCopyData->GetIndex()),
751  SheetIndex( nNewSheet, pRangeData->GetIndex())));
752  }
753  }
754  else
755  {
756  // First check if the name is already available as copy.
757  const ScRangeData* pFoundData = pNewRangeName->findByUpperName( pCopyData->GetUpperName());
758  if (pFoundData)
759  {
760  // Just add the resulting sheet/index mapping.
761  rSheetIndexMap.insert( std::make_pair( SheetIndex( nOldSheet, pCopyData->GetIndex()),
762  SheetIndex( nNewSheet, pFoundData->GetIndex())));
763  }
764  else
765  {
766  ScRangeData* pTmpData = copyRangeName( pCopyData, rNewDoc, rOldDoc, rNewPos, rOldPos,
767  bGlobalNamesToLocal, nOldSheet, nNewSheet, bSameDoc);
768  if (pTmpData)
769  {
770  rRangeDataVec.push_back(pTmpData);
771  rSheetIndexMap.insert( std::make_pair( SheetIndex( nOldSheet, pCopyData->GetIndex()),
772  SheetIndex( nNewSheet, pTmpData->GetIndex())));
773  }
774  }
775  }
776  }
777  }
778  }
779  return pRangeData;
780 }
781 
782 } // namespace
783 
784 bool ScDocument::CopyAdjustRangeName( SCTAB& rSheet, sal_uInt16& rIndex, ScRangeData*& rpRangeData,
785  ScDocument& rNewDoc, const ScAddress& rNewPos, const ScAddress& rOldPos, const bool bGlobalNamesToLocal,
786  const bool bUsedByFormula ) const
787 {
788  ScDocument* pThis = const_cast<ScDocument*>(this);
789  const bool bSameDoc = (rNewDoc.GetPool() == pThis->GetPool());
790  if (bSameDoc && ((rSheet < 0 && !bGlobalNamesToLocal) || (rSheet >= 0
791  && (rSheet != rOldPos.Tab() || (IsClipboard() && pThis->IsCutMode())))))
792  // Same doc and global name, if not copied to local name, or
793  // sheet-local name on other sheet stays the same. Sheet-local on
794  // same sheet also in a clipboard cut&paste / move operation.
795  return false;
796 
797  // Ensure we don't fiddle with the references until exit.
798  const SCTAB nOldSheet = rSheet;
799  const sal_uInt16 nOldIndex = rIndex;
800 
801  SAL_WARN_IF( !bSameDoc && nOldSheet >= 0 && nOldSheet != rOldPos.Tab(),
802  "sc.core", "adjustCopyRangeName - sheet-local name was on other sheet in other document");
803  /* TODO: can we do something about that? e.g. loop over sheets? */
804 
805  OUString aRangeName;
806  ScRangeData* pOldRangeData = nullptr;
807 
808  // XXX bGlobalNamesToLocal is also a synonym for copied sheet.
809  bool bInsertingBefore = (bGlobalNamesToLocal && bSameDoc && rNewPos.Tab() <= rOldPos.Tab());
810 
811  // The Tab where an old local name is to be found or that a global name
812  // references. May differ below from nOldSheet if a sheet was inserted
813  // before the old position. Global names and local names other than on the
814  // old sheet or new sheet are already updated, local names on the old sheet
815  // or inserted sheet will be updated later. Confusing stuff. Watch out.
816  SCTAB nOldTab = (nOldSheet < 0 ? rOldPos.Tab() : nOldSheet);
817  if (bInsertingBefore)
818  // Sheet was already inserted before old position.
819  ++nOldTab;
820 
821  // Search the name of the RangeName.
822  if (nOldSheet >= 0)
823  {
824  const ScRangeName* pNames = GetRangeName(nOldTab);
825  pOldRangeData = pNames ? pNames->findByIndex(nOldIndex) : nullptr;
826  if (!pOldRangeData)
827  return false; // might be an error in the formula array
828  aRangeName = pOldRangeData->GetUpperName();
829  }
830  else
831  {
832  pOldRangeData = GetRangeName()->findByIndex(nOldIndex);
833  if (!pOldRangeData)
834  return false; // might be an error in the formula array
835  aRangeName = pOldRangeData->GetUpperName();
836  }
837 
838  // Find corresponding range name in new document.
839  // First search for local range name then global range names.
840  SCTAB nNewSheet = rNewPos.Tab();
841  ScRangeName* pNewNames = rNewDoc.GetRangeName(nNewSheet);
842  // Search local range names.
843  if (pNewNames)
844  {
845  rpRangeData = pNewNames->findByUpperName(aRangeName);
846  }
847  // Search global range names.
848  if (!rpRangeData && !bGlobalNamesToLocal)
849  {
850  nNewSheet = -1;
851  pNewNames = rNewDoc.GetRangeName();
852  if (pNewNames)
853  rpRangeData = pNewNames->findByUpperName(aRangeName);
854  }
855  // If no range name was found copy it.
856  if (!rpRangeData)
857  {
858  // Do not copy global name if it doesn't reference sheet or is not used
859  // by a formula copied to another document.
860  bool bEarlyBailOut = (nOldSheet < 0 && (bSameDoc || !bUsedByFormula));
861  MightReferenceSheet eMightReference = mightRangeNameReferenceSheet( pOldRangeData, nOldTab);
862  if (bEarlyBailOut && eMightReference == MightReferenceSheet::NONE)
863  return false;
864 
865  if (eMightReference == MightReferenceSheet::NAME)
866  {
867  // Name these to clarify what is passed where.
868  const SCTAB nGlobalRefTab = nOldTab;
869  const SCTAB nLocalRefTab = (bInsertingBefore ? nOldTab-1 : nOldTab);
870  const SCTAB nOldTokenTab = (nOldSheet < 0 ? (bInsertingBefore ? nOldTab-1 : nOldTab) : nOldSheet);
871  const SCTAB nOldTokenTabReplacement = nOldTab;
872  sc::UpdatedRangeNames aReferencingNames;
873  FindRangeNamesReferencingSheet( aReferencingNames, nOldSheet, nOldIndex,
874  nGlobalRefTab, nLocalRefTab, nOldTokenTab, nOldTokenTabReplacement, bSameDoc, 0);
875  if (bEarlyBailOut && aReferencingNames.isEmpty(-1) && aReferencingNames.isEmpty(nOldTokenTabReplacement))
876  return false;
877 
878  SheetIndexMap aSheetIndexMap;
879  std::vector<ScRangeData*> aRangeDataVec;
880  if (!aReferencingNames.isEmpty(nOldTokenTabReplacement))
881  {
882  const SCTAB nTmpOldSheet = (nOldSheet < 0 ? nOldTab : nOldSheet);
883  nNewSheet = rNewPos.Tab();
884  rpRangeData = copyRangeNames( aSheetIndexMap, aRangeDataVec, aReferencingNames, nOldTab,
885  pOldRangeData, rNewDoc, *this, rNewPos, rOldPos,
886  bGlobalNamesToLocal, nTmpOldSheet, nNewSheet, bSameDoc);
887  }
888  if ((bGlobalNamesToLocal || !bSameDoc) && !aReferencingNames.isEmpty(-1))
889  {
890  const SCTAB nTmpOldSheet = -1;
891  const SCTAB nTmpNewSheet = (bGlobalNamesToLocal ? rNewPos.Tab() : -1);
892  ScRangeData* pTmpData = copyRangeNames( aSheetIndexMap, aRangeDataVec, aReferencingNames, -1,
893  pOldRangeData, rNewDoc, *this, rNewPos, rOldPos,
894  bGlobalNamesToLocal, nTmpOldSheet, nTmpNewSheet, bSameDoc);
895  if (!rpRangeData)
896  {
897  rpRangeData = pTmpData;
898  nNewSheet = nTmpNewSheet;
899  }
900  }
901 
902  // Adjust copied nested names to new sheet/index.
903  for (auto & iRD : aRangeDataVec)
904  {
905  ScTokenArray* pCode = iRD->GetCode();
906  if (pCode)
907  {
909  for (formula::FormulaToken* p = aIter.First(); p; p = aIter.Next())
910  {
911  if (p->GetOpCode() == ocName)
912  {
913  auto it = aSheetIndexMap.find( SheetIndex( p->GetSheet(), p->GetIndex()));
914  if (it != aSheetIndexMap.end())
915  {
916  p->SetSheet( it->second.mnSheet);
917  p->SetIndex( it->second.mnIndex);
918  }
919  else if (!bSameDoc)
920  {
921  SAL_WARN("sc.core","adjustCopyRangeName - mapping to new name in other doc missing");
922  p->SetIndex(0); // #NAME? error instead of arbitrary name.
923  }
924  }
925  }
926  }
927  }
928  }
929  else
930  {
931  nNewSheet = ((nOldSheet < 0 && !bGlobalNamesToLocal) ? -1 : rNewPos.Tab());
932  rpRangeData = copyRangeName( pOldRangeData, rNewDoc, *this, rNewPos, rOldPos, bGlobalNamesToLocal,
933  nOldSheet, nNewSheet, bSameDoc);
934  }
935 
936  if (rpRangeData && !rNewDoc.IsClipOrUndo())
937  {
938  ScDocShell* pDocSh = static_cast<ScDocShell*>(rNewDoc.GetDocumentShell());
939  if (pDocSh)
941  }
942  }
943 
944  rSheet = nNewSheet;
945  rIndex = rpRangeData ? rpRangeData->GetIndex() : 0; // 0 means not inserted
946  return true;
947 }
948 
950  sc::ColRowEditAction eAction, SCTAB nTab, SCCOLROW nStart, SCCOLROW nEnd ) const
951 {
952  const ScTable* pTab = FetchTable(nTab);
953  if (!pTab)
954  return false;
955 
956  return pTab->IsEditActionAllowed(eAction, nStart, nEnd);
957 }
958 
960  sc::ColRowEditAction eAction, const ScMarkData& rMark, SCCOLROW nStart, SCCOLROW nEnd ) const
961 {
962  return std::all_of(rMark.begin(), rMark.end(),
963  [this, &eAction, &nStart, &nEnd](const SCTAB& rTab) { return IsEditActionAllowed(eAction, rTab, nStart, nEnd); });
964 }
965 
966 std::optional<sc::ColumnIterator> ScDocument::GetColumnIterator( SCTAB nTab, SCCOL nCol, SCROW nRow1, SCROW nRow2 ) const
967 {
968  const ScTable* pTab = FetchTable(nTab);
969  if (!pTab)
970  return {};
971 
972  return pTab->GetColumnIterator(nCol, nRow1, nRow2);
973 }
974 
976 {
977  const ScTable* pTab = FetchTable(nTab);
978  if (!pTab)
979  return;
980 
981  pTab->CreateColumnIfNotExists(nCol);
982 }
983 
984 bool ScDocument::EnsureFormulaCellResults( const ScRange& rRange, bool bSkipRunning )
985 {
986  bool bAnyDirty = false;
987  for (SCTAB nTab = rRange.aStart.Tab(); nTab <= rRange.aEnd.Tab(); ++nTab)
988  {
989  ScTable* pTab = FetchTable(nTab);
990  if (!pTab)
991  continue;
992 
993  bool bRet = pTab->EnsureFormulaCellResults(
994  rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row(), bSkipRunning);
995  bAnyDirty = bAnyDirty || bRet;
996  }
997 
998  return bAnyDirty;
999 }
1000 
1002 {
1003  if (!mpDataMapper)
1004  mpDataMapper.reset(new sc::ExternalDataMapper(*this));
1005 
1006  return *mpDataMapper;
1007 }
1008 
1010 {
1011  const ScTable* pTab = FetchTable(nTab);
1012  if (!pTab)
1013  return;
1014 
1015  pTab->StoreToCache(rStrm);
1016 }
1017 
1019 {
1020  ScTable* pTab = FetchTable(nTab);
1021  if (!pTab)
1022  return;
1023 
1024  pTab->RestoreFromCache(rStrm);
1025 }
1026 
1027 OString ScDocument::dumpSheetGeomData(SCTAB nTab, bool bColumns, SheetGeomType eGeomType)
1028 {
1029  ScTable* pTab = FetchTable(nTab);
1030  if (!pTab)
1031  return "";
1032 
1033  return pTab->dumpSheetGeomData(bColumns, eGeomType);
1034 }
1035 
1037 {
1038  const ScTable* pTab = FetchTable(nTab);
1039  if (!pTab)
1040  return -1;
1041 
1042  return pTab->GetLOKFreezeCol();
1043 }
1045 {
1046  const ScTable* pTab = FetchTable(nTab);
1047  if (!pTab)
1048  return -1;
1049 
1050  return pTab->GetLOKFreezeRow();
1051 }
1052 
1054 {
1055  ScTable* pTab = FetchTable(nTab);
1056  if (!pTab)
1057  return false;
1058 
1059  return pTab->SetLOKFreezeCol(nFreezeCol);
1060 }
1061 
1063 {
1064  ScTable* pTab = FetchTable(nTab);
1065  if (!pTab)
1066  return false;
1067 
1068  return pTab->SetLOKFreezeRow(nFreezeRow);
1069 }
1070 
1071 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void AddDelayedFormulaGroupingCell(const ScFormulaCell *cell)
To be used only by SharedFormulaUtil::joinFormulaCells().
Definition: document10.cxx:391
ScCalcConfig maCalcConfig
Definition: document.hxx:363
SCROW mnRowDelta
Amount and direction of movement in the row direction.
ScAddress aStart
Definition: address.hxx:499
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:421
SCROW Row() const
Definition: address.hxx:261
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)
std::unique_ptr< ContentProperties > pData
ScTable * FetchTable(SCTAB nTab)
Definition: document.cxx:2521
void RegroupFormulaCells(SCTAB nTab, SCCOL nCol)
Definition: document10.cxx:360
void UpdateScriptTypes(const SCCOL nCol1, SCROW nRow1, const SCCOL nCol2, SCROW nRow2)
Definition: table7.cxx:246
const OUString & GetUpperName() const
Definition: rangenam.hxx:112
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:966
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:315
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)
MightReferenceSheet
Definition: document10.cxx:643
InsertDeleteFlags getInsertFlag() const
bool IsClipOrUndo() const
Definition: document.hxx:1532
void EndListeningIntersectedGroup(sc::EndListeningContext &rCxt, const ScAddress &rPos, std::vector< ScAddress > *pGroupPos)
Definition: document10.cxx:463
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:500
std::shared_ptr< T > make_shared(Args &&...args)
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:488
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:6087
NAME
ScColumn & CreateColumnIfNotExists(const SCCOL nScCol) const
Definition: table.hxx:287
bool IsEditActionAllowed(sc::ColRowEditAction eAction, SCCOLROW nStart, SCCOLROW nEnd) const
Definition: table7.cxx:344
SC_DLLPUBLIC ScPostIt * GetNote(const ScAddress &rPos)
Notes.
Definition: document.cxx:6534
std::unordered_map< ScColumn *, std::pair< SCROW, SCROW > > pDelayedStartListeningFormulaCells
Definition: document.hxx:525
void StartListeningFormulaCells(sc::StartListeningContext &rStartCxt, sc::EndListeningContext &rEndCxt, SCROW nRow1, SCROW nRow2)
Definition: column4.cxx:1497
ScClipParam & GetClipParam()
Definition: document.cxx:2565
void UpdateReference(sc::RefUpdateContext &rCxt, ScDocument *pUndoDoc=nullptr, bool bIncludeDraw=true, bool bUpdateNoteCaptionPos=true)
Definition: documen3.cxx:1005
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:426
SC_DLLPUBLIC void PreprocessAllRangeNamesUpdate(const std::map< OUString, std::unique_ptr< ScRangeName >> &rRangeMap)
Call this immediately before updating all named ranges.
Definition: document10.cxx:245
TableContainer maTabs
Definition: document.hxx:375
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:333
void PreprocessRangeNameUpdate(sc::EndListeningContext &rEndListenCxt, sc::CompileFormulaContext &rCompileCxt)
Definition: table7.cxx:225
SCTAB Tab() const
Definition: address.hxx:270
void EndListeningIntersectedGroups(sc::EndListeningContext &rCxt, const ScRange &rRange, std::vector< ScAddress > *pGroupPos)
Definition: document10.cxx:473
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:4766
void SetCol(SCCOL nColP)
Definition: address.hxx:278
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:2153
bool IsClipboard() const
Definition: document.hxx:1534
A pretty assertion that checks that the relevant bits in the are not set on the document at entry an...
Definition: document.hxx:2662
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:223
void SetTab(SCTAB nTabP)
Definition: address.hxx:282
SC_DLLPUBLIC ScRangeData * findByUpperName(const OUString &rName)
Definition: rangenam.cxx:681
void DelayFormulaGrouping(bool delay)
If set, joining cells into shared formula groups will be delayed until reset again (RegroupFormulaCel...
Definition: document10.cxx:376
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:342
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:303
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:400
void UnshareFormulaCells(SCCOL nCol, std::vector< SCROW > &rRows)
Definition: table7.cxx:278
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:326
Structure that stores segments of boolean flags per column, and perform custom action on those segmen...
bool IsCutMode()
Definition: document.cxx:2039
void CopyCellValuesFrom(const ScAddress &rTopPos, const sc::CellValues &rSrc)
Definition: document10.cxx:172
const ScRange & getRange() const
Definition: cellvalues.cxx:317
void CreateColumnIfNotExists(SCTAB nTab, SCCOL nCol)
Definition: document10.cxx:975
ScColContainer aCol
Definition: table.hxx:158
void StartListeningFormulaCells(sc::StartListeningContext &rStartCxt, sc::EndListeningContext &rEndCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
Definition: table2.cxx:1291
exports com.sun.star.awt. tab
iterator end()
Definition: markdata.cxx:952
void UpdateScriptTypes(SCROW nRow1, SCROW nRow2)
Definition: column4.cxx:1097
SC_DLLPUBLIC ScRangeData * findByIndex(sal_uInt16 i) const
Definition: rangenam.cxx:693
void SetAreasChangedNeedBroadcast()
Definition: docsh.hxx:389
bool IsValid() const
Definition: address.hxx:546
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.
void setSingleCellPattern(size_t nColOffset, const ScPatternAttr *pAttr)
SCCOL Col() const
Definition: address.hxx:266
SheetGeomType
Represents the type of sheet geometry data.
Definition: document.hxx:267
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:949
Configuration options for formula interpreter.
Definition: calcconfig.hxx:43
SCROW GetLOKFreezeRow() const
Definition: table7.cxx:594
bool SetLOKFreezeCol(SCCOL nFreezeCol)
Definition: table7.cxx:599
NameIndicesType getUpdatedNames(SCTAB nTab) const
constexpr TypedWhichId< SvxBrushItem > ATTR_BACKGROUND(148)
void finalizeOutlineImport()
Definition: document10.cxx:568
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.
Definition: document10.cxx:984
void SetNeedsListeningGroups(const std::vector< ScAddress > &rPosArray)
Definition: document10.cxx:503
iterator begin()
Definition: markdata.cxx:947
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:3927
void SetIndex(sal_uInt16 nInd)
Definition: rangenam.hxx:115
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:436
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:445
#define SAL_WARN_IF(condition, area, stream)
std::unique_ptr< ScTable, o3tl::default_delete< ScTable > > ScTableUniquePtr
Definition: document.hxx:311
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:351
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:397
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:181
FormulaToken ** GetCode() const
SCTAB getTabEnd() const
Definition: clipcontext.cxx:69
Item2Range GetItemSurrogates(sal_uInt16 nWhich) const
ScDocument * getUndoDoc()
Definition: clipcontext.cxx:92
SCTAB getTabStart() const
Definition: clipcontext.cxx:64
ScDocument * getClipDoc()
Definition: clipcontext.cxx:97
void * p
SC_DLLPUBLIC void PreprocessDBDataUpdate()
Definition: document10.cxx:303
bool IsMerged(const ScAddress &rPos) const
Definition: document10.cxx:32
std::vector< ScTableUniquePtr > TableContainer
Definition: document.hxx:344
bool SetLOKFreezeRow(SCROW nFreezeRow)
Definition: table7.cxx:616
void StartNeededListeners()
Definition: document10.cxx:537
std::shared_ptr< svl::SharedStringPool > mpCellStringPool
Definition: document.hxx:357
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:355
void ConvertFormulaToValue(const ScRange &rRange, sc::TableValues *pUndo)
Definition: document10.cxx:205
SfxObjectShell * GetDocumentShell() const
Definition: document.hxx:1057
#define SAL_WARN(area, stream)
void StartAllListeners()
Definition: documen7.cxx:582
bool GetTableSelect(SCTAB nTab) const
Definition: markdata.cxx:183
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:784
int mnIndex
void EndListeningIntersectedGroup(sc::EndListeningContext &rCxt, SCCOL nCol, SCROW nRow, std::vector< ScAddress > *pGroupPos)
Definition: table7.cxx:308
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:199
SCCOL GetLOKFreezeCol() const
Definition: table7.cxx:589
void SetValues(const ScAddress &rPos, const std::vector< double > &rVals)
Definition: document10.cxx:154
ScTokenArray * GetCode()
Definition: rangenam.hxx:119
std::unique_ptr< ScRange > pDelayedFormulaGrouping
Definition: document.hxx:521
SC_DLLPUBLIC bool insert(ScRangeData *p, bool bReuseFreeIndex=true)
Insert object into set.
Definition: rangenam.cxx:814
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:291
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:577
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:163