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(OUString aUpper, OUString aReal);
150 SC_DLLPUBLIC ::std::pair< SCROW, SCROW >
getRowRange()
const;
173 template<
typename P >
174 void getAllRows(::std::vector<SCROW>& rRows, P predicate)
const;
175 template<
typename P >
188 typedef std::unordered_map< OUString, size_t>
194 const OUString*
getRealTableName(sal_uInt16 nFileId,
const OUString& rTabName)
const;
195 const OUString*
getRealRangeName(sal_uInt16 nFileId,
const OUString& rRangeName)
const;
208 sal_uInt16 nFileId,
const OUString& rTabName,
SCCOL nCol,
SCROW nRow, sal_uInt32* pnFmtIndex);
218 sal_uInt16 nFileId,
const OUString& rTabName,
const ScRange& rRange);
223 void setRangeName(sal_uInt16 nFileId,
const OUString& rName);
225 void setCellData(sal_uInt16 nFileId,
const OUString& rTabName,
238 void initializeDoc(sal_uInt16 nFileId, const ::std::vector<OUString>& rTabNames,
const OUString& rBaseName);
239 OUString
getTableName(sal_uInt16 nFileId,
size_t nCacheId)
const;
240 void getAllTableNames(sal_uInt16 nFileId, ::std::vector<OUString>& rTabNames)
const;
241 SCTAB getTabSpan( sal_uInt16 nFileId,
const OUString& rStartTabName,
const OUString& rEndTabName )
const;
284 void reset(
size_t nDocs );
294 size_t* pnIndex,
const OUString* pExtUrl);
318 hash = hash * 37 + s.
Tab();
319 hash = hash * 37 + s.
Col();
320 hash = hash * 37 + s.
Row();
321 hash = hash * 37 + e.
Tab();
322 hash = hash * 37 + e.
Col();
323 hash = hash * 37 + e.
Row();
329 typedef std::unordered_map<ScRange, TokenArrayRef, RangeHash>
RangeArrayMap;
357 TableNameIndexMap::const_iterator
findTableNameIndex(
const OUString& rTabName )
const;
375 typedef std::unordered_map<sal_uInt16, RefCellSet>
RefCellMap;
420 typedef std::unordered_map<sal_uInt16, SvNumberFormatterMergeMap>
NumFmtMap;
435 void maybeCreateRealFileName(std::u16string_view rOwnDocName);
442 virtual OUString
getCacheTableName(sal_uInt16 nFileId,
size_t nTabIndex)
const override;
481 size_t* pnIndex =
nullptr,
const OUString* pExtUrl =
nullptr);
489 void getAllCachedTableNames(sal_uInt16 nFileId, ::std::vector<OUString>& rTabNames)
const;
506 SCTAB getCachedTabSpan(
507 sal_uInt16 nFileId,
const OUString& rStartTabName,
const OUString& rEndTabName)
const;
515 void getAllCachedNumberFormats(::std::vector<sal_uInt32>& rNumFmts)
const;
517 sal_uInt16 getExternalFileCount()
const;
523 void markUsedByLinkListeners();
525 void markUsedExternalRefCells();
531 bool setCacheTableReferenced( sal_uInt16 nFileId,
const OUString& rTabName,
size_t nSheets );
532 void setAllCacheTableReferencedStati(
bool bReferenced );
540 void storeRangeNameTokens(sal_uInt16 nFileId,
const OUString& rName,
const ScTokenArray& rArray);
543 sal_uInt16 nFileId,
const OUString& rTabName,
const ScAddress& rCell,
560 sal_uInt16 nFileId,
const OUString& rTabName,
const ScRange& rRange,
const ScAddress* pCurPos);
574 sal_uInt16 nFileId,
const OUString& rName,
const ScAddress* pCurPos =
nullptr);
576 bool isValidRangeName(sal_uInt16 nFileId,
const OUString& rName);
578 OUString getOwnDocumentName()
const;
579 bool isOwnDocument(std::u16string_view rFile)
const;
587 void convertToAbsName(OUString& rFile)
const;
588 sal_uInt16 getExternalFileId(
const OUString& rFile);
603 const OUString* getExternalFileName(sal_uInt16 nFileId,
bool bForceOriginal =
false);
608 sal_uInt16 convertFileIdToUsedFileId(sal_uInt16 nFileId);
609 void setSkipUnusedFileIds(std::vector<sal_uInt16>& pExternFileIds);
610 void disableSkipUnusedFileIds();
616 std::vector<OUString> getAllCachedExternalFileNames()
const;
618 bool hasExternalFile(sal_uInt16 nFileId)
const;
619 bool hasExternalFile(
const OUString& rFile)
const;
620 const SrcFileData* getExternalFileData(sal_uInt16 nFileId)
const;
622 const OUString* getRealTableName(sal_uInt16 nFileId,
const OUString& rTabName)
const;
623 const OUString* getRealRangeName(sal_uInt16 nFileId,
const OUString& rRangeName)
const;
624 void clearCache(sal_uInt16 nFileId);
625 bool refreshSrcDocument(sal_uInt16 nFileId);
626 void breakLink(sal_uInt16 nFileId);
627 void switchSrcFile(sal_uInt16 nFileId,
const OUString& rNewFile,
const OUString& rNewFilter);
636 void setRelativeFileName(sal_uInt16 nFileId,
const OUString& rRelUrl);
646 void setFilterData(sal_uInt16 nFileId,
const OUString& rFilterName,
const OUString& rOptions);
650 bool hasExternalData()
const;
660 void resetSrcFileData(
const OUString& rBaseFileUrl);
665 void updateAbsAfterLoad();
680 void addLinkListener(sal_uInt16 nFileId, LinkListener* pListener);
686 void removeLinkListener(sal_uInt16 nFileId, LinkListener* pListener);
688 void removeLinkListener(LinkListener* pListener);
696 void notifyAllLinkListeners(sal_uInt16 nFileId, LinkUpdateType eType);
702 bool isFileLoadable(
const OUString& rFile)
const;
713 void insertRefCell(sal_uInt16 nFileId,
const ScAddress& rCell);
719 bool hasCellExternalReference(
const ScAddress& rCell);
721 void enableDocTimer(
bool bEnable );
724 void addFilesToLinkManager();
729 void refreshAllRefCells(sal_uInt16 nFileId);
733 bool getSrcDocTable(
const ScDocument& rSrcDoc,
const OUString& rTabName,
SCTAB& rTab, sal_uInt16 nFileId )
const;
755 ::std::vector<ScExternalRefCache::SingleRangeData>& rCacheData);
770 sal_uInt16 nFileId,
const ScDocument& rSrcDoc, OUString& rName);
772 ScDocument* getInMemorySrcDocument(sal_uInt16 nFileId);
773 ScDocument* getSrcDocument(sal_uInt16 nFileId);
781 void maybeLinkExternalFile( sal_uInt16 nFileId,
bool bDeferFilterDetection =
false );
794 void maybeCreateRealFileName(sal_uInt16 nFileId);
802 void purgeStaleSrcDocument(sal_Int32 nTimeOut);
804 sal_uInt32 getMappedNumberFormat(sal_uInt16 nFileId, sal_uInt32 nNumFmt,
const ScDocument& rSrcDoc);
860 bool mbSkipUnusedFileIds =
false;
Represents a single cached table in an external document.
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 getAllRows(::std::vector< SCROW > &rRows) 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.
void getAllCols(SCROW nRow, ::std::vector< SCCOL > &rCols, P predicate) const
bool isInCachedRanges(SCCOL nCol, SCROW nRow) const
void getAllRows(::std::vector< SCROW > &rRows, P predicate) 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) const
ScRangeList maCachedRanges
Collection of individual cached ranges.
RowsDataType maRows
Data cache.
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.
std::unordered_map< SCROW, RowDataType > RowsDataType
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
std::unordered_map< OUString, OUString > NamePairMap
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)
std::unordered_map< ScRange, TokenArrayRef, RangeHash > RangeArrayMap
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
std::unordered_map< sal_uInt16, DocItem > DocDataType
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(const ScExternalRefLink &)=delete
ScExternalRefLink()=delete
Use this guard when performing something from the API that might query values from external reference...
ScExternalRefManager * mpMgr
bool mbOldInteractionEnabled
Base class for objects that need to listen to link updates.
virtual void notify(sal_uInt16 nFileId, LinkUpdateType eType)=0
std::unordered_map< sal_uInt16, SrcShell > DocShellMap
DocShellMap maUnsavedDocShells
DocShells to unsaved but referenced documents.
DocShellMap maDocShells
Source document cache.
ScExternalRefCache maRefCache
cache of referenced ranges and names from source documents.
LinkListenerMap maLinkListeners
std::unordered_map< sal_uInt16, RefCellSet > RefCellMap
bool containsUnsavedReferences() const
If we still contain unsaved files we should warn the user before saving.
LinkedDocMap maLinkedDocs
list of source documents that are managed by the link manager.
std::vector< sal_uInt16 > maConvertFileIdToUsedFileId
bool isInReferenceMarking() const
std::set< ScFormulaCell * > RefCellSet
std::unordered_map< sal_uInt16, SvNumberFormatterMergeMap > NumFmtMap
o3tl::sorted_vector< LinkListener * > LinkListeners
bool mbInReferenceMarking
Status whether in reference marking state.
RefCellMap maRefCells
List of referencing cells that may contain external names.
std::unordered_map< sal_uInt16, LinkListeners > LinkListenerMap
ScExternalRefManager(const ScExternalRefManager &)=delete
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.
std::unordered_map< sal_uInt16, bool > LinkedDocMap
DECL_DLLPRIVATE_LINK(TimeOutHdl, Timer *, void)
Structure that stores segments of boolean flags per column, and perform custom action on those segmen...
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 >())
CAUTION! The following defines must be in the same namespace as the respective type.
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.
size_t operator()(const ScRange &rRange) const
bool mbAllTablesReferenced
::std::vector< bool > maTables
::std::vector< DocReferenced > DocReferencedVec
OUString maTableName
This name must be in upper-case.
TableName(OUString aUpper, OUString aReal)
Source document meta-data container.
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
::boost::intrusive_ptr< ScMatrix > ScMatrixRef