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