21#include <document.hxx>
23#include <tokenarray.hxx>
40#include <osl/file.hxx>
62#include <com/sun/star/document/MacroExecMode.hpp>
63#include <com/sun/star/document/UpdateDocMode.hpp>
69using ::std::unique_ptr;
70using ::com::sun::star::uno::Any;
78#define SRCDOC_LIFE_SPAN 30000
79#define SRCDOC_SCAN_INTERVAL 1000*30
83class TabNameSearchPredicate
86 explicit TabNameSearchPredicate(
const OUString& rSearchName) :
98 OUString maSearchName;
101class FindSrcFileByName
104 explicit FindSrcFileByName(
const OUString& rMatchName) :
105 mrMatchName(rMatchName)
115 const OUString& mrMatchName;
118class NotifyLinkListener
133struct UpdateFormulaCell
157class RemoveFormulaCell
161 void operator() (pair<const sal_uInt16, ScExternalRefManager::RefCellSet>& r)
const
169class ConvertFormulaToStatic
172 explicit ConvertFormulaToStatic(
ScDocument* pDoc) : mpDoc(pDoc) {}
183 mpDoc->SetValue(aPos, pCell->
GetValue());
211 if (!
p->IsExternalRef())
214 if (
p->GetIndex() == nFileId)
220class EraseRangeByIterator
224 explicit EraseRangeByIterator(
ScRangeName& rRanges) : mrRanges(rRanges) {}
235void removeRangeNamesBySrcDoc(
ScRangeName& rRanges, sal_uInt16 nFileId)
238 vector<ScRangeName::const_iterator>
v;
239 for (; itr != itrEnd; ++itr)
241 if (hasRefsToSrcDoc(*itr->second, nFileId))
244 for_each(
v.begin(),
v.end(), EraseRangeByIterator(rRanges));
250 : mbReferenced( true )
262 maCachedRanges.RemoveAll();
268 mbReferenced = bReferenced;
279 RowsDataType::iterator itrRow = maRows.find(nRow);
280 if (itrRow == maRows.end())
283 pair<RowsDataType::iterator, bool> res = maRows.emplace(
298 rRow.emplace(nCol, aCell);
300 setCachedCell(nCol, nRow);
305 RowsDataType::const_iterator itrTable = maRows.find(nRow);
306 if (itrTable == maRows.end())
309 return getEmptyOrNullToken(nCol, nRow);
313 RowDataType::const_iterator itrRow = rRowData.find(nCol);
314 if (itrRow == rRowData.end())
317 return getEmptyOrNullToken(nCol, nRow);
320 const Cell& rCell = itrRow->second;
329 RowsDataType::const_iterator itrRow = maRows.find(nRow);
330 return itrRow != maRows.end();
333template<
typename P >
337 aRows.reserve(maRows.size());
338 for (
const auto& rEntry : maRows)
339 if (predicate(rEntry))
340 aRows.push_back(rEntry.first);
343 ::std::sort(aRows.begin(), aRows.end());
350 [nLow, nHigh](std::pair<SCROW, RowDataType> rEntry) {
return (nLow <= rEntry.first && rEntry.first <= nHigh); });
355 getAllRows(rRows, [](std::pair<SCROW, RowDataType>) {
return true; } );
360 ::std::pair< SCROW, SCROW > aRange( 0, 0 );
361 if( !maRows.empty() )
364 auto itMinMax = std::minmax_element(maRows.begin(), maRows.end(),
365 [](
const RowsDataType::value_type&
a,
const RowsDataType::value_type& b) { return a.first < b.first; });
366 aRange.first = itMinMax.first->first;
367 aRange.second = itMinMax.second->first + 1;
372template<
typename P >
375 RowsDataType::const_iterator itrRow = maRows.find(nRow);
376 if (itrRow == maRows.end())
382 aCols.reserve(rRowData.size());
383 for (
const auto& rCol : rRowData)
385 aCols.push_back(rCol.first);
388 ::std::sort(aCols.begin(), aCols.end());
394 getAllCols(nRow, rCols,
395 [nLow, nHigh](std::pair<SCCOL, Cell> rCol) {
return nLow <= rCol.first && rCol.first <= nHigh; } );
400 getAllCols(nRow, rCols, [](std::pair<SCCOL, Cell>) {
return true; } );
405 ::std::pair< SCCOL, SCCOL > aRange( 0, 0 );
407 RowsDataType::const_iterator itrRow = maRows.find( nRow );
408 if (itrRow == maRows.end())
413 if( !rRowData.empty() )
416 auto itMinMax = std::minmax_element(rRowData.begin(), rRowData.end(),
417 [](
const RowDataType::value_type&
a,
const RowDataType::value_type& b) { return a.first < b.first; });
418 aRange.first = itMinMax.first->first;
419 aRange.second = itMinMax.second->first + 1;
426 for (
const auto& rRow : maRows)
429 for (
const auto& rCol : rRowData)
431 const Cell& rCell = rCol.second;
439 return maCachedRanges.Contains(
ScRange(nCol1, nRow1, 0, nCol2, nRow2, 0));
444 setCachedCellRange(nCol, nRow, nCol, nRow);
449 ScRange aRange(nCol1, nRow1, 0, nCol2, nRow2, 0);
450 maCachedRanges.Join(aRange);
460 return maCachedRanges.Contains(
ScRange(nCol, nRow, 0, nCol, nRow, 0));
466 if (isInCachedRanges(nCol, nRow))
475 maUpperName(rUpper), maRealName(rReal)
495 DocDataType::const_iterator itrDoc =
maDocs.find(nFileId);
496 if (itrDoc ==
maDocs.end())
502 const DocItem& rDoc = itrDoc->second;
517 DocDataType::const_iterator itrDoc =
maDocs.find(nFileId);
518 if (itrDoc ==
maDocs.end())
524 const DocItem& rDoc = itrDoc->second;
535 sal_uInt16 nFileId,
const OUString& rTabName,
SCCOL nCol,
SCROW nRow, sal_uInt32* pnFmtIndex)
539 DocDataType::const_iterator itrDoc =
maDocs.find(nFileId);
540 if (itrDoc ==
maDocs.end())
546 const DocItem& rDoc = itrDoc->second;
561 return pTableData->getCell(nCol, nRow, pnFmtIndex);
565 sal_uInt16 nFileId,
const OUString& rTabName,
const ScRange& rRange)
569 DocDataType::iterator itrDoc =
maDocs.find(nFileId);
570 if (itrDoc ==
maDocs.end())
574 DocItem& rDoc = itrDoc->second;
589 size_t nTabFirstId = itrTabId->second;
590 size_t nTabLastId = nTabFirstId + nTab2 - nTab1;
591 if (nTabLastId >= rDoc.
maTables.size())
595 ScRange aCacheRange( nCol1, nRow1,
static_cast<SCTAB>(nTabFirstId), nCol2, nRow2,
static_cast<SCTAB>(nTabLastId));
597 RangeArrayMap::const_iterator itrRange = rDoc.
maRangeArrays.find( aCacheRange);
600 return itrRange->second;
602 std::unique_ptr<ScRange> pNewRange;
604 bool bFirstTab =
true;
605 for (
size_t nTab = nTabFirstId; nTab <= nTabLastId; ++nTab)
611 SCCOL nDataCol1 = nCol1, nDataCol2 = nCol2;
612 SCROW nDataRow1 = nRow1, nDataRow2 = nRow2;
614 if (!pTab->isRangeCached(nDataCol1, nDataRow1, nDataCol2, nDataRow2))
620 SCSIZE nMatrixColumns =
static_cast<SCSIZE>(nDataCol2-nDataCol1+1);
621 SCSIZE nMatrixRows =
static_cast<SCSIZE>(nDataRow2-nDataRow1+1);
626 pTab->getAllRows(aRows, nDataRow1, nDataRow2);
637 SCSIZE nMatCols, nMatRows;
638 xMat->GetDimensions( nMatCols, nMatRows);
639 if (nMatCols != nMatrixColumns || nMatRows != nMatrixRows)
648 else if ((nCol1 == 0 && nCol2 ==
MAXCOL) || (nRow1 == 0 && nRow2 ==
MAXROW))
650 nDataRow1 = aRows.front();
651 nDataRow2 = aRows.back();
652 SCCOL nMinCol = std::numeric_limits<SCCOL>::max();
653 SCCOL nMaxCol = std::numeric_limits<SCCOL>::min();
654 for (
const auto& rRow : aRows)
657 pTab->getAllCols(rRow, aCols, nDataCol1, nDataCol2);
660 nMinCol = std::min( nMinCol, aCols.front());
661 nMaxCol = std::max( nMaxCol, aCols.back());
668 nMatrixColumns =
static_cast<SCSIZE>(nMaxCol-nMinCol+1);
669 nMatrixRows =
static_cast<SCSIZE>(nDataRow2-nDataRow1+1);
670 xMat =
new ScMatrix( nMatrixColumns, nMatrixRows);
671 xMat->GetDimensions( nMatCols, nMatRows);
672 if (nMatCols == nMatrixColumns && nMatRows == nMatrixRows)
685 for (
SCROW nRow : aRows)
688 pTab->getAllCols(nRow, aCols, nDataCol1, nDataCol2);
689 for (
SCCOL nCol : aCols)
691 TokenRef pToken = pTab->getCell(nCol, nRow);
696 SCSIZE nC = nCol - nDataCol1, nR = nRow - nDataRow1;
697 switch (pToken->GetType())
700 xMat->PutDouble(pToken->GetDouble(), nC, nR);
703 xMat->PutString(pToken->GetString(), nC, nR);
712 pArray->AddOpCode(
ocSep);
716 pArray = std::make_shared<ScTokenArray>(
mrDoc);
717 pArray->AddToken(aToken);
722 pNewRange.reset(
new ScRange(nDataCol1, nDataRow1, nTab, nDataCol2, nDataRow2, nTab));
724 pNewRange->ExtendTo(
ScRange(nDataCol1, nDataRow1, nTab, nDataCol2, nDataRow2, nTab));
729 if (pNewRange && *pNewRange != aCacheRange)
744 RangeNameMap::const_iterator itr = rMap.find(
746 if (itr == rMap.end())
762 rMap.emplace(aUpperName, pArray);
776 return rMap.count(aUpperName) > 0;
812 pTableData = std::make_shared<Table>();
814 pTableData->setCell(nCol, nRow, pToken, nFmtIndex);
815 pTableData->setCachedCell(nCol, nRow);
834 const OUString& rFirstTabName =
rData.front().maTableName;
835 TableNameIndexMap::const_iterator itrTabName = rDoc.
findTableNameIndex( rFirstTabName);
842 size_t nTabFirstId = itrTabName->second;
845 size_t i = nTabFirstId;
846 for (
const auto& rItem :
rData)
850 pTabData = std::make_shared<Table>();
853 SCSIZE nMatCols, nMatRows;
854 pMat->GetDimensions( nMatCols, nMatRows);
873 pMat->ExecuteOperation(std::pair<size_t, size_t>(0, 0),
874 std::pair<size_t, size_t>(nRow2-nRow1, nCol2-nCol1),
875 std::move(aDoubleFunc), std::move(aBoolFunc), std::move(aStringFunc), std::move(aEmptyFunc));
877 pTabData->setCachedCellRange(nCol1, nRow1, nCol2, nRow2);
883 SAL_WARN(
"sc.ui",
"ScExternalRefCache::setCellRangeData - matrix size mismatch");
884 if (nMatCols != 1 || nMatRows != 1)
885 SAL_WARN(
"sc.ui",
"ScExternalRefCache::setCellRangeData - not a one element matrix");
889 SAL_WARN(
"sc.ui",
"ScExternalRefCache::setCellRangeData - matrix error value is " <<
static_cast<int>(nErr) <<
890 (nErr == FormulaError::MatrixSize ?
", ok" :
", not ok"));
897 ScRange aCacheRange( nCol1, nRow1,
static_cast<SCTAB>(nTabFirstId), nCol2, nRow2,
static_cast<SCTAB>(nTabLastId));
913 ScExternalRefCache::TableNameIndexMap::const_iterator itr = rMap.find(rName);
914 if (itr == rMap.end())
917 rIndex = itr->second;
923 ScExternalRefCache::TableNameIndexMap::const_iterator itr =
findTableNameIndex(rTabName);
927 rIndex = itr->second;
932OUString getFirstSheetName()
943 const OUString& rBaseName)
949 size_t n = rTabNames.size();
954 vector<TableName> aNewTabNames;
955 aNewTabNames.reserve(
n);
956 for (
const auto& rTabName : rTabNames)
959 aNewTabNames.push_back(aNameItem);
965 vector<TableTypeRef> aNewTables(
n);
966 for (
size_t i = 0;
i <
n; ++
i)
978 for (
size_t i = 0;
i <
n; ++
i)
985 if (!rBaseName.isEmpty() && pDoc->
maTableNames.size() == 1)
987 OUString aSheetName = getFirstSheetName();
1001 const OUString& rTabName )
const
1004 TableNameIndexMap::const_iterator itrTabName = maTableNameIndex.find( aTabNameUpper);
1005 if (itrTabName != maTableNameIndex.end())
1011 if (maSingleTableNameAlias.isEmpty() || maTableNameIndex.size() != 1)
1018 return maTableNameIndex.begin();
1025 if (maSingleTableNameAlias.isEmpty() || maTableNames.size() != 1)
1029 rTabName = maSingleTableNameAlias;
1034 rTabName = maTableNames[0].maRealName;
1041 sal_uInt16 nFileId )
const
1043 bool bFound = rSrcDoc.
GetTable( rTabName, rTab);
1050 OUString aTabName( rTabName);
1052 bFound = rSrcDoc.
GetTable( aTabName, rTab);
1061 if( nCacheId < pDoc->maTableNames.size() )
1062 return pDoc->maTableNames[ nCacheId ].maRealName;
1074 rTabNames.reserve(
n);
1076 rTabNames.push_back(rTableName.maRealName);
1085 vector<TableName>::const_iterator itrBeg = pDoc->
maTableNames.begin();
1086 vector<TableName>::const_iterator itrEnd = pDoc->
maTableNames.end();
1088 vector<TableName>::const_iterator itrStartTab = ::std::find_if( itrBeg, itrEnd,
1089 TabNameSearchPredicate( rStartTabName));
1090 if (itrStartTab == itrEnd)
1093 vector<TableName>::const_iterator itrEndTab = ::std::find_if( itrBeg, itrEnd,
1094 TabNameSearchPredicate( rEndTabName));
1095 if (itrEndTab == itrEnd)
1098 size_t nStartDist = ::std::distance( itrBeg, itrStartTab);
1099 size_t nEndDist = ::std::distance( itrBeg, itrEndTab);
1100 return nStartDist <= nEndDist ? static_cast<SCTAB>(nEndDist - nStartDist + 1) : -
static_cast<SCTAB>(nStartDist - nEndDist + 1);
1108 using ::std::unique;
1110 vector<sal_uInt32> aNumFmts;
1111 for (
const auto& rEntry :
maDocs)
1113 const vector<TableTypeRef>& rTables = rEntry.second.maTables;
1119 pTab->getAllNumberFormats(aNumFmts);
1124 sort(aNumFmts.begin(), aNumFmts.end());
1125 aNumFmts.erase(unique(aNumFmts.begin(), aNumFmts.end()), aNumFmts.end());
1126 rNumFmts.swap(aNumFmts);
1135 for (
auto& rxTab : pDocItem->
maTables)
1138 rxTab->setReferenced(
true);
1152 size_t nStop = ::std::min(
nIndex + nSheets, pDoc->
maTables.size());
1158 if (!pTab->isReferenced())
1160 pTab->setReferenced(
true);
1177 for (
auto& rEntry :
maDocs)
1180 for (
auto& rxTab : rDocItem.
maTables)
1183 rxTab->setReferenced(
true);
1190 auto itrMax = std::max_element(
maDocs.begin(),
maDocs.end(),
1191 [](
const DocDataType::value_type&
a,
const DocDataType::value_type& b) { return a.first < b.first; });
1192 if (itrMax !=
maDocs.end())
1193 nDocs = itrMax->first + 1;
1196 for (
auto& [nFileId, rDocItem] :
maDocs)
1198 size_t nTables = rDocItem.maTables.size();
1201 rDocReferenced.
maTables.resize( nTables,
true);
1202 for (
size_t i=0;
i < nTables; ++
i)
1207 xTab->setReferenced(
false);
1225 size_t nTables = rTables.size();
1233 while (
i < nTables && rTables[
i])
1251 size_t nSize = rTables.size();
1252 for (
size_t i=0;
i < nSize; ++
i)
1266 const std::vector<TableTypeRef>& rTables = pDocItem->
maTables;
1267 for (
size_t nTab = 0, nTabCount = rTables.size(); nTab < nTabCount; ++nTab)
1273 std::vector<SCROW> aRows;
1274 pTab->getAllRows(aRows);
1275 for (
SCROW nRow : aRows)
1277 std::vector<SCCOL> aCols;
1278 pTab->getAllCols(nRow, aCols);
1279 for (
SCCOL nCol : aCols)
1281 rSet.set(rSrcDoc, nTab, nCol, nRow,
true);
1288 mbAllReferenced(false)
1297 mbAllReferenced =
false;
1303 mbAllReferenced =
true;
1312 mbAllReferenced =
true;
1318 if (!pDoc || nTabIndex >= pDoc->
maTables.size())
1325 bool bCreateNew,
size_t* pnIndex,
const OUString* pExtUrl)
1331 const size_t nNotAvailable =
static_cast<size_t>(
static_cast<sal_Int32
>( -1));
1336 if (pnIndex) *pnIndex = nNotAvailable;
1346 if( pnIndex ) *pnIndex =
nIndex;
1355 if (pnIndex) *pnIndex = nNotAvailable;
1366 const OUString aSheetName( getFirstSheetName());
1381 if( pnIndex ) *pnIndex =
nIndex;
1384 rDoc.
maTableNames.emplace_back(aTabNameUpper, rTabName);
1404 std::vector<TableTypeRef>& rTabs = pDocItem->
maTables;
1424 DocDataType::iterator itrDoc =
maDocs.find(nFileId);
1425 if (itrDoc ==
maDocs.end())
1428 pair<DocDataType::iterator, bool> res =
maDocs.emplace(
1438 return &itrDoc->second;
1464 OUString aFile, aFilter;
1475 if (*pCurFile == aFile)
1526 if (nError != FormulaError::NONE)
1540 OSL_FAIL(
"attempted to convert an unknown cell type.");
1564 std::unique_ptr<ScRange> pUsedRange;
1566 unique_ptr<ScTokenArray> pArray(
new ScTokenArray(rSrcDoc));
1567 bool bFirstTab =
true;
1568 vector<ScExternalRefCache::SingleRangeData>::iterator
1569 itrCache = rCacheData.begin(), itrCacheEnd = rCacheData.end();
1571 for (
SCTAB nTab = nTab1; nTab <= nTab2 && itrCache != itrCacheEnd; ++nTab, ++itrCache)
1574 SCCOL nDataCol1 = nCol1, nDataCol2 = nCol2;
1575 SCROW nDataRow1 = nRow1, nDataRow2 = nRow2;
1577 if (!rSrcDoc.
ShrinkToUsedDataArea( bShrunk, nTab, nDataCol1, nDataRow1, nDataCol2, nDataRow2,
false))
1583 pUsedRange->ExtendTo(
ScRange(nDataCol1, nDataRow1, 0, nDataCol2, nDataRow2, 0));
1585 pUsedRange.reset(
new ScRange(nDataCol1, nDataRow1, 0, nDataCol2, nDataRow2, 0));
1587 SCSIZE nMatrixColumns =
static_cast<SCSIZE>(nCol2-nCol1+1);
1588 SCSIZE nMatrixRows =
static_cast<SCSIZE>(nRow2-nRow1+1);
1599 SCSIZE nMatCols, nMatRows;
1600 xMat->GetDimensions( nMatCols, nMatRows);
1601 if (nMatCols == nMatrixColumns && nMatRows == nMatrixRows)
1605 else if ((nCol1 == 0 && nCol2 == rSrcDoc.
MaxCol()) || (nRow1 == 0 && nRow2 == rSrcDoc.
MaxRow()))
1610 nMatrixColumns =
static_cast<SCSIZE>(nDataCol2-nDataCol1+1);
1611 nMatrixRows =
static_cast<SCSIZE>(nDataRow2-nDataRow1+1);
1612 xMat =
new ScMatrix( nMatrixColumns, nMatrixRows);
1613 xMat->GetDimensions( nMatCols, nMatRows);
1614 if (nMatCols == nMatrixColumns && nMatRows == nMatrixRows)
1620 pArray->AddOpCode(
ocSep);
1623 pArray->AddToken(aToken);
1625 itrCache->mpRangeData = xMat;
1633 s.
SetCol(pUsedRange->aStart.Col());
1634 s.
SetRow(pUsedRange->aStart.Row());
1635 e.
SetCol(pUsedRange->aEnd.Col());
1636 e.
SetRow(pUsedRange->aEnd.Row());
1648 unique_ptr<ScTokenArray> pArray(
new ScTokenArray(rDoc));
1649 pArray->AddToken(aToken);
1654bool isLinkUpdateAllowedInDoc(
const ScDocument& rDoc)
1667 mbInReferenceMarking(false),
1668 mbUserInteractionEnabled(true),
1669 mbDocTimerEnabled(true),
1670 maSrcDocTimer(
"sc::ScExternalRefManager maSrcDocTimer" )
1692 sal_uInt16 nFileId,
const OUString& rTabName,
bool bCreateNew,
size_t* pnIndex,
const OUString* pExtUrl)
1706 mpMgr(rDoc.GetExternalRefManager()),
1716 mpMgr->mbUserInteractionEnabled = mbOldInteractionEnabled;
1736 return static_cast< sal_uInt16
>(
maSrcFiles.size() );
1741 bool bAllMarked =
false;
1744 if (!rLinkListeners.empty())
1787 pNewArray = std::make_shared<ScTokenArray>(
mrDoc);
1791 bool bTokenAdded =
false;
1792 switch (pToken->GetType())
1798 if (
SCTAB nCacheId = rRef.
Tab(); nCacheId >= 0)
1801 *pToken->GetSingleRef());
1802 pNewArray->AddToken(aNewToken);
1810 if (
SCTAB nCacheId = rRef.
Tab(); nCacheId >= 0)
1813 *pToken->GetDoubleRef());
1814 pNewArray->AddToken(aNewToken);
1823 pNewArray->AddToken(*pToken);
1827 pNewArray = rArray.
Clone();
1840void putCellDataIntoCache(
1842 sal_uInt16 nFileId,
const OUString& rTabName,
const ScAddress& rCell,
1849 rRefCache.
setCellData(nFileId, rTabName, rCell.
Col(), rCell.
Row(), pToken, nFmtIndex);
1866void putRangeDataIntoCache(
1868 sal_uInt16 nFileId,
const OUString& rTabName,
1869 const vector<ScExternalRefCache::SingleRangeData>& rCacheData,
1883 rRefCache.
getCacheTable(nFileId, rTabName,
true,
nullptr,
nullptr);
1885 pCacheTab->setCachedCellRange(
1914 vector<OUString> aTabNames;
1915 aTabNames.reserve(nTabCount);
1916 for (
SCTAB i = 0;
i < nTabCount; ++
i)
1920 aTabNames.push_back(aName);
1941 sal_uInt16 nFileId )
const
1947 sal_uInt16 nFileId,
const OUString& rTabName,
const ScAddress& rCell,
1980 putCellDataIntoCache(
maRefCache, pToken, nFileId, rTabName, rCell, pFmt);
1985 sal_uInt32 nFmtIndex = 0;
1987 nFileId, rTabName, rCell.
Col(), rCell.
Row(), &nFmtIndex);
2000 if (!isLinkUpdateAllowedInDoc(
mrDoc))
2024 SCCOL nDataCol1 = 0, nDataCol2 = pSrcDoc->
MaxCol();
2025 SCROW nDataRow1 = 0, nDataRow2 = pSrcDoc->
MaxRow();
2026 bool bData = pSrcDoc->
ShrinkToDataArea(nTab, nDataCol1, nDataRow1, nDataCol2, nDataRow2);
2027 if (!bData || rCell.
Col() < nDataCol1 || nDataCol2 < rCell.
Col() || rCell.
Row() < nDataRow1 || nDataRow2 < rCell.
Row())
2035 pCacheTab->setCachedCell(rCell.
Col(), rCell.
Row());
2044 putCellDataIntoCache(
maRefCache, pToken, nFileId, rTabName, rCell, pFmt);
2049 sal_uInt16 nFileId,
const OUString& rTabName,
const ScRange& rRange,
const ScAddress* pCurPos)
2061 vector<ScExternalRefCache::SingleRangeData> aCacheData;
2066 putRangeDataIntoCache(
maRefCache, pArray, nFileId, rTabName, aCacheData, rRange, aDataRange);
2086 vector<ScExternalRefCache::SingleRangeData> aCacheData;
2090 putRangeDataIntoCache(
maRefCache, pArray, nFileId, rTabName, aCacheData, rRange, aDataRange);
2095 sal_uInt16 nFileId,
const OUString& rName,
const ScAddress* pCurPos)
2102 OUString
aName = rName;
2138bool hasRangeName(
const ScDocument& rDoc,
const OUString& rName)
2143 return pRangeData !=
nullptr;
2155 if (hasRangeName(*pSrcDoc, rName))
2172 if (hasRangeName(*pSrcDoc, rName))
2183 RefCellMap::iterator itrFile =
maRefCells.find(nFileId);
2188 for_each(rRefCells.begin(), rRefCells.end(), UpdateFormulaCell());
2206void insertRefCellByIterator(
2207 const ScExternalRefManager::RefCellMap::iterator& itr,
ScFormulaCell* pCell)
2211 itr->second.insert(pCell);
2220 RefCellMap::iterator itr =
maRefCells.find(nFileId);
2224 pair<RefCellMap::iterator, bool> r =
maRefCells.emplace(
2225 nFileId, aRefCells);
2238 if (!pTemplateCell || !pCell)
2243 if (itr->second.find(pTemplateCell) != itr->second.end())
2244 insertRefCellByIterator(itr, pCell);
2254 [&pCell](
const RefCellMap::value_type& rEntry) { return rEntry.second.find(pCell) != rEntry.second.end(); });
2285 if (nFmtType != SvNumFormatType::UNDEFINED)
2316 vector<ScExternalRefCache::SingleRangeData>& rCacheData)
2321 if (!rSrcDoc.
GetTable(rTabName, nTab1))
2324 pArray = std::make_shared<ScTokenArray>(rSrcDoc);
2333 vector<ScExternalRefCache::SingleRangeData> aCacheData;
2334 aCacheData.reserve(nTabSpan+1);
2335 aCacheData.emplace_back();
2338 for (
SCTAB i = 1;
i < nTabSpan + 1; ++
i)
2341 if (!rSrcDoc.
GetName(nTab1 + 1, aTabName))
2345 aCacheData.emplace_back();
2354 rCacheData.swap(aCacheData);
2359 sal_uInt16 nFileId,
const ScDocument& rSrcDoc, OUString& rName)
2378 bool bTokenAdded =
false;
2379 switch (pToken->GetType())
2387 *pToken->GetSingleRef());
2388 pNew->AddToken(aNewToken);
2398 *pToken->GetDoubleRef());
2399 pNew->AddToken(aNewToken);
2408 pNew->AddToken(*pToken);
2411 rName = pRangeData->
GetName();
2422 if (!isLinkUpdateAllowedInDoc(
mrDoc))
2430 if (pMedium && !pMedium->
GetName().isEmpty())
2433 if (pFileName->equalsIgnoreAsciiCase(pMedium->
GetName()))
2444 if (pFileName->equalsIgnoreAsciiCase(
aName))
2458 initDocInCache(
maRefCache, pSrcDoc, nFileId);
2468 DocShellMap::iterator itr =
maDocShells.find(nFileId);
2476 return &
static_cast<ScDocShell*
>(
p)->GetDocument();
2487 return &
static_cast<ScDocShell*
>(
p)->GetDocument();
2501 catch (
const css::uno::Exception&)
2516 if (!isLinkUpdateAllowedInDoc(
mrDoc))
2540 std::shared_ptr<const SfxFilter> pFilter = ScDocShell::Factory().GetFilterContainer()->GetFilter4FilterName(rFilter);
2555 if (!aOptions.isEmpty())
2576 pItem->
GetValue() != css::document::MacroExecMode::NEVER_EXECUTE)
2577 pSet->Put(
SfxUInt16Item( SID_MACROEXECMODE, css::document::MacroExecMode::USE_CONFIG));
2580 pSet->Put(
SfxUInt16Item( SID_UPDATEDOCMODE, css::document::UpdateDocMode::FULL_UPDATE));
2583 unique_ptr<SfxMedium> pMedium(
new SfxMedium(aFile, StreamMode::STD_READ, pFilter, std::move(pSet)));
2610 if (!pNewShell->
DoLoad(pMedium.release()))
2619 if (!aNew.isEmpty() && aNew != aOptions)
2635 initDocInCache(
maRefCache, &rSrcDoc, nFileId);
2641 if (rFile.isEmpty())
2647 if (osl::FileBase::getSystemPathFromFileURL(rFile, aPhysical)
2648 == osl::FileBase::E_None)
2672 OUString aFilter, aOptions;
2681 if (!bDeferFilterDetection)
2682 bDeferFilterDetection = !isLinkUpdateAllowedInDoc(
mrDoc);
2688 if (aFilter.isEmpty() && !bDeferFilterDetection)
2693 SAL_WARN(
"sc.ui",
"ScExternalRefManager::maybeLinkExternalFile: pLinkMgr==NULL");
2697 OSL_ENSURE(pFileName,
"ScExternalRefManager::maybeLinkExternalFile: file name pointer is NULL");
2699 (aFilter.isEmpty() && bDeferFilterDetection ?
nullptr : &aFilter));
2701 pLink->SetDoRefresh(
false);
2703 pLink->SetDoRefresh(
true);
2714 "sc.ui",
"ScExternalRefManager::addFilesToLinkManager: files overflow");
2716 for (sal_uInt16 nFileId = 0; nFileId < nSize; ++nFileId)
2722 if (maRelativeName.isEmpty())
2726 if (!maRealFileName.isEmpty())
2731 const OUString& rRelPath = maRelativeName;
2734 bool bWasAbs =
false;
2749 return "file:///tmp/document";
2774 if (rFile == pShell->
GetName())
2787 vector<SrcFileData>::const_iterator itr = find_if(itrBeg, itrEnd, FindSrcFileByName(rFile));
2791 return static_cast<sal_uInt16
>(
nId);
2795 aData.maFileName = rFile;
2797 return static_cast<sal_uInt16
>(
maSrcFiles.size() - 1);
2810 if (!
maSrcFiles[nFileId].maRealFileName.isEmpty())
2830 for (
auto nEntry : rExternFileIds)
2843 std::vector<OUString> aNames;
2847 aNames.push_back(
rData.maFileName);
2881template<
typename MapContainer>
2884 typename MapContainer::iterator itr = rMap.find(nFileId);
2885 if (itr != rMap.end())
2888 itr->second.maShell->DoClose();
2906 sal_uInt16 mnFileId;
2912 mrStrPool(rStrPool), mrRefCache(rRefCache), mnFileId(nFileId), mpCurCol(nullptr) {}
2914 virtual void startColumn(
ScColumn* pCol )
override
2924 virtual void execute(
SCROW nRow1,
SCROW nRow2,
bool bVal )
override
2926 if (!mpCurCol || !bVal)
2932 for (
SCROW nRow = nRow1; nRow <= nRow2; ++nRow)
2979 mpRefTab->setCachedCell(mpCurCol->
GetCol(), nRow);
2995 catch (
const css::uno::Exception& ) {}
2997 if (!xDocShell.
is())
3013 DocShellMap::iterator it =
maDocShells.find(nFileId);
3016 it->second.maShell->DoClose();
3017 it->second.maShell = xDocShell;
3040 RefCellMap::iterator itrRefs =
maRefCells.find(nFileId);
3046 for_each(aSet.begin(), aSet.end(), ConvertFormulaToStatic(&
mrDoc));
3055 removeRangeNamesBySrcDoc(*pRanges, nFileId);
3062 removeRangeNamesBySrcDoc(*pRanges, nFileId);
3071 LinkedDocMap::iterator itr =
maLinkedDocs.find(nFileId);
3073 itr->second =
false;
3083 if (
maSrcFiles[nFileId].maFilterName != rNewFilter)
3086 maSrcFiles[nFileId].maFilterName = rNewFilter;
3096 maSrcFiles[nFileId].maRelativeName = rRelUrl;
3103 maSrcFiles[nFileId].maFilterName = rFilterName;
3104 maSrcFiles[nFileId].maFilterOptions = rOptions;
3111 for (
auto& it : rEntry.second)
3118 rEntry.second.maShell->DoClose();
3134 OUString aAbsName = rSrcFile.maRealFileName;
3135 if (aAbsName.isEmpty())
3136 aAbsName = rSrcFile.maFileName;
3139 rBaseFileUrl, aAbsName);
3151 rSrcFile.maybeCreateRealFileName( aOwn );
3152 OUString aReal = rSrcFile.maRealFileName;
3153 if (!aReal.isEmpty())
3154 rSrcFile.maFileName = aReal;
3172 OSL_FAIL(
"insertion of new link listener list failed");
3191 rList.
erase(pListener);
3201 rEntry.second.erase(pListener);
3212 for_each(rList.
begin(), rList.
end(), NotifyLinkListener(nFileId,
eType));
3219 [nTimeOut](
const DocShellMap::value_type& rEntry) {
3221 sal_Int32 nSinceLastAccess = (tools::Time( tools::Time::SYSTEM ) - rEntry.second.maLastAccess).GetTime();
3222 return nSinceLastAccess >= nTimeOut;
3227 itr->second.maShell->DoClose();
3251 itr->second.swap(
aMap);
3254 SvNumberFormatterMergeMap::const_iterator itrNumFmt = rMap.find(nNumFmt);
3255 if (itrNumFmt != rMap.end())
3257 return itrNumFmt->second;
3267 if ( itr->second.maShell.get() == pShell )
3289 case SfxEventHintId::PrepareCloseDoc:
3292 VclMessageType::Warning, VclButtonsType::Ok,
3293 ScResId(STR_CLOSE_WITH_UNSAVED_REFS)));
3297 case SfxEventHintId::SaveDocDone:
3298 case SfxEventHintId::SaveAsDocDone:
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 ...
SfxApplication * SfxGetpApp()
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
OUString uppercase(const OUString &rStr, sal_Int32 nPos, sal_Int32 nCount) const
sal_uInt16 GetValue() const
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
INetURLObject smartRel2Abs(OUString const &rTheRelURIRef, bool &rWasAbsolute, bool bIgnoreFragment=false, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, bool bRelativeNonURIs=false, FSysStyle eStyle=FSysStyle::Detect) const
bool insertName(std::u16string_view rTheName, bool bAppendFinalSlash=false, sal_Int32 nIndex=LAST_SEGMENT, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
void InitBlockPosition(sc::ColumnBlockPosition &rBlockPos)
ScRefCellValue GetCellValue(SCROW nRow) const
ScDocument & GetDoc() const
sal_uInt32 GetNumberFormat(const ScInterpreterContext &rContext, SCROW nRow) const
const OUString & GetInitTabPrefix() const
Create before modifications of the document and destroy thereafter.
void SetDocumentModified()
static weld::Window * GetActiveDialogParent()
const ScDocument & GetDocument() const
static ScViewData * GetViewData()
static OUString GetOptions(const SfxMedium &rMedium)
static bool GetFilterName(const OUString &rFileName, OUString &rFilter, OUString &rOptions, bool bWithContent, bool bWithInteraction)
Returns the filter name and options from a file name.
SC_DLLPUBLIC sal_uInt32 GetNumberFormat(SCCOL nCol, SCROW nRow, SCTAB nTab) const
SC_DLLPUBLIC void EnableUserInteraction(bool bVal)
SC_DLLPUBLIC bool GetTable(const OUString &rName, SCTAB &rTab) const
bool ShrinkToDataArea(SCTAB nTab, SCCOL &rStartCol, SCROW &rStartRow, SCCOL &rEndCol, SCROW &rEndRow) const
Shrink a range to only include data area.
SC_DLLPUBLIC SCCOL MaxCol() const
SC_DLLPUBLIC SCROW MaxRow() const
SC_DLLPUBLIC void EnableUndo(bool bVal)
ScInterpreterContext & GetNonThreadedContext() const
bool ShrinkToUsedDataArea(bool &o_bShrunk, SCTAB nTab, SCCOL &rStartCol, SCROW &rStartRow, SCCOL &rEndCol, SCROW &rEndRow, bool bColumnsOnly, bool bStickyTopRow=false, bool bStickyLeftCol=false, ScDataAreaExtras *pDataAreaExtras=nullptr) const
Shrink a range to only include used data area.
SC_DLLPUBLIC ScExternalRefManager * GetExternalRefManager() const
void EnableExecuteLink(bool bVal)
ScExtDocOptions * GetExtDocOptions()
bool IsFunctionAccess() const
bool IsExecuteLinkEnabled() const
SfxObjectShell * GetDocumentShell() const
SC_DLLPUBLIC svl::SharedStringPool & GetSharedStringPool()
SC_DLLPUBLIC void SetExtDocOptions(std::unique_ptr< ScExtDocOptions > pNewOptions)
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
SC_DLLPUBLIC ScRangeName * GetRangeName(SCTAB nTab) const
SC_DLLPUBLIC const ScFormulaCell * GetFormulaCell(const ScAddress &rPos) const
SC_DLLPUBLIC sfx2::LinkManager * GetLinkManager()
SC_DLLPUBLIC bool GetName(SCTAB nTab, OUString &rName) const
void FillMatrix(ScMatrix &rMat, SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, svl::SharedStringPool *pPool=nullptr) const
SC_DLLPUBLIC SCTAB GetTableCount() const
Extended options held by an ScDocument containing additional settings for filters.
const ScExtDocSettings & GetDocSettings() const
void getAllRows(::std::vector< SCROW > &rRows, SCROW nLow, SCROW nHigh) const
Obtain a sorted vector of rows.
bool hasRow(SCROW nRow) const
SC_DLLPUBLIC TokenRef getCell(SCCOL nCol, SCROW nRow, sal_uInt32 *pnFmtIndex=nullptr) const
void getAllNumberFormats(::std::vector< sal_uInt32 > &rNumFmts) const
bool isRangeCached(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const
void setReferenced(bool bReferenced)
Set/clear referenced status flag only if current status is not REFERENCED_PERMANENT.
SC_DLLPUBLIC void setWholeTableCached()
Call this to mark the entire table "cached".
bool isReferenced() const
SC_DLLPUBLIC void setCell(SCCOL nCol, SCROW nRow, TokenRef const &pToken, sal_uLong nFmtIndex=0, bool bSetCacheRange=true)
Add cell value to the cache.
bool isInCachedRanges(SCCOL nCol, SCROW nRow) const
TokenRef getEmptyOrNullToken(SCCOL nCol, SCROW nRow) const
void setCachedCellRange(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
void setCachedCell(SCCOL nCol, SCROW nRow)
SC_DLLPUBLIC ::std::pair< SCROW, SCROW > getRowRange() const
Returns the half-open range of used rows in this table. Returns [0,0) if table is empty.
SC_DLLPUBLIC ::std::pair< SCCOL, SCCOL > getColRange(SCROW nRow) const
Returns the half-open range of used columns in the specified row. Returns [0,0) if row is empty.
void getAllCols(SCROW nRow, ::std::vector< SCCOL > &rCols, SCCOL nLow, SCCOL nHigh) const
Obtain a sorted vector of columns.
Cache table for external reference data.
bool setCacheDocReferenced(sal_uInt16 nFileId)
Set all tables of a document as referenced, used only during store-to-file.
bool isValidRangeName(sal_uInt16 nFileId, const OUString &rName) const
bool isDocInitialized(sal_uInt16 nFileId)
void clearCache(sal_uInt16 nFileId)
Clear all caches including the cache tables.
std::unordered_map< OUString, TokenArrayRef > RangeNameMap
std::shared_ptr< Table > TableTypeRef
void getAllTableNames(sal_uInt16 nFileId, ::std::vector< OUString > &rTabNames) const
ScExternalRefCache::TokenArrayRef getCellRangeData(sal_uInt16 nFileId, const OUString &rTabName, const ScRange &rRange)
Get a cached cell range data.
std::unordered_map< OUString, size_t > TableNameIndexMap
DocItem * getDocItem(sal_uInt16 nFileId) const
ScExternalRefCache::TokenArrayRef getRangeNameTokens(sal_uInt16 nFileId, const OUString &rName)
void setRangeNameTokens(sal_uInt16 nFileId, const OUString &rName, TokenArrayRef pArray)
void getAllNumberFormats(::std::vector< sal_uInt32 > &rNumFmts) const
struct ScExternalRefCache::ReferencedStatus maReferenced
void setAllCacheTableReferencedStati(bool bReferenced)
void setRangeName(sal_uInt16 nFileId, const OUString &rName)
void getAllCachedDataSpans(const ScDocument &rSrcDoc, sal_uInt16 nFileId, sc::ColumnSpanSet &rSet) const
Collect all cached non-empty cell positions, inferred directly from the cached data,...
bool setCacheTableReferenced(sal_uInt16 nFileId, const OUString &rTabName, size_t nSheets)
Set a table as referenced, used only during store-to-file.
const ScDocument & getDoc() const
void setCellRangeData(sal_uInt16 nFileId, const ScRange &rRange, const ::std::vector< SingleRangeData > &rData, const TokenArrayRef &pArray)
SCTAB getTabSpan(sal_uInt16 nFileId, const OUString &rStartTabName, const OUString &rEndTabName) const
void clearCacheTables(sal_uInt16 nFileId)
Clear all caches but keep the tables.
std::unordered_map< SCCOL, Cell > RowDataType
void addCacheDocToReferenced(sal_uInt16 nFileId)
ScExternalRefCache(const ScDocument &rDoc)
void initializeDoc(sal_uInt16 nFileId, const ::std::vector< OUString > &rTabNames, const OUString &rBaseName)
void addCacheTableToReferenced(sal_uInt16 nFileId, size_t nIndex)
::formula::FormulaTokenRef TokenRef
OUString getTableName(sal_uInt16 nFileId, size_t nCacheId) const
const OUString * getRealRangeName(sal_uInt16 nFileId, const OUString &rRangeName) const
bool getSrcDocTable(const ScDocument &rSrcDoc, const OUString &rTabName, SCTAB &rTab, sal_uInt16 nFileId) const
ScExternalRefCache::TokenRef getCellData(sal_uInt16 nFileId, const OUString &rTabName, SCCOL nCol, SCROW nRow, sal_uInt32 *pnFmtIndex)
Get a cached cell data at specified cell location.
bool areAllCacheTablesReferenced() const
const OUString * getRealTableName(sal_uInt16 nFileId, const OUString &rTabName) const
std::shared_ptr< ScTokenArray > TokenArrayRef
void setCellData(sal_uInt16 nFileId, const OUString &rTabName, SCCOL nCol, SCROW nRow, TokenRef const &pToken, sal_uLong nFmtIndex)
ScExternalRefCache::TableTypeRef getCacheTable(sal_uInt16 nFileId, size_t nTabIndex) const
void SetDoRefresh(bool b)
virtual void Closed() override
virtual ::sfx2::SvBaseLink::UpdateResult DataChanged(const OUString &rMimeType, const css::uno::Any &rValue) override
virtual ~ScExternalRefLink() override
virtual void Edit(weld::Window *pParent, const Link< SvBaseLink &, void > &rEndEditHdl) override
ScExternalRefLink()=delete
ScExternalRefManager * mpMgr
ApiGuard(const ScDocument &rDoc)
Base class for objects that need to listen to link updates.
virtual ~LinkListener() COVERITY_NOEXCEPT_FALSE=0
sal_uInt16 getExternalFileCount() const
sal_uInt32 getMappedNumberFormat(sal_uInt16 nFileId, sal_uInt32 nNumFmt, const ScDocument &rSrcDoc)
SCTAB getCachedTabSpan(sal_uInt16 nFileId, const OUString &rStartTabName, const OUString &rEndTabName) const
Get the span (distance+sign(distance)) of two sheets of a specified file.
void setFilterData(sal_uInt16 nFileId, const OUString &rFilterName, const OUString &rOptions)
Set the filter name and options if any for a given source document.
bool isFileLoadable(const OUString &rFile) const
Check if the file specified by the path is a legitimate file that exists & can be loaded.
DocShellMap maUnsavedDocShells
DocShells to unsaved but referenced documents.
DocShellMap maDocShells
Source document cache.
ScExternalRefCache maRefCache
cache of referenced ranges and names from source documents.
void insertRefCellFromTemplate(ScFormulaCell *pTemplateCell, ScFormulaCell *pCell)
Add a cell to reference the same files as the template cell.
void enableDocTimer(bool bEnable)
SfxObjectShellRef loadSrcDocument(sal_uInt16 nFileId, OUString &rFilter)
bool getSrcDocTable(const ScDocument &rSrcDoc, const OUString &rTabName, SCTAB &rTab, sal_uInt16 nFileId) const
ScExternalRefCache::TokenArrayRef getDoubleRefTokensFromSrcDoc(const ScDocument &rSrcDoc, const OUString &rTabName, ScRange &rRange, ::std::vector< ScExternalRefCache::SingleRangeData > &rCacheData)
Retrieve a range token array from a source document instance.
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
LinkListenerMap maLinkListeners
sal_uInt16 getExternalFileId(const OUString &rFile)
const OUString * getRealTableName(sal_uInt16 nFileId, const OUString &rTabName) const
LinkedDocMap maLinkedDocs
list of source documents that are managed by the link manager.
void markUsedExternalRefCells()
void maybeLinkExternalFile(sal_uInt16 nFileId, bool bDeferFilterDetection=false)
void resetSrcFileData(const OUString &rBaseFileUrl)
Re-generates relative names for all stored source files.
std::vector< sal_uInt16 > maConvertFileIdToUsedFileId
void getAllCachedNumberFormats(::std::vector< sal_uInt32 > &rNumFmts) const
Get all unique number format indices that are used in the cache tables.
ScExternalRefManager(ScDocument &rDoc)
void removeRefCell(ScFormulaCell *pCell)
Stop tracking a specific formula cell.
ScDocument & cacheNewDocShell(sal_uInt16 nFileId, SrcShell &rSrcShell)
Caller must ensure that the passed shell is not already stored.
void setAllCacheTableReferencedStati(bool bReferenced)
std::set< ScFormulaCell * > RefCellSet
virtual ~ScExternalRefManager() override
void addLinkListener(sal_uInt16 nFileId, LinkListener *pListener)
Register a new link listener to a specified external document.
virtual OUString getCacheTableName(sal_uInt16 nFileId, size_t nTabIndex) const override
void maybeCreateRealFileName(sal_uInt16 nFileId)
Try to create a "real" file name from the relative path.
bool setCacheTableReferenced(sal_uInt16 nFileId, const OUString &rTabName, size_t nSheets)
Set a table as referenced, used only during store-to-file.
bool hasExternalFile(sal_uInt16 nFileId) const
ScDocument * getSrcDocument(sal_uInt16 nFileId)
o3tl::sorted_vector< LinkListener * > LinkListeners
bool isValidRangeName(sal_uInt16 nFileId, const OUString &rName)
void setSkipUnusedFileIds(std::vector< sal_uInt16 > &pExternFileIds)
sal_uInt16 convertFileIdToUsedFileId(sal_uInt16 nFileId)
Reindex external file references to skip unused files, if skipping is enabled.
void switchSrcFile(sal_uInt16 nFileId, const OUString &rNewFile, const OUString &rNewFilter)
ScExternalRefCache::TableTypeRef getCacheTable(sal_uInt16 nFileId, size_t nTabIndex) const
Get a cache table instance for specified table and table index.
void refreshAllRefCells(sal_uInt16 nFileId)
const SrcFileData * getExternalFileData(sal_uInt16 nFileId) const
void disableSkipUnusedFileIds()
void removeLinkListener(sal_uInt16 nFileId, LinkListener *pListener)
Remove an existing link listener.
void updateAbsAfterLoad()
Replace the original URL with the real URL that was generated from the relative URL.
bool mbInReferenceMarking
Status whether in reference marking state.
RefCellMap maRefCells
List of referencing cells that may contain external names.
void markUsedByLinkListeners()
Mark all tables as referenced that are used by any LinkListener, used only during store-to-file.
const OUString * getRealRangeName(sal_uInt16 nFileId, const OUString &rRangeName) const
void addFilesToLinkManager()
Add all known external files to the LinkManager.
OUString getOwnDocumentName() const
bool hasCellExternalReference(const ScAddress &rCell)
const OUString * getExternalFileName(sal_uInt16 nFileId, bool bForceOriginal=false)
It returns a pointer to the name of the URI associated with a given external file ID.
ScExternalRefCache::TokenRef getSingleRefTokenFromSrcDoc(sal_uInt16 nFileId, ScDocument &rSrcDoc, const ScAddress &rPos, ScExternalRefCache::CellFormat *pFmt)
ScExternalRefCache::TokenArrayRef getDoubleRefTokens(sal_uInt16 nFileId, const OUString &rTabName, const ScRange &rRange, const ScAddress *pCurPos)
Get an array of tokens that consist of the specified external cell range.
void transformUnsavedRefToSavedRef(SfxObjectShell *pShell)
If in maUnsavedDocShells move it to maDocShells and create a correct external reference entry.
void convertToAbsName(OUString &rFile) const
Takes a flat file name, and convert it to an absolute URL path.
void insertRefCell(sal_uInt16 nFileId, const ScAddress &rCell)
void getAllCachedTableNames(sal_uInt16 nFileId, ::std::vector< OUString > &rTabNames) const
Returns a vector containing all (real) table names and cache tables of the specified file.
bool hasExternalData() const
void notifyAllLinkListeners(sal_uInt16 nFileId, LinkUpdateType eType)
Notify all listeners that are listening to a specified external document.
bool mbUserInteractionEnabled
Controls whether or not to allow user interaction.
std::vector< SrcFileData > maSrcFiles
List of external source document meta-data, used to keep track of external document identifiers.
void clearCache(sal_uInt16 nFileId)
void setRelativeFileName(sal_uInt16 nFileId, const OUString &rRelUrl)
Set a relative file path for the specified file ID.
std::vector< OUString > getAllCachedExternalFileNames() const
Get all cached external file names as an array.
bool isOwnDocument(std::u16string_view rFile) const
void fillCellFormat(sal_uLong nFmtIndex, ScExternalRefCache::CellFormat *pFmt) const
ScDocument * getInMemorySrcDocument(sal_uInt16 nFileId)
void storeRangeNameTokens(sal_uInt16 nFileId, const OUString &rName, const ScTokenArray &rArray)
@ OH_NO_WE_ARE_GOING_TO_DIE
ScExternalRefCache::TokenRef getSingleRefToken(sal_uInt16 nFileId, const OUString &rTabName, const ScAddress &rCell, const ScAddress *pCurPos, SCTAB *pTab, ScExternalRefCache::CellFormat *pFmt=nullptr)
void purgeStaleSrcDocument(sal_Int32 nTimeOut)
Purge those source document instances that have not been accessed for the specified duration.
ScExternalRefCache::TokenArrayRef getRangeNameTokens(sal_uInt16 nFileId, const OUString &rName, const ScAddress *pCurPos=nullptr)
Get an array of tokens corresponding with a specified name in a specified file.
void breakLink(sal_uInt16 nFileId)
static ScExternalRefCache::TokenArrayRef getRangeNameTokensFromSrcDoc(sal_uInt16 nFileId, const ScDocument &rSrcDoc, OUString &rName)
Retrieve range name token array from a source document instance.
bool refreshSrcDocument(sal_uInt16 nFileId)
static SC_DLLPUBLIC ::utl::TransliterationWrapper & GetTransliteration()
static SC_DLLPUBLIC OUString GetAbsDocName(const OUString &rFileName, const SfxObjectShell *pShell)
static SC_DLLPUBLIC const CharClass & getCharClass()
Matrix data type that can store values of mixed types.
std::function< void(size_t, size_t)> EmptyOpFunction
std::function< void(size_t, size_t, svl::SharedString)> StringOpFunction
std::function< void(size_t, size_t, double)> DoubleOpFunction
std::function< void(size_t, size_t, bool)> BoolOpFunction
void GetName(OUString &rName) const
SC_DLLPUBLIC ScRangeData * findByUpperName(const OUString &rName)
void erase(const ScRangeData &r)
SC_DLLPUBLIC const_iterator end() const
DataType::const_iterator const_iterator
SC_DLLPUBLIC const_iterator begin() const
std::unique_ptr< ScTokenArray > Clone() const
ScDocShell * GetDocShell() const
ScTabViewShell * GetViewShell() const
SfxEventHintId GetEventId() const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
void EndListening(SfxBroadcaster &rBroadcaster, bool bRemoveAllDuplicates=false)
const INetURLObject & GetURLObject() const
SfxItemSet * GetItemSet() const
const OUString & GetName() const
comphelper::EmbeddedObjectContainer & GetEmbeddedObjectContainer() const
static SfxObjectShell * GetNext(const SfxObjectShell &rPrev, const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
SfxMedium * GetMedium() const
bool DoLoad(SfxMedium *pMedium)
static SfxObjectShell * GetFirst(const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
const OUString & GetName() const
virtual void Invalidate(sal_uInt16 nId=0)
void SetTimeout(sal_uInt64 nTimeoutMs)
void SetInvokeHandler(const Link< Timer *, void > &rLink)
virtual void Start(bool bStartTimer=true) override
bool getUserAllowsLinkUpdate() const
const_iterator begin() const
size_type erase(const Value &x)
const_iterator end() const
std::pair< const_iterator, bool > insert(Value &&x)
Structure that stores segments of boolean flags per column, and perform custom action on those segmen...
void executeColumnAction(ScDocument &rDoc, ColumnAction &ac) const
void InsertFileLink(sfx2::SvBaseLink &, SvBaseLinkObjectType nFileType, std::u16string_view rFileNm, const OUString *pFilterNm=nullptr, const OUString *pRange=nullptr)
static bool GetDisplayNames(const SvBaseLink *, OUString *pType, OUString *pFile=nullptr, OUString *pLink=nullptr, OUString *pFilter=nullptr)
SharedString intern(const OUString &rStr)
OUString getString() const
FormulaError GetDoubleErrorValue(double fVal)
static std::unique_ptr< ScTokenArray > convertToTokenArray(ScDocument &rHostDoc, const ScDocument &rSrcDoc, ScRange &rRange, vector< ScExternalRefCache::SingleRangeData > &rCacheData)
static FormulaToken * convertToToken(ScDocument &rHostDoc, const ScDocument &rSrcDoc, ScRefCellValue &rCell)
#define SRCDOC_SCAN_INTERVAL
static std::unique_ptr< ScTokenArray > lcl_fillEmptyMatrix(const ScDocument &rDoc, const ScRange &rRange)
static void lcl_removeByFileId(sal_uInt16 nFileId, MapContainer &rMap)
static bool lcl_getStrictTableDataIndex(const ScExternalRefCache::TableNameIndexMap &rMap, const OUString &rName, size_t &rIndex)
IMPL_LINK(ScExternalRefManager, TimeOutHdl, Timer *, pTimer, void)
#define LINK(Instance, Class, Member)
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
const ContentProperties & rData
constexpr OUStringLiteral aData
SVL_DLLPUBLIC OUString simpleNormalizedMakeRelative(OUString const &baseUriReference, OUString const &uriReference)
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
UNOTOOLS_DLLPUBLIC bool Exists(OUString const &url)
UNOTOOLS_DLLPUBLIC bool IsFolder(OUString const &url)
HashMap_OWString_Interface aMap
OUString ScResId(TranslateId aId)
sal_uInt32 mnLinkCnt
Recursive counter for loading external documents.
individual cell within cached external ref table.
Represents data cached for a single external document.
TableNameIndexMap::const_iterator findTableNameIndex(const OUString &rTabName) const
bool getTableDataIndex(const OUString &rTabName, size_t &rIndex) const
::std::vector< TableTypeRef > maTables
The raw cache tables.
TableNameIndexMap maTableNameIndex
Table name to index map.
RangeNameMap maRangeNames
Range name cache.
::std::vector< TableName > maTableNames
Table name list in correct order, in both upper- and real-case.
NamePairMap maRealRangeNameMap
Upper- to real-case mapping for range names.
OUString maSingleTableNameAlias
Either the base name that was stored as sheet name for CSV files if sheet name is Sheet1,...
bool getSingleTableNameAlternative(OUString &rTabName) const
RangeArrayMap maRangeArrays
Token array cache for cell ranges.
bool mbAllTablesReferenced
::std::vector< bool > maTables
::std::vector< DocReferenced > DocReferencedVec
TableName(const OUString &rUpper, const OUString &rReal)
Source document meta-data container.
void maybeCreateRealFileName(std::u16string_view rOwnDocName)
OUString maRealFileName
original file name as loaded from the file.
OUString maRelativeName
file name created from the relative name.
Shell instance for a source document.
SfxObjectShellRef maShell
This is very similar to ScCellValue, except that it references the original value instead of copying ...
ScFormulaCell * getFormula() const
OUString getString(const ScDocument *pDoc) const
Retrieve string value.
Store parameters used in the ScDocument::SetString() method.
void setTextInput()
Call this whenever you need to unconditionally set input as text, no matter what the input is.
Single reference (one address) into the sheet.
::boost::intrusive_ptr< ScMatrix > ScMatrixRef
std::unordered_map< sal_uInt32, sal_uInt32 > SvNumberFormatterMergeMap