1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xilink.cxx,v $
10 * $Revision: 1.25.46.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #include "document.hxx"
36 #include "scextopt.hxx"
37 #include "tablink.hxx"
38 #include "xistream.hxx"
39 #include "xihelper.hxx"
41 #include "excform.hxx"
42 #include "tokenarray.hxx"
43 #include "externalrefmgr.hxx"
49 // ============================================================================
50 // *** Helper classes ***
51 // ============================================================================
53 // Cached external cells ======================================================
55 /** Contains the address and value of an external referenced cell. */
56 class XclImpCrn
: public XclImpCachedValue
59 /** Reads a cached value and stores it with its cell address. */
60 explicit XclImpCrn( XclImpStream
& rStrm
, const XclAddress
& rXclPos
);
62 const XclAddress
& GetAddress() const;
65 XclAddress maXclPos
; /// Excel position of the cached cell.
68 // Sheet in an external document ==============================================
70 /** Contains the name and sheet index of one sheet in an external document. */
71 class XclImpSupbookTab
74 /** Stores the sheet name and marks the sheet index as invalid.
75 The sheet index is set while creating the Calc sheet with CreateTable(). */
76 explicit XclImpSupbookTab( const String
& rTabName
);
79 inline const String
& GetTabName() const { return maTabName
; }
81 /** Reads a CRN record (external referenced cell) at the specified address. */
82 void ReadCrn( XclImpStream
& rStrm
, const XclAddress
& rXclPos
);
84 void LoadCachedValues(ScExternalRefCache::TableTypeRef pCacheTable
);
87 typedef ScfDelList
< XclImpCrn
> XclImpCrnList
;
89 XclImpCrnList maCrnList
; /// List of CRN records (cached cell values).
90 String maTabName
; /// Name of the external sheet.
91 SCTAB mnScTab
; /// New sheet index in Calc document.
94 // External document (SUPBOOK) ================================================
96 /** This class represents an external linked document (record SUPBOOK).
97 @descr Contains a list of all referenced sheets in the document. */
98 class XclImpSupbook
: protected XclImpRoot
101 /** Reads the SUPBOOK record from stream. */
102 explicit XclImpSupbook( XclImpStream
& rStrm
);
104 /** Reads an XCT record (count of following CRNs and current sheet). */
105 void ReadXct( XclImpStream
& rStrm
);
106 /** Reads a CRN record (external referenced cell). */
107 void ReadCrn( XclImpStream
& rStrm
);
108 /** Reads an EXTERNNAME record. */
109 void ReadExternname( XclImpStream
& rStrm
, ExcelToSc
* pFormulaConv
= NULL
);
111 /** Returns the SUPBOOK record type. */
112 inline XclSupbookType
GetType() const { return meType
; }
114 /** Returns the URL of the external document. */
115 inline const String
& GetXclUrl() const { return maXclUrl
; }
117 /** Returns the external name specified by an index from the Excel document (one-based). */
118 const XclImpExtName
* GetExternName( sal_uInt16 nXclIndex
) const;
119 /** Tries to decode the URL to OLE or DDE link components.
120 @descr For DDE links: Decodes to application name and topic.
121 For OLE object links: Decodes to class name and document URL.
122 @return true = decoding was successful, returned strings are valid (not empty). */
123 bool GetLinkData( String
& rApplic
, String
& rDoc
) const;
124 /** Returns the specified macro name (1-based) or an empty string on error. */
125 const String
& GetMacroName( sal_uInt16 nXclNameIdx
) const;
127 const String
& GetTabName( sal_uInt16 nXtiTab
) const;
129 sal_uInt16
GetTabCount() const;
131 void LoadCachedValues();
134 typedef ScfDelList
< XclImpSupbookTab
> XclImpSupbookTabList
;
135 typedef ScfDelList
< XclImpExtName
> XclImpExtNameList
;
137 XclImpSupbookTabList maSupbTabList
; /// All sheet names of the document.
138 XclImpExtNameList maExtNameList
; /// All external names of the document.
139 String maXclUrl
; /// URL of the external document (Excel mode).
140 String maFilterName
; /// Detected filer name.
141 String maFilterOpt
; /// Detected filer options.
142 XclSupbookType meType
; /// Type of the supbook record.
143 sal_uInt16 mnSBTab
; /// Current Excel sheet index from SUPBOOK for XCT/CRN records.
146 // Import link manager ========================================================
148 /** Contains the SUPBOOK index and sheet indexes of an external link.
149 @descr It is possible to enter a formula like =SUM(Sheet1:Sheet3!A1),
150 therefore here occurs a sheet range. */
153 sal_uInt16 mnSupbook
; /// Index to SUPBOOK record.
154 sal_uInt16 mnSBTabFirst
; /// Index to the first sheet of the range in the SUPBOOK.
155 sal_uInt16 mnSBTabLast
; /// Index to the last sheet of the range in the SUPBOOK.
158 inline XclImpStream
& operator>>( XclImpStream
& rStrm
, XclImpXti
& rXti
)
160 return rStrm
>> rXti
.mnSupbook
>> rXti
.mnSBTabFirst
>> rXti
.mnSBTabLast
;
163 // ----------------------------------------------------------------------------
165 /** Implementation of the link manager. */
166 class XclImpLinkManagerImpl
: protected XclImpRoot
169 explicit XclImpLinkManagerImpl( const XclImpRoot
& rRoot
);
171 /** Reads the EXTERNSHEET record. */
172 void ReadExternsheet( XclImpStream
& rStrm
);
173 /** Reads a SUPBOOK record. */
174 void ReadSupbook( XclImpStream
& rStrm
);
175 /** Reads an XCT record and appends it to the current SUPBOOK. */
176 void ReadXct( XclImpStream
& rStrm
);
177 /** Reads a CRN record and appends it to the current SUPBOOK. */
178 void ReadCrn( XclImpStream
& rStrm
);
179 /** Reads an EXTERNNAME record and appends it to the current SUPBOOK. */
180 void ReadExternname( XclImpStream
& rStrm
, ExcelToSc
* pFormulaConv
= NULL
);
182 /** Returns true, if the specified XTI entry contains an internal reference. */
183 bool IsSelfRef( sal_uInt16 nXtiIndex
) const;
184 /** Returns the Calc sheet index range of the specified XTI entry.
185 @return true = XTI data found, returned sheet index range is valid. */
187 SCTAB
& rnFirstScTab
, SCTAB
& rnLastScTab
,
188 sal_uInt16 nXtiIndex
) const;
189 /** Returns the specified external name or 0 on error. */
190 const XclImpExtName
* GetExternName( sal_uInt16 nXtiIndex
, sal_uInt16 nExtName
) const;
192 /** Returns the absolute file URL of a supporting workbook specified by
194 const String
* GetSupbookUrl( sal_uInt16 nXtiIndex
) const;
196 const String
& GetSupbookTabName( sal_uInt16 nXti
, sal_uInt16 nXtiTab
) const;
198 /** Tries to decode the URL of the specified XTI entry to OLE or DDE link components.
199 @descr For DDE links: Decodes to application name and topic.
200 For OLE object links: Decodes to class name and document URL.
201 @return true = decoding was successful, returned strings are valid (not empty). */
202 bool GetLinkData( String
& rApplic
, String
& rTopic
, sal_uInt16 nXtiIndex
) const;
203 /** Returns the specified macro name or an empty string on error. */
204 const String
& GetMacroName( sal_uInt16 nExtSheet
, sal_uInt16 nExtName
) const;
207 /** Returns the specified SUPBOOK (external document). */
208 const XclImpSupbook
* GetSupbook( sal_uInt32 nXtiIndex
) const;
209 //UNUSED2009-05 /** Returns the SUPBOOK (external workbook) specified by its URL. */
210 //UNUSED2009-05 const XclImpSupbook* GetSupbook( const String& rUrl ) const;
212 void LoadCachedValues();
214 //UNUSED2009-05 /** Finds the largest range of sheet indexes in a SUPBOOK after a start sheet index.
215 //UNUSED2009-05 @param rnSBTabFirst (out-param) The first sheet index of the range in SUPBOOK is returned here.
216 //UNUSED2009-05 @param rnSBTabLast (out-param) The last sheet index of the range in SUPBOOK is returned here (inclusive).
217 //UNUSED2009-05 @param nSupbook The list index of the SUPBOOK.
218 //UNUSED2009-05 @param nSBTabStart The first allowed sheet index. Sheet ranges with an earlier start index are ignored.
219 //UNUSED2009-05 @return true = the return values are valid; false = nothing found. */
220 //UNUSED2009-05 bool FindNextTabRange(
221 //UNUSED2009-05 sal_uInt16& rnSBTabFirst, sal_uInt16& rnSBTabLast,
222 //UNUSED2009-05 sal_uInt16 nSupbook, sal_uInt16 nSBTabStart ) const;
225 typedef ScfDelList
< XclImpXti
> XclImpXtiList
;
226 typedef ScfDelList
< XclImpSupbook
> XclImpSupbookList
;
228 XclImpXtiList maXtiList
; /// List of all XTI structures.
229 XclImpSupbookList maSupbookList
; /// List of external documents.
230 bool mbCreated
; /// true = Calc sheets already created.
233 // ============================================================================
234 // *** Implementation ***
235 // ============================================================================
237 // Excel sheet indexes ========================================================
239 // original Excel sheet names -------------------------------------------------
241 void XclImpTabInfo::AppendXclTabName( const String
& rXclTabName
, SCTAB nScTab
)
243 maTabNames
[ rXclTabName
] = nScTab
;
246 void XclImpTabInfo::InsertScTab( SCTAB nScTab
)
248 for( XclTabNameMap::iterator aIt
= maTabNames
.begin(), aEnd
= maTabNames
.end(); aIt
!= aEnd
; ++aIt
)
249 if( aIt
->second
>= nScTab
)
253 SCTAB
XclImpTabInfo::GetScTabFromXclName( const String
& rXclTabName
) const
255 XclTabNameMap::const_iterator aIt
= maTabNames
.find( rXclTabName
);
256 return (aIt
!= maTabNames
.end()) ? aIt
->second
: SCTAB_INVALID
;
259 // record creation order - TABID record ---------------------------------------
261 void XclImpTabInfo::ReadTabid( XclImpStream
& rStrm
)
263 DBG_ASSERT_BIFF( rStrm
.GetRoot().GetBiff() == EXC_BIFF8
);
264 if( rStrm
.GetRoot().GetBiff() == EXC_BIFF8
)
266 rStrm
.EnableDecryption();
267 sal_Size nReadCount
= rStrm
.GetRecLeft() / 2;
268 DBG_ASSERT( nReadCount
<= 0xFFFF, "XclImpTabInfo::ReadTabid - record too long" );
270 maTabIdVec
.reserve( nReadCount
);
271 for( sal_Size nIndex
= 0; rStrm
.IsValid() && (nIndex
< nReadCount
); ++nIndex
)
272 // #93471# zero index is not allowed in BIFF8, but it seems that it occurs in real life
273 maTabIdVec
.push_back( rStrm
.ReaduInt16() );
277 sal_uInt16
XclImpTabInfo::GetCurrentIndex( sal_uInt16 nCreatedId
, sal_uInt16 nMaxTabId
) const
279 sal_uInt16 nReturn
= 0;
280 for( ScfUInt16Vec::const_iterator aIt
= maTabIdVec
.begin(), aEnd
= maTabIdVec
.end(); aIt
!= aEnd
; ++aIt
)
282 sal_uInt16 nValue
= *aIt
;
283 if( nValue
== nCreatedId
)
285 if( nValue
<= nMaxTabId
)
291 // External names =============================================================
293 XclImpExtName::XclImpExtName( const XclImpSupbook
& rSupbook
, XclImpStream
& rStrm
, XclSupbookType eSubType
, ExcelToSc
* pFormulaConv
)
298 rStrm
>> nFlags
>> mnStorageId
>> nLen
;
299 maName
= rStrm
.ReadUniString( nLen
);
300 if( ::get_flag( nFlags
, EXC_EXTN_BUILTIN
) || !::get_flag( nFlags
, EXC_EXTN_OLE_OR_DDE
) )
302 if( eSubType
== EXC_SBTYPE_ADDIN
)
305 maName
= rStrm
.GetRoot().GetScAddInName( maName
);
307 else if ( (eSubType
== EXC_SBTYPE_EUROTOOL
) &&
308 maName
.EqualsIgnoreCaseAscii( "EUROCONVERT" ) )
309 meType
= xlExtEuroConvert
;
313 ScfTools::ConvertToScDefinedName( maName
);
318 meType
= ::get_flagvalue( nFlags
, EXC_EXTN_OLE
, xlExtOLE
, xlExtDDE
);
321 if( (meType
== xlExtDDE
) && (rStrm
.GetRecLeft() > 1) )
322 mxDdeMatrix
.reset( new XclImpCachedMatrix( rStrm
) );
324 if (meType
== xlExtName
)
326 // TODO: For now, only global external names are supported. In future
327 // we should extend this to supporting per-sheet external names.
328 if (mnStorageId
== 0)
332 const ScTokenArray
* pArray
= NULL
;
335 vector
<String
> aTabNames
;
336 sal_uInt16 nCount
= rSupbook
.GetTabCount();
337 aTabNames
.reserve(nCount
);
338 for (sal_uInt16 i
= 0; i
< nCount
; ++i
)
339 aTabNames
.push_back(rSupbook
.GetTabName(i
));
341 pFormulaConv
->ConvertExternName(pArray
, rStrm
, nFmlaLen
, rSupbook
.GetXclUrl(), aTabNames
);
343 mxArray
.reset(pArray
->Clone());
349 XclImpExtName::~XclImpExtName()
353 void XclImpExtName::CreateDdeData( ScDocument
& rDoc
, const String
& rApplic
, const String
& rTopic
) const
355 ScMatrixRef xResults
;
356 if( mxDdeMatrix
.get() )
357 xResults
= mxDdeMatrix
->CreateScMatrix();
358 rDoc
.CreateDdeLink( rApplic
, rTopic
, maName
, SC_DDE_DEFAULT
, xResults
);
361 void XclImpExtName::CreateExtNameData( ScDocument
& rDoc
, sal_uInt16 nFileId
) const
366 ScExternalRefManager
* pRefMgr
= rDoc
.GetExternalRefManager();
367 pRefMgr
->storeRangeNameTokens(nFileId
, maName
, *mxArray
);
370 bool XclImpExtName::HasFormulaTokens() const
372 return (mxArray
.get() != NULL
);
375 // Cached external cells ======================================================
377 XclImpCrn::XclImpCrn( XclImpStream
& rStrm
, const XclAddress
& rXclPos
) :
378 XclImpCachedValue( rStrm
),
383 const XclAddress
& XclImpCrn::GetAddress() const
388 // Sheet in an external document ==============================================
390 XclImpSupbookTab::XclImpSupbookTab( const String
& rTabName
) :
391 maTabName( rTabName
),
392 mnScTab( SCTAB_INVALID
)
396 XclImpSupbookTab::~XclImpSupbookTab()
400 void XclImpSupbookTab::ReadCrn( XclImpStream
& rStrm
, const XclAddress
& rXclPos
)
402 maCrnList
.Append( new XclImpCrn( rStrm
, rXclPos
) );
405 void XclImpSupbookTab::LoadCachedValues(ScExternalRefCache::TableTypeRef pCacheTable
)
407 if (maCrnList
.Empty())
410 for (XclImpCrn
* p
= maCrnList
.First(); p
; p
= maCrnList
.Next())
412 const XclAddress
& rAddr
= p
->GetAddress();
413 switch (p
->GetType())
415 case EXC_CACHEDVAL_BOOL
:
417 case EXC_CACHEDVAL_DOUBLE
:
419 double f
= p
->GetValue();
420 ScExternalRefCache::TokenRef
pToken(new formula::FormulaDoubleToken(f
));
421 pCacheTable
->setCell(rAddr
.mnCol
, rAddr
.mnRow
, pToken
);
424 case EXC_CACHEDVAL_EMPTY
:
426 case EXC_CACHEDVAL_ERROR
:
428 case EXC_CACHEDVAL_STRING
:
430 const String
& rStr
= p
->GetString();
431 ScExternalRefCache::TokenRef
pToken(new formula::FormulaStringToken(rStr
));
432 pCacheTable
->setCell(rAddr
.mnCol
, rAddr
.mnRow
, pToken
);
441 // External document (SUPBOOK) ================================================
443 XclImpSupbook::XclImpSupbook( XclImpStream
& rStrm
) :
444 XclImpRoot( rStrm
.GetRoot() ),
445 meType( EXC_SBTYPE_UNKNOWN
),
446 mnSBTab( EXC_TAB_DELETED
)
448 sal_uInt16 nSBTabCnt
;
451 if( rStrm
.GetRecLeft() == 2 )
453 switch( rStrm
.ReaduInt16() )
455 case EXC_SUPB_SELF
: meType
= EXC_SBTYPE_SELF
; break;
456 case EXC_SUPB_ADDIN
: meType
= EXC_SBTYPE_ADDIN
; break;
457 default: DBG_ERRORFILE( "XclImpSupbook::XclImpSupbook - unknown special SUPBOOK type" );
462 String
aEncUrl( rStrm
.ReadUniString() );
464 XclImpUrlHelper::DecodeUrl( maXclUrl
, bSelf
, GetRoot(), aEncUrl
);
466 if( maXclUrl
.EqualsIgnoreCaseAscii( "\010EUROTOOL.XLA" ) )
468 meType
= EXC_SBTYPE_EUROTOOL
;
469 maSupbTabList
.Append( new XclImpSupbookTab( maXclUrl
) );
473 meType
= EXC_SBTYPE_EXTERN
;
474 for( sal_uInt16 nSBTab
= 0; nSBTab
< nSBTabCnt
; ++nSBTab
)
476 String
aTabName( rStrm
.ReadUniString() );
477 maSupbTabList
.Append( new XclImpSupbookTab( aTabName
) );
482 meType
= EXC_SBTYPE_SPECIAL
;
483 // create dummy list entry
484 maSupbTabList
.Append( new XclImpSupbookTab( maXclUrl
) );
488 void XclImpSupbook::ReadXct( XclImpStream
& rStrm
)
494 void XclImpSupbook::ReadCrn( XclImpStream
& rStrm
)
496 if( XclImpSupbookTab
* pSBTab
= maSupbTabList
.GetObject( mnSBTab
) )
498 sal_uInt8 nXclColLast
, nXclColFirst
;
500 rStrm
>> nXclColLast
>> nXclColFirst
>> nXclRow
;
502 for( sal_uInt8 nXclCol
= nXclColFirst
; (nXclCol
<= nXclColLast
) && (rStrm
.GetRecLeft() > 1); ++nXclCol
)
503 pSBTab
->ReadCrn( rStrm
, XclAddress( nXclCol
, nXclRow
) );
507 void XclImpSupbook::ReadExternname( XclImpStream
& rStrm
, ExcelToSc
* pFormulaConv
)
509 maExtNameList
.Append( new XclImpExtName( *this, rStrm
, meType
, pFormulaConv
) );
512 const XclImpExtName
* XclImpSupbook::GetExternName( sal_uInt16 nXclIndex
) const
514 DBG_ASSERT( nXclIndex
> 0, "XclImpSupbook::GetExternName - index must be >0" );
515 return (meType
== EXC_SBTYPE_SELF
) ? 0 : maExtNameList
.GetObject( nXclIndex
- 1 );
518 bool XclImpSupbook::GetLinkData( String
& rApplic
, String
& rTopic
) const
520 return (meType
== EXC_SBTYPE_SPECIAL
) && XclImpUrlHelper::DecodeLink( rApplic
, rTopic
, maXclUrl
);
523 const String
& XclImpSupbook::GetMacroName( sal_uInt16 nXclNameIdx
) const
525 DBG_ASSERT( nXclNameIdx
> 0, "XclImpSupbook::GetMacroName - index must be >0" );
526 const XclImpName
* pName
= (meType
== EXC_SBTYPE_SELF
) ? GetNameManager().GetName( nXclNameIdx
) : 0;
527 return (pName
&& pName
->IsVBName()) ? pName
->GetScName() : EMPTY_STRING
;
530 const String
& XclImpSupbook::GetTabName( sal_uInt16 nXtiTab
) const
532 if (maSupbTabList
.Empty())
536 for (XclImpSupbookTab
* p
= maSupbTabList
.First(); p
; p
= maSupbTabList
.Next(), ++i
)
539 return p
->GetTabName();
545 sal_uInt16
XclImpSupbook::GetTabCount() const
547 return ulimit_cast
<sal_uInt16
>(maSupbTabList
.Count());
550 void XclImpSupbook::LoadCachedValues()
552 if (meType
!= EXC_SBTYPE_EXTERN
|| GetExtDocOptions().GetDocSettings().mnLinkCnt
> 0 || !GetDocShell())
555 String
aAbsUrl( ScGlobal::GetAbsDocName(maXclUrl
, GetDocShell()) );
557 ScExternalRefManager
* pRefMgr
= GetRoot().GetDoc().GetExternalRefManager();
558 sal_uInt16 nFileId
= pRefMgr
->getExternalFileId(aAbsUrl
);
560 sal_uInt16 nCount
= static_cast< sal_uInt16
>( maSupbTabList
.Count() );
561 for (sal_uInt16 i
= 0; i
< nCount
; ++i
)
563 XclImpSupbookTab
* pTab
= maSupbTabList
.GetObject(i
);
567 const String
& rTabName
= pTab
->GetTabName();
568 ScExternalRefCache::TableTypeRef pCacheTable
= pRefMgr
->getCacheTable(nFileId
, rTabName
, true);
569 pTab
->LoadCachedValues(pCacheTable
);
573 // Import link manager ========================================================
575 XclImpLinkManagerImpl::XclImpLinkManagerImpl( const XclImpRoot
& rRoot
) :
581 void XclImpLinkManagerImpl::ReadExternsheet( XclImpStream
& rStrm
)
583 sal_uInt16 nXtiCount
;
589 pXti
= new XclImpXti
;
591 maXtiList
.Append( pXti
);
598 void XclImpLinkManagerImpl::ReadSupbook( XclImpStream
& rStrm
)
600 maSupbookList
.Append( new XclImpSupbook( rStrm
) );
603 void XclImpLinkManagerImpl::ReadXct( XclImpStream
& rStrm
)
605 if( XclImpSupbook
* pSupbook
= maSupbookList
.Last() )
606 pSupbook
->ReadXct( rStrm
);
609 void XclImpLinkManagerImpl::ReadCrn( XclImpStream
& rStrm
)
611 if( XclImpSupbook
* pSupbook
= maSupbookList
.Last() )
612 pSupbook
->ReadCrn( rStrm
);
615 void XclImpLinkManagerImpl::ReadExternname( XclImpStream
& rStrm
, ExcelToSc
* pFormulaConv
)
617 if( XclImpSupbook
* pSupbook
= maSupbookList
.Last() )
618 pSupbook
->ReadExternname( rStrm
, pFormulaConv
);
621 bool XclImpLinkManagerImpl::IsSelfRef( sal_uInt16 nXtiIndex
) const
623 const XclImpSupbook
* pSupbook
= GetSupbook( nXtiIndex
);
624 return pSupbook
&& (pSupbook
->GetType() == EXC_SBTYPE_SELF
);
627 bool XclImpLinkManagerImpl::GetScTabRange(
628 SCTAB
& rnFirstScTab
, SCTAB
& rnLastScTab
, sal_uInt16 nXtiIndex
) const
630 if( const XclImpXti
* pXti
= maXtiList
.GetObject( nXtiIndex
) )
632 if (maSupbookList
.GetObject(pXti
->mnSupbook
))
634 rnFirstScTab
= pXti
->mnSBTabFirst
;
635 rnLastScTab
= pXti
->mnSBTabLast
;
642 const XclImpExtName
* XclImpLinkManagerImpl::GetExternName( sal_uInt16 nXtiIndex
, sal_uInt16 nExtName
) const
644 const XclImpSupbook
* pSupbook
= GetSupbook( nXtiIndex
);
645 return pSupbook
? pSupbook
->GetExternName( nExtName
) : 0;
648 const String
* XclImpLinkManagerImpl::GetSupbookUrl( sal_uInt16 nXtiIndex
) const
650 const XclImpSupbook
* p
= GetSupbook( nXtiIndex
);
653 return &p
->GetXclUrl();
656 const String
& XclImpLinkManagerImpl::GetSupbookTabName( sal_uInt16 nXti
, sal_uInt16 nXtiTab
) const
658 const XclImpSupbook
* p
= GetSupbook(nXti
);
659 return p
? p
->GetTabName(nXtiTab
) : EMPTY_STRING
;
662 bool XclImpLinkManagerImpl::GetLinkData( String
& rApplic
, String
& rTopic
, sal_uInt16 nXtiIndex
) const
664 const XclImpSupbook
* pSupbook
= GetSupbook( nXtiIndex
);
665 return pSupbook
&& pSupbook
->GetLinkData( rApplic
, rTopic
);
668 const String
& XclImpLinkManagerImpl::GetMacroName( sal_uInt16 nExtSheet
, sal_uInt16 nExtName
) const
670 const XclImpSupbook
* pSupbook
= GetSupbook( nExtSheet
);
671 return pSupbook
? pSupbook
->GetMacroName( nExtName
) : EMPTY_STRING
;
674 const XclImpSupbook
* XclImpLinkManagerImpl::GetSupbook( sal_uInt32 nXtiIndex
) const
676 const XclImpXti
* pXti
= maXtiList
.GetObject( nXtiIndex
);
677 return pXti
? maSupbookList
.GetObject( pXti
->mnSupbook
) : 0;
680 //UNUSED2009-05 const XclImpSupbook* XclImpLinkManagerImpl::GetSupbook( const String& rUrl ) const
682 //UNUSED2009-05 for( const XclImpSupbook* pSupbook = maSupbookList.First(); pSupbook; pSupbook = maSupbookList.Next() )
683 //UNUSED2009-05 if( pSupbook->GetXclUrl() == rUrl )
684 //UNUSED2009-05 return pSupbook;
685 //UNUSED2009-05 return 0;
688 void XclImpLinkManagerImpl::LoadCachedValues()
690 // Read all CRN records which can be accessed via XclImpSupbook, and store
691 // the cached values to the external reference manager.
693 sal_uInt32 nCount
= maSupbookList
.Count();
694 for (sal_uInt16 nSupbook
= 0; nSupbook
< nCount
; ++nSupbook
)
696 XclImpSupbook
* pSupbook
= maSupbookList
.GetObject(nSupbook
);
697 pSupbook
->LoadCachedValues();
701 //UNUSED2009-05 bool XclImpLinkManagerImpl::FindNextTabRange(
702 //UNUSED2009-05 sal_uInt16& rnSBTabFirst, sal_uInt16& rnSBTabLast,
703 //UNUSED2009-05 sal_uInt16 nSupbook, sal_uInt16 nSBTabStart ) const
705 //UNUSED2009-05 rnSBTabFirst = rnSBTabLast = EXC_NOTAB;
706 //UNUSED2009-05 for( const XclImpXti* pXti = maXtiList.First(); pXti; pXti = maXtiList.Next() )
708 //UNUSED2009-05 if( (nSupbook == pXti->mnSupbook) && (nSBTabStart <= pXti->mnSBTabLast) && (pXti->mnSBTabFirst < rnSBTabFirst) )
710 //UNUSED2009-05 rnSBTabFirst = ::std::max( nSBTabStart, pXti->mnSBTabFirst );
711 //UNUSED2009-05 rnSBTabLast = pXti->mnSBTabLast;
714 //UNUSED2009-05 return rnSBTabFirst != EXC_NOTAB;
717 // ============================================================================
719 XclImpLinkManager::XclImpLinkManager( const XclImpRoot
& rRoot
) :
721 mxImpl( new XclImpLinkManagerImpl( rRoot
) )
725 XclImpLinkManager::~XclImpLinkManager()
729 void XclImpLinkManager::ReadExternsheet( XclImpStream
& rStrm
)
731 mxImpl
->ReadExternsheet( rStrm
);
734 void XclImpLinkManager::ReadSupbook( XclImpStream
& rStrm
)
736 mxImpl
->ReadSupbook( rStrm
);
739 void XclImpLinkManager::ReadXct( XclImpStream
& rStrm
)
741 mxImpl
->ReadXct( rStrm
);
744 void XclImpLinkManager::ReadCrn( XclImpStream
& rStrm
)
746 mxImpl
->ReadCrn( rStrm
);
749 void XclImpLinkManager::ReadExternname( XclImpStream
& rStrm
, ExcelToSc
* pFormulaConv
)
751 mxImpl
->ReadExternname( rStrm
, pFormulaConv
);
754 bool XclImpLinkManager::IsSelfRef( sal_uInt16 nXtiIndex
) const
756 return mxImpl
->IsSelfRef( nXtiIndex
);
759 bool XclImpLinkManager::GetScTabRange(
760 SCTAB
& rnFirstScTab
, SCTAB
& rnLastScTab
, sal_uInt16 nXtiIndex
) const
762 return mxImpl
->GetScTabRange( rnFirstScTab
, rnLastScTab
, nXtiIndex
);
765 const XclImpExtName
* XclImpLinkManager::GetExternName( sal_uInt16 nXtiIndex
, sal_uInt16 nExtName
) const
767 return mxImpl
->GetExternName( nXtiIndex
, nExtName
);
770 const String
* XclImpLinkManager::GetSupbookUrl( sal_uInt16 nXtiIndex
) const
772 return mxImpl
->GetSupbookUrl(nXtiIndex
);
775 const String
& XclImpLinkManager::GetSupbookTabName( sal_uInt16 nXti
, sal_uInt16 nXtiTab
) const
777 return mxImpl
->GetSupbookTabName(nXti
, nXtiTab
);
780 bool XclImpLinkManager::GetLinkData( String
& rApplic
, String
& rTopic
, sal_uInt16 nXtiIndex
) const
782 return mxImpl
->GetLinkData( rApplic
, rTopic
, nXtiIndex
);
785 const String
& XclImpLinkManager::GetMacroName( sal_uInt16 nExtSheet
, sal_uInt16 nExtName
) const
787 return mxImpl
->GetMacroName( nExtSheet
, nExtName
);
790 // ============================================================================