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