LibreOffice Module sc (master)  1
documen3.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  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
21 #include <com/sun/star/sheet/TableValidationVisibility.hpp>
22 #include <scitems.hxx>
23 #include <editeng/langitem.hxx>
24 #include <svl/srchitem.hxx>
25 #include <sfx2/linkmgr.hxx>
26 #include <sfx2/bindings.hxx>
27 #include <sfx2/objsh.hxx>
28 #include <sfx2/viewsh.hxx>
29 #include <vcl/svapp.hxx>
30 #include <osl/thread.hxx>
31 #include <osl/diagnose.h>
32 #include <document.hxx>
33 #include <attrib.hxx>
34 #include <table.hxx>
35 #include <rangenam.hxx>
36 #include <dbdata.hxx>
37 #include <docpool.hxx>
38 #include <poolhelp.hxx>
39 #include <rangelst.hxx>
40 #include <chartlock.hxx>
41 #include <refupdat.hxx>
42 #include <docoptio.hxx>
43 #include <scmod.hxx>
44 #include <clipoptions.hxx>
45 #include <viewopti.hxx>
46 #include <scextopt.hxx>
47 #include <tablink.hxx>
48 #include <externalrefmgr.hxx>
49 #include <markdata.hxx>
50 #include <validat.hxx>
51 #include <dociter.hxx>
52 #include <detdata.hxx>
53 #include <inputopt.hxx>
54 #include <chartlis.hxx>
55 #include <sc.hrc>
56 #include <hints.hxx>
57 #include <dpobject.hxx>
58 #include <drwlayer.hxx>
59 #include <unoreflist.hxx>
60 #include <listenercalls.hxx>
61 #include <tabprotection.hxx>
62 #include <formulaparserpool.hxx>
63 #include <clipparam.hxx>
64 #include <sheetevents.hxx>
65 #include <queryentry.hxx>
66 #include <formulacell.hxx>
67 #include <refupdatecontext.hxx>
68 #include <scopetools.hxx>
69 #include <filterentries.hxx>
70 #include <queryparam.hxx>
71 
72 #include <globalnames.hxx>
73 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
74 #include <comphelper/lok.hxx>
75 #include <config_fuzzers.h>
76 #include <memory>
77 
78 using namespace com::sun::star;
79 
80 namespace {
81 
82 void sortAndRemoveDuplicates(std::vector<ScTypedStrData>& rStrings, bool bCaseSens)
83 {
84  if (bCaseSens)
85  {
86  std::sort(rStrings.begin(), rStrings.end(), ScTypedStrData::LessCaseSensitive());
87  std::vector<ScTypedStrData>::iterator it =
88  std::unique(rStrings.begin(), rStrings.end(), ScTypedStrData::EqualCaseSensitive());
89  rStrings.erase(it, rStrings.end());
90  }
91  else
92  {
93  std::sort(rStrings.begin(), rStrings.end(), ScTypedStrData::LessCaseInsensitive());
94  std::vector<ScTypedStrData>::iterator it =
95  std::unique(rStrings.begin(), rStrings.end(), ScTypedStrData::EqualCaseInsensitive());
96  rStrings.erase(it, rStrings.end());
97  }
98 }
99 
100 }
101 
103 {
105  for (SCTAB i = 0; i < static_cast<SCTAB>(maTabs.size()); ++i)
106  {
107  if (!maTabs[i])
108  // no more tables to iterate through.
109  break;
110 
111  const ScRangeName* p = maTabs[i]->mpRangeName.get();
112  if (!p || p->empty())
113  // ignore empty ones.
114  continue;
115 
116  aNames.emplace(i, p);
117  }
118  rNames.swap(aNames);
119 }
120 
121 void ScDocument::SetAllRangeNames(const std::map<OUString, std::unique_ptr<ScRangeName>>& rRangeMap)
122 {
123  for (const auto& [rName, rxRangeName] : rRangeMap)
124  {
125  if (rName == STR_GLOBAL_RANGE_NAME)
126  {
127  pRangeName.reset();
128  const ScRangeName *const pName = rxRangeName.get();
129  if (!pName->empty())
130  pRangeName.reset( new ScRangeName( *pName ) );
131  }
132  else
133  {
134  const ScRangeName *const pName = rxRangeName.get();
135  SCTAB nTab;
136  bool bFound = GetTable(rName, nTab);
137  assert(bFound); (void)bFound; // fouled up?
138  if (pName->empty())
139  SetRangeName( nTab, nullptr );
140  else
141  SetRangeName( nTab, std::unique_ptr<ScRangeName>(new ScRangeName( *pName )) );
142  }
143  }
144 }
145 
146 void ScDocument::GetRangeNameMap(std::map<OUString, ScRangeName*>& aRangeNameMap)
147 {
148  for (SCTAB i = 0; i < static_cast<SCTAB>(maTabs.size()); ++i)
149  {
150  if (!maTabs[i])
151  continue;
152  ScRangeName* p = maTabs[i]->GetRangeName();
153  if (!p )
154  {
155  p = new ScRangeName();
156  SetRangeName(i, std::unique_ptr<ScRangeName>(p));
157  }
158  OUString aTableName = maTabs[i]->GetName();
159  aRangeNameMap.insert(std::pair<OUString, ScRangeName*>(aTableName,p));
160  }
161  if (!pRangeName)
162  {
163  pRangeName.reset(new ScRangeName());
164  }
165  aRangeNameMap.insert(std::pair<OUString, ScRangeName*>(STR_GLOBAL_RANGE_NAME, pRangeName.get()));
166 }
167 
169 {
170  if (!ValidTab(nTab) || nTab >= static_cast<SCTAB>(maTabs.size()) || !maTabs[nTab])
171  return nullptr;
172 
173  return maTabs[nTab]->GetRangeName();
174 }
175 
177 {
178  if (!pRangeName)
179  pRangeName.reset(new ScRangeName);
180  return pRangeName.get();
181 }
182 
183 void ScDocument::SetRangeName(SCTAB nTab, std::unique_ptr<ScRangeName> pNew)
184 {
185  if (!ValidTab(nTab) || nTab >= static_cast<SCTAB>(maTabs.size()) || !maTabs[nTab])
186  return;
187 
188  return maTabs[nTab]->SetRangeName(std::move(pNew));
189 }
190 
191 void ScDocument::SetRangeName( std::unique_ptr<ScRangeName> pNewRangeName )
192 {
193  pRangeName = std::move(pNewRangeName);
194 }
195 
197 {
198  ScRangeName* pRangeNames;
199  ScRange aNameRange;
200 
201  if (eScope == RangeNameScope::GLOBAL)
202  pRangeNames= GetRangeName();
203  else
204  pRangeNames= GetRangeName(rAddress.Tab());
205 
206  for (const auto& rEntry : *pRangeNames)
207  {
208  if (rEntry.second->IsValidReference(aNameRange))
209  {
210  if (aNameRange.In(rAddress))
211  return true;
212  }
213  }
214 
215  return false;
216 }
217 
218 bool ScDocument::InsertNewRangeName( const OUString& rName, const ScAddress& rPos, const OUString& rExpr )
219 {
220  ScRangeName* pGlobalNames = GetRangeName();
221  if (!pGlobalNames)
222  return false;
223 
224  ScRangeData* pName = new ScRangeData(*this, rName, rExpr, rPos, ScRangeData::Type::Name, GetGrammar());
225  return pGlobalNames->insert(pName);
226 }
227 
228 bool ScDocument::InsertNewRangeName( SCTAB nTab, const OUString& rName, const ScAddress& rPos, const OUString& rExpr )
229 {
230  ScRangeName* pLocalNames = GetRangeName(nTab);
231  if (!pLocalNames)
232  return false;
233 
234  ScRangeData* pName = new ScRangeData(*this, rName, rExpr, rPos, ScRangeData::Type::Name, GetGrammar());
235  return pLocalNames->insert(pName);
236 }
237 
238 const ScRangeData* ScDocument::GetRangeAtBlock( const ScRange& rBlock, OUString& rName, bool* pSheetLocal ) const
239 {
240  const ScRangeData* pData = nullptr;
241  if (rBlock.aStart.Tab() == rBlock.aEnd.Tab())
242  {
243  const ScRangeName* pLocalNames = GetRangeName(rBlock.aStart.Tab());
244  if (pLocalNames)
245  {
246  pData = pLocalNames->findByRange( rBlock );
247  if (pData)
248  {
249  rName = pData->GetName();
250  if (pSheetLocal)
251  *pSheetLocal = true;
252  return pData;
253  }
254  }
255  }
256  if ( pRangeName )
257  {
258  pData = pRangeName->findByRange( rBlock );
259  if (pData)
260  {
261  rName = pData->GetName();
262  if (pSheetLocal)
263  *pSheetLocal = false;
264  }
265  }
266  return pData;
267 }
268 
270 {
271  const ScRangeName* pRN = (nTab < 0 ? GetRangeName() : GetRangeName(nTab));
272  return (pRN ? pRN->findByIndex( nIndex) : nullptr);
273 }
274 
275 void ScDocument::SetDBCollection( std::unique_ptr<ScDBCollection> pNewDBCollection, bool bRemoveAutoFilter )
276 {
277  if (pDBCollection && bRemoveAutoFilter)
278  {
279  // remove auto filter attribute if new db data don't contain auto filter flag
280  // start position is also compared, so bRemoveAutoFilter must not be set from ref-undo!
281 
282  ScDBCollection::NamedDBs& rNamedDBs = pDBCollection->getNamedDBs();
283  for (const auto& rxNamedDB : rNamedDBs)
284  {
285  const ScDBData& rOldData = *rxNamedDB;
286  if (!rOldData.HasAutoFilter())
287  continue;
288 
289  ScRange aOldRange;
290  rOldData.GetArea(aOldRange);
291 
292  bool bFound = false;
293  if (pNewDBCollection)
294  {
295  ScDBData* pNewData = pNewDBCollection->getNamedDBs().findByUpperName(rOldData.GetUpperName());
296  if (pNewData)
297  {
298  if (pNewData->HasAutoFilter())
299  {
300  ScRange aNewRange;
301  pNewData->GetArea(aNewRange);
302  if (aOldRange.aStart == aNewRange.aStart)
303  bFound = true;
304  }
305  }
306  }
307 
308  if (!bFound)
309  {
310  aOldRange.aEnd.SetRow(aOldRange.aStart.Row());
311  RemoveFlagsTab( aOldRange.aStart.Col(), aOldRange.aStart.Row(),
312  aOldRange.aEnd.Col(), aOldRange.aEnd.Row(),
313  aOldRange.aStart.Tab(), ScMF::Auto );
314  RepaintRange( aOldRange );
315  }
316  }
317  }
318 
319  pDBCollection = std::move(pNewDBCollection);
320 }
321 
322 const ScDBData* ScDocument::GetDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, ScDBDataPortion ePortion) const
323 {
324  if (pDBCollection)
325  return pDBCollection->GetDBAtCursor(nCol, nRow, nTab, ePortion);
326  else
327  return nullptr;
328 }
329 
331 {
332  if (pDBCollection)
333  return pDBCollection->GetDBAtCursor(nCol, nRow, nTab, ePortion);
334  else
335  return nullptr;
336 }
337 
338 const ScDBData* ScDocument::GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const
339 {
340  if (pDBCollection)
341  return pDBCollection->GetDBAtArea(nTab, nCol1, nRow1, nCol2, nRow2);
342  else
343  return nullptr;
344 }
345 
346 ScDBData* ScDocument::GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
347 {
348  if (pDBCollection)
349  return pDBCollection->GetDBAtArea(nTab, nCol1, nRow1, nCol2, nRow2);
350  else
351  return nullptr;
352 }
353 
355 {
356  if (pDBCollection)
357  pDBCollection->RefreshDirtyTableColumnNames();
358 }
359 
361 {
362  return pDPCollection && pDPCollection->GetCount();
363 }
364 
366 {
367  if (!pDPCollection)
368  pDPCollection.reset( new ScDPCollection(*this) );
369  return pDPCollection.get();
370 }
371 
373 {
374  return pDPCollection.get();
375 }
376 
378 {
379  if (!pDPCollection)
380  return nullptr;
381 
382  sal_uInt16 nCount = pDPCollection->GetCount();
383  ScAddress aPos( nCol, nRow, nTab );
384  for (sal_uInt16 i=0; i<nCount; i++)
385  if ( (*pDPCollection)[i].GetOutRange().In( aPos ) )
386  return &(*pDPCollection)[i];
387 
388  return nullptr;
389 }
390 
392 {
393  if (!pDPCollection)
394  return nullptr;
395 
396  /* Walk the collection in reverse order to get something of an
397  * approximation of MS Excels 'most recent' effect. */
398  sal_uInt16 i = pDPCollection->GetCount();
399  while ( i-- > 0 )
400  if ( (*pDPCollection)[i].GetOutRange().In( rBlock ) )
401  return &(*pDPCollection)[i];
402 
403  return nullptr;
404 }
405 
407 {
408  if (apTemporaryChartLock)
409  apTemporaryChartLock->StopLocking();
410 }
411 
413  std::unique_ptr<ScChartListenerCollection> pNewChartListenerCollection,
414  bool bSetChartRangeLists )
415 {
416  std::unique_ptr<ScChartListenerCollection> pOld = std::move(pChartListenerCollection);
417  pChartListenerCollection = std::move(pNewChartListenerCollection);
418  if ( pChartListenerCollection )
419  {
420  if ( pOld )
421  pChartListenerCollection->SetDiffDirty( *pOld, bSetChartRangeLists );
422  pChartListenerCollection->StartAllListeners();
423  }
424 }
425 
426 void ScDocument::SetScenario( SCTAB nTab, bool bFlag )
427 {
428  if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
429  maTabs[nTab]->SetScenario(bFlag);
430 }
431 
432 bool ScDocument::IsScenario( SCTAB nTab ) const
433 {
434  return ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] &&maTabs[nTab]->IsScenario();
435 }
436 
437 void ScDocument::SetScenarioData( SCTAB nTab, const OUString& rComment,
438  const Color& rColor, ScScenarioFlags nFlags )
439 {
440  if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] && maTabs[nTab]->IsScenario())
441  {
442  maTabs[nTab]->SetScenarioComment( rComment );
443  maTabs[nTab]->SetScenarioColor( rColor );
444  maTabs[nTab]->SetScenarioFlags( nFlags );
445  }
446 }
447 
449 {
450  if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
451  return maTabs[nTab]->GetTabBgColor();
452  return COL_AUTO;
453 }
454 
455 void ScDocument::SetTabBgColor( SCTAB nTab, const Color& rColor )
456 {
457  if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
458  maTabs[nTab]->SetTabBgColor(rColor);
459 }
460 
462 {
463  if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
464  return maTabs[nTab]->GetTabBgColor() == COL_AUTO;
465  return true;
466 }
467 
468 void ScDocument::GetScenarioData( SCTAB nTab, OUString& rComment,
469  Color& rColor, ScScenarioFlags& rFlags ) const
470 {
471  if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] && maTabs[nTab]->IsScenario())
472  {
473  maTabs[nTab]->GetScenarioComment( rComment );
474  rColor = maTabs[nTab]->GetScenarioColor();
475  rFlags = maTabs[nTab]->GetScenarioFlags();
476  }
477 }
478 
480 {
481  if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] && maTabs[nTab]->IsScenario())
482  rFlags = maTabs[nTab]->GetScenarioFlags();
483 }
484 
485 bool ScDocument::IsLinked( SCTAB nTab ) const
486 {
487  return ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] && maTabs[nTab]->IsLinked();
488  // equivalent to
489  //if (ValidTab(nTab) && pTab[nTab])
490  // return pTab[nTab]->IsLinked();
491  //return false;
492 }
493 
495 {
497 }
498 
500 {
501  eGrammar = eGram;
502 }
503 
505 {
506  if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
507  return maTabs[nTab]->GetLinkMode();
508  return ScLinkMode::NONE;
509 }
510 
511 OUString ScDocument::GetLinkDoc( SCTAB nTab ) const
512 {
513  if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
514  return maTabs[nTab]->GetLinkDoc();
515  return OUString();
516 }
517 
518 OUString ScDocument::GetLinkFlt( SCTAB nTab ) const
519 {
520  if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
521  return maTabs[nTab]->GetLinkFlt();
522  return OUString();
523 }
524 
525 OUString ScDocument::GetLinkOpt( SCTAB nTab ) const
526 {
527  if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
528  return maTabs[nTab]->GetLinkOpt();
529  return OUString();
530 }
531 
532 OUString ScDocument::GetLinkTab( SCTAB nTab ) const
533 {
534  if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
535  return maTabs[nTab]->GetLinkTab();
536  return OUString();
537 }
538 
540 {
541  if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
542  return maTabs[nTab]->GetLinkRefreshDelay();
543  return 0;
544 }
545 
546 void ScDocument::SetLink( SCTAB nTab, ScLinkMode nMode, const OUString& rDoc,
547  const OUString& rFilter, const OUString& rOptions,
548  const OUString& rTabName, sal_uLong nRefreshDelay )
549 {
550  if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
551  maTabs[nTab]->SetLink( nMode, rDoc, rFilter, rOptions, rTabName, nRefreshDelay );
552 }
553 
554 bool ScDocument::HasLink( std::u16string_view rDoc,
555  std::u16string_view rFilter, std::u16string_view rOptions ) const
556 {
557  SCTAB nCount = static_cast<SCTAB>(maTabs.size());
558  for (SCTAB i=0; i<nCount; i++)
559  if (maTabs[i]->IsLinked()
560  && maTabs[i]->GetLinkDoc() == rDoc
561  && maTabs[i]->GetLinkFlt() == rFilter
562  && maTabs[i]->GetLinkOpt() == rOptions)
563  return true;
564 
565  return false;
566 }
567 
568 bool ScDocument::LinkExternalTab( SCTAB& rTab, const OUString& aDocTab,
569  const OUString& aFileName, const OUString& aTabName )
570 {
571  if ( IsClipboard() )
572  {
573  OSL_FAIL( "LinkExternalTab in Clipboard" );
574  return false;
575  }
576  rTab = 0;
577 #if ENABLE_FUZZERS
578  return false;
579 #endif
580  OUString aFilterName; // Is filled by the Loader
581  OUString aOptions; // Filter options
582  sal_uInt32 nLinkCnt = pExtDocOptions ? pExtDocOptions->GetDocSettings().mnLinkCnt : 0;
583  ScDocumentLoader aLoader( aFileName, aFilterName, aOptions, nLinkCnt + 1 );
584  if ( aLoader.IsError() )
585  return false;
586  ScDocument* pSrcDoc = aLoader.GetDocument();
587 
588  // Copy table
589  SCTAB nSrcTab;
590  if ( pSrcDoc->GetTable( aTabName, nSrcTab ) )
591  {
592  if ( !InsertTab( SC_TAB_APPEND, aDocTab, true ) )
593  {
594  OSL_FAIL("can't insert external document table");
595  return false;
596  }
597  rTab = GetTableCount() - 1;
598  // Don't insert anew, just the results
599  TransferTab( *pSrcDoc, nSrcTab, rTab, false, true );
600  }
601  else
602  return false;
603 
604  sal_uLong nRefreshDelay = 0;
605 
606  bool bWasThere = HasLink( aFileName, aFilterName, aOptions );
607  SetLink( rTab, ScLinkMode::VALUE, aFileName, aFilterName, aOptions, aTabName, nRefreshDelay );
608  if ( !bWasThere ) // Add link only once per source document
609  {
610  ScTableLink* pLink = new ScTableLink( mpShell, aFileName, aFilterName, aOptions, nRefreshDelay );
611  pLink->SetInCreate( true );
612  OUString aFilName = aFilterName;
613  GetLinkManager()->InsertFileLink( *pLink, sfx2::SvBaseLinkObjectType::ClientFile, aFileName, &aFilName );
614  pLink->Update();
615  pLink->SetInCreate( false );
616  SfxBindings* pBindings = GetViewBindings();
617  if (pBindings)
618  pBindings->Invalidate( SID_LINKS );
619  }
620  return true;
621 }
622 
624 {
625  ScDocument* pThis = const_cast<ScDocument*>(this);
626  if (!pExternalRefMgr)
627  pThis->pExternalRefMgr.reset( new ScExternalRefManager(*pThis));
628 
629  return pExternalRefMgr.get();
630 }
631 
633 {
634  return pExternalRefMgr && pExternalRefMgr->isInReferenceMarking();
635 }
636 
638 {
639  if (!pExternalRefMgr)
640  return;
641  if (!pExternalRefMgr->hasExternalData())
642  return;
643  // Charts.
644  pExternalRefMgr->markUsedByLinkListeners();
645  // Formula cells.
646  pExternalRefMgr->markUsedExternalRefCells();
647 
648  /* NOTE: Conditional formats and validation objects are marked when
649  * collecting them during export. */
650 }
651 
653 {
654  if (!mxFormulaParserPool)
655  mxFormulaParserPool.reset( new ScFormulaParserPool( *this ) );
656  return *mxFormulaParserPool;
657 }
658 
660 {
661  if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
662  return maTabs[nTab]->GetSheetEvents();
663  return nullptr;
664 }
665 
666 void ScDocument::SetSheetEvents( SCTAB nTab, std::unique_ptr<ScSheetEvents> pNew )
667 {
668  if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
669  maTabs[nTab]->SetSheetEvents( std::move(pNew) );
670 }
671 
672 bool ScDocument::HasSheetEventScript( SCTAB nTab, ScSheetEventId nEvent, bool bWithVbaEvents ) const
673 {
674  if (nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
675  {
676  // check if any event handler script has been configured
677  const ScSheetEvents* pEvents = maTabs[nTab]->GetSheetEvents();
678  if ( pEvents && pEvents->GetScript( nEvent ) )
679  return true;
680  // check if VBA event handlers exist
681  if (bWithVbaEvents && mxVbaEvents.is()) try
682  {
683  uno::Sequence< uno::Any > aArgs( 1 );
684  aArgs[ 0 ] <<= nTab;
685  if (mxVbaEvents->hasVbaEventHandler( ScSheetEvents::GetVbaSheetEventId( nEvent ), aArgs ) ||
686  mxVbaEvents->hasVbaEventHandler( ScSheetEvents::GetVbaDocumentEventId( nEvent ), uno::Sequence< uno::Any >() ))
687  return true;
688  }
689  catch( uno::Exception& )
690  {
691  }
692  }
693  return false;
694 }
695 
696 bool ScDocument::HasAnySheetEventScript( ScSheetEventId nEvent, bool bWithVbaEvents ) const
697 {
698  SCTAB nSize = static_cast<SCTAB>(maTabs.size());
699  for (SCTAB nTab = 0; nTab < nSize; nTab++)
700  if (HasSheetEventScript( nTab, nEvent, bWithVbaEvents ))
701  return true;
702  return false;
703 }
704 
706 {
707  SCTAB nSize = static_cast<SCTAB>(maTabs.size());
708  for (SCTAB nTab = 0; nTab < nSize; nTab++)
709  if (maTabs[nTab] && maTabs[nTab]->GetCalcNotification())
710  return true;
711  return false;
712 }
713 
715 {
716  if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
717  return maTabs[nTab]->GetCalcNotification();
718  return false;
719 }
720 
722 {
723  // set only if not set before
724  if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] && !maTabs[nTab]->GetCalcNotification())
725  maTabs[nTab]->SetCalcNotification(true);
726 }
727 
729 {
730  SCTAB nSize = static_cast<SCTAB>(maTabs.size());
731  for (SCTAB nTab = 0; nTab < nSize; nTab++)
732  if (maTabs[nTab] && maTabs[nTab]->GetCalcNotification())
733  maTabs[nTab]->SetCalcNotification(false);
734 }
735 
737 {
738  ScOutlineTable* pVal = nullptr;
739 
740  if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()))
741  if (maTabs[nTab])
742  {
743  pVal = maTabs[nTab]->GetOutlineTable();
744  if (!pVal && bCreate)
745  {
746  maTabs[nTab]->StartOutlineTable();
747  pVal = maTabs[nTab]->GetOutlineTable();
748  }
749  }
750 
751  return pVal;
752 }
753 
754 bool ScDocument::SetOutlineTable( SCTAB nTab, const ScOutlineTable* pNewOutline )
755 {
756  return ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] && maTabs[nTab]->SetOutlineTable(pNewOutline);
757 }
758 
759 void ScDocument::DoAutoOutline( SCCOL nStartCol, SCROW nStartRow,
760  SCCOL nEndCol, SCROW nEndRow, SCTAB nTab )
761 {
762  if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
763  maTabs[nTab]->DoAutoOutline( nStartCol, nStartRow, nEndCol, nEndRow );
764 }
765 
767 {
768  return ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] && maTabs[nTab]->TestRemoveSubTotals( rParam );
769 }
770 
772 {
773  if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
774  maTabs[nTab]->RemoveSubTotals( rParam );
775 }
776 
778 {
779  return ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] && maTabs[nTab]->DoSubTotals( rParam );
780 }
781 
783 {
784  ScCellIterator aIter(*this, rRange);
785  for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
786  {
787  if (aIter.getType() != CELLTYPE_FORMULA)
788  continue;
789 
790  if (aIter.getFormulaCell()->IsSubTotal())
791  return true;
792  }
793  return false; // none found
794 }
795 
800 void ScDocument::CopyUpdated( ScDocument* pPosDoc, ScDocument* pDestDoc )
801 {
802  SCTAB nCount = static_cast<SCTAB>(maTabs.size());
803  for (SCTAB nTab=0; nTab<nCount; nTab++)
804  if (maTabs[nTab] && pPosDoc->maTabs[nTab] && pDestDoc->maTabs[nTab])
805  maTabs[nTab]->CopyUpdated( pPosDoc->maTabs[nTab].get(), pDestDoc->maTabs[nTab].get() );
806 }
807 
808 void ScDocument::CopyScenario( SCTAB nSrcTab, SCTAB nDestTab, bool bNewScenario )
809 {
810  if (!(ValidTab(nSrcTab) && ValidTab(nDestTab) && nSrcTab < static_cast<SCTAB>(maTabs.size())
811  && nDestTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nSrcTab] && maTabs[nDestTab]))
812  return;
813 
814  // Set flags correctly for active scenarios
815  // and write current values back to recently active scenarios
816  ScRangeList aRanges = *maTabs[nSrcTab]->GetScenarioRanges();
817 
818  // nDestTab is the target table
819  for ( SCTAB nTab = nDestTab+1;
820  nTab< static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] && maTabs[nTab]->IsScenario();
821  nTab++ )
822  {
823  if ( maTabs[nTab]->IsActiveScenario() ) // Even if it's the same scenario
824  {
825  bool bTouched = false;
826  for ( size_t nR=0, nRangeCount = aRanges.size(); nR < nRangeCount && !bTouched; nR++ )
827  {
828  const ScRange& rRange = aRanges[ nR ];
829  if ( maTabs[nTab]->HasScenarioRange( rRange ) )
830  bTouched = true;
831  }
832  if (bTouched)
833  {
834  maTabs[nTab]->SetActiveScenario(false);
835  if ( maTabs[nTab]->GetScenarioFlags() & ScScenarioFlags::TwoWay )
836  maTabs[nTab]->CopyScenarioFrom( maTabs[nDestTab].get() );
837  }
838  }
839  }
840 
841  maTabs[nSrcTab]->SetActiveScenario(true); // This is where it's from ...
842  if (!bNewScenario) // Copy data from the selected scenario
843  {
844  sc::AutoCalcSwitch aACSwitch(*this, false);
845  maTabs[nSrcTab]->CopyScenarioTo( maTabs[nDestTab].get() );
846 
848  SetAllFormulasDirty(aCxt);
849  }
850 }
851 
852 void ScDocument::MarkScenario( SCTAB nSrcTab, SCTAB nDestTab, ScMarkData& rDestMark,
853  bool bResetMark, ScScenarioFlags nNeededBits ) const
854 {
855  if (bResetMark)
856  rDestMark.ResetMark();
857 
858  if (ValidTab(nSrcTab) && nSrcTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nSrcTab])
859  maTabs[nSrcTab]->MarkScenarioIn( rDestMark, nNeededBits );
860 
861  rDestMark.SetAreaTab( nDestTab );
862 }
863 
864 bool ScDocument::HasScenarioRange( SCTAB nTab, const ScRange& rRange ) const
865 {
866  return ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] && maTabs[nTab]->HasScenarioRange( rRange );
867 }
868 
870 {
871  if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
872  return maTabs[nTab]->GetScenarioRanges();
873 
874  return nullptr;
875 }
876 
878 {
879  return ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] && maTabs[nTab]->IsActiveScenario( );
880 }
881 
882 void ScDocument::SetActiveScenario( SCTAB nTab, bool bActive )
883 {
884  if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
885  maTabs[nTab]->SetActiveScenario( bActive );
886 }
887 
888 bool ScDocument::TestCopyScenario( SCTAB nSrcTab, SCTAB nDestTab ) const
889 {
890  if (ValidTab(nSrcTab) && nSrcTab < static_cast<SCTAB>(maTabs.size())
891  && nDestTab < static_cast<SCTAB>(maTabs.size())&& ValidTab(nDestTab))
892  return maTabs[nSrcTab]->TestCopyScenarioTo( maTabs[nDestTab].get() );
893 
894  OSL_FAIL("wrong table at TestCopyScenario");
895  return false;
896 }
897 
899 {
900  if (!pUnoBroadcaster)
901  pUnoBroadcaster.reset( new SfxBroadcaster );
902 
903  rObject.StartListening( *pUnoBroadcaster );
904 }
905 
907 {
908  if (pUnoBroadcaster)
909  {
910  rObject.EndListening( *pUnoBroadcaster );
911 
912  if ( bInUnoBroadcast )
913  {
914  // Broadcasts from ScDocument::BroadcastUno are the only way that
915  // uno object methods are called without holding a reference.
916  //
917  // If RemoveUnoObject is called from an object dtor in the finalizer thread
918  // while the main thread is calling BroadcastUno, the dtor thread must wait
919  // (or the object's Notify might try to access a deleted object).
920  // The SolarMutex can't be locked here because if a component is called from
921  // a VCL event, the main thread has the SolarMutex locked all the time.
922  //
923  // This check is done after calling EndListening, so a later BroadcastUno call
924  // won't touch this object.
925 
927  if (g.isAcquired())
928  {
929  // BroadcastUno is always called with the SolarMutex locked, so if it
930  // can be acquired, this is within the same thread (should not happen)
931  OSL_FAIL( "RemoveUnoObject called from BroadcastUno" );
932  }
933  else
934  {
935  // Let the thread that called BroadcastUno continue
936  while ( bInUnoBroadcast )
937  {
938  osl::Thread::yield();
939  }
940  }
941  }
942  }
943  else
944  {
945  OSL_FAIL("No Uno broadcaster");
946  }
947 }
948 
949 void ScDocument::BroadcastUno( const SfxHint &rHint )
950 {
951  if (!pUnoBroadcaster)
952  return;
953 
954  bInUnoBroadcast = true;
955  pUnoBroadcaster->Broadcast( rHint );
956  bInUnoBroadcast = false;
957 
958  // During Broadcast notification, Uno objects can add to pUnoListenerCalls.
959  // The listener calls must be processed after completing the broadcast,
960  // because they can add or remove objects from pUnoBroadcaster.
961 
962  if ( pUnoListenerCalls &&
963  rHint.GetId() == SfxHintId::DataChanged &&
964  !bInUnoListenerCall )
965  {
966  // Listener calls may lead to BroadcastUno calls again. The listener calls
967  // are not nested, instead the calls are collected in the list, and the
968  // outermost call executes them all.
969 
970  ScChartLockGuard aChartLockGuard(this);
971  bInUnoListenerCall = true;
972  pUnoListenerCalls->ExecuteAndClear();
973  bInUnoListenerCall = false;
974  }
975 }
976 
977 void ScDocument::AddUnoListenerCall( const uno::Reference<util::XModifyListener>& rListener,
978  const lang::EventObject& rEvent )
979 {
980  OSL_ENSURE( bInUnoBroadcast, "AddUnoListenerCall is supposed to be called from BroadcastUno only" );
981 
982  if ( !pUnoListenerCalls )
983  pUnoListenerCalls.reset( new ScUnoListenerCalls );
984  pUnoListenerCalls->Add( rListener, rEvent );
985 }
986 
988 {
989  OSL_ENSURE( !pUnoRefUndoList, "BeginUnoRefUndo twice" );
990  pUnoRefUndoList.reset( new ScUnoRefList );
991 }
992 
993 std::unique_ptr<ScUnoRefList> ScDocument::EndUnoRefUndo()
994 {
995  return std::move(pUnoRefUndoList);
996  // Must be deleted by caller!
997 }
998 
999 void ScDocument::AddUnoRefChange( sal_Int64 nId, const ScRangeList& rOldRanges )
1000 {
1001  if ( pUnoRefUndoList )
1002  pUnoRefUndoList->Add( nId, rOldRanges );
1003 }
1004 
1006  sc::RefUpdateContext& rCxt, ScDocument* pUndoDoc, bool bIncludeDraw, bool bUpdateNoteCaptionPos )
1007 {
1008  if (!ValidRange(rCxt.maRange) && !(rCxt.meMode == URM_INSDEL &&
1009  ((rCxt.mnColDelta < 0 && // convention from ScDocument::DeleteCol()
1010  rCxt.maRange.aStart.Col() == MAXCOLCOUNT && rCxt.maRange.aEnd.Col() == MAXCOLCOUNT) ||
1011  (rCxt.mnRowDelta < 0 && // convention from ScDocument::DeleteRow()
1012  rCxt.maRange.aStart.Row() == GetSheetLimits().GetMaxRowCount() && rCxt.maRange.aEnd.Row() == GetSheetLimits().GetMaxRowCount()))))
1013  return;
1014 
1015  std::unique_ptr<sc::ExpandRefsSwitch> pExpandRefsSwitch;
1016  if (rCxt.isInserted())
1017  pExpandRefsSwitch.reset(new sc::ExpandRefsSwitch(*this, SC_MOD()->GetInputOptions().GetExpandRefs()));
1018 
1019  size_t nFirstTab, nLastTab;
1020  if (rCxt.meMode == URM_COPY)
1021  {
1022  nFirstTab = rCxt.maRange.aStart.Tab();
1023  nLastTab = rCxt.maRange.aEnd.Tab();
1024  }
1025  else
1026  {
1027  // TODO: Have these methods use the context object directly.
1028  ScRange aRange = rCxt.maRange;
1029  UpdateRefMode eUpdateRefMode = rCxt.meMode;
1030  SCCOL nDx = rCxt.mnColDelta;
1031  SCROW nDy = rCxt.mnRowDelta;
1032  SCTAB nDz = rCxt.mnTabDelta;
1033  SCCOL nCol1 = rCxt.maRange.aStart.Col(), nCol2 = rCxt.maRange.aEnd.Col();
1034  SCROW nRow1 = rCxt.maRange.aStart.Row(), nRow2 = rCxt.maRange.aEnd.Row();
1035  SCTAB nTab1 = rCxt.maRange.aStart.Tab(), nTab2 = rCxt.maRange.aEnd.Tab();
1036 
1037  xColNameRanges->UpdateReference( eUpdateRefMode, this, aRange, nDx, nDy, nDz );
1038  xRowNameRanges->UpdateReference( eUpdateRefMode, this, aRange, nDx, nDy, nDz );
1039  pDBCollection->UpdateReference( eUpdateRefMode, nCol1, nRow1, nTab1, nCol2, nRow2, nTab2, nDx, nDy, nDz );
1040  if (pRangeName)
1041  pRangeName->UpdateReference(rCxt);
1042  if ( pDPCollection )
1043  pDPCollection->UpdateReference( eUpdateRefMode, aRange, nDx, nDy, nDz );
1044  UpdateChartRef( eUpdateRefMode, nCol1, nRow1, nTab1, nCol2, nRow2, nTab2, nDx, nDy, nDz );
1045  UpdateRefAreaLinks( eUpdateRefMode, aRange, nDx, nDy, nDz );
1046  if ( pValidationList )
1047  {
1049  pValidationList->UpdateReference(rCxt);
1050  }
1051  if ( pDetOpList )
1052  pDetOpList->UpdateReference( this, eUpdateRefMode, aRange, nDx, nDy, nDz );
1053  if ( pUnoBroadcaster )
1054  pUnoBroadcaster->Broadcast( ScUpdateRefHint(
1055  eUpdateRefMode, aRange, nDx, nDy, nDz ) );
1056 
1057  nFirstTab = 0;
1058  nLastTab = maTabs.size()-1;
1059  }
1060 
1061  for (size_t i = nFirstTab, n = maTabs.size() ; i <= nLastTab && i < n; ++i)
1062  {
1063  if (!maTabs[i])
1064  continue;
1065 
1066  maTabs[i]->UpdateReference(rCxt, pUndoDoc, bIncludeDraw, bUpdateNoteCaptionPos);
1067  }
1068 
1069  if ( bIsEmbedded )
1070  {
1071  SCCOL theCol1;
1072  SCROW theRow1;
1073  SCTAB theTab1;
1074  SCCOL theCol2;
1075  SCROW theRow2;
1076  SCTAB theTab2;
1077  theCol1 = aEmbedRange.aStart.Col();
1078  theRow1 = aEmbedRange.aStart.Row();
1079  theTab1 = aEmbedRange.aStart.Tab();
1080  theCol2 = aEmbedRange.aEnd.Col();
1081  theRow2 = aEmbedRange.aEnd.Row();
1082  theTab2 = aEmbedRange.aEnd.Tab();
1083 
1084  // TODO: Have ScRefUpdate::Update() use the context object directly.
1085  UpdateRefMode eUpdateRefMode = rCxt.meMode;
1086  SCCOL nDx = rCxt.mnColDelta;
1087  SCROW nDy = rCxt.mnRowDelta;
1088  SCTAB nDz = rCxt.mnTabDelta;
1089  SCCOL nCol1 = rCxt.maRange.aStart.Col(), nCol2 = rCxt.maRange.aEnd.Col();
1090  SCROW nRow1 = rCxt.maRange.aStart.Row(), nRow2 = rCxt.maRange.aEnd.Row();
1091  SCTAB nTab1 = rCxt.maRange.aStart.Tab(), nTab2 = rCxt.maRange.aEnd.Tab();
1092 
1093  if ( ScRefUpdate::Update( this, eUpdateRefMode, nCol1,nRow1,nTab1, nCol2,nRow2,nTab2,
1094  nDx,nDy,nDz, theCol1,theRow1,theTab1, theCol2,theRow2,theTab2 ) )
1095  {
1096  aEmbedRange = ScRange( theCol1,theRow1,theTab1, theCol2,theRow2,theTab2 );
1097  }
1098  }
1099 
1100  // After moving, no clipboard move ref-updates are possible
1101  if (rCxt.meMode != URM_COPY && IsClipboardSource())
1102  {
1103  ScDocument* pClipDoc = ScModule::GetClipDoc();
1104  if (pClipDoc)
1105  pClipDoc->GetClipParam().mbCutMode = false;
1106  }
1107 }
1108 
1109 void ScDocument::UpdateTranspose( const ScAddress& rDestPos, ScDocument* pClipDoc,
1110  const ScMarkData& rMark, ScDocument* pUndoDoc )
1111 {
1112  OSL_ENSURE(pClipDoc->bIsClip, "UpdateTranspose: No Clip");
1113 
1114  ScRange aSource;
1115  ScClipParam& rClipParam = GetClipParam();
1116  if (!rClipParam.maRanges.empty())
1117  aSource = rClipParam.maRanges.front();
1118  ScAddress aDest = rDestPos;
1119 
1120  SCTAB nClipTab = 0;
1121  for (SCTAB nDestTab=0; nDestTab< static_cast<SCTAB>(maTabs.size()) && maTabs[nDestTab]; nDestTab++)
1122  if (rMark.GetTableSelect(nDestTab))
1123  {
1124  while (!pClipDoc->maTabs[nClipTab]) nClipTab = (nClipTab+1) % (MAXTAB+1);
1125  aSource.aStart.SetTab( nClipTab );
1126  aSource.aEnd.SetTab( nClipTab );
1127  aDest.SetTab( nDestTab );
1128 
1129  // Like UpdateReference
1130  if (pRangeName)
1131  pRangeName->UpdateTranspose( aSource, aDest ); // Before the cells!
1132  for (SCTAB i=0; i< static_cast<SCTAB>(maTabs.size()); i++)
1133  if (maTabs[i])
1134  maTabs[i]->UpdateTranspose( aSource, aDest, pUndoDoc );
1135 
1136  nClipTab = (nClipTab+1) % (MAXTAB+1);
1137  }
1138 }
1139 
1140 void ScDocument::UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY )
1141 {
1142  //TODO: pDBCollection
1143  //TODO: pPivotCollection
1144  //TODO: UpdateChartRef
1145 
1146  if (pRangeName)
1147  pRangeName->UpdateGrow( rArea, nGrowX, nGrowY );
1148 
1149  for (SCTAB i=0; i< static_cast<SCTAB>(maTabs.size()) && maTabs[i]; i++)
1150  maTabs[i]->UpdateGrow( rArea, nGrowX, nGrowY );
1151 }
1152 
1153 void ScDocument::Fill(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScProgress* pProgress, const ScMarkData& rMark,
1154  sal_uLong nFillCount, FillDir eFillDir, FillCmd eFillCmd, FillDateCmd eFillDateCmd,
1155  double nStepValue, double nMaxValue)
1156 {
1157  PutInOrder( nCol1, nCol2 );
1158  PutInOrder( nRow1, nRow2 );
1159  ScRange aRange;
1160  rMark.GetMarkArea(aRange);
1161  SCTAB nMax = maTabs.size();
1162  for (const auto& rTab : rMark)
1163  {
1164  if (rTab >= nMax)
1165  break;
1166  if (maTabs[rTab])
1167  {
1168  maTabs[rTab]->Fill(nCol1, nRow1, nCol2, nRow2,
1169  nFillCount, eFillDir, eFillCmd, eFillDateCmd,
1170  nStepValue, nMaxValue, pProgress);
1171  RefreshAutoFilter(aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row(), rTab);
1172  }
1173  }
1174 }
1175 
1176 OUString ScDocument::GetAutoFillPreview( const ScRange& rSource, SCCOL nEndX, SCROW nEndY )
1177 {
1178  SCTAB nTab = rSource.aStart.Tab();
1179  if (nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
1180  return maTabs[nTab]->GetAutoFillPreview( rSource, nEndX, nEndY );
1181 
1182  return OUString();
1183 }
1184 
1185 void ScDocument::AutoFormat( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
1186  sal_uInt16 nFormatNo, const ScMarkData& rMark )
1187 {
1188  PutInOrder( nStartCol, nEndCol );
1189  PutInOrder( nStartRow, nEndRow );
1190  SCTAB nMax = maTabs.size();
1191  for (const auto& rTab : rMark)
1192  {
1193  if (rTab >= nMax)
1194  break;
1195  if (maTabs[rTab])
1196  maTabs[rTab]->AutoFormat( nStartCol, nStartRow, nEndCol, nEndRow, nFormatNo );
1197  }
1198 }
1199 
1200 void ScDocument::GetAutoFormatData(SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
1201  ScAutoFormatData& rData)
1202 {
1203  if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()))
1204  {
1205  if (maTabs[nTab])
1206  {
1207  PutInOrder(nStartCol, nEndCol);
1208  PutInOrder(nStartRow, nEndRow);
1209  maTabs[nTab]->GetAutoFormatData(nStartCol, nStartRow, nEndCol, nEndRow, rData);
1210  }
1211  }
1212 }
1213 
1215  SCCOL& rCol, SCROW& rRow )
1216 {
1217  SvxSearchCmd nCommand = rSearchItem.GetCommand();
1218  bool bReplace = ( nCommand == SvxSearchCmd::REPLACE ||
1219  nCommand == SvxSearchCmd::REPLACE_ALL );
1220  if ( rSearchItem.GetBackward() )
1221  {
1222  if ( rSearchItem.GetRowDirection() )
1223  {
1224  if ( rSearchItem.GetPattern() )
1225  {
1226  rCol = MaxCol();
1227  rRow = MaxRow()+1;
1228  }
1229  else if ( bReplace )
1230  {
1231  rCol = MaxCol();
1232  rRow = MaxRow();
1233  }
1234  else
1235  {
1236  rCol = MaxCol()+1;
1237  rRow = MaxRow();
1238  }
1239  }
1240  else
1241  {
1242  if ( rSearchItem.GetPattern() )
1243  {
1244  rCol = MaxCol()+1;
1245  rRow = MaxRow();
1246  }
1247  else if ( bReplace )
1248  {
1249  rCol = MaxCol();
1250  rRow = MaxRow();
1251  }
1252  else
1253  {
1254  rCol = MaxCol();
1255  rRow = MaxRow()+1;
1256  }
1257  }
1258  }
1259  else
1260  {
1261  if ( rSearchItem.GetRowDirection() )
1262  {
1263  if ( rSearchItem.GetPattern() )
1264  {
1265  rCol = 0;
1266  rRow = SCROW(-1);
1267  }
1268  else if ( bReplace )
1269  {
1270  rCol = 0;
1271  rRow = 0;
1272  }
1273  else
1274  {
1275  rCol = SCCOL(-1);
1276  rRow = 0;
1277  }
1278  }
1279  else
1280  {
1281  if ( rSearchItem.GetPattern() )
1282  {
1283  rCol = SCCOL(-1);
1284  rRow = 0;
1285  }
1286  else if ( bReplace )
1287  {
1288  rCol = 0;
1289  rRow = 0;
1290  }
1291  else
1292  {
1293  rCol = 0;
1294  rRow = SCROW(-1);
1295  }
1296  }
1297  }
1298 }
1299 
1301  const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow, SCTAB& rTab,
1302  const ScMarkData& rMark, ScRangeList& rMatchedRanges,
1303  OUString& rUndoStr, ScDocument* pUndoDoc)
1304 {
1305  // FIXME: Manage separated marks per table!
1306  bool bFound = false;
1307  if (rTab >= static_cast<SCTAB>(maTabs.size()))
1308  OSL_FAIL("table out of range");
1309  if (ValidTab(rTab))
1310  {
1311  SCCOL nCol;
1312  SCROW nRow;
1313  SCTAB nTab;
1314  SvxSearchCmd nCommand = rSearchItem.GetCommand();
1315  if ( nCommand == SvxSearchCmd::FIND_ALL ||
1316  nCommand == SvxSearchCmd::REPLACE_ALL )
1317  {
1318  SCTAB nMax = maTabs.size();
1319  for (const auto& rMarkedTab : rMark)
1320  {
1321  if (rMarkedTab >= nMax)
1322  break;
1323  if (maTabs[rMarkedTab])
1324  {
1325  nCol = 0;
1326  nRow = 0;
1327  bFound |= maTabs[rMarkedTab]->SearchAndReplace(
1328  rSearchItem, nCol, nRow, rMark, rMatchedRanges, rUndoStr, pUndoDoc);
1329  }
1330  }
1331 
1332  // Mark is set completely inside already
1333  }
1334  else
1335  {
1336  nCol = rCol;
1337  nRow = rRow;
1338  if (rSearchItem.GetBackward())
1339  {
1340  for (nTab = rTab; (nTab >= 0) && !bFound; nTab--)
1341  if (maTabs[nTab])
1342  {
1343  if (rMark.GetTableSelect(nTab))
1344  {
1345  bFound = maTabs[nTab]->SearchAndReplace(
1346  rSearchItem, nCol, nRow, rMark, rMatchedRanges, rUndoStr, pUndoDoc);
1347  if (bFound)
1348  {
1349  rCol = nCol;
1350  rRow = nRow;
1351  rTab = nTab;
1352  }
1353  else
1354  {
1356  rSearchItem, nCol, nRow );
1357 
1358  // notify LibreOfficeKit about changed page
1360  {
1361  OString aPayload = OString::number(nTab);
1362  if (SfxViewShell* pViewShell = SfxViewShell::Current())
1363  pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_SET_PART, aPayload.getStr());
1364  }
1365  }
1366  }
1367  }
1368  }
1369  else
1370  {
1371  for (nTab = rTab; (nTab < static_cast<SCTAB>(maTabs.size())) && !bFound; nTab++)
1372  if (maTabs[nTab])
1373  {
1374  if (rMark.GetTableSelect(nTab))
1375  {
1376  bFound = maTabs[nTab]->SearchAndReplace(
1377  rSearchItem, nCol, nRow, rMark, rMatchedRanges, rUndoStr, pUndoDoc);
1378  if (bFound)
1379  {
1380  rCol = nCol;
1381  rRow = nRow;
1382  rTab = nTab;
1383  }
1384  else
1385  {
1387  rSearchItem, nCol, nRow );
1388 
1389  // notify LibreOfficeKit about changed page
1391  {
1392  OString aPayload = OString::number(nTab);
1393  if(SfxViewShell* pViewShell = SfxViewShell::Current())
1394  pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_SET_PART, aPayload.getStr());
1395  }
1396  }
1397  }
1398  }
1399  }
1400  }
1401  }
1402  return bFound;
1403 }
1404 
1408 bool ScDocument::UpdateOutlineCol( SCCOL nStartCol, SCCOL nEndCol, SCTAB nTab, bool bShow )
1409 {
1410  if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
1411  return maTabs[nTab]->UpdateOutlineCol( nStartCol, nEndCol, bShow );
1412 
1413  OSL_FAIL("missing tab");
1414  return false;
1415 }
1416 
1417 bool ScDocument::UpdateOutlineRow( SCROW nStartRow, SCROW nEndRow, SCTAB nTab, bool bShow )
1418 {
1419  if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
1420  return maTabs[nTab]->UpdateOutlineRow( nStartRow, nEndRow, bShow );
1421 
1422  OSL_FAIL("missing tab");
1423  return false;
1424 }
1425 
1427  SCTAB nTab, const ScSortParam& rSortParam, bool bKeepQuery, bool bUpdateRefs,
1428  ScProgress* pProgress, sc::ReorderParam* pUndo )
1429 {
1430  if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
1431  {
1432  bool bOldEnableIdle = IsIdleEnabled();
1433  EnableIdle(false);
1434  maTabs[nTab]->Sort(rSortParam, bKeepQuery, bUpdateRefs, pProgress, pUndo);
1435  EnableIdle(bOldEnableIdle);
1436  }
1437 }
1438 
1440 {
1441  ScTable* pTab = FetchTable(rParam.maSortRange.aStart.Tab());
1442  if (!pTab)
1443  return;
1444 
1445  bool bOldEnableIdle = IsIdleEnabled();
1446  EnableIdle(false);
1447  pTab->Reorder(rParam);
1448  EnableIdle(bOldEnableIdle);
1449 }
1450 
1451 void ScDocument::PrepareQuery( SCTAB nTab, ScQueryParam& rQueryParam )
1452 {
1453  if( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
1454  maTabs[nTab]->PrepareQuery(rQueryParam);
1455  else
1456  {
1457  OSL_FAIL("missing tab");
1458  return;
1459  }
1460 }
1461 
1462 SCSIZE ScDocument::Query(SCTAB nTab, const ScQueryParam& rQueryParam, bool bKeepSub)
1463 {
1464  if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
1465  return maTabs[nTab]->Query(rQueryParam, bKeepSub);
1466 
1467  OSL_FAIL("missing tab");
1468  return 0;
1469 }
1470 
1471 void ScDocument::GetUpperCellString(SCCOL nCol, SCROW nRow, SCTAB nTab, OUString& rStr)
1472 {
1473  if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
1474  maTabs[nTab]->GetUpperCellString( nCol, nRow, rStr );
1475  else
1476  rStr.clear();
1477 }
1478 
1479 bool ScDocument::CreateQueryParam( const ScRange& rRange, ScQueryParam& rQueryParam )
1480 {
1481  ScTable* pTab = FetchTable(rRange.aStart.Tab());
1482  if (!pTab)
1483  {
1484  OSL_FAIL("missing tab");
1485  return false;
1486  }
1487 
1488  return pTab->CreateQueryParam(
1489  rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row(), rQueryParam);
1490 }
1491 
1492 bool ScDocument::HasAutoFilter( SCCOL nCurCol, SCROW nCurRow, SCTAB nCurTab )
1493 {
1494  const ScDBData* pDBData = GetDBAtCursor( nCurCol, nCurRow, nCurTab, ScDBDataPortion::AREA );
1495  bool bHasAutoFilter = (pDBData != nullptr);
1496 
1497  if ( pDBData )
1498  {
1499  if ( pDBData->HasHeader() )
1500  {
1501  SCCOL nCol;
1502  SCROW nRow;
1503  ScMF nFlag;
1504 
1505  ScQueryParam aParam;
1506  pDBData->GetQueryParam( aParam );
1507  nRow = aParam.nRow1;
1508 
1509  for ( nCol=aParam.nCol1; nCol<=aParam.nCol2 && bHasAutoFilter; nCol++ )
1510  {
1511  nFlag = GetAttr( nCol, nRow, nCurTab, ATTR_MERGE_FLAG )->GetValue();
1512 
1513  if ( !(nFlag & ScMF::Auto) )
1514  bHasAutoFilter = false;
1515  }
1516  }
1517  else
1518  bHasAutoFilter = false;
1519  }
1520 
1521  return bHasAutoFilter;
1522 }
1523 
1524 bool ScDocument::HasColHeader( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
1525  SCTAB nTab )
1526 {
1527  return ValidTab(nTab) && maTabs[nTab] && maTabs[nTab]->HasColHeader( nStartCol, nStartRow, nEndCol, nEndRow );
1528 }
1529 
1530 bool ScDocument::HasRowHeader( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
1531  SCTAB nTab )
1532 {
1533  return ValidTab(nTab) && maTabs[nTab] && maTabs[nTab]->HasRowHeader( nStartCol, nStartRow, nEndCol, nEndRow );
1534 }
1535 
1536 void ScDocument::GetFilterSelCount( SCCOL nCol, SCROW nRow, SCTAB nTab, SCSIZE& nSelected, SCSIZE& nTotal )
1537 {
1538  nSelected = 0;
1539  nTotal = 0;
1540  if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
1541  {
1542  ScDBData* pDBData = GetDBAtCursor( nCol, nRow, nTab, ScDBDataPortion::AREA );
1543  if( pDBData && pDBData->HasAutoFilter() )
1544  pDBData->GetFilterSelCount( nSelected, nTotal );
1545  }
1546 }
1547 
1552  SCCOL nCol, SCROW nRow, SCTAB nTab, ScFilterEntries& rFilterEntries )
1553 {
1554  if ( !(ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] && pDBCollection) )
1555  return;
1556 
1557  ScDBData* pDBData = pDBCollection->GetDBAtCursor(nCol, nRow, nTab, ScDBDataPortion::AREA);
1558  if (!pDBData)
1559  return;
1560 
1561  pDBData->ExtendDataArea(*this);
1562  SCTAB nAreaTab;
1563  SCCOL nStartCol;
1564  SCROW nStartRow;
1565  SCCOL nEndCol;
1566  SCROW nEndRow;
1567  pDBData->GetArea( nAreaTab, nStartCol, nStartRow, nEndCol, nEndRow );
1568 
1569  if (pDBData->HasHeader())
1570  ++nStartRow;
1571 
1572  ScQueryParam aParam;
1573  pDBData->GetQueryParam( aParam );
1574 
1575  // Return all filter entries, if a filter condition is connected with a boolean OR
1576  bool bFilter = true;
1577  SCSIZE nEntryCount = aParam.GetEntryCount();
1578  for ( SCSIZE i = 0; i < nEntryCount && aParam.GetEntry(i).bDoQuery; ++i )
1579  {
1580  ScQueryEntry& rEntry = aParam.GetEntry(i);
1581  if ( rEntry.eConnect != SC_AND )
1582  {
1583  bFilter = false;
1584  break;
1585  }
1586  }
1587 
1588  if ( bFilter )
1589  {
1590  maTabs[nTab]->GetFilteredFilterEntries( nCol, nStartRow, nEndRow, aParam, rFilterEntries, bFilter );
1591  }
1592  else
1593  {
1594  maTabs[nTab]->GetFilterEntries( nCol, nStartRow, nEndRow, rFilterEntries );
1595  }
1596 
1597  sortAndRemoveDuplicates( rFilterEntries.maStrData, aParam.bCaseSens);
1598 }
1599 
1604  SCCOL nCol, SCROW nStartRow, SCROW nEndRow, SCTAB nTab, bool bCaseSens,
1605  ScFilterEntries& rFilterEntries )
1606 {
1607  if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
1608  {
1609  maTabs[nTab]->GetFilterEntries( nCol, nStartRow, nEndRow, rFilterEntries );
1610  sortAndRemoveDuplicates( rFilterEntries.maStrData, bCaseSens);
1611  }
1612 }
1613 
1618  SCCOL nCol, SCROW nRow, SCTAB nTab,
1619  std::vector<ScTypedStrData>& rStrings, bool bLimit )
1620 {
1621  if( !bLimit )
1622  {
1623  /* Try to generate the list from list validation. This part is skipped,
1624  if bLimit==true, because in that case this function is called to get
1625  cell values for auto completion on input. */
1626  sal_uInt32 nValidation = GetAttr( nCol, nRow, nTab, ATTR_VALIDDATA )->GetValue();
1627  if( nValidation )
1628  {
1629  const ScValidationData* pData = GetValidationEntry( nValidation );
1630  if( pData && pData->FillSelectionList( rStrings, ScAddress( nCol, nRow, nTab ) ) )
1631  {
1632  if (pData->GetListType() == css::sheet::TableValidationVisibility::SORTEDASCENDING)
1633  sortAndRemoveDuplicates(rStrings, true/*bCaseSens*/);
1634 
1635  return;
1636  }
1637  }
1638  }
1639 
1640  if (!ValidTab(nTab) || nTab >= static_cast<SCTAB>(maTabs.size()))
1641  return;
1642 
1643  if (!maTabs[nTab])
1644  return;
1645 
1646  std::set<ScTypedStrData> aStrings;
1647  if (maTabs[nTab]->GetDataEntries(nCol, nRow, aStrings, bLimit))
1648  {
1649  rStrings.insert(rStrings.end(), aStrings.begin(), aStrings.end());
1650  sortAndRemoveDuplicates(rStrings, true/*bCaseSens*/);
1651  }
1652 }
1653 
1658 {
1659 
1660  // Range name
1661  if ( pRangeName )
1662  {
1663  for (const auto& rEntry : *pRangeName)
1664  rStrings.insert(ScTypedStrData(rEntry.second->GetName(), 0.0, ScTypedStrData::Name));
1665  }
1666 
1667  // Database collection
1668  if ( pDBCollection )
1669  {
1670  const ScDBCollection::NamedDBs& rDBs = pDBCollection->getNamedDBs();
1671  for (const auto& rxDB : rDBs)
1672  rStrings.insert(ScTypedStrData(rxDB->GetName(), 0.0, ScTypedStrData::DbName));
1673  }
1674 
1675  // Content of name ranges
1676  ScRangePairList* pLists[2];
1677  pLists[0] = GetColNameRanges();
1678  pLists[1] = GetRowNameRanges();
1679  for (ScRangePairList* pList : pLists)
1680  {
1681  if (!pList)
1682  continue;
1683 
1684  for ( size_t i = 0, nPairs = pList->size(); i < nPairs; ++i )
1685  {
1686  const ScRangePair & rPair = (*pList)[i];
1687  const ScRange & rRange = rPair.GetRange(0);
1688  ScCellIterator aIter( *this, rRange );
1689  for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
1690  {
1691  if (!aIter.hasString())
1692  continue;
1693 
1694  OUString aStr = aIter.getString();
1695  rStrings.insert(ScTypedStrData(aStr, 0.0, ScTypedStrData::Header));
1696  }
1697  }
1698  }
1699 }
1700 
1701 void ScDocument::GetEmbedded( ScRange& rRange ) const
1702 {
1703  rRange = aEmbedRange;
1704 }
1705 
1707 {
1708  tools::Rectangle aRect;
1709  ScTable* pTable = nullptr;
1710  if ( aEmbedRange.aStart.Tab() < static_cast<SCTAB>(maTabs.size()) )
1711  pTable = maTabs[aEmbedRange.aStart.Tab()].get();
1712  else
1713  OSL_FAIL("table out of range");
1714  if (!pTable)
1715  {
1716  OSL_FAIL("GetEmbeddedRect without a table");
1717  }
1718  else
1719  {
1720  SCCOL i;
1721 
1722  for (i=0; i<aEmbedRange.aStart.Col(); i++)
1723  aRect.AdjustLeft(pTable->GetColWidth(i) );
1724  aRect.AdjustTop(pTable->GetRowHeight( 0, aEmbedRange.aStart.Row() - 1) );
1725  aRect.SetRight( aRect.Left() );
1726  for (i=aEmbedRange.aStart.Col(); i<=aEmbedRange.aEnd.Col(); i++)
1727  aRect.AdjustRight(pTable->GetColWidth(i) );
1728  aRect.SetBottom( aRect.Top() );
1729  aRect.AdjustBottom(pTable->GetRowHeight( aEmbedRange.aStart.Row(), aEmbedRange.aEnd.Row()) );
1730 
1731  aRect.SetLeft( static_cast<tools::Long>( aRect.Left() * HMM_PER_TWIPS ) );
1732  aRect.SetRight( static_cast<tools::Long>( aRect.Right() * HMM_PER_TWIPS ) );
1733  aRect.SetTop( static_cast<tools::Long>( aRect.Top() * HMM_PER_TWIPS ) );
1734  aRect.SetBottom( static_cast<tools::Long>( aRect.Bottom() * HMM_PER_TWIPS ) );
1735  }
1736  return aRect;
1737 }
1738 
1739 void ScDocument::SetEmbedded( const ScRange& rRange )
1740 {
1741  bIsEmbedded = true;
1742  aEmbedRange = rRange;
1743 }
1744 
1746 {
1747  bIsEmbedded = false;
1748  aEmbedRange = ScRange();
1749 }
1750 
1755 static bool lcl_AddTwipsWhile( tools::Long & rTwips, tools::Long nStopTwips, SCROW & rPosY, SCROW nEndRow, const ScTable * pTable, bool bHiddenAsZero )
1756 {
1757  SCROW nRow = rPosY;
1758  bool bAdded = false;
1759  bool bStop = false;
1760  while (rTwips < nStopTwips && nRow <= nEndRow && !bStop)
1761  {
1762  SCROW nHeightEndRow;
1763  sal_uInt16 nHeight = pTable->GetRowHeight( nRow, nullptr, &nHeightEndRow, bHiddenAsZero );
1764  if (nHeightEndRow > nEndRow)
1765  nHeightEndRow = nEndRow;
1766  if (!nHeight)
1767  nRow = nHeightEndRow + 1;
1768  else
1769  {
1770  SCROW nRows = nHeightEndRow - nRow + 1;
1771  sal_Int64 nAdd = static_cast<sal_Int64>(nHeight) * nRows;
1772  if (nAdd + rTwips >= nStopTwips)
1773  {
1774  sal_Int64 nDiff = nAdd + rTwips - nStopTwips;
1775  nRows -= static_cast<SCROW>(nDiff / nHeight);
1776  nAdd = static_cast<sal_Int64>(nHeight) * nRows;
1777  // We're looking for a value that satisfies loop condition.
1778  if (nAdd + rTwips >= nStopTwips)
1779  {
1780  --nRows;
1781  nAdd -= nHeight;
1782  }
1783  bStop = true;
1784  }
1785  rTwips += static_cast<tools::Long>(nAdd);
1786  nRow += nRows;
1787  }
1788  }
1789  if (nRow > rPosY)
1790  {
1791  --nRow;
1792  bAdded = true;
1793  }
1794  rPosY = nRow;
1795  return bAdded;
1796 }
1797 
1798 ScRange ScDocument::GetRange( SCTAB nTab, const tools::Rectangle& rMMRect, bool bHiddenAsZero ) const
1799 {
1800  ScTable* pTable = nullptr;
1801  if (nTab < static_cast<SCTAB>(maTabs.size()))
1802  pTable = maTabs[nTab].get();
1803  else
1804  OSL_FAIL("table out of range");
1805  if (!pTable)
1806  {
1807  OSL_FAIL("GetRange without a table");
1808  return ScRange();
1809  }
1810 
1811  tools::Rectangle aPosRect = rMMRect;
1812  if ( IsNegativePage( nTab ) )
1813  ScDrawLayer::MirrorRectRTL( aPosRect ); // Always with positive (LTR) values
1814 
1815  tools::Long nSize;
1816  tools::Long nTwips;
1817  tools::Long nAdd;
1818  bool bEnd;
1819 
1820  nSize = 0;
1821  nTwips = static_cast<tools::Long>(aPosRect.Left() / HMM_PER_TWIPS);
1822 
1823  SCCOL nX1 = 0;
1824  bEnd = false;
1825  while (!bEnd)
1826  {
1827  nAdd = static_cast<tools::Long>(pTable->GetColWidth(nX1, bHiddenAsZero));
1828  if (nSize+nAdd <= nTwips+1 && nX1<MaxCol())
1829  {
1830  nSize += nAdd;
1831  ++nX1;
1832  }
1833  else
1834  bEnd = true;
1835  }
1836 
1837 
1838  SCCOL nX2 = nX1;
1839  if (!aPosRect.IsEmpty())
1840  {
1841  bEnd = false;
1842  nTwips = static_cast<tools::Long>(aPosRect.Right() / HMM_PER_TWIPS);
1843  while (!bEnd)
1844  {
1845  nAdd = static_cast<tools::Long>(pTable->GetColWidth(nX2, bHiddenAsZero));
1846  if (nSize+nAdd < nTwips && nX2<MaxCol())
1847  {
1848  nSize += nAdd;
1849  ++nX2;
1850  }
1851  else
1852  bEnd = true;
1853  }
1854  }
1855 
1856  nSize = 0;
1857  nTwips = static_cast<tools::Long>(aPosRect.Top() / HMM_PER_TWIPS);
1858 
1859  SCROW nY1 = 0;
1860  // Was if(nSize+nAdd<=nTwips+1) inside loop => if(nSize+nAdd<nTwips+2)
1861  if (lcl_AddTwipsWhile( nSize, nTwips+2, nY1, MaxRow(), pTable, bHiddenAsZero) && nY1 < MaxRow())
1862  ++nY1; // original loop ended on last matched +1 unless that was rDoc.MaxRow()
1863 
1864  SCROW nY2 = nY1;
1865  if (!aPosRect.IsEmpty())
1866  {
1867  nTwips = static_cast<tools::Long>(aPosRect.Bottom() / HMM_PER_TWIPS);
1868  // Was if(nSize+nAdd<nTwips) inside loop => if(nSize+nAdd<nTwips)
1869  if (lcl_AddTwipsWhile( nSize, nTwips, nY2, MaxRow(), pTable, bHiddenAsZero) && nY2 < MaxRow())
1870  ++nY2; // original loop ended on last matched +1 unless that was rDoc.MaxRow()
1871  }
1872 
1873  return ScRange( nX1,nY1,nTab, nX2,nY2,nTab );
1874 }
1875 
1876 void ScDocument::SetEmbedded( SCTAB nTab, const tools::Rectangle& rRect ) // From VisArea (1/100 mm)
1877 {
1878  bIsEmbedded = true;
1879  aEmbedRange = GetRange( nTab, rRect );
1880 }
1881 
1883 {
1884  return pDocProtection.get();
1885 }
1886 
1888 {
1889  if (pProtect)
1890  pDocProtection.reset(new ScDocProtection(*pProtect));
1891  else
1892  pDocProtection.reset();
1893 }
1894 
1896 {
1897  return pDocProtection && pDocProtection->isProtected();
1898 }
1899 
1901 {
1902  // Import into read-only document is possible
1903  return !IsDocProtected() && ( bImportingXML || mbChangeReadOnlyEnabled || !mpShell || !mpShell->IsReadOnly() );
1904 }
1905 
1907 {
1908  if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
1909  return maTabs[nTab]->IsProtected();
1910 
1911  OSL_FAIL("Wrong table number");
1912  return false;
1913 }
1914 
1916 {
1917  if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
1918  return maTabs[nTab]->GetProtection();
1919 
1920  return nullptr;
1921 }
1922 
1924 {
1925  if (!ValidTab(nTab) || nTab >= static_cast<SCTAB>(maTabs.size()))
1926  return;
1927 
1928  maTabs[nTab]->SetProtection(pProtect);
1929 }
1930 
1932 {
1933  if (!ValidTab(nTabSrc) || nTabSrc >= static_cast<SCTAB>(maTabs.size()) || nTabDest >= static_cast<SCTAB>(maTabs.size()) || !ValidTab(nTabDest))
1934  return;
1935 
1936  maTabs[nTabDest]->SetProtection( maTabs[nTabSrc]->GetProtection() );
1937 }
1938 
1940 {
1941  assert(pDocOptions && "No DocOptions! :-(");
1942  return *pDocOptions;
1943 }
1944 
1946 {
1947  assert(pDocOptions && "No DocOptions! :-(");
1948 
1949  *pDocOptions = rOpt;
1950  mxPoolHelper->SetFormTableOpt(rOpt);
1951 }
1952 
1954 {
1955  assert(pViewOptions && "No ViewOptions! :-(");
1956  return *pViewOptions;
1957 }
1958 
1960 {
1961  assert(pViewOptions && "No ViewOptions! :-(");
1962  *pViewOptions = rOpt;
1963 }
1964 
1966 {
1967  rLatin = eLanguage;
1968  rCjk = eCjkLanguage;
1969  rCtl = eCtlLanguage;
1970 }
1971 
1973 {
1974  eLanguage = eLatin;
1975  eCjkLanguage = eCjk;
1976  eCtlLanguage = eCtl;
1977  if ( mxPoolHelper.is() )
1978  {
1979  ScDocumentPool* pPool = mxPoolHelper->GetDocPool();
1980  pPool->SetPoolDefaultItem( SvxLanguageItem( eLanguage, ATTR_FONT_LANGUAGE ) );
1981  pPool->SetPoolDefaultItem( SvxLanguageItem( eCjkLanguage, ATTR_CJK_FONT_LANGUAGE ) );
1982  pPool->SetPoolDefaultItem( SvxLanguageItem( eCtlLanguage, ATTR_CTL_FONT_LANGUAGE ) );
1983  }
1984 
1985  UpdateDrawLanguages(); // Set edit engine defaults in drawing layer pool
1986 }
1987 
1988 tools::Rectangle ScDocument::GetMMRect( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab, bool bHiddenAsZero ) const
1989 {
1990  if (!ValidTab(nTab) || nTab >= static_cast<SCTAB>(maTabs.size()) || !maTabs[nTab])
1991  {
1992  OSL_FAIL("GetMMRect: wrong table");
1993  return tools::Rectangle(0,0,0,0);
1994  }
1995 
1996  SCCOL i;
1997  tools::Rectangle aRect;
1998 
1999  for (i=0; i<nStartCol; i++)
2000  aRect.AdjustLeft(GetColWidth(i,nTab, bHiddenAsZero ) );
2001  aRect.AdjustTop(GetRowHeight( 0, nStartRow-1, nTab, bHiddenAsZero ) );
2002 
2003  aRect.SetRight( aRect.Left() );
2004  aRect.SetBottom( aRect.Top() );
2005 
2006  for (i=nStartCol; i<=nEndCol; i++)
2007  aRect.AdjustRight(GetColWidth(i,nTab, bHiddenAsZero) );
2008  aRect.AdjustBottom(GetRowHeight( nStartRow, nEndRow, nTab, bHiddenAsZero ) );
2009 
2010  aRect.SetLeft( static_cast<tools::Long>(aRect.Left() * HMM_PER_TWIPS) );
2011  aRect.SetRight( static_cast<tools::Long>(aRect.Right() * HMM_PER_TWIPS) );
2012  aRect.SetTop( static_cast<tools::Long>(aRect.Top() * HMM_PER_TWIPS) );
2013  aRect.SetBottom( static_cast<tools::Long>(aRect.Bottom() * HMM_PER_TWIPS) );
2014 
2015  if ( IsNegativePage( nTab ) )
2016  ScDrawLayer::MirrorRectRTL( aRect );
2017 
2018  return aRect;
2019 }
2020 
2021 void ScDocument::SetExtDocOptions( std::unique_ptr<ScExtDocOptions> pNewOptions )
2022 {
2023  pExtDocOptions = std::move(pNewOptions);
2024 }
2025 
2026 void ScDocument::SetClipOptions(std::unique_ptr<ScClipOptions> pClipOptions)
2027 {
2028  mpClipOptions = std::move(pClipOptions);
2029 }
2030 
2031 void ScDocument::DoMergeContents( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow,
2032  SCCOL nEndCol, SCROW nEndRow )
2033 {
2034  OUStringBuffer aTotal;
2035  OUString aCellStr;
2036  SCCOL nCol;
2037  SCROW nRow;
2038  for (nRow=nStartRow; nRow<=nEndRow; nRow++)
2039  for (nCol=nStartCol; nCol<=nEndCol; nCol++)
2040  {
2041  aCellStr = GetString(nCol, nRow, nTab);
2042  if (!aCellStr.isEmpty())
2043  {
2044  if (!aTotal.isEmpty())
2045  aTotal.append(' ');
2046  aTotal.append(aCellStr);
2047  }
2048  if (nCol != nStartCol || nRow != nStartRow)
2049  SetString(nCol,nRow,nTab,"");
2050  }
2051 
2052  SetString(nStartCol,nStartRow,nTab,aTotal.makeStringAndClear());
2053 }
2054 
2055 void ScDocument::DoEmptyBlock( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow,
2056  SCCOL nEndCol, SCROW nEndRow )
2057 {
2058  SCCOL nCol;
2059  SCROW nRow;
2060  for (nRow=nStartRow; nRow<=nEndRow; nRow++)
2061  for (nCol=nStartCol; nCol<=nEndCol; nCol++)
2062  { // empty block except first cell
2063  if (nCol != nStartCol || nRow != nStartRow)
2064  SetString(nCol,nRow,nTab,"");
2065  }
2066 }
2067 
2068 void ScDocument::DoMerge( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow,
2069  SCCOL nEndCol, SCROW nEndRow, bool bDeleteCaptions )
2070 {
2071  ScTable* pTab = FetchTable(nTab);
2072  if (!pTab)
2073  return;
2074 
2075  pTab->SetMergedCells(nStartCol, nStartRow, nEndCol, nEndRow);
2076 
2077  // Remove all covered notes (removed captions are collected by drawing undo if active)
2079  if( nStartCol < nEndCol )
2080  DeleteAreaTab( nStartCol + 1, nStartRow, nEndCol, nStartRow, nTab, nDelFlag );
2081  if( nStartRow < nEndRow )
2082  DeleteAreaTab( nStartCol, nStartRow + 1, nEndCol, nEndRow, nTab, nDelFlag );
2083 }
2084 
2085 void ScDocument::RemoveMerge( SCCOL nCol, SCROW nRow, SCTAB nTab )
2086 {
2087  const ScMergeAttr* pAttr = GetAttr( nCol, nRow, nTab, ATTR_MERGE );
2088 
2089  if ( pAttr->GetColMerge() <= 1 && pAttr->GetRowMerge() <= 1 )
2090  return;
2091 
2092  SCCOL nEndCol = nCol + pAttr->GetColMerge() - 1;
2093  SCROW nEndRow = nRow + pAttr->GetRowMerge() - 1;
2094 
2095  RemoveFlagsTab( nCol, nRow, nEndCol, nEndRow, nTab, ScMF::Hor | ScMF::Ver );
2096 
2097  const ScMergeAttr* pDefAttr = &mxPoolHelper->GetDocPool()->GetDefaultItem( ATTR_MERGE );
2098  ApplyAttr( nCol, nRow, nTab, *pDefAttr );
2099 }
2100 
2102  SCCOL nStartCol, SCROW nStartRow, SCCOL& rEndCol, SCROW nEndRow ) const
2103 {
2104  if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
2105  maTabs[nTab]->ExtendPrintArea( pDev, nStartCol, nStartRow, rEndCol, nEndRow );
2106 }
2107 
2109 {
2110  if( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
2111  return maTabs[nTab]->GetPatternCount( nCol );
2112  else
2113  return 0;
2114 }
2115 
2116 SCSIZE ScDocument::GetPatternCount( SCTAB nTab, SCCOL nCol, SCROW nRow1, SCROW nRow2 ) const
2117 {
2118  if( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
2119  return maTabs[nTab]->GetPatternCount( nCol, nRow1, nRow2 );
2120  else
2121  return 0;
2122 }
2123 
2125 {
2126  if( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
2127  maTabs[nTab]->ReservePatternCount( nCol, nReserve );
2128 }
2129 
2131 {
2132  rParam = mSheetSortParams[ nTab ];
2133 }
2134 
2135 void ScDocument::SetSortParam( const ScSortParam& rParam, SCTAB nTab )
2136 {
2137  mSheetSortParams[ nTab ] = rParam;
2138 }
2139 
2141 {
2142  return maTabs[nTab]->ClampToAllocatedColumns(nCol);
2143 }
2144 
2146 {
2147  return maTabs[nTab]->GetAllocatedColumnsCount();
2148 }
2149 
2150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SC_DLLPUBLIC void UpdateTranspose(const ScAddress &rDestPos, ScDocument *pClipDoc, const ScMarkData &rMark, ScDocument *pUndoDoc)
Definition: documen3.cxx:1109
SC_DLLPUBLIC bool IsDocProtected() const
Definition: documen3.cxx:1895
SC_DLLPUBLIC OUString GetLinkDoc(SCTAB nTab) const
Definition: documen3.cxx:511
void SetMergedCells(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
Definition: table2.cxx:2122
OUString GetLinkOpt(SCTAB nTab) const
Definition: documen3.cxx:525
void RemoveMerge(SCCOL nCol, SCROW nRow, SCTAB nTab)
Definition: documen3.cxx:2085
SC_DLLPUBLIC ScDPObject * GetDPAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: documen3.cxx:377
SCCOL GetColMerge() const
Definition: attrib.hxx:68
SCROW mnRowDelta
Amount and direction of movement in the row direction.
Temporarily switch on/off auto calculation mode.
Definition: scopetools.hxx:26
bool insert(std::unique_ptr< ScDBData > p)
Takes ownership of p and attempts to insert it into the collection.
Definition: dbdata.cxx:1160
bool HasAutoFilter() const
Definition: dbdata.hxx:203
SC_DLLPUBLIC bool HasColHeader(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab)
Definition: documen3.cxx:1524
static ScRefUpdateRes Update(const ScDocument *pDoc, UpdateRefMode eUpdateRefMode, SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2, SCCOL nDx, SCROW nDy, SCTAB nDz, SCCOL &theCol1, SCROW &theRow1, SCTAB &theTab1, SCCOL &theCol2, SCROW &theRow2, SCTAB &theTab2)
Definition: refupdat.cxx:188
bool HasLink(std::u16string_view rDoc, std::u16string_view rFilter, std::u16string_view rOptions) const
Definition: documen3.cxx:554
OUString getString() const
Definition: dociter.cxx:984
bool HasScenarioRange(SCTAB nTab, const ScRange &rRange) const
Definition: documen3.cxx:864
ScAddress aStart
Definition: address.hxx:499
SC_DLLPUBLIC void SetScenario(SCTAB nTab, bool bFlag)
Definition: documen3.cxx:426
SC_DLLPUBLIC bool IsTabProtected(SCTAB nTab) const
Definition: documen3.cxx:1906
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:42
bool FillSelectionList(std::vector< ScTypedStrData > &rStrings, const ScAddress &rPos) const
Tries to fill the passed collection with list validation entries.
Definition: validat.cxx:908
void GetFilterSelCount(SCSIZE &nSelected, SCSIZE &nTotal)
Definition: dbdata.cxx:934
ScUnoListenerCalls stores notifications to XModifyListener that can't be processed during BroadcastUn...
tools::Long AdjustRight(tools::Long nHorzMoveDelta)
Sheet / outlining (grouping) information.
SCROW Row() const
Definition: address.hxx:261
SC_DLLPUBLIC ScRangeName * GetRangeName() const
Definition: documen3.cxx:176
bool UpdateOutlineCol(SCCOL nStartCol, SCCOL nEndCol, SCTAB nTab, bool bShow)
Adapt Outline.
Definition: documen3.cxx:1408
SCSIZE Query(SCTAB nTab, const ScQueryParam &rQueryParam, bool bKeepSub)
Definition: documen3.cxx:1462
constexpr TypedWhichId< SvxLanguageItem > ATTR_CJK_FONT_LANGUAGE(115)
SC_DLLPUBLIC void SetTabProtection(SCTAB nTab, const ScTableProtection *pProtect)
Definition: documen3.cxx:1923
SC_DLLPUBLIC void DoMergeContents(SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow)
Definition: documen3.cxx:2031
FillDir
Definition: global.hxx:317
void SetSheetEvents(SCTAB nTab, std::unique_ptr< ScSheetEvents > pNew)
Definition: documen3.cxx:666
std::unique_ptr< ContentProperties > pData
bool HasHeader() const
Definition: dbdata.hxx:129
void ReservePatternCount(SCTAB nTab, SCCOL nCol, SCSIZE nReserve)
Definition: documen3.cxx:2124
SC_DLLPUBLIC bool IsActiveScenario(SCTAB nTab) const
Definition: documen3.cxx:877
sheet protection state container
SC_DLLPUBLIC void SetTabBgColor(SCTAB nTab, const Color &rColor)
Definition: documen3.cxx:455
ScScenarioFlags
Definition: global.hxx:235
void ResetMark()
Definition: markdata.cxx:85
bool IsAddressInRangeName(RangeNameScope eScope, const ScAddress &rAddress)
Definition: documen3.cxx:196
void CopyScenario(SCTAB nSrcTab, SCTAB nDestTab, bool bNewScenario=false)
Definition: documen3.cxx:808
sal_uIntPtr sal_uLong
long Long
constexpr TypedWhichId< SvxLanguageItem > ATTR_FONT_LANGUAGE(110)
Context for reference update during shifting, moving or copying of cell ranges.
constexpr::Color COL_AUTO(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
sal_Int64 n
SC_DLLPUBLIC ScDPCollection * GetDPCollection()
Definition: documen3.cxx:365
List of RefUpdate changes made to UNO objects during ScUpdateRefHint broadcast.
Definition: unoreflist.hxx:41
SC_DLLPUBLIC const ScDBData * GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const
Definition: documen3.cxx:338
void SC_DLLPUBLIC SetSortParam(const ScSortParam &rParam, SCTAB nTab)
Definition: documen3.cxx:2135
ScAddress aEnd
Definition: address.hxx:500
bool hasString() const
Definition: dociter.cxx:1015
void GetEmbedded(ScRange &rRange) const
Definition: documen3.cxx:1701
bool InsertNewRangeName(const OUString &rName, const ScAddress &rPos, const OUString &rExpr)
Insert a new named expression to the global scope.
Definition: documen3.cxx:218
SC_DLLPUBLIC bool CreateQueryParam(const ScRange &rRange, ScQueryParam &rQueryParam)
Definition: documen3.cxx:1479
SC_DLLPUBLIC ScRange GetRange(SCTAB nTab, const tools::Rectangle &rMMRect, bool bHiddenAsZero=true) const
Definition: documen3.cxx:1798
void Invalidate(sal_uInt16 nId)
const SCCOL MAXCOLCOUNT
Definition: address.hxx:63
void SetClipOptions(std::unique_ptr< ScClipOptions > pClipOptions)
Definition: documen3.cxx:2026
bool IsLinked(SCTAB nTab) const
Definition: documen3.cxx:485
SCSIZE GetPatternCount(SCTAB nTab, SCCOL nCol) const
Definition: documen3.cxx:2108
bool DoSubTotals(SCTAB nTab, ScSubTotalParam &rParam)
Definition: documen3.cxx:777
SC_DLLPUBLIC void Fill(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScProgress *pProgress, const ScMarkData &rMark, sal_uLong nFillCount, FillDir eFillDir=FILL_TO_BOTTOM, FillCmd eFillCmd=FILL_LINEAR, FillDateCmd eFillDateCmd=FILL_DAY, double nStepValue=1.0, double nMaxValue=1E307)
Definition: documen3.cxx:1153
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:494
ScFormulaCell * getFormulaCell()
Definition: dociter.hxx:238
bool HasAutoFilter(SCCOL nCol, SCROW nRow, SCTAB nTab)
Definition: documen3.cxx:1492
::std::map< SCTAB, const ScRangeName * > TabNameCopyMap
Map that stores non-managed pointers to ScRangeName instances.
Definition: rangenam.hxx:193
SfxHintId GetId() const
void SetRight(tools::Long v)
void ExtendDataArea(const ScDocument &rDoc)
Definition: dbdata.cxx:625
static sal_Int32 GetVbaDocumentEventId(ScSheetEventId nEvent)
Definition: sheetevents.cxx:58
constexpr TypedWhichId< ScMergeAttr > ATTR_MERGE(144)
void AddUnoRefChange(sal_Int64 nId, const ScRangeList &rOldRanges)
Definition: documen3.cxx:999
void SetString(SwCursor &rCursor, const OUString &rString)
bool HasAnySheetEventScript(ScSheetEventId nEvent, bool bWithVbaEvents=false) const
Definition: documen3.cxx:696
void Sort(SCTAB nTab, const ScSortParam &rSortParam, bool bKeepQuery, bool bUpdateRefs, ScProgress *pProgress, sc::ReorderParam *pUndo)
Sort a range of data.
Definition: documen3.cxx:1426
CellType getType() const
Definition: dociter.hxx:235
void GetMarkArea(ScRange &rRange) const
Definition: markdata.cxx:112
bool IsEmpty() const
OUString GetString(int nId)
SC_DLLPUBLIC void SetGrammar(formula::FormulaGrammar::Grammar eGram)
Definition: documen3.cxx:499
SC_DLLPUBLIC bool LinkExternalTab(SCTAB &nTab, const OUString &aDocTab, const OUString &aFileName, const OUString &aTabName)
Definition: documen3.cxx:568
void DoAutoOutline(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab)
Definition: documen3.cxx:759
void Reorder(const sc::ReorderParam &rParam)
Definition: table3.cxx:1763
tools::Long Left() const
ScClipParam & GetClipParam()
Definition: document.cxx:2541
void SetLeft(tools::Long v)
void UpdateReference(sc::RefUpdateContext &rCxt, ScDocument *pUndoDoc=nullptr, bool bIncludeDraw=true, bool bUpdateNoteCaptionPos=true)
Definition: documen3.cxx:1005
ScRange maSortRange
This sort range already takes into account the presence or absence of header row / column i...
Definition: sortparam.hxx:90
size_t SCSIZE
size_t typedef to be able to find places where code was changed from USHORT to size_t and is used to ...
Definition: address.hxx:44
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
SC_DLLPUBLIC void CopyUpdated(ScDocument *pPosDoc, ScDocument *pDestDoc)
From this document this method copies the cells of positions at which there are also cells in pPosDoc...
Definition: documen3.cxx:800
bool empty() const
Definition: rangenam.cxx:802
TableContainer maTabs
Definition: document.hxx:374
void SetAreaTab(SCTAB nTab)
Definition: markdata.cxx:164
int nCount
FillDateCmd
Definition: global.hxx:342
SC_DLLPUBLIC SCSIZE GetEntryCount() const
Definition: queryparam.cxx:119
tools::Long Bottom() const
static SfxViewShell * Current()
void SetChartListenerCollection(std::unique_ptr< ScChartListenerCollection >, bool bSetChartRangeLists)
Definition: documen3.cxx:412
bool ValidRange(const ScRange &rRange, SCCOL nMaxCol=MAXCOL, SCROW nMaxRow=MAXROW)
Definition: address.hxx:792
SC_DLLPUBLIC bool GetTable(const OUString &rName, SCTAB &rTab) const
Definition: document.cxx:259
SC_DLLPUBLIC ScExternalRefManager * GetExternalRefManager() const
Definition: documen3.cxx:623
SC_DLLPUBLIC const ScQueryEntry & GetEntry(SCSIZE n) const
Definition: queryparam.cxx:124
Walk through all cells in an area.
Definition: dociter.hxx:207
tools::Rectangle GetEmbeddedRect() const
Definition: documen3.cxx:1706
ScLinkMode
Definition: global.hxx:224
#define HMM_PER_TWIPS
Definition: global.hxx:92
SCTAB Tab() const
Definition: address.hxx:270
void SetRow(SCROW nRowP)
Definition: address.hxx:274
static sal_Int32 GetVbaSheetEventId(ScSheetEventId nEvent)
Definition: sheetevents.cxx:39
bool mbCutMode
Definition: clipparam.hxx:35
bool HasSheetEventScript(SCTAB nTab, ScSheetEventId nEvent, bool bWithVbaEvents=false) const
Definition: documen3.cxx:672
static AddressConvention extractRefConvention(const Grammar eGrammar)
void CopyTabProtection(SCTAB nTabSrc, SCTAB nTabDest)
Definition: documen3.cxx:1931
bool SetOutlineTable(SCTAB nTab, const ScOutlineTable *pNewOutline)
Definition: documen3.cxx:754
void GetName(OUString &rName) const
Definition: rangenam.hxx:110
tools::Long AdjustBottom(tools::Long nVertMoveDelta)
void MarkUsedExternalReferences()
Definition: documen3.cxx:637
static ScDocument * GetClipDoc()
Definition: scmod.cxx:617
void GetFilterEntries(SCCOL nCol, SCROW nRow, SCTAB nTab, ScFilterEntries &rFilterEntries)
Get a list of unique strings to use in filtering criteria.
Definition: documen3.cxx:1551
Stores the used instances of the FilterFormulaParser service implementations, mapped by the formula n...
SC_DLLPUBLIC void SetAllRangeNames(const std::map< OUString, std::unique_ptr< ScRangeName >> &rRangeMap)
Definition: documen3.cxx:121
bool GetPattern() const
SC_DLLPUBLIC SCCOL GetAllocatedColumnsCount(SCTAB nTab) const
Definition: documen3.cxx:2145
void ResetEmbedded()
Definition: documen3.cxx:1745
void PutInOrder(T &nStart, T &nEnd)
Definition: address.hxx:953
bool empty() const
Definition: rangelst.hxx:88
All current charts in the calc will be locked in constructor and unlocked in destructor.
Definition: chartlock.hxx:35
SC_DLLPUBLIC bool HasRowHeader(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab)
Definition: documen3.cxx:1530
SC_DLLPUBLIC const ScDocOptions & GetDocOptions() const
Definition: documen3.cxx:1939
bool HasCalcNotification(SCTAB nTab) const
Definition: documen3.cxx:714
A pretty assertion that checks that the relevant bits in the are not set on the document at entry an...
Definition: document.hxx:2656
constexpr TypedWhichId< SfxUInt32Item > ATTR_VALIDDATA(153)
ScDBDataPortion
Enum used to indicate which portion of the DBArea is to be considered.
Definition: dbdata.hxx:40
SC_DLLPUBLIC ScDocProtection * GetDocProtection() const
Definition: documen3.cxx:1882
void SetTab(SCTAB nTabP)
Definition: address.hxx:282
bool HasAnyCalcNotification() const
Definition: documen3.cxx:705
SC_DLLPUBLIC void SetScenarioData(SCTAB nTab, const OUString &rComment, const Color &rColor, ScScenarioFlags nFlags)
Definition: documen3.cxx:437
ScDocument * GetDocument()
Definition: tablink.cxx:573
sal_uInt16 char * pName
Definition: callform.cxx:57
std::unique_ptr< ScUnoRefList > EndUnoRefUndo()
Definition: documen3.cxx:993
void GetScenarioFlags(SCTAB nTab, ScScenarioFlags &rFlags) const
Definition: documen3.cxx:479
SC_DLLPUBLIC const ScRangeData * findByRange(const ScRange &rRange) const
Definition: rangenam.cxx:672
void Reorder(const sc::ReorderParam &rParam)
Definition: documen3.cxx:1439
FillCmd
Definition: global.hxx:325
void SetDBCollection(std::unique_ptr< ScDBCollection > pNewDBCollection, bool bRemoveAutoFilter=false)
Definition: documen3.cxx:275
const SCTAB SC_TAB_APPEND
Definition: address.hxx:83
SC_DLLPUBLIC bool HasPivotTable() const
Definition: documen3.cxx:360
#define STR_GLOBAL_RANGE_NAME
Definition: globalnames.hxx:15
SC_DLLPUBLIC const ScRangeList * GetScenarioRanges(SCTAB nTab) const
Definition: documen3.cxx:869
SC_DLLPUBLIC bool IsDefaultTabBgColor(SCTAB nTab) const
Definition: documen3.cxx:461
SC_DLLPUBLIC void GetRangeNameMap(std::map< OUString, ScRangeName * > &rRangeName)
Definition: documen3.cxx:146
int i
SvxSearchCmd GetCommand() const
UpdateRefMode meMode
update mode - insert/delete, copy, or move.
SC_DLLPUBLIC void SetActiveScenario(SCTAB nTab, bool bActive)
Definition: documen3.cxx:882
void GetFormulaEntries(ScTypedCaseStrSet &rStrings)
Entries for Formula auto input.
Definition: documen3.cxx:1657
sal_Int16 SCCOL
Definition: types.hxx:21
sal_uInt16 GetColWidth(SCCOL nCol, bool bHiddenAsZero=true) const
Definition: table2.cxx:3128
InsertDeleteFlags
Definition: global.hxx:157
void GetAutoFormatData(SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, ScAutoFormatData &rData)
Definition: documen3.cxx:1200
#define SC_MOD()
Definition: scmod.hxx:249
void ExtendPrintArea(OutputDevice *pDev, SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL &rEndCol, SCROW nEndRow) const
Find the maximum column position that contains printable data for the specified row range...
Definition: documen3.cxx:2101
SC_DLLPUBLIC void SetViewOptions(const ScViewOptions &rOpt)
Definition: documen3.cxx:1959
ScFormulaParserPool & GetFormulaParserPool() const
Returns the pool containing external formula parsers.
Definition: documen3.cxx:652
OUString GetAutoFillPreview(const ScRange &rSource, SCCOL nEndX, SCROW nEndY)
Definition: documen3.cxx:1176
size_t size() const
Definition: rangelst.hxx:89
SC_DLLPUBLIC SCCOL ClampToAllocatedColumns(SCTAB nTab, SCCOL nCol) const
Definition: documen3.cxx:2140
const ScRange & GetRange(sal_uInt16 n) const
Definition: address.hxx:816
void MarkScenario(SCTAB nSrcTab, SCTAB nDestTab, ScMarkData &rDestMark, bool bResetMark=true, ScScenarioFlags nNeededBits=ScScenarioFlags::NONE) const
Definition: documen3.cxx:852
ScDPObject * GetDPAtBlock(const ScRange &rBlock) const
Definition: documen3.cxx:391
void SetLink(SCTAB nTab, ScLinkMode nMode, const OUString &rDoc, const OUString &rFilter, const OUString &rOptions, const OUString &rTabName, sal_uLong nRefreshDelay)
Definition: documen3.cxx:546
bool GetBackward() const
void BroadcastUno(const SfxHint &rHint)
Definition: documen3.cxx:949
OUString GetLinkFlt(SCTAB nTab) const
Definition: documen3.cxx:518
void SetTop(tools::Long v)
void SetBottom(tools::Long v)
bool IsInExternalReferenceMarking() const
Definition: documen3.cxx:632
SC_DLLPUBLIC tools::Rectangle GetMMRect(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: documen3.cxx:1988
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
SC_DLLPUBLIC ScRangeData * findByIndex(sal_uInt16 i) const
Definition: rangenam.cxx:691
bool In(const ScAddress &) const
is Address& in Range?
Definition: address.hxx:732
std::set< ScTypedStrData, ScTypedStrData::LessCaseSensitive > ScTypedCaseStrSet
RangeNameScope
Definition: document.hxx:259
void GetSearchAndReplaceStart(const SvxSearchItem &rSearchItem, SCCOL &rCol, SCROW &rRow)
Definition: documen3.cxx:1214
SC_DLLPUBLIC void DoMerge(SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, bool bDeleteCaptions=true)
Definition: documen3.cxx:2068
const SCTAB MAXTAB
Definition: address.hxx:70
tools::Long Top() const
ScRangeList maRanges
Definition: clipparam.hxx:33
void GetArea(SCTAB &rTab, SCCOL &rCol1, SCROW &rRow1, SCCOL &rCol2, SCROW &rRow2) const
Definition: dbdata.cxx:300
ScRange maRange
Range of cells that are about to be moved for insert/delete/move modes.
void GetDataEntries(SCCOL nCol, SCROW nRow, SCTAB nTab, std::vector< ScTypedStrData > &rStrings, bool bLimit=false)
Entries for selection list listbox (no numbers/formulas)
Definition: documen3.cxx:1617
SCCOL Col() const
Definition: address.hxx:266
SC_DLLPUBLIC void GetFilterEntriesArea(SCCOL nCol, SCROW nStartRow, SCROW nEndRow, SCTAB nTab, bool bCaseSens, ScFilterEntries &rFilterEntries)
Entries for Filter dialog.
Definition: documen3.cxx:1603
void SetCalcNotification(SCTAB nTab)
Definition: documen3.cxx:721
SC_DLLPUBLIC const ScViewOptions & GetViewOptions() const
Definition: documen3.cxx:1953
tools::Long AdjustTop(tools::Long nVertMoveDelta)
void RemoveSubTotals(SCTAB nTab, ScSubTotalParam &rParam)
Definition: documen3.cxx:771
void AddUnoObject(SfxListener &rObject)
Definition: documen3.cxx:898
const OUString * GetScript(ScSheetEventId nEvent) const
Definition: sheetevents.cxx:99
void GetUpperCellString(SCCOL nCol, SCROW nRow, SCTAB nTab, OUString &rStr)
Definition: documen3.cxx:1471
SC_DLLPUBLIC void DoEmptyBlock(SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow)
Definition: documen3.cxx:2055
SC_DLLPUBLIC ScLkUpdMode GetLinkMode() const
Definition: document.hxx:2173
bool IsError() const
Definition: tablink.cxx:578
SC_DLLPUBLIC void GetScenarioData(SCTAB nTab, OUString &rComment, Color &rColor, ScScenarioFlags &rFlags) const
Definition: documen3.cxx:468
constexpr TypedWhichId< SvxLanguageItem > ATTR_CTL_FONT_LANGUAGE(120)
bool GetRowDirection() const
Stores global named database ranges.
Definition: dbdata.hxx:234
UpdateRefMode
Definition: global.hxx:309
SC_DLLPUBLIC Color GetTabBgColor(SCTAB nTab) const
Definition: documen3.cxx:448
constexpr TypedWhichId< ScMergeFlagAttr > ATTR_MERGE_FLAG(145)
void GetFilterSelCount(SCCOL nCol, SCROW nRow, SCTAB nTab, SCSIZE &nSelected, SCSIZE &nTotal)
Definition: documen3.cxx:1536
void SetEmbedded(const ScRange &rRange)
Definition: documen3.cxx:1739
sal_Int32 SCROW
Definition: types.hxx:17
void StopTemporaryChartLock()
Definition: documen3.cxx:406
bool CreateQueryParam(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScQueryParam &rQueryParam)
Definition: table3.cxx:3396
bool IsSubTotal() const
ScMF
Definition: attrib.hxx:34
SC_DLLPUBLIC void SetDocOptions(const ScDocOptions &rOpt)
Definition: documen3.cxx:1945
void SC_DLLPUBLIC GetSortParam(ScSortParam &rParam, SCTAB nTab)
Definition: documen3.cxx:2130
SC_DLLPUBLIC bool IsScenario(SCTAB nTab) const
Definition: documen3.cxx:432
void AutoFormat(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, sal_uInt16 nFormatNo, const ScMarkData &rMark)
Definition: documen3.cxx:1185
const OUString & GetUpperName() const
Definition: dbdata.hxx:122
SvBaseLink * pLink
static bool lcl_AddTwipsWhile(tools::Long &rTwips, tools::Long nStopTwips, SCROW &rPosY, SCROW nEndRow, const ScTable *pTable, bool bHiddenAsZero)
Similar to ScViewData::AddPixelsWhile(), but add height twips and only while result is less than nSto...
Definition: documen3.cxx:1755
SCTAB mnTabDelta
Amount and direction of movement in the sheet direction.
sal_uLong GetLinkRefreshDelay(SCTAB nTab) const
Definition: documen3.cxx:539
bool IsDocEditable() const
Definition: documen3.cxx:1900
void UpdateGrow(const ScRange &rArea, SCCOL nGrowX, SCROW nGrowY)
Definition: documen3.cxx:1140
const ScSheetEvents * GetSheetEvents(SCTAB nTab) const
Definition: documen3.cxx:659
static void MirrorRectRTL(tools::Rectangle &rRect)
Definition: drwlayer.cxx:2086
void EndListening(SfxBroadcaster &rBroadcaster, bool bRemoveAllDuplicates=false)
SC_DLLPUBLIC ScOutlineTable * GetOutlineTable(SCTAB nTab, bool bCreate=false)
Definition: documen3.cxx:736
void RemoveUnoObject(SfxListener &rObject)
Definition: documen3.cxx:906
bool UpdateOutlineRow(SCROW nStartRow, SCROW nEndRow, SCTAB nTab, bool bShow)
Definition: documen3.cxx:1417
void * p
void SetLanguage(LanguageType eLatin, LanguageType eCjk, LanguageType eCtl)
Definition: documen3.cxx:1972
SC_DLLPUBLIC OUString GetLinkTab(SCTAB nTab) const
Definition: documen3.cxx:532
sal_Int16 GetListType() const
Definition: validat.hxx:116
SC_DLLPUBLIC void GetQueryParam(ScQueryParam &rQueryParam) const
Definition: dbdata.cxx:409
bool TestRemoveSubTotals(SCTAB nTab, const ScSubTotalParam &rParam)
Definition: documen3.cxx:766
ScQueryConnect eConnect
Definition: queryentry.hxx:53
SvxSearchCmd
void SetRangeName(SCTAB nTab, std::unique_ptr< ScRangeName > pNew)
Definition: documen3.cxx:183
void ResetCalcNotifications()
Definition: documen3.cxx:728
bool SearchAndReplace(const SvxSearchItem &rSearchItem, SCCOL &rCol, SCROW &rRow, SCTAB &rTab, const ScMarkData &rMark, ScRangeList &rMatchedRanges, OUString &rUndoStr, ScDocument *pUndoDoc=nullptr)
Definition: documen3.cxx:1300
void AddUnoListenerCall(const css::uno::Reference< css::util::XModifyListener > &rListener, const css::lang::EventObject &rEvent)
Definition: documen3.cxx:977
ScRange & front()
Definition: rangelst.hxx:92
SC_DLLPUBLIC void SetDocProtection(const ScDocProtection *pProtect)
Definition: documen3.cxx:1887
tools::Long AdjustLeft(tools::Long nHorzMoveDelta)
SC_DLLPUBLIC const ScRangeData * GetRangeAtBlock(const ScRange &rBlock, OUString &rName, bool *pSheetLocal=nullptr) const
Definition: documen3.cxx:238
void PrepareQuery(SCTAB nTab, ScQueryParam &rQueryParam)
Definition: documen3.cxx:1451
SCROW GetRowMerge() const
Definition: attrib.hxx:69
bool HasSubTotalCells(const ScRange &rRange)
Definition: documen3.cxx:782
SC_DLLPUBLIC void SetExtDocOptions(std::unique_ptr< ScExtDocOptions > pNewOptions)
Definition: documen3.cxx:2021
bool GetTableSelect(SCTAB nTab) const
Definition: markdata.cxx:184
bool TestCopyScenario(SCTAB nSrcTab, SCTAB nDestTab) const
Definition: documen3.cxx:888
const ScDBData * GetDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, ScDBDataPortion ePortion) const
Definition: documen3.cxx:322
std::vector< ScTypedStrData > maStrData
SC_DLLPUBLIC void GetLanguage(LanguageType &rLatin, LanguageType &rCjk, LanguageType &rCtl) const
Definition: documen3.cxx:1965
This struct stores general clipboard parameters associated with a ScDocument instance created in clip...
Definition: clipparam.hxx:29
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.
ScSheetEventId
Definition: sheetevents.hxx:27
sal_uInt16 GetRowHeight(SCROW nRow, SCROW *pStartRow, SCROW *pEndRow, bool bHiddenAsZero=true) const
Definition: table2.cxx:3226
SC_DLLPUBLIC void GetAllTabRangeNames(ScRangeName::TabNameCopyMap &rRangeNames) const
Get all range names that are local to each table.
Definition: documen3.cxx:102
void RefreshDirtyTableColumnNames()
Definition: documen3.cxx:354
aStr
bool ValidTab(SCTAB nTab)
Definition: address.hxx:104
SC_DLLPUBLIC bool insert(ScRangeData *p, bool bReuseFreeIndex=true)
Insert object into set.
Definition: rangenam.cxx:807
Each instance of this struct represents a single filtering criteria.
Definition: queryentry.hxx:32
tools::Long Right() const
Strings (and string results if InsertDeleteFlags::FORMULA is not set).
void BeginUnoRefUndo()
Definition: documen3.cxx:987
bool bIsClip
Definition: document.hxx:489
sal_Int16 SCTAB
Definition: types.hxx:22
void SetPoolDefaultItem(const SfxPoolItem &)
SC_DLLPUBLIC const ScTableProtection * GetTabProtection(SCTAB nTab) const
Definition: documen3.cxx:1915
std::unique_ptr< ScExternalRefManager > pExternalRefMgr
Definition: document.hxx:406
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo