1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SC_INC_EXTERNALREFMGR_HXX
21 #define INCLUDED_SC_INC_EXTERNALREFMGR_HXX
24 #include "address.hxx"
25 #include <sfx2/objsh.hxx>
26 #include <sfx2/lnkbase.hxx>
27 #include <sfx2/event.hxx>
28 #include <tools/time.hxx>
29 #include <vcl/timer.hxx>
30 #include <svl/zforlist.hxx>
31 #include <svl/lstner.hxx>
33 #include "rangelst.hxx"
34 #include <formula/token.hxx>
35 #include <osl/mutex.hxx>
37 #include <boost/unordered_map.hpp>
38 #include <boost/unordered_set.hpp>
39 #include <boost/shared_ptr.hpp>
43 #include <formula/ExternalReferenceHelper.hxx>
50 class ScExternalRefCache
;
54 class SharedStringPool
;
58 class ScExternalRefLink
: public ::sfx2::SvBaseLink
61 ScExternalRefLink(ScDocument
* pDoc
, sal_uInt16 nFileId
, const OUString
& rFilter
);
62 virtual ~ScExternalRefLink();
64 virtual void Closed() SAL_OVERRIDE
;
65 virtual ::sfx2::SvBaseLink::UpdateResult
DataChanged(
66 const OUString
& rMimeType
, const ::com::sun::star::uno::Any
& rValue
) SAL_OVERRIDE
;
67 virtual void Edit(Window
* pParent
, const Link
& rEndEditHdl
) SAL_OVERRIDE
;
69 void SetDoReferesh(bool b
);
72 ScExternalRefLink(); // disabled
73 ScExternalRefLink(const ScExternalRefLink
&); // disabled
75 DECL_LINK( ExternalRefEndEditHdl
, void* );
78 OUString maFilterName
;
84 * Cache table for external reference data.
86 class ScExternalRefCache
89 typedef ::formula::FormulaTokenRef TokenRef
;
90 typedef ::boost::shared_ptr
<ScTokenArray
> TokenArrayRef
;
97 explicit TableName(const OUString
& rUppper
, const OUString
& rReal
);
106 explicit CellFormat();
110 /** individual cell within cached external ref table. */
114 sal_uLong mnFmtIndex
;
116 typedef ::boost::unordered_map
<SCCOL
, Cell
> RowDataType
;
117 typedef ::boost::unordered_map
<SCROW
, RowDataType
> RowsDataType
;
120 // SUNWS needs a forward declared friend, otherwise types and members
121 // of the outer class are not accessible.
123 friend class ScExternalRefCache::Table
;
126 * Represents a single cached table in an external document. It only
127 * stores non-empty cells; empty cells should never be stored in the data
128 * cache. Instead, cached ranges should be used to determine whether or
129 * not a cell is empty or needs fetching from the source document. If a
130 * cell's value is not stored but its address is within the cached ranges,
131 * that cell is already queried in the source document and we know it's
141 REFERENCED_MARKED
, // marked as referenced during store to file
142 REFERENCED_PERMANENT
// permanently marked, e.g. from within interpreter
149 * Add cell value to the cache.
151 * @param bSetCacheRange if true, mark this cell 'cached'. This is
152 * false _only when_ adding a range of cell
153 * values, for performance reasons.
155 SC_DLLPUBLIC
void setCell(SCCOL nCol
, SCROW nRow
, TokenRef pToken
, sal_uLong nFmtIndex
= 0, bool bSetCacheRange
= true);
156 SC_DLLPUBLIC TokenRef
getCell(SCCOL nCol
, SCROW nRow
, sal_uInt32
* pnFmtIndex
= NULL
) const;
157 bool hasRow( SCROW nRow
) const;
158 /** Set/clear referenced status flag only if current status is not
159 REFERENCED_PERMANENT. */
160 void setReferenced( bool bReferenced
);
161 /// Unconditionally set the reference status flag.
162 void setReferencedFlag( ReferencedFlag eFlag
);
163 ReferencedFlag
getReferencedFlag() const;
164 bool isReferenced() const;
165 /// Obtain a sorted vector of rows.
166 void getAllRows(::std::vector
<SCROW
>& rRows
, SCROW nLow
= 0, SCROW nHigh
= MAXROW
) const;
167 /// Returns the half-open range of used rows in this table. Returns [0,0) if table is empty.
168 SC_DLLPUBLIC ::std::pair
< SCROW
, SCROW
> getRowRange() const;
169 /// Obtain a sorted vector of columns.
170 void getAllCols(SCROW nRow
, ::std::vector
<SCCOL
>& rCols
, SCCOL nLow
= 0, SCCOL nHigh
= MAXCOL
) const;
171 /// Returns the half-open range of used columns in the specified row. Returns [0,0) if row is empty.
172 SC_DLLPUBLIC ::std::pair
< SCCOL
, SCCOL
> getColRange( SCROW nRow
) const;
173 void getAllNumberFormats(::std::vector
<sal_uInt32
>& rNumFmts
) const;
174 bool isRangeCached(SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
) const;
176 void setCachedCell(SCCOL nCol
, SCROW nRow
);
177 void setCachedCellRange(SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
);
180 * Call this to mark the entire table "cached". This will prevent all
181 * future attempts to access the source document even when non-cached
182 * cells are queried. In such case, non-cached cells are treated as
183 * empty cells. Useful when loading a document with own external data
186 SC_DLLPUBLIC
void setWholeTableCached();
188 bool isInCachedRanges(SCCOL nCol
, SCROW nRow
) const;
189 TokenRef
getEmptyOrNullToken(SCCOL nCol
, SCROW nRow
) const;
194 /** Collection of individual cached ranges. The table ranges are
195 * not used & always zero. */
196 ScRangeList maCachedRanges
;
197 ReferencedFlag meReferenced
;
200 typedef ::boost::shared_ptr
<Table
> TableTypeRef
;
201 typedef ::boost::unordered_map
< OUString
, size_t, OUStringHash
>
204 ScExternalRefCache();
205 ~ScExternalRefCache();
207 const OUString
* getRealTableName(sal_uInt16 nFileId
, const OUString
& rTabName
) const;
208 const OUString
* getRealRangeName(sal_uInt16 nFileId
, const OUString
& rRangeName
) const;
211 * Get a cached cell data at specified cell location.
213 * @param nFileId file ID of an external document
214 * @param rTabName sheet name
218 * @return pointer to the token instance in the cache.
220 ScExternalRefCache::TokenRef
getCellData(
221 sal_uInt16 nFileId
, const OUString
& rTabName
, SCCOL nCol
, SCROW nRow
, sal_uInt32
* pnFmtIndex
);
224 * Get a cached cell range data.
226 * @return a new token array instance. Note that <i>the caller must
227 * manage the life cycle of the returned instance</i>, which is
228 * guaranteed if the TokenArrayRef is properly used..
230 ScExternalRefCache::TokenArrayRef
getCellRangeData(
231 sal_uInt16 nFileId
, const OUString
& rTabName
, const ScRange
& rRange
);
233 ScExternalRefCache::TokenArrayRef
getRangeNameTokens(sal_uInt16 nFileId
, const OUString
& rName
);
234 void setRangeNameTokens(sal_uInt16 nFileId
, const OUString
& rName
, TokenArrayRef pArray
);
235 bool isValidRangeName(sal_uInt16 nFileId
, const OUString
& rName
) const;
237 void setCellData(sal_uInt16 nFileId
, const OUString
& rTabName
,
238 SCCOL nCol
, SCROW nRow
, TokenRef pToken
, sal_uLong nFmtIndex
);
240 struct SingleRangeData
242 /** This name must be in upper-case. */
243 OUString maTableName
;
244 ScMatrixRef mpRangeData
;
246 void setCellRangeData(sal_uInt16 nFileId
, const ScRange
& rRange
, const ::std::vector
<SingleRangeData
>& rData
,
247 const TokenArrayRef
& pArray
);
249 bool isDocInitialized(sal_uInt16 nFileId
);
250 void initializeDoc(sal_uInt16 nFileId
, const ::std::vector
<OUString
>& rTabNames
);
251 OUString
getTableName(sal_uInt16 nFileId
, size_t nCacheId
) const;
252 void getAllTableNames(sal_uInt16 nFileId
, ::std::vector
<OUString
>& rTabNames
) const;
253 SCsTAB
getTabSpan( sal_uInt16 nFileId
, const OUString
& rStartTabName
, const OUString
& rEndTabName
) const;
254 void getAllNumberFormats(::std::vector
<sal_uInt32
>& rNumFmts
) const;
257 * Set all tables of a document as referenced, used only during
259 * @returns <TRUE/> if ALL tables of ALL documents are marked.
261 bool setCacheDocReferenced( sal_uInt16 nFileId
);
264 * Set a table as referenced, used only during store-to-file.
265 * @returns <TRUE/> if ALL tables of ALL documents are marked.
267 bool setCacheTableReferenced( sal_uInt16 nFileId
, const OUString
& rTabName
, size_t nSheets
, bool bPermanent
);
268 void setAllCacheTableReferencedStati( bool bReferenced
);
269 bool areAllCacheTablesReferenced() const;
272 struct ReferencedStatus
276 ::std::vector
<bool> maTables
;
277 bool mbAllTablesReferenced
;
278 // Initially, documents have no tables but all referenced.
279 DocReferenced() : mbAllTablesReferenced(true) {}
281 typedef ::std::vector
<DocReferenced
> DocReferencedVec
;
283 DocReferencedVec maDocs
;
284 bool mbAllReferenced
;
287 void reset( size_t nDocs
);
291 void addCacheTableToReferenced( sal_uInt16 nFileId
, size_t nIndex
);
292 void addCacheDocToReferenced( sal_uInt16 nFileId
);
295 ScExternalRefCache::TableTypeRef
getCacheTable(sal_uInt16 nFileId
, size_t nTabIndex
) const;
296 ScExternalRefCache::TableTypeRef
getCacheTable(sal_uInt16 nFileId
, const OUString
& rTabName
, bool bCreateNew
, size_t* pnIndex
);
298 void clearCache(sal_uInt16 nFileId
);
303 size_t operator()(const ScRange
& rRange
) const
305 const ScAddress
& s
= rRange
.aStart
;
306 const ScAddress
& e
= rRange
.aEnd
;
307 return s
.Tab() + s
.Col() + s
.Row() + e
.Tab() + e
.Col() + e
.Row();
311 typedef ::boost::unordered_map
<OUString
, TokenArrayRef
, OUStringHash
> RangeNameMap
;
312 typedef ::boost::unordered_map
<ScRange
, TokenArrayRef
, RangeHash
> RangeArrayMap
;
313 typedef ::boost::unordered_map
<OUString
, OUString
, OUStringHash
> NamePairMap
;
315 // SUNWS needs a forward declared friend, otherwise types and members
316 // of the outer class are not accessible.
318 friend struct ScExternalRefCache::DocItem
;
320 /** Represents data cached for a single external document. */
323 /** The raw cache tables. */
324 ::std::vector
<TableTypeRef
> maTables
;
325 /** Table name list in correct order, in both upper- and real-case. */
326 ::std::vector
<TableName
> maTableNames
;
327 /** Table name to index map. The names must be stored upper-case. */
328 TableNameIndexMap maTableNameIndex
;
329 /** Range name cache. */
330 RangeNameMap maRangeNames
;
331 /** Token array cache for cell ranges. */
332 RangeArrayMap maRangeArrays
;
333 /** Upper- to real-case mapping for range names. */
334 NamePairMap maRealRangeNameMap
;
336 bool mbInitFromSource
;
338 DocItem() : mbInitFromSource(false) {}
340 typedef ::boost::unordered_map
<sal_uInt16
, DocItem
> DocDataType
;
341 DocItem
* getDocItem(sal_uInt16 nFileId
) const;
344 mutable osl::Mutex maMtxDocs
;
345 mutable DocDataType maDocs
;
348 class SC_DLLPUBLIC ScExternalRefManager
: public formula::ExternalReferenceHelper
, SfxListener
352 typedef ::std::set
<ScFormulaCell
*> RefCellSet
;
353 typedef ::boost::unordered_map
<sal_uInt16
, RefCellSet
> RefCellMap
;
355 enum LinkUpdateType
{ LINK_MODIFIED
, LINK_BROKEN
};
358 * Base class for objects that need to listen to link updates. When a
359 * link to a certain external file is updated, the notify() method gets
366 virtual ~LinkListener() = 0;
367 virtual void notify(sal_uInt16 nFileId
, LinkUpdateType eType
) = 0;
371 size_t operator() (const LinkListener
* p
) const
373 return reinterpret_cast<size_t>(p
);
379 * Use this guard when performing something from the API that might query
380 * values from external references. Interpreting formula strings is one
383 class SC_DLLPUBLIC ApiGuard
386 ApiGuard(ScDocument
* pDoc
);
389 ScExternalRefManager
* mpMgr
;
390 bool mbOldInteractionEnabled
;
394 /** Shell instance for a source document. */
397 SfxObjectShellRef maShell
;
400 SrcShell() : maLastAccess( Time::SYSTEM
) {}
403 typedef ::boost::unordered_map
<sal_uInt16
, SrcShell
> DocShellMap
;
404 typedef ::boost::unordered_map
<sal_uInt16
, bool> LinkedDocMap
;
406 typedef ::boost::unordered_map
<sal_uInt16
, SvNumberFormatterMergeMap
> NumFmtMap
;
409 typedef ::boost::unordered_set
<LinkListener
*, LinkListener::Hash
> LinkListeners
;
410 typedef ::boost::unordered_map
<sal_uInt16
, LinkListeners
> LinkListenerMap
;
413 /** Source document meta-data container. */
416 OUString maFileName
; /// original file name as loaded from the file.
417 OUString maRealFileName
; /// file name created from the relative name.
418 OUString maRelativeName
;
419 OUString maFilterName
;
420 OUString maFilterOptions
;
423 void maybeCreateRealFileName(const OUString
& rOwnDocName
);
427 explicit ScExternalRefManager(ScDocument
* pDoc
);
428 virtual ~ScExternalRefManager();
430 virtual OUString
getCacheTableName(sal_uInt16 nFileId
, size_t nTabIndex
) const SAL_OVERRIDE
;
433 * Get a cache table instance for specified table and table index. Unlike
434 * the other method that takes a table name, this method does not create a
435 * new table when a table is not available for specified index.
437 * @param nFileId file ID
438 * @param nTabIndex cache table index
440 * @return shared_ptr to the cache table instance
442 ScExternalRefCache::TableTypeRef
getCacheTable(sal_uInt16 nFileId
, size_t nTabIndex
) const;
445 * Get a cache table instance for specified file and table name. If the
446 * table instance is not already present, it'll instantiate a new one and
447 * append it to the end of the table array. <I>It's important to be
448 * aware of this fact especially for multi-table ranges for which
449 * table orders are critical.</I>
451 * Excel filter calls this method to populate the cache table from the
454 * @param nFileId file ID
455 * @param rTabName table name
456 * @param bCreateNew if true, create a new table instance if it's not
457 * already present. If false, it returns NULL if the
458 * specified table's cache doesn't exist.
459 * @param pnIndex if non-NULL pointer is passed, it stores the internal
460 * index of a cache table instance.
462 * @return shared_ptr to the cache table instance
464 ScExternalRefCache::TableTypeRef
getCacheTable(sal_uInt16 nFileId
, const OUString
& rTabName
, bool bCreateNew
, size_t* pnIndex
= 0);
466 /** Returns a vector containing all (real) table names and cache tables of
469 The index in the returned vector corresponds to the table index used to
470 access the cache table, e.g. in getCacheTable().
472 void getAllCachedTableNames(sal_uInt16 nFileId
, ::std::vector
<OUString
>& rTabNames
) const;
475 * Get the span (distance+sign(distance)) of two sheets of a specified
478 * @param nFileId file ID
479 * @param rStartTabName name of first sheet (sheet1)
480 * @param rEndTabName name of second sheet (sheet2)
483 * 1 if sheet2 == sheet1
484 * > 1 if sheet2 > sheet1
485 * < -1 if sheet2 < sheet1
486 * -1 if nFileId or rStartTabName not found
487 * 0 if rEndTabName not found
489 SCsTAB
getCachedTabSpan(
490 sal_uInt16 nFileId
, const OUString
& rStartTabName
, const OUString
& rEndTabName
) const;
493 * Get all unique number format indices that are used in the cache tables.
494 * The retrieved indices are sorted in ascending order.
496 * @param rNumFmts (reference) all unique number format indices.
498 void getAllCachedNumberFormats(::std::vector
<sal_uInt32
>& rNumFmts
) const;
500 sal_uInt16
getExternalFileCount() const;
503 * Mark all tables as referenced that are used by any LinkListener, used
504 * only during store-to-file.
505 * @returns <TRUE/> if ALL tables of ALL external documents are marked.
507 bool markUsedByLinkListeners();
509 bool markUsedExternalRefCells();
512 * Set a table as referenced, used only during store-to-file.
513 * @returns <TRUE/> if ALL tables of ALL external documents are marked.
515 bool setCacheTableReferenced( sal_uInt16 nFileId
, const OUString
& rTabName
, size_t nSheets
);
516 void setAllCacheTableReferencedStati( bool bReferenced
);
519 * @returns <TRUE/> if setAllCacheTableReferencedStati(false) was called,
520 * <FALSE/> if setAllCacheTableReferencedStati(true) was called.
522 bool isInReferenceMarking() const { return mbInReferenceMarking
; }
524 void storeRangeNameTokens(sal_uInt16 nFileId
, const OUString
& rName
, const ScTokenArray
& rArray
);
526 ScExternalRefCache::TokenRef
getSingleRefToken(
527 sal_uInt16 nFileId
, const OUString
& rTabName
, const ScAddress
& rCell
,
528 const ScAddress
* pCurPos
, SCTAB
* pTab
, ScExternalRefCache::CellFormat
* pFmt
= NULL
);
531 * Get an array of tokens that consist of the specified external cell
534 * @param nFileId file ID for an external document
535 * @param rTabName referenced sheet name
536 * @param rRange referenced cell range
537 * @param pCurPos current cursor position to keep track of cells that
538 * reference an external data.
540 * @return shared_ptr to a token array instance. <i>The caller must not
541 * delete the instance returned by this method.</i>
543 ScExternalRefCache::TokenArrayRef
getDoubleRefTokens(
544 sal_uInt16 nFileId
, const OUString
& rTabName
, const ScRange
& rRange
, const ScAddress
* pCurPos
);
547 * Get an array of tokens corresponding with a specified name in a
550 * @param pCurPos currnet cell address where this name token is used.
551 * This is purely to keep track of all cells containing
552 * external names for refreshing purposes. If this is
553 * NULL, then the cell will not be added to the list.
555 * @return shared_ptr to array of tokens composing the name
557 ScExternalRefCache::TokenArrayRef
getRangeNameTokens(
558 sal_uInt16 nFileId
, const OUString
& rName
, const ScAddress
* pCurPos
= NULL
);
560 bool isValidRangeName(sal_uInt16 nFileId
, const OUString
& rName
);
562 OUString
getOwnDocumentName() const;
563 bool isOwnDocument(const OUString
& rFile
) const;
566 * Takes a flat file name, and convert it to an absolute URL path. An
567 * absolute URL path begines with 'file:///.
569 * @param rFile file name to convert
571 void convertToAbsName(OUString
& rFile
) const;
572 sal_uInt16
getExternalFileId(const OUString
& rFile
);
575 * It returns a pointer to the name of the URI associated with a given
576 * external file ID. In case the original document has moved, it returns
577 * an URI adjusted for the relocation.
579 * @param nFileId file ID for an external document
580 * @param bForceOriginal If true, it always returns the original document
581 * URI even if the referring document has relocated.
582 * If false, it returns an URI adjusted for
583 * relocated document.
585 * @return const OUString* external document URI.
587 const OUString
* getExternalFileName(sal_uInt16 nFileId
, bool bForceOriginal
= false);
590 * Get all cached external file names as an array. Array indices of the
591 * returned name array correspond with external file ID's.
593 std::vector
<OUString
> getAllCachedExternalFileNames() const;
595 bool hasExternalFile(sal_uInt16 nFileId
) const;
596 bool hasExternalFile(const OUString
& rFile
) const;
597 const SrcFileData
* getExternalFileData(sal_uInt16 nFileId
) const;
599 const OUString
* getRealTableName(sal_uInt16 nFileId
, const OUString
& rTabName
) const;
600 const OUString
* getRealRangeName(sal_uInt16 nFileId
, const OUString
& rRangeName
) const;
601 void clearCache(sal_uInt16 nFileId
);
602 void refreshNames(sal_uInt16 nFileId
);
603 void breakLink(sal_uInt16 nFileId
);
604 void switchSrcFile(sal_uInt16 nFileId
, const OUString
& rNewFile
, const OUString
& rNewFilter
);
607 * Set a relative file path for the specified file ID. Note that the
608 * caller must ensure that the passed URL is a valid relative URL.
610 * @param nFileId file ID for an external document
611 * @param rRelUrl relative URL
613 void setRelativeFileName(sal_uInt16 nFileId
, const OUString
& rRelUrl
);
616 * Set the filter name and options if any for a given source document.
617 * These values get reset when the source document ever gets reloaded.
623 void setFilterData(sal_uInt16 nFileId
, const OUString
& rFilterName
, const OUString
& rOptions
);
627 bool hasExternalData() const;
630 * Re-generates relative names for all stored source files. This is
631 * necessary when exporting to an ods document, to ensure that all source
632 * files have their respective relative names for xlink:href export.
634 * @param rBaseFileUrl Absolute URL of the content.xml fragment of the
635 * document being exported.
637 void resetSrcFileData(const OUString
& rBaseFileUrl
);
640 * Replace the original URL wirh the real URL that was generated from the relative URL.
642 void updateAbsAfterLoad();
645 * Stop tracking a specific formula cell.
647 * @param pCell pointer to cell that formerly contained external
650 void removeRefCell(ScFormulaCell
* pCell
);
653 * Register a new link listener to a specified external document. Note
654 * that the caller is responsible for managing the life cycle of the
657 void addLinkListener(sal_uInt16 nFileId
, LinkListener
* pListener
);
660 * Remove an existing link listener. Note that removing a listener
661 * pointer here does not delete the listener object instance.
663 void removeLinkListener(sal_uInt16 nFileId
, LinkListener
* pListener
);
665 void removeLinkListener(LinkListener
* pListener
);
668 * Notify all listeners that are listening to a specified external
671 * @param nFileId file ID for an external document.
673 void notifyAllLinkListeners(sal_uInt16 nFileId
, LinkUpdateType eType
);
676 * Check if the file specified by the path is a legitimate file that
677 * exists & can be loaded.
679 bool isFileLoadable(const OUString
& rFile
) const;
681 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) SAL_OVERRIDE
;
684 * If we still contain unsaved files we should warn the user before saving
686 * @return true if the document still contains references to an unsaved file
688 bool containsUnsavedReferences() const { return !maUnsavedDocShells
.empty(); }
690 void insertRefCell(sal_uInt16 nFileId
, const ScAddress
& rCell
);
693 ScExternalRefManager();
694 ScExternalRefManager(const ScExternalRefManager
&);
696 void refreshAllRefCells(sal_uInt16 nFileId
);
698 void fillCellFormat(sal_uLong nFmtIndex
, ScExternalRefCache::CellFormat
* pFmt
) const;
700 ScExternalRefCache::TokenRef
getSingleRefTokenFromSrcDoc(
701 sal_uInt16 nFileId
, ScDocument
* pSrcDoc
, const ScAddress
& rPos
,
702 ScExternalRefCache::CellFormat
* pFmt
);
705 * Retrieve a range token array from a source document instance.
707 * @param pSrcDoc pointer to the source document instance.
708 * @param rTabName name of the first table.
709 * @param rRange range specified. Upon successful retrieval, this range
710 * gets modified to contain the correct table IDs, and in
711 * case the range is larger than the data area of the source
712 * document, it gets reduced to the data area.
713 * @param rCacheData an array of structs, with each struct containing the
714 * table name and the data in the specified range.
716 * @return range token array
718 ScExternalRefCache::TokenArrayRef
getDoubleRefTokensFromSrcDoc(
719 ScDocument
* pSrcDoc
, const OUString
& rTabName
, ScRange
& rRange
,
720 ::std::vector
<ScExternalRefCache::SingleRangeData
>& rCacheData
);
723 * Retrieve range name token array from a source document instance.
725 * @param nFileId file ID of the source document.
726 * @param pSrcDoc pointer to the source document instance
727 * @param rName range name to retrieve. Note that the range name lookup
728 * is case <i>in</i>-sensitive, and upon successful retrieval
729 * of the range name array, this name gets updated to the
730 * actual range name with the correct casing.
732 * @return range name token array
734 ScExternalRefCache::TokenArrayRef
getRangeNameTokensFromSrcDoc(
735 sal_uInt16 nFileId
, ScDocument
* pSrcDoc
, OUString
& rName
);
737 ScDocument
* getInMemorySrcDocument(sal_uInt16 nFileId
);
738 ScDocument
* getSrcDocument(sal_uInt16 nFileId
);
739 SfxObjectShellRef
loadSrcDocument(sal_uInt16 nFileId
, OUString
& rFilter
);
741 void maybeLinkExternalFile(sal_uInt16 nFileId
);
744 * Try to create a "real" file name from the relative path. The original
745 * file name may not point to the real document when the referencing and
746 * referenced documents have been moved.
748 * For the real file name to be created, the relative name should not be
749 * empty before calling this method, or the real file name will not be
752 * @param nFileId file ID for an external document
754 void maybeCreateRealFileName(sal_uInt16 nFileId
);
757 * Purge those source document instances that have not been accessed for
758 * the specified duration.
760 * @param nTimeOut time out value in 100th of a second
762 void purgeStaleSrcDocument(sal_Int32 nTimeOut
);
764 sal_uInt32
getMappedNumberFormat(sal_uInt16 nFileId
, sal_uInt32 nNumFmt
, const ScDocument
* pSrcDoc
);
767 * If in maUnsavedDocShells move it to maDocShells and create a correct
768 * external reference entry
770 * @param Pointer to the newly saved DocumentShell
772 void transformUnsavedRefToSavedRef( SfxObjectShell
* pShell
);
777 /** cache of referenced ranges and names from source documents. */
778 ScExternalRefCache maRefCache
;
781 * Source document cache. This stores the original source document shell
782 * instances. They get purged after a certain period of time.
784 DocShellMap maDocShells
;
787 * DocShells to unsaved but referenced documents. If not empty ask before saving!
788 * Move to maDocShells if document referenced here is saved
790 DocShellMap maUnsavedDocShells
;
792 /** list of source documents that are managed by the link manager. */
793 LinkedDocMap maLinkedDocs
;
796 * List of referencing cells that may contain external names. There is
797 * one list per source document.
799 RefCellMap maRefCells
;
801 LinkListenerMap maLinkListeners
;
803 NumFmtMap maNumFormatMap
;
806 * List of external source document meta-data, used to keep track of
807 * external document identifiers.
809 std::vector
<SrcFileData
> maSrcFiles
;
811 /** Status whether in reference marking state. See isInReferenceMarking(). */
812 bool mbInReferenceMarking
:1;
815 * Controls whether or not to allow user interaction. We don't want any
816 * user interaction when calling from the API.
818 bool mbUserInteractionEnabled
:1;
820 AutoTimer maSrcDocTimer
;
821 DECL_LINK(TimeOutHdl
, AutoTimer
*);
827 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */