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