update emoji autocorrect entries from po-files
[LibreOffice.git] / sc / inc / externalrefmgr.hxx
blobedc6208dd617ffd5181de57d6f1ee0261c5b912d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
23 #include "global.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>
32 #include "types.hxx"
33 #include "rangelst.hxx"
34 #include <formula/token.hxx>
35 #include <osl/mutex.hxx>
37 #include <boost/shared_ptr.hpp>
38 #include <unordered_map>
39 #include <unordered_set>
40 #include <vector>
41 #include <list>
42 #include <set>
43 #include <formula/ExternalReferenceHelper.hxx>
45 class ScDocument;
46 class ScTokenArray;
47 namespace vcl { class Window; }
48 class ScFormulaCell;
50 class ScExternalRefCache;
52 namespace svl {
54 class SharedStringPool;
58 namespace sc {
60 class ColumnSpanSet;
64 class ScExternalRefLink : public ::sfx2::SvBaseLink
66 public:
67 ScExternalRefLink(ScDocument* pDoc, sal_uInt16 nFileId, const OUString& rFilter);
68 virtual ~ScExternalRefLink();
70 virtual void Closed() SAL_OVERRIDE;
71 virtual ::sfx2::SvBaseLink::UpdateResult DataChanged(
72 const OUString& rMimeType, const ::com::sun::star::uno::Any & rValue) SAL_OVERRIDE;
73 virtual void Edit(vcl::Window* pParent, const Link<>& rEndEditHdl) SAL_OVERRIDE;
75 void SetDoReferesh(bool b);
77 private:
78 ScExternalRefLink() SAL_DELETED_FUNCTION;
79 ScExternalRefLink(const ScExternalRefLink&) SAL_DELETED_FUNCTION;
81 DECL_STATIC_LINK( ScExternalRefLink, ExternalRefEndEditHdl, void* );
83 sal_uInt16 mnFileId;
84 OUString maFilterName;
85 ScDocument* mpDoc;
86 bool mbDoRefresh;
89 /**
90 * Cache table for external reference data.
92 class ScExternalRefCache
94 public:
95 typedef ::formula::FormulaTokenRef TokenRef;
96 typedef ::boost::shared_ptr<ScTokenArray> TokenArrayRef;
98 struct TableName
100 OUString maUpperName;
101 OUString maRealName;
103 explicit TableName(const OUString& rUppper, const OUString& rReal);
106 struct CellFormat
108 bool mbIsSet;
109 short mnType;
110 sal_uLong mnIndex;
112 explicit CellFormat();
115 private:
116 /** individual cell within cached external ref table. */
117 struct Cell
119 TokenRef mxToken;
120 sal_uLong mnFmtIndex;
122 typedef std::unordered_map<SCCOL, Cell> RowDataType;
123 typedef std::unordered_map<SCROW, RowDataType> RowsDataType;
125 public:
127 * Represents a single cached table in an external document. It only
128 * stores non-empty cells; empty cells should never be stored in the data
129 * cache. Instead, cached ranges should be used to determine whether or
130 * not a cell is empty or needs fetching from the source document. If a
131 * cell's value is not stored but its address is within the cached ranges,
132 * that cell is already queried in the source document and we know it's
133 * empty.
135 class Table
137 public:
139 enum ReferencedFlag
141 UNREFERENCED,
142 REFERENCED_MARKED, // marked as referenced during store to file
143 REFERENCED_PERMANENT // permanently marked, e.g. from within interpreter
146 Table();
147 ~Table();
149 void clear();
152 * Add cell value to the cache.
154 * @param bSetCacheRange if true, mark this cell 'cached'. This is
155 * false _only when_ adding a range of cell
156 * values, for performance reasons.
158 SC_DLLPUBLIC void setCell(SCCOL nCol, SCROW nRow, TokenRef pToken, sal_uLong nFmtIndex = 0, bool bSetCacheRange = true);
159 SC_DLLPUBLIC TokenRef getCell(SCCOL nCol, SCROW nRow, sal_uInt32* pnFmtIndex = NULL) const;
160 bool hasRow( SCROW nRow ) const;
161 /** Set/clear referenced status flag only if current status is not
162 REFERENCED_PERMANENT. */
163 void setReferenced( bool bReferenced );
164 /// Unconditionally set the reference status flag.
165 void setReferencedFlag( ReferencedFlag eFlag );
166 ReferencedFlag getReferencedFlag() const { return meReferenced;}
167 bool isReferenced() const;
168 /// Obtain a sorted vector of rows.
169 void getAllRows(::std::vector<SCROW>& rRows, SCROW nLow = 0, SCROW nHigh = MAXROW) const;
170 /// Returns the half-open range of used rows in this table. Returns [0,0) if table is empty.
171 SC_DLLPUBLIC ::std::pair< SCROW, SCROW > getRowRange() const;
172 /// Obtain a sorted vector of columns.
173 void getAllCols(SCROW nRow, ::std::vector<SCCOL>& rCols, SCCOL nLow = 0, SCCOL nHigh = MAXCOL) const;
174 /// Returns the half-open range of used columns in the specified row. Returns [0,0) if row is empty.
175 SC_DLLPUBLIC ::std::pair< SCCOL, SCCOL > getColRange( SCROW nRow ) const;
176 void getAllNumberFormats(::std::vector<sal_uInt32>& rNumFmts) const;
177 bool isRangeCached(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const;
179 void setCachedCell(SCCOL nCol, SCROW nRow);
180 void setCachedCellRange(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
183 * Call this to mark the entire table "cached". This will prevent all
184 * future attempts to access the source document even when non-cached
185 * cells are queried. In such case, non-cached cells are treated as
186 * empty cells. Useful when loading a document with own external data
187 * cache.
189 SC_DLLPUBLIC void setWholeTableCached();
190 private:
191 bool isInCachedRanges(SCCOL nCol, SCROW nRow) const;
192 TokenRef getEmptyOrNullToken(SCCOL nCol, SCROW nRow) const;
194 private:
195 /** Data cache */
196 RowsDataType maRows;
197 /** Collection of individual cached ranges. The table ranges are
198 * not used & always zero. */
199 ScRangeList maCachedRanges;
200 ReferencedFlag meReferenced;
203 typedef ::boost::shared_ptr<Table> TableTypeRef;
204 typedef std::unordered_map< OUString, size_t, OUStringHash>
205 TableNameIndexMap;
207 ScExternalRefCache();
208 ~ScExternalRefCache();
210 const OUString* getRealTableName(sal_uInt16 nFileId, const OUString& rTabName) const;
211 const OUString* getRealRangeName(sal_uInt16 nFileId, const OUString& rRangeName) const;
214 * Get a cached cell data at specified cell location.
216 * @param nFileId file ID of an external document
217 * @param rTabName sheet name
218 * @param nCol
219 * @param nRow
221 * @return pointer to the token instance in the cache.
223 ScExternalRefCache::TokenRef getCellData(
224 sal_uInt16 nFileId, const OUString& rTabName, SCCOL nCol, SCROW nRow, sal_uInt32* pnFmtIndex);
227 * Get a cached cell range data.
229 * @return a new token array instance. Note that <i>the caller must
230 * manage the life cycle of the returned instance</i>, which is
231 * guaranteed if the TokenArrayRef is properly used..
233 ScExternalRefCache::TokenArrayRef getCellRangeData(
234 sal_uInt16 nFileId, const OUString& rTabName, const ScRange& rRange);
236 ScExternalRefCache::TokenArrayRef getRangeNameTokens(sal_uInt16 nFileId, const OUString& rName);
237 void setRangeNameTokens(sal_uInt16 nFileId, const OUString& rName, TokenArrayRef pArray);
238 bool isValidRangeName(sal_uInt16 nFileId, const OUString& rName) const;
240 void setCellData(sal_uInt16 nFileId, const OUString& rTabName,
241 SCCOL nCol, SCROW nRow, TokenRef pToken, sal_uLong nFmtIndex);
243 struct SingleRangeData
245 /** This name must be in upper-case. */
246 OUString maTableName;
247 ScMatrixRef mpRangeData;
249 void setCellRangeData(sal_uInt16 nFileId, const ScRange& rRange, const ::std::vector<SingleRangeData>& rData,
250 const TokenArrayRef& pArray);
252 bool isDocInitialized(sal_uInt16 nFileId);
253 void initializeDoc(sal_uInt16 nFileId, const ::std::vector<OUString>& rTabNames);
254 OUString getTableName(sal_uInt16 nFileId, size_t nCacheId) const;
255 void getAllTableNames(sal_uInt16 nFileId, ::std::vector<OUString>& rTabNames) const;
256 SCsTAB getTabSpan( sal_uInt16 nFileId, const OUString& rStartTabName, const OUString& rEndTabName ) const;
257 void getAllNumberFormats(::std::vector<sal_uInt32>& rNumFmts) const;
260 * Set all tables of a document as referenced, used only during
261 * store-to-file.
262 * @returns <TRUE/> if ALL tables of ALL documents are marked.
264 bool setCacheDocReferenced( sal_uInt16 nFileId );
267 * Set a table as referenced, used only during store-to-file.
268 * @returns <TRUE/> if ALL tables of ALL documents are marked.
270 bool setCacheTableReferenced( sal_uInt16 nFileId, const OUString& rTabName, size_t nSheets, bool bPermanent );
271 void setAllCacheTableReferencedStati( bool bReferenced );
272 bool areAllCacheTablesReferenced() const { return maReferenced.mbAllReferenced;}
275 * Collect all cached non-empty cell positions, inferred directly from the
276 * cached data, not the cached range metadata stored separately in the
277 * Table.
279 void getAllCachedDataSpans( sal_uInt16 nFileId, sc::ColumnSpanSet& rSet ) const;
281 private:
282 struct ReferencedStatus
284 struct DocReferenced
286 ::std::vector<bool> maTables;
287 bool mbAllTablesReferenced;
288 // Initially, documents have no tables but all referenced.
289 DocReferenced() : mbAllTablesReferenced(true) {}
291 typedef ::std::vector<DocReferenced> DocReferencedVec;
293 DocReferencedVec maDocs;
294 bool mbAllReferenced;
296 ReferencedStatus();
297 void reset( size_t nDocs );
298 void checkAllDocs();
300 } maReferenced;
301 void addCacheTableToReferenced( sal_uInt16 nFileId, size_t nIndex );
302 void addCacheDocToReferenced( sal_uInt16 nFileId );
303 public:
305 ScExternalRefCache::TableTypeRef getCacheTable(sal_uInt16 nFileId, size_t nTabIndex) const;
306 ScExternalRefCache::TableTypeRef getCacheTable(sal_uInt16 nFileId, const OUString& rTabName, bool bCreateNew, size_t* pnIndex);
309 * Clear all caches including the cache tables.
311 void clearCache(sal_uInt16 nFileId);
314 * Clear all caches but keep the tables. All cache tables will be empty
315 * after the call, but the tables will not be removed.
317 void clearCacheTables(sal_uInt16 nFileId);
319 private:
320 struct RangeHash
322 size_t operator()(const ScRange& rRange) const
324 const ScAddress& s = rRange.aStart;
325 const ScAddress& e = rRange.aEnd;
326 return s.Tab() + s.Col() + s.Row() + e.Tab() + e.Col() + e.Row();
330 typedef std::unordered_map<OUString, TokenArrayRef, OUStringHash> RangeNameMap;
331 typedef std::unordered_map<ScRange, TokenArrayRef, RangeHash> RangeArrayMap;
332 typedef std::unordered_map<OUString, OUString, OUStringHash> NamePairMap;
334 /** Represents data cached for a single external document. */
335 struct DocItem
337 /** The raw cache tables. */
338 ::std::vector<TableTypeRef> maTables;
339 /** Table name list in correct order, in both upper- and real-case. */
340 ::std::vector<TableName> maTableNames;
341 /** Table name to index map. The names must be stored upper-case. */
342 TableNameIndexMap maTableNameIndex;
343 /** Range name cache. */
344 RangeNameMap maRangeNames;
345 /** Token array cache for cell ranges. */
346 RangeArrayMap maRangeArrays;
347 /** Upper- to real-case mapping for range names. */
348 NamePairMap maRealRangeNameMap;
350 bool mbInitFromSource;
352 DocItem() : mbInitFromSource(false) {}
354 typedef std::unordered_map<sal_uInt16, DocItem> DocDataType;
355 DocItem* getDocItem(sal_uInt16 nFileId) const;
357 private:
358 mutable osl::Mutex maMtxDocs;
359 mutable DocDataType maDocs;
362 class SC_DLLPUBLIC ScExternalRefManager : public formula::ExternalReferenceHelper, SfxListener
364 public:
366 typedef std::set<ScFormulaCell*> RefCellSet;
367 typedef std::unordered_map<sal_uInt16, RefCellSet> RefCellMap;
369 enum LinkUpdateType { LINK_MODIFIED, LINK_BROKEN };
372 * Base class for objects that need to listen to link updates. When a
373 * link to a certain external file is updated, the notify() method gets
374 * called.
376 class LinkListener
378 public:
379 LinkListener();
380 virtual ~LinkListener() = 0;
381 virtual void notify(sal_uInt16 nFileId, LinkUpdateType eType) = 0;
383 struct Hash
385 size_t operator() (const LinkListener* p) const
387 return reinterpret_cast<size_t>(p);
393 * Use this guard when performing something from the API that might query
394 * values from external references. Interpreting formula strings is one
395 * such example.
397 class SC_DLLPUBLIC ApiGuard
399 public:
400 ApiGuard(ScDocument* pDoc);
401 ~ApiGuard();
402 private:
403 ScExternalRefManager* mpMgr;
404 bool mbOldInteractionEnabled;
407 private:
408 /** Shell instance for a source document. */
409 struct SrcShell
411 SfxObjectShellRef maShell;
412 tools::Time maLastAccess;
414 SrcShell() : maLastAccess( tools::Time::SYSTEM ) {}
417 typedef std::unordered_map<sal_uInt16, SrcShell> DocShellMap;
418 typedef std::unordered_map<sal_uInt16, bool> LinkedDocMap;
420 typedef std::unordered_map<sal_uInt16, SvNumberFormatterMergeMap> NumFmtMap;
422 typedef std::unordered_set<LinkListener*, LinkListener::Hash> LinkListeners;
423 typedef std::unordered_map<sal_uInt16, LinkListeners> LinkListenerMap;
425 public:
426 /** Source document meta-data container. */
427 struct SrcFileData
429 OUString maFileName; /// original file name as loaded from the file.
430 OUString maRealFileName; /// file name created from the relative name.
431 OUString maRelativeName;
432 OUString maFilterName;
433 OUString maFilterOptions;
434 bool bUnsaved;
436 void maybeCreateRealFileName(const OUString& rOwnDocName);
439 public:
440 explicit ScExternalRefManager(ScDocument* pDoc);
441 virtual ~ScExternalRefManager();
443 virtual OUString getCacheTableName(sal_uInt16 nFileId, size_t nTabIndex) const SAL_OVERRIDE;
446 * Get a cache table instance for specified table and table index. Unlike
447 * the other method that takes a table name, this method does not create a
448 * new table when a table is not available for specified index.
450 * @param nFileId file ID
451 * @param nTabIndex cache table index
453 * @return shared_ptr to the cache table instance
455 ScExternalRefCache::TableTypeRef getCacheTable(sal_uInt16 nFileId, size_t nTabIndex) const;
458 * Get a cache table instance for specified file and table name. If the
459 * table instance is not already present, it'll instantiate a new one and
460 * append it to the end of the table array. <I>It's important to be
461 * aware of this fact especially for multi-table ranges for which
462 * table orders are critical.</I>
464 * Excel filter calls this method to populate the cache table from the
465 * XCT/CRN records.
467 * @param nFileId file ID
468 * @param rTabName table name
469 * @param bCreateNew if true, create a new table instance if it's not
470 * already present. If false, it returns NULL if the
471 * specified table's cache doesn't exist.
472 * @param pnIndex if non-NULL pointer is passed, it stores the internal
473 * index of a cache table instance.
475 * @return shared_ptr to the cache table instance
477 ScExternalRefCache::TableTypeRef getCacheTable(sal_uInt16 nFileId, const OUString& rTabName, bool bCreateNew, size_t* pnIndex = 0);
479 /** Returns a vector containing all (real) table names and cache tables of
480 the specified file.
482 The index in the returned vector corresponds to the table index used to
483 access the cache table, e.g. in getCacheTable().
485 void getAllCachedTableNames(sal_uInt16 nFileId, ::std::vector<OUString>& rTabNames) const;
488 * Get the span (distance+sign(distance)) of two sheets of a specified
489 * file.
491 * @param nFileId file ID
492 * @param rStartTabName name of first sheet (sheet1)
493 * @param rEndTabName name of second sheet (sheet2)
495 * @return span
496 * 1 if sheet2 == sheet1
497 * > 1 if sheet2 > sheet1
498 * < -1 if sheet2 < sheet1
499 * -1 if nFileId or rStartTabName not found
500 * 0 if rEndTabName not found
502 SCsTAB getCachedTabSpan(
503 sal_uInt16 nFileId, const OUString& rStartTabName, const OUString& rEndTabName) const;
506 * Get all unique number format indices that are used in the cache tables.
507 * The retrieved indices are sorted in ascending order.
509 * @param rNumFmts (reference) all unique number format indices.
511 void getAllCachedNumberFormats(::std::vector<sal_uInt32>& rNumFmts) const;
513 sal_uInt16 getExternalFileCount() const;
516 * Mark all tables as referenced that are used by any LinkListener, used
517 * only during store-to-file.
518 * @returns <TRUE/> if ALL tables of ALL external documents are marked.
520 bool markUsedByLinkListeners();
522 bool markUsedExternalRefCells();
525 * Set a table as referenced, used only during store-to-file.
526 * @returns <TRUE/> if ALL tables of ALL external documents are marked.
528 bool setCacheTableReferenced( sal_uInt16 nFileId, const OUString& rTabName, size_t nSheets );
529 void setAllCacheTableReferencedStati( bool bReferenced );
532 * @returns <TRUE/> if setAllCacheTableReferencedStati(false) was called,
533 * <FALSE/> if setAllCacheTableReferencedStati(true) was called.
535 bool isInReferenceMarking() const { return mbInReferenceMarking; }
537 void storeRangeNameTokens(sal_uInt16 nFileId, const OUString& rName, const ScTokenArray& rArray);
539 ScExternalRefCache::TokenRef getSingleRefToken(
540 sal_uInt16 nFileId, const OUString& rTabName, const ScAddress& rCell,
541 const ScAddress* pCurPos, SCTAB* pTab, ScExternalRefCache::CellFormat* pFmt = NULL);
544 * Get an array of tokens that consist of the specified external cell
545 * range.
547 * @param nFileId file ID for an external document
548 * @param rTabName referenced sheet name
549 * @param rRange referenced cell range
550 * @param pCurPos current cursor position to keep track of cells that
551 * reference an external data.
553 * @return shared_ptr to a token array instance. <i>The caller must not
554 * delete the instance returned by this method.</i>
556 ScExternalRefCache::TokenArrayRef getDoubleRefTokens(
557 sal_uInt16 nFileId, const OUString& rTabName, const ScRange& rRange, const ScAddress* pCurPos);
560 * Get an array of tokens corresponding with a specified name in a
561 * specified file.
563 * @param pCurPos currnet cell address where this name token is used.
564 * This is purely to keep track of all cells containing
565 * external names for refreshing purposes. If this is
566 * NULL, then the cell will not be added to the list.
568 * @return shared_ptr to array of tokens composing the name
570 ScExternalRefCache::TokenArrayRef getRangeNameTokens(
571 sal_uInt16 nFileId, const OUString& rName, const ScAddress* pCurPos = NULL);
573 bool isValidRangeName(sal_uInt16 nFileId, const OUString& rName);
575 OUString getOwnDocumentName() const;
576 bool isOwnDocument(const OUString& rFile) const;
579 * Takes a flat file name, and convert it to an absolute URL path. An
580 * absolute URL path begines with 'file:///.
582 * @param rFile file name to convert
584 void convertToAbsName(OUString& rFile) const;
585 sal_uInt16 getExternalFileId(const OUString& rFile);
588 * It returns a pointer to the name of the URI associated with a given
589 * external file ID. In case the original document has moved, it returns
590 * an URI adjusted for the relocation.
592 * @param nFileId file ID for an external document
593 * @param bForceOriginal If true, it always returns the original document
594 * URI even if the referring document has relocated.
595 * If false, it returns an URI adjusted for
596 * relocated document.
598 * @return const OUString* external document URI.
600 const OUString* getExternalFileName(sal_uInt16 nFileId, bool bForceOriginal = false);
603 * Get all cached external file names as an array. Array indices of the
604 * returned name array correspond with external file ID's.
606 std::vector<OUString> getAllCachedExternalFileNames() const;
608 bool hasExternalFile(sal_uInt16 nFileId) const;
609 bool hasExternalFile(const OUString& rFile) const;
610 const SrcFileData* getExternalFileData(sal_uInt16 nFileId) const;
612 const OUString* getRealTableName(sal_uInt16 nFileId, const OUString& rTabName) const;
613 const OUString* getRealRangeName(sal_uInt16 nFileId, const OUString& rRangeName) const;
614 void clearCache(sal_uInt16 nFileId);
615 bool refreshSrcDocument(sal_uInt16 nFileId);
616 void breakLink(sal_uInt16 nFileId);
617 void switchSrcFile(sal_uInt16 nFileId, const OUString& rNewFile, const OUString& rNewFilter);
620 * Set a relative file path for the specified file ID. Note that the
621 * caller must ensure that the passed URL is a valid relative URL.
623 * @param nFileId file ID for an external document
624 * @param rRelUrl relative URL
626 void setRelativeFileName(sal_uInt16 nFileId, const OUString& rRelUrl);
629 * Set the filter name and options if any for a given source document.
630 * These values get reset when the source document ever gets reloaded.
632 * @param nFileId
633 * @param rFilterName
634 * @param rOptions
636 void setFilterData(sal_uInt16 nFileId, const OUString& rFilterName, const OUString& rOptions);
638 void clear();
640 bool hasExternalData() const;
643 * Re-generates relative names for all stored source files. This is
644 * necessary when exporting to an ods document, to ensure that all source
645 * files have their respective relative names for xlink:href export.
647 * @param rBaseFileUrl Absolute URL of the content.xml fragment of the
648 * document being exported.
650 void resetSrcFileData(const OUString& rBaseFileUrl);
653 * Replace the original URL wirh the real URL that was generated from the relative URL.
655 void updateAbsAfterLoad();
658 * Stop tracking a specific formula cell.
660 * @param pCell pointer to cell that formerly contained external
661 * reference.
663 void removeRefCell(ScFormulaCell* pCell);
666 * Register a new link listener to a specified external document. Note
667 * that the caller is responsible for managing the life cycle of the
668 * listener object.
670 void addLinkListener(sal_uInt16 nFileId, LinkListener* pListener);
673 * Remove an existing link listener. Note that removing a listener
674 * pointer here does not delete the listener object instance.
676 void removeLinkListener(sal_uInt16 nFileId, LinkListener* pListener);
678 void removeLinkListener(LinkListener* pListener);
681 * Notify all listeners that are listening to a specified external
682 * document.
684 * @param nFileId file ID for an external document.
686 void notifyAllLinkListeners(sal_uInt16 nFileId, LinkUpdateType eType);
689 * Check if the file specified by the path is a legitimate file that
690 * exists & can be loaded.
692 bool isFileLoadable(const OUString& rFile) const;
694 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) SAL_OVERRIDE;
697 * If we still contain unsaved files we should warn the user before saving
699 * @return true if the document still contains references to an unsaved file
701 bool containsUnsavedReferences() const { return !maUnsavedDocShells.empty(); }
703 void insertRefCell(sal_uInt16 nFileId, const ScAddress& rCell);
705 * Add a cell to reference the same files as the template cell.
707 void insertRefCellFromTemplate( ScFormulaCell* pTemplateCell, ScFormulaCell* pCell );
709 bool hasCellExternalReference(const ScAddress& rCell);
711 void enableDocTimer( bool bEnable );
713 private:
714 ScExternalRefManager(const ScExternalRefManager&) SAL_DELETED_FUNCTION;
716 void refreshAllRefCells(sal_uInt16 nFileId);
718 void fillCellFormat(sal_uLong nFmtIndex, ScExternalRefCache::CellFormat* pFmt) const;
720 ScExternalRefCache::TokenRef getSingleRefTokenFromSrcDoc(
721 sal_uInt16 nFileId, ScDocument* pSrcDoc, const ScAddress& rPos,
722 ScExternalRefCache::CellFormat* pFmt);
725 * Retrieve a range token array from a source document instance.
727 * @param pSrcDoc pointer to the source document instance.
728 * @param rTabName name of the first table.
729 * @param rRange range specified. Upon successful retrieval, this range
730 * gets modified to contain the correct table IDs, and in
731 * case the range is larger than the data area of the source
732 * document, it gets reduced to the data area.
733 * @param rCacheData an array of structs, with each struct containing the
734 * table name and the data in the specified range.
736 * @return range token array
738 ScExternalRefCache::TokenArrayRef getDoubleRefTokensFromSrcDoc(
739 ScDocument* pSrcDoc, const OUString& rTabName, ScRange& rRange,
740 ::std::vector<ScExternalRefCache::SingleRangeData>& rCacheData);
743 * Retrieve range name token array from a source document instance.
745 * @param nFileId file ID of the source document.
746 * @param pSrcDoc pointer to the source document instance
747 * @param rName range name to retrieve. Note that the range name lookup
748 * is case <i>in</i>-sensitive, and upon successful retrieval
749 * of the range name array, this name gets updated to the
750 * actual range name with the correct casing.
752 * @return range name token array
754 static ScExternalRefCache::TokenArrayRef getRangeNameTokensFromSrcDoc(
755 sal_uInt16 nFileId, ScDocument* pSrcDoc, OUString& rName);
757 ScDocument* getInMemorySrcDocument(sal_uInt16 nFileId);
758 ScDocument* getSrcDocument(sal_uInt16 nFileId);
759 SfxObjectShellRef loadSrcDocument(sal_uInt16 nFileId, OUString& rFilter);
762 * Caller must ensure that the passed shell is not already stored.
764 ScDocument& cacheNewDocShell( sal_uInt16 nFileId, SrcShell& rSrcShell );
766 void maybeLinkExternalFile(sal_uInt16 nFileId);
769 * Try to create a "real" file name from the relative path. The original
770 * file name may not point to the real document when the referencing and
771 * referenced documents have been moved.
773 * For the real file name to be created, the relative name should not be
774 * empty before calling this method, or the real file name will not be
775 * created.
777 * @param nFileId file ID for an external document
779 void maybeCreateRealFileName(sal_uInt16 nFileId);
782 * Purge those source document instances that have not been accessed for
783 * the specified duration.
785 * @param nTimeOut time out value in 100th of a second
787 void purgeStaleSrcDocument(sal_Int32 nTimeOut);
789 sal_uInt32 getMappedNumberFormat(sal_uInt16 nFileId, sal_uInt32 nNumFmt, const ScDocument* pSrcDoc);
792 * If in maUnsavedDocShells move it to maDocShells and create a correct
793 * external reference entry
795 * @param Pointer to the newly saved DocumentShell
797 void transformUnsavedRefToSavedRef( SfxObjectShell* pShell );
799 private:
800 ScDocument* mpDoc;
802 /** cache of referenced ranges and names from source documents. */
803 ScExternalRefCache maRefCache;
806 * Source document cache. This stores the original source document shell
807 * instances. They get purged after a certain period of time.
809 DocShellMap maDocShells;
812 * DocShells to unsaved but referenced documents. If not empty ask before saving!
813 * Move to maDocShells if document referenced here is saved
815 DocShellMap maUnsavedDocShells;
817 /** list of source documents that are managed by the link manager. */
818 LinkedDocMap maLinkedDocs;
821 * List of referencing cells that may contain external names. There is
822 * one list per source document.
824 RefCellMap maRefCells;
826 LinkListenerMap maLinkListeners;
828 NumFmtMap maNumFormatMap;
831 * List of external source document meta-data, used to keep track of
832 * external document identifiers.
834 std::vector<SrcFileData> maSrcFiles;
836 /** Status whether in reference marking state. See isInReferenceMarking(). */
837 bool mbInReferenceMarking:1;
840 * Controls whether or not to allow user interaction. We don't want any
841 * user interaction when calling from the API.
843 bool mbUserInteractionEnabled:1;
845 bool mbDocTimerEnabled:1;
847 AutoTimer maSrcDocTimer;
848 DECL_LINK_TYPED(TimeOutHdl, Timer*, void);
851 #endif
853 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */