Bump version to 4.3-4
[LibreOffice.git] / sc / inc / externalrefmgr.hxx
blob9bcc64d36f8f2a1194f3034785584bfb93e82c19
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/unordered_map.hpp>
38 #include <boost/unordered_set.hpp>
39 #include <boost/shared_ptr.hpp>
40 #include <vector>
41 #include <list>
42 #include <set>
43 #include <formula/ExternalReferenceHelper.hxx>
45 class ScDocument;
46 class ScTokenArray;
47 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(Window* pParent, const Link& rEndEditHdl) SAL_OVERRIDE;
75 void SetDoReferesh(bool b);
77 private:
78 ScExternalRefLink(); // disabled
79 ScExternalRefLink(const ScExternalRefLink&); // disabled
81 DECL_LINK( 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 ::boost::unordered_map<SCCOL, Cell> RowDataType;
123 typedef ::boost::unordered_map<SCROW, RowDataType> RowsDataType;
125 public:
126 // SUNWS needs a forward declared friend, otherwise types and members
127 // of the outer class are not accessible.
128 class Table;
129 friend class ScExternalRefCache::Table;
132 * Represents a single cached table in an external document. It only
133 * stores non-empty cells; empty cells should never be stored in the data
134 * cache. Instead, cached ranges should be used to determine whether or
135 * not a cell is empty or needs fetching from the source document. If a
136 * cell's value is not stored but its address is within the cached ranges,
137 * that cell is already queried in the source document and we know it's
138 * empty.
140 class Table
142 public:
144 enum ReferencedFlag
146 UNREFERENCED,
147 REFERENCED_MARKED, // marked as referenced during store to file
148 REFERENCED_PERMANENT // permanently marked, e.g. from within interpreter
151 Table();
152 ~Table();
154 void clear();
157 * Add cell value to the cache.
159 * @param bSetCacheRange if true, mark this cell 'cached'. This is
160 * false _only when_ adding a range of cell
161 * values, for performance reasons.
163 SC_DLLPUBLIC void setCell(SCCOL nCol, SCROW nRow, TokenRef pToken, sal_uLong nFmtIndex = 0, bool bSetCacheRange = true);
164 SC_DLLPUBLIC TokenRef getCell(SCCOL nCol, SCROW nRow, sal_uInt32* pnFmtIndex = NULL) const;
165 bool hasRow( SCROW nRow ) const;
166 /** Set/clear referenced status flag only if current status is not
167 REFERENCED_PERMANENT. */
168 void setReferenced( bool bReferenced );
169 /// Unconditionally set the reference status flag.
170 void setReferencedFlag( ReferencedFlag eFlag );
171 ReferencedFlag getReferencedFlag() const;
172 bool isReferenced() const;
173 /// Obtain a sorted vector of rows.
174 void getAllRows(::std::vector<SCROW>& rRows, SCROW nLow = 0, SCROW nHigh = MAXROW) const;
175 /// Returns the half-open range of used rows in this table. Returns [0,0) if table is empty.
176 SC_DLLPUBLIC ::std::pair< SCROW, SCROW > getRowRange() const;
177 /// Obtain a sorted vector of columns.
178 void getAllCols(SCROW nRow, ::std::vector<SCCOL>& rCols, SCCOL nLow = 0, SCCOL nHigh = MAXCOL) const;
179 /// Returns the half-open range of used columns in the specified row. Returns [0,0) if row is empty.
180 SC_DLLPUBLIC ::std::pair< SCCOL, SCCOL > getColRange( SCROW nRow ) const;
181 void getAllNumberFormats(::std::vector<sal_uInt32>& rNumFmts) const;
182 bool isRangeCached(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const;
184 void setCachedCell(SCCOL nCol, SCROW nRow);
185 void setCachedCellRange(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
188 * Call this to mark the entire table "cached". This will prevent all
189 * future attempts to access the source document even when non-cached
190 * cells are queried. In such case, non-cached cells are treated as
191 * empty cells. Useful when loading a document with own external data
192 * cache.
194 SC_DLLPUBLIC void setWholeTableCached();
195 private:
196 bool isInCachedRanges(SCCOL nCol, SCROW nRow) const;
197 TokenRef getEmptyOrNullToken(SCCOL nCol, SCROW nRow) const;
199 private:
200 /** Data cache */
201 RowsDataType maRows;
202 /** Collection of individual cached ranges. The table ranges are
203 * not used & always zero. */
204 ScRangeList maCachedRanges;
205 ReferencedFlag meReferenced;
208 typedef ::boost::shared_ptr<Table> TableTypeRef;
209 typedef ::boost::unordered_map< OUString, size_t, OUStringHash>
210 TableNameIndexMap;
212 ScExternalRefCache();
213 ~ScExternalRefCache();
215 const OUString* getRealTableName(sal_uInt16 nFileId, const OUString& rTabName) const;
216 const OUString* getRealRangeName(sal_uInt16 nFileId, const OUString& rRangeName) const;
219 * Get a cached cell data at specified cell location.
221 * @param nFileId file ID of an external document
222 * @param rTabName sheet name
223 * @param nCol
224 * @param nRow
226 * @return pointer to the token instance in the cache.
228 ScExternalRefCache::TokenRef getCellData(
229 sal_uInt16 nFileId, const OUString& rTabName, SCCOL nCol, SCROW nRow, sal_uInt32* pnFmtIndex);
232 * Get a cached cell range data.
234 * @return a new token array instance. Note that <i>the caller must
235 * manage the life cycle of the returned instance</i>, which is
236 * guaranteed if the TokenArrayRef is properly used..
238 ScExternalRefCache::TokenArrayRef getCellRangeData(
239 sal_uInt16 nFileId, const OUString& rTabName, const ScRange& rRange);
241 ScExternalRefCache::TokenArrayRef getRangeNameTokens(sal_uInt16 nFileId, const OUString& rName);
242 void setRangeNameTokens(sal_uInt16 nFileId, const OUString& rName, TokenArrayRef pArray);
243 bool isValidRangeName(sal_uInt16 nFileId, const OUString& rName) const;
245 void setCellData(sal_uInt16 nFileId, const OUString& rTabName,
246 SCCOL nCol, SCROW nRow, TokenRef pToken, sal_uLong nFmtIndex);
248 struct SingleRangeData
250 /** This name must be in upper-case. */
251 OUString maTableName;
252 ScMatrixRef mpRangeData;
254 void setCellRangeData(sal_uInt16 nFileId, const ScRange& rRange, const ::std::vector<SingleRangeData>& rData,
255 const TokenArrayRef& pArray);
257 bool isDocInitialized(sal_uInt16 nFileId);
258 void initializeDoc(sal_uInt16 nFileId, const ::std::vector<OUString>& rTabNames);
259 OUString getTableName(sal_uInt16 nFileId, size_t nCacheId) const;
260 void getAllTableNames(sal_uInt16 nFileId, ::std::vector<OUString>& rTabNames) const;
261 SCsTAB getTabSpan( sal_uInt16 nFileId, const OUString& rStartTabName, const OUString& rEndTabName ) const;
262 void getAllNumberFormats(::std::vector<sal_uInt32>& rNumFmts) const;
265 * Set all tables of a document as referenced, used only during
266 * store-to-file.
267 * @returns <TRUE/> if ALL tables of ALL documents are marked.
269 bool setCacheDocReferenced( sal_uInt16 nFileId );
272 * Set a table as referenced, used only during store-to-file.
273 * @returns <TRUE/> if ALL tables of ALL documents are marked.
275 bool setCacheTableReferenced( sal_uInt16 nFileId, const OUString& rTabName, size_t nSheets, bool bPermanent );
276 void setAllCacheTableReferencedStati( bool bReferenced );
277 bool areAllCacheTablesReferenced() const;
280 * Collect all cached non-empty cell positions, inferred directly from the
281 * cached data, not the cached range metadata stored separately in the
282 * Table.
284 void getAllCachedDataSpans( sal_uInt16 nFileId, sc::ColumnSpanSet& rSet ) const;
286 private:
287 struct ReferencedStatus
289 struct DocReferenced
291 ::std::vector<bool> maTables;
292 bool mbAllTablesReferenced;
293 // Initially, documents have no tables but all referenced.
294 DocReferenced() : mbAllTablesReferenced(true) {}
296 typedef ::std::vector<DocReferenced> DocReferencedVec;
298 DocReferencedVec maDocs;
299 bool mbAllReferenced;
301 ReferencedStatus();
302 void reset( size_t nDocs );
303 void checkAllDocs();
305 } maReferenced;
306 void addCacheTableToReferenced( sal_uInt16 nFileId, size_t nIndex );
307 void addCacheDocToReferenced( sal_uInt16 nFileId );
308 public:
310 ScExternalRefCache::TableTypeRef getCacheTable(sal_uInt16 nFileId, size_t nTabIndex) const;
311 ScExternalRefCache::TableTypeRef getCacheTable(sal_uInt16 nFileId, const OUString& rTabName, bool bCreateNew, size_t* pnIndex);
314 * Clear all caches including the cache tables.
316 void clearCache(sal_uInt16 nFileId);
319 * Clear all caches but keep the tables. All cache tables will be empty
320 * after the call, but the tables will not be removed.
322 void clearCacheTables(sal_uInt16 nFileId);
324 private:
325 struct RangeHash
327 size_t operator()(const ScRange& rRange) const
329 const ScAddress& s = rRange.aStart;
330 const ScAddress& e = rRange.aEnd;
331 return s.Tab() + s.Col() + s.Row() + e.Tab() + e.Col() + e.Row();
335 typedef ::boost::unordered_map<OUString, TokenArrayRef, OUStringHash> RangeNameMap;
336 typedef ::boost::unordered_map<ScRange, TokenArrayRef, RangeHash> RangeArrayMap;
337 typedef ::boost::unordered_map<OUString, OUString, OUStringHash> NamePairMap;
339 // SUNWS needs a forward declared friend, otherwise types and members
340 // of the outer class are not accessible.
341 struct DocItem;
342 friend struct ScExternalRefCache::DocItem;
344 /** Represents data cached for a single external document. */
345 struct DocItem
347 /** The raw cache tables. */
348 ::std::vector<TableTypeRef> maTables;
349 /** Table name list in correct order, in both upper- and real-case. */
350 ::std::vector<TableName> maTableNames;
351 /** Table name to index map. The names must be stored upper-case. */
352 TableNameIndexMap maTableNameIndex;
353 /** Range name cache. */
354 RangeNameMap maRangeNames;
355 /** Token array cache for cell ranges. */
356 RangeArrayMap maRangeArrays;
357 /** Upper- to real-case mapping for range names. */
358 NamePairMap maRealRangeNameMap;
360 bool mbInitFromSource;
362 DocItem() : mbInitFromSource(false) {}
364 typedef ::boost::unordered_map<sal_uInt16, DocItem> DocDataType;
365 DocItem* getDocItem(sal_uInt16 nFileId) const;
367 private:
368 mutable osl::Mutex maMtxDocs;
369 mutable DocDataType maDocs;
372 class SC_DLLPUBLIC ScExternalRefManager : public formula::ExternalReferenceHelper, SfxListener
374 public:
376 typedef ::std::set<ScFormulaCell*> RefCellSet;
377 typedef ::boost::unordered_map<sal_uInt16, RefCellSet> RefCellMap;
379 enum LinkUpdateType { LINK_MODIFIED, LINK_BROKEN };
382 * Base class for objects that need to listen to link updates. When a
383 * link to a certain external file is updated, the notify() method gets
384 * called.
386 class LinkListener
388 public:
389 LinkListener();
390 virtual ~LinkListener() = 0;
391 virtual void notify(sal_uInt16 nFileId, LinkUpdateType eType) = 0;
393 struct Hash
395 size_t operator() (const LinkListener* p) const
397 return reinterpret_cast<size_t>(p);
403 * Use this guard when performing something from the API that might query
404 * values from external references. Interpreting formula strings is one
405 * such example.
407 class SC_DLLPUBLIC ApiGuard
409 public:
410 ApiGuard(ScDocument* pDoc);
411 ~ApiGuard();
412 private:
413 ScExternalRefManager* mpMgr;
414 bool mbOldInteractionEnabled;
417 private:
418 /** Shell instance for a source document. */
419 struct SrcShell
421 SfxObjectShellRef maShell;
422 Time maLastAccess;
424 SrcShell() : maLastAccess( Time::SYSTEM ) {}
427 typedef ::boost::unordered_map<sal_uInt16, SrcShell> DocShellMap;
428 typedef ::boost::unordered_map<sal_uInt16, bool> LinkedDocMap;
430 typedef ::boost::unordered_map<sal_uInt16, SvNumberFormatterMergeMap> NumFmtMap;
433 typedef ::boost::unordered_set<LinkListener*, LinkListener::Hash> LinkListeners;
434 typedef ::boost::unordered_map<sal_uInt16, LinkListeners> LinkListenerMap;
436 public:
437 /** Source document meta-data container. */
438 struct SrcFileData
440 OUString maFileName; /// original file name as loaded from the file.
441 OUString maRealFileName; /// file name created from the relative name.
442 OUString maRelativeName;
443 OUString maFilterName;
444 OUString maFilterOptions;
445 bool bUnsaved;
447 void maybeCreateRealFileName(const OUString& rOwnDocName);
450 public:
451 explicit ScExternalRefManager(ScDocument* pDoc);
452 virtual ~ScExternalRefManager();
454 virtual OUString getCacheTableName(sal_uInt16 nFileId, size_t nTabIndex) const SAL_OVERRIDE;
457 * Get a cache table instance for specified table and table index. Unlike
458 * the other method that takes a table name, this method does not create a
459 * new table when a table is not available for specified index.
461 * @param nFileId file ID
462 * @param nTabIndex cache table index
464 * @return shared_ptr to the cache table instance
466 ScExternalRefCache::TableTypeRef getCacheTable(sal_uInt16 nFileId, size_t nTabIndex) const;
469 * Get a cache table instance for specified file and table name. If the
470 * table instance is not already present, it'll instantiate a new one and
471 * append it to the end of the table array. <I>It's important to be
472 * aware of this fact especially for multi-table ranges for which
473 * table orders are critical.</I>
475 * Excel filter calls this method to populate the cache table from the
476 * XCT/CRN records.
478 * @param nFileId file ID
479 * @param rTabName table name
480 * @param bCreateNew if true, create a new table instance if it's not
481 * already present. If false, it returns NULL if the
482 * specified table's cache doesn't exist.
483 * @param pnIndex if non-NULL pointer is passed, it stores the internal
484 * index of a cache table instance.
486 * @return shared_ptr to the cache table instance
488 ScExternalRefCache::TableTypeRef getCacheTable(sal_uInt16 nFileId, const OUString& rTabName, bool bCreateNew, size_t* pnIndex = 0);
490 /** Returns a vector containing all (real) table names and cache tables of
491 the specified file.
493 The index in the returned vector corresponds to the table index used to
494 access the cache table, e.g. in getCacheTable().
496 void getAllCachedTableNames(sal_uInt16 nFileId, ::std::vector<OUString>& rTabNames) const;
499 * Get the span (distance+sign(distance)) of two sheets of a specified
500 * file.
502 * @param nFileId file ID
503 * @param rStartTabName name of first sheet (sheet1)
504 * @param rEndTabName name of second sheet (sheet2)
506 * @return span
507 * 1 if sheet2 == sheet1
508 * > 1 if sheet2 > sheet1
509 * < -1 if sheet2 < sheet1
510 * -1 if nFileId or rStartTabName not found
511 * 0 if rEndTabName not found
513 SCsTAB getCachedTabSpan(
514 sal_uInt16 nFileId, const OUString& rStartTabName, const OUString& rEndTabName) const;
517 * Get all unique number format indices that are used in the cache tables.
518 * The retrieved indices are sorted in ascending order.
520 * @param rNumFmts (reference) all unique number format indices.
522 void getAllCachedNumberFormats(::std::vector<sal_uInt32>& rNumFmts) const;
524 sal_uInt16 getExternalFileCount() const;
527 * Mark all tables as referenced that are used by any LinkListener, used
528 * only during store-to-file.
529 * @returns <TRUE/> if ALL tables of ALL external documents are marked.
531 bool markUsedByLinkListeners();
533 bool markUsedExternalRefCells();
536 * Set a table as referenced, used only during store-to-file.
537 * @returns <TRUE/> if ALL tables of ALL external documents are marked.
539 bool setCacheTableReferenced( sal_uInt16 nFileId, const OUString& rTabName, size_t nSheets );
540 void setAllCacheTableReferencedStati( bool bReferenced );
543 * @returns <TRUE/> if setAllCacheTableReferencedStati(false) was called,
544 * <FALSE/> if setAllCacheTableReferencedStati(true) was called.
546 bool isInReferenceMarking() const { return mbInReferenceMarking; }
548 void storeRangeNameTokens(sal_uInt16 nFileId, const OUString& rName, const ScTokenArray& rArray);
550 ScExternalRefCache::TokenRef getSingleRefToken(
551 sal_uInt16 nFileId, const OUString& rTabName, const ScAddress& rCell,
552 const ScAddress* pCurPos, SCTAB* pTab, ScExternalRefCache::CellFormat* pFmt = NULL);
555 * Get an array of tokens that consist of the specified external cell
556 * range.
558 * @param nFileId file ID for an external document
559 * @param rTabName referenced sheet name
560 * @param rRange referenced cell range
561 * @param pCurPos current cursor position to keep track of cells that
562 * reference an external data.
564 * @return shared_ptr to a token array instance. <i>The caller must not
565 * delete the instance returned by this method.</i>
567 ScExternalRefCache::TokenArrayRef getDoubleRefTokens(
568 sal_uInt16 nFileId, const OUString& rTabName, const ScRange& rRange, const ScAddress* pCurPos);
571 * Get an array of tokens corresponding with a specified name in a
572 * specified file.
574 * @param pCurPos currnet cell address where this name token is used.
575 * This is purely to keep track of all cells containing
576 * external names for refreshing purposes. If this is
577 * NULL, then the cell will not be added to the list.
579 * @return shared_ptr to array of tokens composing the name
581 ScExternalRefCache::TokenArrayRef getRangeNameTokens(
582 sal_uInt16 nFileId, const OUString& rName, const ScAddress* pCurPos = NULL);
584 bool isValidRangeName(sal_uInt16 nFileId, const OUString& rName);
586 OUString getOwnDocumentName() const;
587 bool isOwnDocument(const OUString& rFile) const;
590 * Takes a flat file name, and convert it to an absolute URL path. An
591 * absolute URL path begines with 'file:///.
593 * @param rFile file name to convert
595 void convertToAbsName(OUString& rFile) const;
596 sal_uInt16 getExternalFileId(const OUString& rFile);
599 * It returns a pointer to the name of the URI associated with a given
600 * external file ID. In case the original document has moved, it returns
601 * an URI adjusted for the relocation.
603 * @param nFileId file ID for an external document
604 * @param bForceOriginal If true, it always returns the original document
605 * URI even if the referring document has relocated.
606 * If false, it returns an URI adjusted for
607 * relocated document.
609 * @return const OUString* external document URI.
611 const OUString* getExternalFileName(sal_uInt16 nFileId, bool bForceOriginal = false);
614 * Get all cached external file names as an array. Array indices of the
615 * returned name array correspond with external file ID's.
617 std::vector<OUString> getAllCachedExternalFileNames() const;
619 bool hasExternalFile(sal_uInt16 nFileId) const;
620 bool hasExternalFile(const OUString& rFile) const;
621 const SrcFileData* getExternalFileData(sal_uInt16 nFileId) const;
623 const OUString* getRealTableName(sal_uInt16 nFileId, const OUString& rTabName) const;
624 const OUString* getRealRangeName(sal_uInt16 nFileId, const OUString& rRangeName) const;
625 void clearCache(sal_uInt16 nFileId);
626 bool refreshSrcDocument(sal_uInt16 nFileId);
627 void breakLink(sal_uInt16 nFileId);
628 void switchSrcFile(sal_uInt16 nFileId, const OUString& rNewFile, const OUString& rNewFilter);
631 * Set a relative file path for the specified file ID. Note that the
632 * caller must ensure that the passed URL is a valid relative URL.
634 * @param nFileId file ID for an external document
635 * @param rRelUrl relative URL
637 void setRelativeFileName(sal_uInt16 nFileId, const OUString& rRelUrl);
640 * Set the filter name and options if any for a given source document.
641 * These values get reset when the source document ever gets reloaded.
643 * @param nFileId
644 * @param rFilterName
645 * @param rOptions
647 void setFilterData(sal_uInt16 nFileId, const OUString& rFilterName, const OUString& rOptions);
649 void clear();
651 bool hasExternalData() const;
654 * Re-generates relative names for all stored source files. This is
655 * necessary when exporting to an ods document, to ensure that all source
656 * files have their respective relative names for xlink:href export.
658 * @param rBaseFileUrl Absolute URL of the content.xml fragment of the
659 * document being exported.
661 void resetSrcFileData(const OUString& rBaseFileUrl);
664 * Replace the original URL wirh the real URL that was generated from the relative URL.
666 void updateAbsAfterLoad();
669 * Stop tracking a specific formula cell.
671 * @param pCell pointer to cell that formerly contained external
672 * reference.
674 void removeRefCell(ScFormulaCell* pCell);
677 * Register a new link listener to a specified external document. Note
678 * that the caller is responsible for managing the life cycle of the
679 * listener object.
681 void addLinkListener(sal_uInt16 nFileId, LinkListener* pListener);
684 * Remove an existing link listener. Note that removing a listener
685 * pointer here does not delete the listener object instance.
687 void removeLinkListener(sal_uInt16 nFileId, LinkListener* pListener);
689 void removeLinkListener(LinkListener* pListener);
692 * Notify all listeners that are listening to a specified external
693 * document.
695 * @param nFileId file ID for an external document.
697 void notifyAllLinkListeners(sal_uInt16 nFileId, LinkUpdateType eType);
700 * Check if the file specified by the path is a legitimate file that
701 * exists & can be loaded.
703 bool isFileLoadable(const OUString& rFile) const;
705 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) SAL_OVERRIDE;
708 * If we still contain unsaved files we should warn the user before saving
710 * @return true if the document still contains references to an unsaved file
712 bool containsUnsavedReferences() const { return !maUnsavedDocShells.empty(); }
714 void insertRefCell(sal_uInt16 nFileId, const ScAddress& rCell);
716 void enableDocTimer( bool bEnable );
718 private:
719 ScExternalRefManager();
720 ScExternalRefManager(const ScExternalRefManager&);
722 void refreshAllRefCells(sal_uInt16 nFileId);
724 void fillCellFormat(sal_uLong nFmtIndex, ScExternalRefCache::CellFormat* pFmt) const;
726 ScExternalRefCache::TokenRef getSingleRefTokenFromSrcDoc(
727 sal_uInt16 nFileId, ScDocument* pSrcDoc, const ScAddress& rPos,
728 ScExternalRefCache::CellFormat* pFmt);
731 * Retrieve a range token array from a source document instance.
733 * @param pSrcDoc pointer to the source document instance.
734 * @param rTabName name of the first table.
735 * @param rRange range specified. Upon successful retrieval, this range
736 * gets modified to contain the correct table IDs, and in
737 * case the range is larger than the data area of the source
738 * document, it gets reduced to the data area.
739 * @param rCacheData an array of structs, with each struct containing the
740 * table name and the data in the specified range.
742 * @return range token array
744 ScExternalRefCache::TokenArrayRef getDoubleRefTokensFromSrcDoc(
745 ScDocument* pSrcDoc, const OUString& rTabName, ScRange& rRange,
746 ::std::vector<ScExternalRefCache::SingleRangeData>& rCacheData);
749 * Retrieve range name token array from a source document instance.
751 * @param nFileId file ID of the source document.
752 * @param pSrcDoc pointer to the source document instance
753 * @param rName range name to retrieve. Note that the range name lookup
754 * is case <i>in</i>-sensitive, and upon successful retrieval
755 * of the range name array, this name gets updated to the
756 * actual range name with the correct casing.
758 * @return range name token array
760 ScExternalRefCache::TokenArrayRef getRangeNameTokensFromSrcDoc(
761 sal_uInt16 nFileId, ScDocument* pSrcDoc, OUString& rName);
763 ScDocument* getInMemorySrcDocument(sal_uInt16 nFileId);
764 ScDocument* getSrcDocument(sal_uInt16 nFileId);
765 SfxObjectShellRef loadSrcDocument(sal_uInt16 nFileId, OUString& rFilter);
768 * Caller must ensure that the passed shell is not already stored.
770 ScDocument* cacheNewDocShell( sal_uInt16 nFileId, SrcShell& rSrcShell );
772 void maybeLinkExternalFile(sal_uInt16 nFileId);
775 * Try to create a "real" file name from the relative path. The original
776 * file name may not point to the real document when the referencing and
777 * referenced documents have been moved.
779 * For the real file name to be created, the relative name should not be
780 * empty before calling this method, or the real file name will not be
781 * created.
783 * @param nFileId file ID for an external document
785 void maybeCreateRealFileName(sal_uInt16 nFileId);
788 * Purge those source document instances that have not been accessed for
789 * the specified duration.
791 * @param nTimeOut time out value in 100th of a second
793 void purgeStaleSrcDocument(sal_Int32 nTimeOut);
795 sal_uInt32 getMappedNumberFormat(sal_uInt16 nFileId, sal_uInt32 nNumFmt, const ScDocument* pSrcDoc);
798 * If in maUnsavedDocShells move it to maDocShells and create a correct
799 * external reference entry
801 * @param Pointer to the newly saved DocumentShell
803 void transformUnsavedRefToSavedRef( SfxObjectShell* pShell );
805 private:
806 ScDocument* mpDoc;
808 /** cache of referenced ranges and names from source documents. */
809 ScExternalRefCache maRefCache;
812 * Source document cache. This stores the original source document shell
813 * instances. They get purged after a certain period of time.
815 DocShellMap maDocShells;
818 * DocShells to unsaved but referenced documents. If not empty ask before saving!
819 * Move to maDocShells if document referenced here is saved
821 DocShellMap maUnsavedDocShells;
823 /** list of source documents that are managed by the link manager. */
824 LinkedDocMap maLinkedDocs;
827 * List of referencing cells that may contain external names. There is
828 * one list per source document.
830 RefCellMap maRefCells;
832 LinkListenerMap maLinkListeners;
834 NumFmtMap maNumFormatMap;
837 * List of external source document meta-data, used to keep track of
838 * external document identifiers.
840 std::vector<SrcFileData> maSrcFiles;
842 /** Status whether in reference marking state. See isInReferenceMarking(). */
843 bool mbInReferenceMarking:1;
846 * Controls whether or not to allow user interaction. We don't want any
847 * user interaction when calling from the API.
849 bool mbUserInteractionEnabled:1;
851 bool mbDocTimerEnabled:1;
853 AutoTimer maSrcDocTimer;
854 DECL_LINK(TimeOutHdl, AutoTimer*);
858 #endif
860 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */