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_SOURCE_FILTER_INC_EXTERNALLINKBUFFER_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_EXTERNALLINKBUFFER_HXX
23 #include <com/sun/star/sheet/ExternalLinkInfo.hpp>
24 #include <oox/helper/containerhelper.hxx>
25 #include "defnamesbuffer.hxx"
27 namespace com
{ namespace sun
{ namespace star
{
28 namespace sheet
{ struct DDEItemInfo
; }
29 namespace sheet
{ class XDDELink
; }
30 namespace sheet
{ class XExternalDocLink
; }
31 namespace sheet
{ class XExternalSheetCache
; }
34 namespace oox
{ namespace core
{
41 struct ExternalNameModel
43 bool mbNotify
; /// Notify application on data change.
44 bool mbPreferPic
; /// Picture link.
45 bool mbStdDocName
; /// Name is the StdDocumentName for DDE.
46 bool mbOleObj
; /// Name is an OLE object.
47 bool mbIconified
; /// Iconified object link.
49 explicit ExternalNameModel();
54 class ExternalName
: public DefinedNameBase
57 explicit ExternalName( const ExternalLink
& rParentLink
);
59 /** Appends the passed value to the result set. */
60 template< typename Type
>
61 inline void appendResultValue( const Type
& rValue
)
62 { if( maCurrIt
!= maResults
.end() ) (*maCurrIt
++) <<= rValue
; }
64 /** Imports the definedName element. */
65 void importDefinedName( const AttributeList
& rAttribs
);
66 /** Imports the ddeItem element describing an item of a DDE link. */
67 void importDdeItem( const AttributeList
& rAttribs
);
68 /** Imports the values element containing the size of the DDE result matrix. */
69 void importValues( const AttributeList
& rAttribs
);
70 /** Imports the oleItem element describing an object of an OLE link. */
71 void importOleItem( const AttributeList
& rAttribs
);
73 /** Imports the EXTERNALNAME record containing the name (only). */
74 void importExternalName( SequenceInputStream
& rStrm
);
75 /** Imports the EXTERNALNAMEFLAGS record containing the settings of an external name. */
76 void importExternalNameFlags( SequenceInputStream
& rStrm
);
77 /** Imports the DDEITEMVALUES record containing the size of the DDE result matrix. */
78 void importDdeItemValues( SequenceInputStream
& rStrm
);
79 /** Imports the DDEITEM_BOOL record containing a boolean value in a link result. */
80 void importDdeItemBool( SequenceInputStream
& rStrm
);
81 /** Imports the DDEITEM_DOUBLE record containing a double value in a link result. */
82 void importDdeItemDouble( SequenceInputStream
& rStrm
);
83 /** Imports the DDEITEM_ERROR record containing an error code in a link result. */
84 void importDdeItemError( SequenceInputStream
& rStrm
);
85 /** Imports the DDEITEM_STRING record containing a string in a link result. */
86 void importDdeItemString( SequenceInputStream
& rStrm
);
89 /** Returns the sheet cache index if this is a sheet-local external name. */
90 sal_Int32
getSheetCacheIndex() const;
93 /** Returns the DDE item info needed by the XML formula parser. */
95 css::sheet::DDEItemInfo
& orItemInfo
) const;
97 /** Returns the complete DDE link data of this DDE item. */
99 OUString
& orDdeServer
,
100 OUString
& orDdeTopic
,
101 OUString
& orDdeItem
);
104 /** Sets the size of the result matrix. */
105 void setResultSize( sal_Int32 nColumns
, sal_Int32 nRows
);
108 typedef Matrix
< css::uno::Any
> ResultMatrix
;
110 const ExternalLink
& mrParentLink
; /// External link this name belongs to.
111 ExternalNameModel maExtNameModel
; /// Additional name data.
112 ResultMatrix maResults
; /// DDE/OLE link results.
113 ResultMatrix::iterator maCurrIt
; /// Current position in result matrix.
114 css::uno::Reference
< css::sheet::XDDELink
>
115 mxDdeLink
; /// Interface of a DDE link.
116 bool mbDdeLinkCreated
; /// True = already tried to create the DDE link.
119 typedef std::shared_ptr
< ExternalName
> ExternalNameRef
;
121 /** Contains indexes for a range of sheets in the spreadsheet document. */
125 inline explicit LinkSheetRange() { setDeleted(); }
127 /** Sets this struct to deleted state. */
129 /** Sets this struct to "use current sheet" state. */
131 /** Sets the passed absolute sheet range to the members of this struct. */
132 void setRange( sal_Int32 nFirst
, sal_Int32 nLast
);
133 /** Sets the passed external sheet cache range to the members of this struct. */
134 void setExternalRange( sal_Int32 nDocLink
, sal_Int32 nFirst
, sal_Int32 nLast
);
136 /** Returns true, if the sheet indexes are valid and different. */
137 inline bool isDeleted() const { return mnFirst
< 0; }
138 /** Returns true, if the sheet range points to an external document. */
139 inline bool isExternal() const { return !isDeleted() && (meType
== LINKSHEETRANGE_EXTERNAL
); }
140 /** Returns true, if the sheet indexes are valid and different. */
141 inline bool isSameSheet() const { return meType
== LINKSHEETRANGE_SAMESHEET
; }
142 /** Returns true, if the sheet indexes are valid and different. */
143 inline bool is3dRange() const { return (0 <= mnFirst
) && (mnFirst
< mnLast
); }
145 inline sal_Int32
getDocLinkIndex() const { return mnDocLink
; }
146 inline sal_Int32
getFirstSheet() const { return mnFirst
; }
147 inline sal_Int32
getLastSheet() const { return mnLast
; }
150 enum LinkSheetRangeType
152 LINKSHEETRANGE_INTERNAL
, /// Sheet range in the own document.
153 LINKSHEETRANGE_EXTERNAL
, /// Sheet range in an external document.
154 LINKSHEETRANGE_SAMESHEET
/// Current sheet depending on context.
157 LinkSheetRangeType meType
; /// Link sheet range type.
158 sal_Int32 mnDocLink
; /// Document link token index for external links.
159 sal_Int32 mnFirst
; /// Index of the first sheet or index of first external sheet cache.
160 sal_Int32 mnLast
; /// Index of the last sheet or index of last external sheet cache.
163 enum ExternalLinkType
165 LINKTYPE_SELF
, /// Link refers to the current workbook.
166 LINKTYPE_SAME
, /// Link refers to the current sheet.
167 LINKTYPE_INTERNAL
, /// Link refers to a sheet in the own workbook.
168 LINKTYPE_EXTERNAL
, /// Link refers to an external spreadsheet document.
169 LINKTYPE_ANALYSIS
, /// Link refers to the Analysis add-in.
170 LINKTYPE_LIBRARY
, /// Link refers to an external add-in.
171 LINKTYPE_DDE
, /// DDE link.
172 LINKTYPE_OLE
, /// OLE link.
173 LINKTYPE_MAYBE_DDE_OLE
, /// Could be DDE or OLE link (BIFF only).
174 LINKTYPE_UNKNOWN
/// Unknown or unsupported link type.
177 class ExternalLink
: public WorkbookHelper
180 explicit ExternalLink( const WorkbookHelper
& rHelper
);
182 /** Imports the externalReference element containing the relation identifier. */
183 void importExternalReference( const AttributeList
& rAttribs
);
184 /** Imports the externalBook element describing an externally linked document. */
185 void importExternalBook( const ::oox::core::Relations
& rRelations
, const AttributeList
& rAttribs
);
186 /** Imports the sheetName element containing the sheet name in an externally linked document. */
187 void importSheetName( const AttributeList
& rAttribs
);
188 /** Imports the definedName element describing an external name. */
189 void importDefinedName( const AttributeList
& rAttribs
);
190 /** Imports the ddeLink element describing a DDE link. */
191 void importDdeLink( const AttributeList
& rAttribs
);
192 /** Imports the ddeItem element describing an item of a DDE link. */
193 ExternalNameRef
importDdeItem( const AttributeList
& rAttribs
);
194 /** Imports the oleLink element describing an OLE link. */
195 void importOleLink( const ::oox::core::Relations
& rRelations
, const AttributeList
& rAttribs
);
196 /** Imports the oleItem element describing an object of an OLE link. */
197 ExternalNameRef
importOleItem( const AttributeList
& rAttribs
);
199 /** Imports the EXTERNALBOOK record describing an externally linked document, DDE link, or OLE link. */
200 void importExternalBook( const ::oox::core::Relations
& rRelations
, SequenceInputStream
& rStrm
);
201 /** Imports the EXTSHEETNAMES record containing the sheet names in an externally linked document. */
202 void importExtSheetNames( SequenceInputStream
& rStrm
);
203 /** Imports the EXTERNALNAME record describing an external name. */
204 ExternalNameRef
importExternalName( SequenceInputStream
& rStrm
);
205 /** Imports the EXTERNALREF record from the passed stream. */
206 void importExternalRef( SequenceInputStream
& rStrm
);
207 /** Imports the EXTERNALSELF record from the passed stream. */
208 void importExternalSelf( SequenceInputStream
& rStrm
);
209 /** Imports the EXTERNALSAME record from the passed stream. */
210 void importExternalSame( SequenceInputStream
& rStrm
);
211 /** Imports the EXTERNALADDIN record from the passed stream. */
212 void importExternalAddin( SequenceInputStream
& rStrm
);
214 /** Sets the link type to 'self reference'. */
215 inline void setSelfLinkType() { meLinkType
= LINKTYPE_SELF
; }
217 /** Returns the type of this external link. */
218 inline ExternalLinkType
getLinkType() const { return meLinkType
; }
219 /** Returns true, if the link refers to the current workbook. */
220 inline bool isInternalLink() const { return (meLinkType
== LINKTYPE_SELF
) || (meLinkType
== LINKTYPE_INTERNAL
); }
222 /** Returns the relation identifier for the external link fragment. */
223 inline const OUString
& getRelId() const { return maRelId
; }
224 /** Returns the class name of this external link. */
225 inline const OUString
& getClassName() const { return maClassName
; }
226 /** Returns the target URL of this external link. */
227 inline const OUString
& getTargetUrl() const { return maTargetUrl
; }
228 /** Returns the link info needed by the XML formula parser. */
229 css::sheet::ExternalLinkInfo
getLinkInfo() const;
231 /** Returns the type of the external library if this is a library link. */
232 FunctionLibraryType
getFuncLibraryType() const;
234 /** Returns the token index of the external document. */
235 sal_Int32
getDocumentLinkIndex() const;
236 /** Returns the external sheet cache index or for the passed sheet. */
237 sal_Int32
getSheetCacheIndex( sal_Int32 nTabId
= 0 ) const;
238 /** Returns the sheet cache of the external sheet with the passed index. */
239 css::uno::Reference
< css::sheet::XExternalSheetCache
>
240 getSheetCache( sal_Int32 nTabId
) const;
242 /** Returns the internal sheet range or range of external sheet caches for the passed sheet range (BIFF only). */
243 void getSheetRange( LinkSheetRange
& orSheetRange
, sal_Int32 nTabId1
, sal_Int32 nTabId2
) const;
245 /** Returns the external name with the passed zero-based index. */
246 ExternalNameRef
getNameByIndex( sal_Int32 nIndex
) const;
249 void setExternalTargetUrl( const OUString
& rTargetUrl
, const OUString
& rTargetType
);
250 void setDdeOleTargetUrl( const OUString
& rClassName
, const OUString
& rTargetUrl
, ExternalLinkType eLinkType
);
251 void parseExternalReference( const ::oox::core::Relations
& rRelations
, const OUString
& rRelId
);
253 /** Creates an external document link and the sheet cache for the passed sheet name. */
254 void insertExternalSheet( const OUString
& rSheetName
);
256 ExternalNameRef
createExternalName();
259 typedef ::std::vector
< sal_Int16
> Int16Vector
;
260 typedef ::std::vector
< sal_Int32
> Int32Vector
;
261 typedef RefVector
< ExternalName
> ExternalNameVector
;
263 ExternalLinkType meLinkType
; /// Type of this link object.
264 FunctionLibraryType meFuncLibType
; /// Type of the function library, if link type is LINKTYPE_LIBRARY.
265 OUString maRelId
; /// Relation identifier for the external link fragment.
266 OUString maClassName
; /// DDE service, OLE class name.
267 OUString maTargetUrl
; /// Target link, DDE topic, OLE target.
268 css::uno::Reference
< css::sheet::XExternalDocLink
>
269 mxDocLink
; /// Interface for an external document.
270 Int32Vector maSheetCaches
; /// External sheet cache indexes.
271 ExternalNameVector maExtNames
; /// Defined names in external document.
274 typedef std::shared_ptr
< ExternalLink
> ExternalLinkRef
;
276 /** Represents a REF entry in the BIFF12 EXTERNALSHEETS or in the BIFF8
279 This struct is used to map ref identifiers to external books (BIFF12:
280 EXTERNALREF records, BIFF8: EXTERNALBOOK records), and provides sheet
281 indexes into the sheet list of the external document.
283 struct RefSheetsModel
285 sal_Int32 mnExtRefId
; /// Zero-based index into list of external documents.
286 sal_Int32 mnTabId1
; /// Zero-based index to first sheet in external document.
287 sal_Int32 mnTabId2
; /// Zero-based index to last sheet in external document.
289 explicit RefSheetsModel();
291 void readBiff12Data( SequenceInputStream
& rStrm
);
294 class ExternalLinkBuffer
: public WorkbookHelper
297 explicit ExternalLinkBuffer( const WorkbookHelper
& rHelper
);
299 /** Imports the externalReference element containing . */
300 ExternalLinkRef
importExternalReference( const AttributeList
& rAttribs
);
302 /** Imports the EXTERNALREF record from the passed stream. */
303 ExternalLinkRef
importExternalRef( SequenceInputStream
& rStrm
);
304 /** Imports the EXTERNALSELF record from the passed stream. */
305 void importExternalSelf( SequenceInputStream
& rStrm
);
306 /** Imports the EXTERNALSAME record from the passed stream. */
307 void importExternalSame( SequenceInputStream
& rStrm
);
308 /** Imports the EXTERNALADDIN record from the passed stream. */
309 void importExternalAddin( SequenceInputStream
& rStrm
);
310 /** Imports the EXTERNALSHEETS record from the passed stream. */
311 void importExternalSheets( SequenceInputStream
& rStrm
);
313 /** Returns the sequence of link infos needed by the XML formula parser. */
314 css::uno::Sequence
< css::sheet::ExternalLinkInfo
>
315 getLinkInfos() const;
317 /** Returns the external link for the passed reference identifier. */
318 ExternalLinkRef
getExternalLink( sal_Int32 nRefId
, bool bUseRefSheets
= true ) const;
320 /** Returns the sheet range for the specified reference (BIFF2-BIFF5 only). */
321 LinkSheetRange
getSheetRange( sal_Int32 nRefId
, sal_Int16 nTabId1
, sal_Int16 nTabId2
) const;
322 /** Returns the sheet range for the specified reference (BIFF8 only). */
323 LinkSheetRange
getSheetRange( sal_Int32 nRefId
) const;
326 /** Creates a new external link and inserts it into the list of links. */
327 ExternalLinkRef
createExternalLink();
329 /** Returns the specified sheet indexes for a reference identifier. */
330 const RefSheetsModel
* getRefSheets( sal_Int32 nRefId
) const;
333 typedef RefVector
< ExternalLink
> ExternalLinkVec
;
334 typedef ::std::vector
< RefSheetsModel
> RefSheetsModelVec
;
336 ExternalLinkRef mxSelfRef
; /// Implicit self reference at index 0.
337 ExternalLinkVec maLinks
; /// List of link structures for all kinds of links.
338 ExternalLinkVec maExtLinks
; /// Real external links needed for formula parser.
339 RefSheetsModelVec maRefSheets
; /// Sheet indexes for reference ids.
340 bool mbUseRefSheets
; /// True = use maRefSheets list (BIFF12 only).
348 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */