32 #include <osl/mutex.hxx>
37 #include <unordered_map>
38 #include <unordered_set>
61 virtual void Closed()
override;
62 virtual ::sfx2::SvBaseLink::UpdateResult
DataChanged(
63 const OUString& rMimeType,
const css::uno::Any &
rValue)
override;
91 explicit TableName(
const OUString& rUpper,
const OUString& rReal);
149 SC_DLLPUBLIC ::std::pair< SCROW, SCROW >
getRowRange()
const;
182 typedef std::unordered_map< OUString, size_t>
188 const OUString*
getRealTableName(sal_uInt16 nFileId,
const OUString& rTabName)
const;
189 const OUString*
getRealRangeName(sal_uInt16 nFileId,
const OUString& rRangeName)
const;
202 sal_uInt16 nFileId,
const OUString& rTabName,
SCCOL nCol,
SCROW nRow, sal_uInt32* pnFmtIndex);
212 sal_uInt16 nFileId,
const OUString& rTabName,
const ScRange& rRange);
215 void setRangeNameTokens(sal_uInt16 nFileId,
const OUString& rName, TokenArrayRef pArray);
217 void setRangeName(sal_uInt16 nFileId,
const OUString& rName);
219 void setCellData(sal_uInt16 nFileId,
const OUString& rTabName,
229 const TokenArrayRef& pArray);
232 void initializeDoc(sal_uInt16 nFileId, const ::std::vector<OUString>& rTabNames,
const OUString& rBaseName);
233 OUString
getTableName(sal_uInt16 nFileId,
size_t nCacheId)
const;
234 void getAllTableNames(sal_uInt16 nFileId, ::std::vector<OUString>& rTabNames)
const;
235 SCTAB getTabSpan( sal_uInt16 nFileId,
const OUString& rStartTabName,
const OUString& rEndTabName )
const;
278 void reset(
size_t nDocs );
288 size_t* pnIndex,
const OUString* pExtUrl);
312 hash = hash * 37 + s.
Tab();
313 hash = hash * 37 + s.
Col();
314 hash = hash * 37 + s.
Row();
315 hash = hash * 37 + e.
Tab();
316 hash = hash * 37 + e.
Col();
317 hash = hash * 37 + e.
Row();
323 typedef std::unordered_map<ScRange, TokenArrayRef, RangeHash>
RangeArrayMap;
351 TableNameIndexMap::const_iterator
findTableNameIndex(
const OUString& rTabName )
const;
369 typedef std::unordered_map<sal_uInt16, RefCellSet>
RefCellMap;
414 typedef std::unordered_map<sal_uInt16, SvNumberFormatterMergeMap>
NumFmtMap;
429 void maybeCreateRealFileName(
const OUString& rOwnDocName);
436 virtual OUString getCacheTableName(sal_uInt16 nFileId,
size_t nTabIndex)
const override;
475 size_t* pnIndex =
nullptr,
const OUString* pExtUrl =
nullptr);
483 void getAllCachedTableNames(sal_uInt16 nFileId, ::std::vector<OUString>& rTabNames)
const;
500 SCTAB getCachedTabSpan(
501 sal_uInt16 nFileId,
const OUString& rStartTabName,
const OUString& rEndTabName)
const;
509 void getAllCachedNumberFormats(::std::vector<sal_uInt32>& rNumFmts)
const;
511 sal_uInt16 getExternalFileCount()
const;
517 void markUsedByLinkListeners();
519 void markUsedExternalRefCells();
525 bool setCacheTableReferenced( sal_uInt16 nFileId,
const OUString& rTabName,
size_t nSheets );
526 void setAllCacheTableReferencedStati(
bool bReferenced );
534 void storeRangeNameTokens(sal_uInt16 nFileId,
const OUString& rName,
const ScTokenArray& rArray);
537 sal_uInt16 nFileId,
const OUString& rTabName,
const ScAddress& rCell,
554 sal_uInt16 nFileId,
const OUString& rTabName,
const ScRange& rRange,
const ScAddress* pCurPos);
568 sal_uInt16 nFileId,
const OUString& rName,
const ScAddress* pCurPos =
nullptr);
570 bool isValidRangeName(sal_uInt16 nFileId,
const OUString& rName);
572 OUString getOwnDocumentName()
const;
573 bool isOwnDocument(std::u16string_view rFile)
const;
581 void convertToAbsName(OUString& rFile)
const;
582 sal_uInt16 getExternalFileId(
const OUString& rFile);
597 const OUString* getExternalFileName(sal_uInt16 nFileId,
bool bForceOriginal =
false);
602 sal_uInt16 convertFileIdToUsedFileId(sal_uInt16 nFileId);
603 void setSkipUnusedFileIds(std::vector<sal_uInt16>& pExternFileIds);
604 void disableSkipUnusedFileIds();
610 std::vector<OUString> getAllCachedExternalFileNames()
const;
612 bool hasExternalFile(sal_uInt16 nFileId)
const;
613 bool hasExternalFile(
const OUString& rFile)
const;
614 const SrcFileData* getExternalFileData(sal_uInt16 nFileId)
const;
616 const OUString* getRealTableName(sal_uInt16 nFileId,
const OUString& rTabName)
const;
617 const OUString* getRealRangeName(sal_uInt16 nFileId,
const OUString& rRangeName)
const;
618 void clearCache(sal_uInt16 nFileId);
619 bool refreshSrcDocument(sal_uInt16 nFileId);
620 void breakLink(sal_uInt16 nFileId);
621 void switchSrcFile(sal_uInt16 nFileId,
const OUString& rNewFile,
const OUString& rNewFilter);
630 void setRelativeFileName(sal_uInt16 nFileId,
const OUString& rRelUrl);
640 void setFilterData(sal_uInt16 nFileId,
const OUString& rFilterName,
const OUString& rOptions);
644 bool hasExternalData()
const;
654 void resetSrcFileData(
const OUString& rBaseFileUrl);
659 void updateAbsAfterLoad();
674 void addLinkListener(sal_uInt16 nFileId, LinkListener* pListener);
680 void removeLinkListener(sal_uInt16 nFileId, LinkListener* pListener);
682 void removeLinkListener(LinkListener* pListener);
690 void notifyAllLinkListeners(sal_uInt16 nFileId, LinkUpdateType eType);
696 bool isFileLoadable(
const OUString& rFile)
const;
707 void insertRefCell(sal_uInt16 nFileId,
const ScAddress& rCell);
713 bool hasCellExternalReference(
const ScAddress& rCell);
715 void enableDocTimer(
bool bEnable );
718 void addFilesToLinkManager();
723 void refreshAllRefCells(sal_uInt16 nFileId);
727 bool getSrcDocTable(
const ScDocument& rSrcDoc,
const OUString& rTabName,
SCTAB& rTab, sal_uInt16 nFileId )
const;
749 ::std::vector<ScExternalRefCache::SingleRangeData>& rCacheData);
764 sal_uInt16 nFileId,
const ScDocument& rSrcDoc, OUString& rName);
766 ScDocument* getInMemorySrcDocument(sal_uInt16 nFileId);
767 ScDocument* getSrcDocument(sal_uInt16 nFileId);
773 ScDocument& cacheNewDocShell( sal_uInt16 nFileId, SrcShell& rSrcShell );
775 void maybeLinkExternalFile( sal_uInt16 nFileId,
bool bDeferFilterDetection =
false );
788 void maybeCreateRealFileName(sal_uInt16 nFileId);
796 void purgeStaleSrcDocument(sal_Int32 nTimeOut);
798 sal_uInt32 getMappedNumberFormat(sal_uInt16 nFileId, sal_uInt32 nNumFmt,
const ScDocument& rSrcDoc);
846 bool mbInReferenceMarking:1;
852 bool mbUserInteractionEnabled:1;
854 bool mbSkipUnusedFileIds =
false;
857 bool mbDocTimerEnabled:1;
std::unordered_map< sal_uInt16, SrcShell > DocShellMap
bool setCacheDocReferenced(sal_uInt16 nFileId)
Set all tables of a document as referenced, used only during store-to-file.
SC_DLLPUBLIC void setCell(SCCOL nCol, SCROW nRow, TokenRef const &pToken, sal_uLong nFmtIndex=0, bool bSetCacheRange=true)
Add cell value to the cache.
void initializeDoc(sal_uInt16 nFileId, const ::std::vector< OUString > &rTabNames, const OUString &rBaseName)
std::unordered_map< sal_uInt16, SvNumberFormatterMergeMap > NumFmtMap
void getAllTableNames(sal_uInt16 nFileId,::std::vector< OUString > &rTabNames) const
void clearCache(sal_uInt16 nFileId)
Clear all caches including the cache tables.
const OUString * getRealRangeName(sal_uInt16 nFileId, const OUString &rRangeName) const
#define DECL_LINK(Member, ArgType, RetType)
bool setCacheTableReferenced(sal_uInt16 nFileId, const OUString &rTabName, size_t nSheets)
Set a table as referenced, used only during store-to-file.
std::set< ScFormulaCell * > RefCellSet
virtual ~ScExternalRefLink() override
Source document meta-data container.
void getAllNumberFormats(::std::vector< sal_uInt32 > &rNumFmts) const
bool areAllCacheTablesReferenced() const
void setRangeNameTokens(sal_uInt16 nFileId, const OUString &rName, TokenArrayRef pArray)
SC_DLLPUBLIC void setWholeTableCached()
Call this to mark the entire table "cached".
std::unordered_map< sal_uInt16, RefCellSet > RefCellMap
Cache table for external reference data.
ScExternalRefManager * mpMgr
bool isValidRangeName(sal_uInt16 nFileId, const OUString &rName) const
bool mbOldInteractionEnabled
bool isDocInitialized(sal_uInt16 nFileId)
ScExternalRefLink()=delete
TableNameIndexMap::const_iterator findTableNameIndex(const OUString &rTabName) const
void getAllCols(SCROW nRow,::std::vector< SCCOL > &rCols, SCCOL nLow=0, SCCOL nHigh=MAXCOL) const
Obtain a sorted vector of columns.
ScRangeList maCachedRanges
Collection of individual cached ranges.
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.
css::uno::Any const & rValue
OUString maRealFileName
original file name as loaded from the file.
TableName(const OUString &rUpper, const OUString &rReal)
ScExternalRefCache::TokenArrayRef getCellRangeData(sal_uInt16 nFileId, const OUString &rTabName, const ScRange &rRange)
Get a cached cell range data.
std::unordered_map< SCROW, RowDataType > RowsDataType
ScExternalRefCache::TokenArrayRef getRangeNameTokens(sal_uInt16 nFileId, const OUString &rName)
bool containsUnsavedReferences() const
If we still contain unsaved files we should warn the user before saving.
::boost::intrusive_ptr< ScMatrix > ScMatrixRef
void setReferenced(bool bReferenced)
Set/clear referenced status flag only if current status is not REFERENCED_PERMANENT.
void setCellData(sal_uInt16 nFileId, const OUString &rTabName, SCCOL nCol, SCROW nRow, TokenRef const &pToken, sal_uLong nFmtIndex)
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 getAllNumberFormats(::std::vector< sal_uInt32 > &rNumFmts) const
::std::vector< DocReferenced > DocReferencedVec
void getAllRows(::std::vector< SCROW > &rRows, SCROW nLow=0, SCROW nHigh=MAXROW) const
Obtain a sorted vector of rows.
struct ScExternalRefCache::ReferencedStatus maReferenced
bool mbAllTablesReferenced
SCTAB getTabSpan(sal_uInt16 nFileId, const OUString &rStartTabName, const OUString &rEndTabName) const
TokenRef getEmptyOrNullToken(SCCOL nCol, SCROW nRow) const
bool isRangeCached(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const
Base class for objects that need to listen to link updates.
SC_DLLPUBLIC TokenRef getCell(SCCOL nCol, SCROW nRow, sal_uInt32 *pnFmtIndex=nullptr) const
OUString maRelativeName
file name created from the relative name.
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...
void Notify(ScModelObj &rModelObj, const ScRangeList &rChangeRanges, const OUString &rType=OUString("cell-change"), const css::uno::Sequence< css::beans::PropertyValue > &rProperties=css::uno::Sequence< css::beans::PropertyValue >())
std::unique_ptr< ScDocument, o3tl::default_delete< ScDocument > > ScDocumentUniquePtr
NamePairMap maRealRangeNameMap
Upper- to real-case mapping for range names.
void setCellRangeData(sal_uInt16 nFileId, const ScRange &rRange, const ::std::vector< SingleRangeData > &rData, const TokenArrayRef &pArray)
::std::vector< TableName > maTableNames
Table name list in correct order, in both upper- and real-case.
const OUString * getRealTableName(sal_uInt16 nFileId, const OUString &rTabName) const
bool isInReferenceMarking() const
Structure that stores segments of boolean flags per column, and perform custom action on those segmen...
std::unordered_map< OUString, OUString > NamePairMap
o3tl::sorted_vector< LinkListener * > LinkListeners
OUString maSingleTableNameAlias
Either the base name that was stored as sheet name for CSV files if sheet name is Sheet1...
::std::vector< TableTypeRef > maTables
The raw cache tables.
void clearCacheTables(sal_uInt16 nFileId)
Clear all caches but keep the tables.
DocShellMap maUnsavedDocShells
DocShells to unsaved but referenced documents.
Represents a single cached table in an external document.
OUString maTableName
This name must be in upper-case.
Shell instance for a source document.
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, not the cached range metadata stored separately in the Table.
std::unordered_map< sal_uInt16, DocItem > DocDataType
SfxObjectShellRef maShell
LinkListenerMap maLinkListeners
ScExternalRefCache::TableTypeRef getCacheTable(sal_uInt16 nFileId, size_t nTabIndex) const
RefCellMap maRefCells
List of referencing cells that may contain external names.
virtual void Edit(weld::Window *pParent, const Link< SvBaseLink &, void > &rEndEditHdl) override
std::vector< SrcFileData > maSrcFiles
List of external source document meta-data, used to keep track of external document identifiers...
individual cell within cached external ref table.
bool getSrcDocTable(const ScDocument &rSrcDoc, const OUString &rTabName, SCTAB &rTab, sal_uInt16 nFileId) const
::formula::FormulaTokenRef TokenRef
void SetDoRefresh(bool b)
std::unordered_map< ScRange, TokenArrayRef, RangeHash > RangeArrayMap
void setRangeName(sal_uInt16 nFileId, const OUString &rName)
ScDocumentUniquePtr mxFakeDoc
size_t operator()(const ScRange &rRange) const
::std::vector< bool > maTables
void setAllCacheTableReferencedStati(bool bReferenced)
virtual ::sfx2::SvBaseLink::UpdateResult DataChanged(const OUString &rMimeType, const css::uno::Any &rValue) override
OUString getTableName(sal_uInt16 nFileId, size_t nCacheId) const
const ScDocument * getFakeDoc() const
DocItem * getDocItem(sal_uInt16 nFileId) const
std::shared_ptr< ScTokenArray > TokenArrayRef
std::shared_ptr< Table > TableTypeRef
virtual void Closed() override
void setCachedCellRange(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
DocShellMap maDocShells
Source document cache.
bool hasRow(SCROW nRow) const
RowsDataType maRows
Data cache.
std::vector< sal_uInt16 > maConvertFileIdToUsedFileId
LinkedDocMap maLinkedDocs
list of source documents that are managed by the link manager.
bool getTableDataIndex(const OUString &rTabName, size_t &rIndex) const
std::unordered_map< sal_uInt16, bool > LinkedDocMap
std::unordered_map< OUString, size_t > TableNameIndexMap
std::unordered_map< OUString, TokenArrayRef > RangeNameMap
bool isReferenced() const
void addCacheDocToReferenced(sal_uInt16 nFileId)
ScExternalRefCache maRefCache
cache of referenced ranges and names from source documents.
bool isInCachedRanges(SCCOL nCol, SCROW nRow) const
void addCacheTableToReferenced(sal_uInt16 nFileId, size_t nIndex)
TableNameIndexMap maTableNameIndex
Table name to index map.
RangeArrayMap maRangeArrays
Token array cache for cell ranges.
RangeNameMap maRangeNames
Range name cache.
std::unordered_map< SCCOL, Cell > RowDataType
void setCachedCell(SCCOL nCol, SCROW nRow)
Use this guard when performing something from the API that might query values from external reference...
Represents data cached for a single external document.
bool getSingleTableNameAlternative(OUString &rTabName) const
std::unordered_map< sal_uInt16, LinkListeners > LinkListenerMap