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