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