Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef OOX_XLS_EXTERNALLINKBUFFER_HXX
30 : : #define OOX_XLS_EXTERNALLINKBUFFER_HXX
31 : :
32 : : #include <com/sun/star/sheet/ExternalLinkInfo.hpp>
33 : : #include "oox/helper/containerhelper.hxx"
34 : : #include "defnamesbuffer.hxx"
35 : :
36 : : namespace com { namespace sun { namespace star {
37 : : namespace sheet { struct DDEItemInfo; }
38 : : namespace sheet { class XDDELink; }
39 : : namespace sheet { class XExternalDocLink; }
40 : : namespace sheet { class XExternalSheetCache; }
41 : : } } }
42 : :
43 : : namespace oox { namespace core {
44 : : class Relations;
45 : : } }
46 : :
47 : : namespace oox {
48 : : namespace xls {
49 : :
50 : : // ============================================================================
51 : :
52 : : struct ExternalNameModel
53 : : {
54 : : bool mbBuiltIn; /// Name is a built-in name.
55 : : bool mbNotify; /// Notify application on data change.
56 : : bool mbPreferPic; /// Picture link.
57 : : bool mbStdDocName; /// Name is the StdDocumentName for DDE.
58 : : bool mbOleObj; /// Name is an OLE object.
59 : : bool mbIconified; /// Iconified object link.
60 : :
61 : : explicit ExternalNameModel();
62 : : };
63 : :
64 : : // ============================================================================
65 : :
66 : : class ExternalLink;
67 : :
68 [ # # ]: 0 : class ExternalName : public DefinedNameBase
69 : : {
70 : : public:
71 : : explicit ExternalName( const ExternalLink& rParentLink );
72 : :
73 : : /** Appends the passed value to the result set. */
74 : : template< typename Type >
75 : 0 : inline void appendResultValue( const Type& rValue )
76 [ # # ][ # # ]: 0 : { if( maCurrIt != maResults.end() ) (*maCurrIt++) <<= rValue; }
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
77 : :
78 : : /** Imports the definedName element. */
79 : : void importDefinedName( const AttributeList& rAttribs );
80 : : /** Imports the ddeItem element describing an item of a DDE link. */
81 : : void importDdeItem( const AttributeList& rAttribs );
82 : : /** Imports the values element containing the size of the DDE result matrix. */
83 : : void importValues( const AttributeList& rAttribs );
84 : : /** Imports the oleItem element describing an object of an OLE link. */
85 : : void importOleItem( const AttributeList& rAttribs );
86 : :
87 : : /** Imports the EXTERNALNAME record containing the name (only). */
88 : : void importExternalName( SequenceInputStream& rStrm );
89 : : /** Imports the EXTERNALNAMEFLAGS record containing the settings of an external name. */
90 : : void importExternalNameFlags( SequenceInputStream& rStrm );
91 : : /** Imports the DDEITEMVALUES record containing the size of the DDE result matrix. */
92 : : void importDdeItemValues( SequenceInputStream& rStrm );
93 : : /** Imports the DDEITEM_BOOL record containing a boolean value in a link result. */
94 : : void importDdeItemBool( SequenceInputStream& rStrm );
95 : : /** Imports the DDEITEM_DOUBLE record containing a double value in a link result. */
96 : : void importDdeItemDouble( SequenceInputStream& rStrm );
97 : : /** Imports the DDEITEM_ERROR record containing an error code in a link result. */
98 : : void importDdeItemError( SequenceInputStream& rStrm );
99 : : /** Imports the DDEITEM_STRING record containing a string in a link result. */
100 : : void importDdeItemString( SequenceInputStream& rStrm );
101 : :
102 : : /** Returns true, if the name refers to an OLE object. */
103 : : inline bool isOleObject() const { return maExtNameModel.mbOleObj; }
104 : :
105 : : #if 0
106 : : /** Returns the sheet cache index if this is a sheet-local external name. */
107 : : sal_Int32 getSheetCacheIndex() const;
108 : : #endif
109 : :
110 : : /** Returns the DDE item info needed by the XML formula parser. */
111 : : bool getDdeItemInfo(
112 : : ::com::sun::star::sheet::DDEItemInfo& orItemInfo ) const;
113 : :
114 : : /** Returns the complete DDE link data of this DDE item. */
115 : : bool getDdeLinkData(
116 : : ::rtl::OUString& orDdeServer,
117 : : ::rtl::OUString& orDdeTopic,
118 : : ::rtl::OUString& orDdeItem );
119 : :
120 : : private:
121 : : /** Sets the size of the result matrix. */
122 : : void setResultSize( sal_Int32 nColumns, sal_Int32 nRows );
123 : :
124 : : private:
125 : : typedef Matrix< ::com::sun::star::uno::Any > ResultMatrix;
126 : :
127 : : const ExternalLink& mrParentLink; /// External link this name belongs to.
128 : : ExternalNameModel maExtNameModel; /// Additional name data.
129 : : ResultMatrix maResults; /// DDE/OLE link results.
130 : : ResultMatrix::iterator maCurrIt; /// Current position in result matrix.
131 : : sal_uInt32 mnStorageId; /// OLE storage identifier (BIFF).
132 : : ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDDELink >
133 : : mxDdeLink; /// Interface of a DDE link.
134 : : bool mbDdeLinkCreated; /// True = already tried to create the DDE link.
135 : : };
136 : :
137 : : typedef ::boost::shared_ptr< ExternalName > ExternalNameRef;
138 : :
139 : : // ============================================================================
140 : :
141 : : /** Contains indexes for a range of sheets in the spreadsheet document. */
142 : : class LinkSheetRange
143 : : {
144 : : public:
145 : 0 : inline explicit LinkSheetRange() { setDeleted(); }
146 : : inline explicit LinkSheetRange( sal_Int32 nFirst, sal_Int32 nLast ) { setRange( nFirst, nLast ); }
147 : : inline explicit LinkSheetRange( sal_Int32 nDocLink, sal_Int32 nFirst, sal_Int32 nLast ) { setExternalRange( nDocLink, nFirst, nLast ); }
148 : :
149 : : /** Sets this struct to deleted state. */
150 : : void setDeleted();
151 : : /** Sets this struct to "use current sheet" state. */
152 : : void setSameSheet();
153 : : /** Sets the passed absolute sheet range to the members of this struct. */
154 : : void setRange( sal_Int32 nFirst, sal_Int32 nLast );
155 : : /** Sets the passed external sheet cache range to the members of this struct. */
156 : : void setExternalRange( sal_Int32 nDocLink, sal_Int32 nFirst, sal_Int32 nLast );
157 : :
158 : : /** Returns true, if the sheet indexes are valid and different. */
159 : 0 : inline bool isDeleted() const { return mnFirst < 0; }
160 : : /** Returns true, if the sheet range points to an external document. */
161 [ # # ][ # # ]: 0 : inline bool isExternal() const { return !isDeleted() && (meType == LINKSHEETRANGE_EXTERNAL); }
162 : : /** Returns true, if the sheet indexes are valid and different. */
163 : 0 : inline bool isSameSheet() const { return meType == LINKSHEETRANGE_SAMESHEET; }
164 : : /** Returns true, if the sheet indexes are valid and different. */
165 [ # # ][ # # ]: 0 : inline bool is3dRange() const { return (0 <= mnFirst) && (mnFirst < mnLast); }
166 : :
167 : 0 : inline sal_Int32 getDocLinkIndex() const { return mnDocLink; }
168 : 0 : inline sal_Int32 getFirstSheet() const { return mnFirst; }
169 : 0 : inline sal_Int32 getLastSheet() const { return mnLast; }
170 : :
171 : : private:
172 : : enum LinkSheetRangeType
173 : : {
174 : : LINKSHEETRANGE_INTERNAL, /// Sheet range in the own document.
175 : : LINKSHEETRANGE_EXTERNAL, /// Sheet range in an external document.
176 : : LINKSHEETRANGE_SAMESHEET /// Current sheet depending on context.
177 : : };
178 : :
179 : : LinkSheetRangeType meType; /// Link sheet range type.
180 : : sal_Int32 mnDocLink; /// Document link token index for external links.
181 : : sal_Int32 mnFirst; /// Index of the first sheet or index of first external sheet cache.
182 : : sal_Int32 mnLast; /// Index of the last sheet or index of last external sheet cache.
183 : : };
184 : :
185 : : // ============================================================================
186 : :
187 : : enum ExternalLinkType
188 : : {
189 : : LINKTYPE_SELF, /// Link refers to the current workbook.
190 : : LINKTYPE_SAME, /// Link refers to the current sheet.
191 : : LINKTYPE_INTERNAL, /// Link refers to a sheet in the own workbook.
192 : : LINKTYPE_EXTERNAL, /// Link refers to an external spreadsheet document.
193 : : LINKTYPE_ANALYSIS, /// Link refers to the Analysis add-in.
194 : : LINKTYPE_LIBRARY, /// Link refers to an external add-in.
195 : : LINKTYPE_DDE, /// DDE link.
196 : : LINKTYPE_OLE, /// OLE link.
197 : : LINKTYPE_MAYBE_DDE_OLE, /// Could be DDE or OLE link (BIFF only).
198 : : LINKTYPE_UNKNOWN /// Unknown or unsupported link type.
199 : : };
200 : :
201 : : // ----------------------------------------------------------------------------
202 : :
203 [ - + ]: 48 : class ExternalLink : public WorkbookHelper
204 : : {
205 : : public:
206 : : explicit ExternalLink( const WorkbookHelper& rHelper );
207 : :
208 : : /** Imports the externalReference element containing the relation identifier. */
209 : : void importExternalReference( const AttributeList& rAttribs );
210 : : /** Imports the externalBook element describing an externally linked document. */
211 : : void importExternalBook( const ::oox::core::Relations& rRelations, const AttributeList& rAttribs );
212 : : /** Imports the sheetName element containing the sheet name in an externally linked document. */
213 : : void importSheetName( const AttributeList& rAttribs );
214 : : /** Imports the definedName element describing an external name. */
215 : : void importDefinedName( const AttributeList& rAttribs );
216 : : /** Imports the ddeLink element describing a DDE link. */
217 : : void importDdeLink( const AttributeList& rAttribs );
218 : : /** Imports the ddeItem element describing an item of a DDE link. */
219 : : ExternalNameRef importDdeItem( const AttributeList& rAttribs );
220 : : /** Imports the oleLink element describing an OLE link. */
221 : : void importOleLink( const ::oox::core::Relations& rRelations, const AttributeList& rAttribs );
222 : : /** Imports the oleItem element describing an object of an OLE link. */
223 : : ExternalNameRef importOleItem( const AttributeList& rAttribs );
224 : :
225 : : /** Imports the EXTERNALBOOK record describing an externally linked document, DDE link, or OLE link. */
226 : : void importExternalBook( const ::oox::core::Relations& rRelations, SequenceInputStream& rStrm );
227 : : /** Imports the EXTSHEETNAMES record containing the sheet names in an externally linked document. */
228 : : void importExtSheetNames( SequenceInputStream& rStrm );
229 : : /** Imports the EXTERNALNAME record describing an external name. */
230 : : ExternalNameRef importExternalName( SequenceInputStream& rStrm );
231 : : /** Imports the EXTERNALREF record from the passed stream. */
232 : : void importExternalRef( SequenceInputStream& rStrm );
233 : : /** Imports the EXTERNALSELF record from the passed stream. */
234 : : void importExternalSelf( SequenceInputStream& rStrm );
235 : : /** Imports the EXTERNALSAME record from the passed stream. */
236 : : void importExternalSame( SequenceInputStream& rStrm );
237 : : /** Imports the EXTERNALADDIN record from the passed stream. */
238 : : void importExternalAddin( SequenceInputStream& rStrm );
239 : :
240 : : /** Sets the link type to 'self reference'. */
241 : 24 : inline void setSelfLinkType() { meLinkType = LINKTYPE_SELF; }
242 : :
243 : : /** Returns the type of this external link. */
244 : 0 : inline ExternalLinkType getLinkType() const { return meLinkType; }
245 : : /** Returns true, if the link refers to the current workbook. */
246 [ # # ][ # # ]: 0 : inline bool isInternalLink() const { return (meLinkType == LINKTYPE_SELF) || (meLinkType == LINKTYPE_INTERNAL); }
247 : :
248 : : /** Returns the relation identifier for the external link fragment. */
249 : 0 : inline const ::rtl::OUString& getRelId() const { return maRelId; }
250 : : /** Returns the class name of this external link. */
251 : 0 : inline const ::rtl::OUString& getClassName() const { return maClassName; }
252 : : /** Returns the target URL of this external link. */
253 : 0 : inline const ::rtl::OUString& getTargetUrl() const { return maTargetUrl; }
254 : : /** Returns the link info needed by the XML formula parser. */
255 : : ::com::sun::star::sheet::ExternalLinkInfo getLinkInfo() const;
256 : :
257 : : /** Returns the type of the external library if this is a library link. */
258 : : FunctionLibraryType getFuncLibraryType() const;
259 : :
260 : : /** Returns the token index of the external document. */
261 : : sal_Int32 getDocumentLinkIndex() const;
262 : : /** Returns the external sheet cache index or for the passed sheet. */
263 : : sal_Int32 getSheetCacheIndex( sal_Int32 nTabId = 0 ) const;
264 : : /** Returns the sheet cache of the external sheet with the passed index. */
265 : : ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XExternalSheetCache >
266 : : getSheetCache( sal_Int32 nTabId ) const;
267 : :
268 : : /** Returns the internal sheet range or range of external sheet caches for the passed sheet range (BIFF only). */
269 : : void getSheetRange( LinkSheetRange& orSheetRange, sal_Int32 nTabId1, sal_Int32 nTabId2 ) const;
270 : :
271 : : /** Returns the external name with the passed zero-based index. */
272 : : ExternalNameRef getNameByIndex( sal_Int32 nIndex ) const;
273 : :
274 : : private:
275 : : void setExternalTargetUrl( const ::rtl::OUString& rTargetUrl, const ::rtl::OUString& rTargetType );
276 : : void setDdeOleTargetUrl( const ::rtl::OUString& rClassName, const ::rtl::OUString& rTargetUrl, ExternalLinkType eLinkType );
277 : : void parseExternalReference( const ::oox::core::Relations& rRelations, const ::rtl::OUString& rRelId );
278 : :
279 : : /** Creates an external locument link and the sheet cache for the passed sheet name. */
280 : : void insertExternalSheet( const ::rtl::OUString& rSheetName );
281 : :
282 : : ExternalNameRef createExternalName();
283 : :
284 : : private:
285 : : typedef ::std::vector< sal_Int16 > Int16Vector;
286 : : typedef ::std::vector< sal_Int32 > Int32Vector;
287 : : typedef RefVector< ExternalName > ExternalNameVector;
288 : :
289 : : ExternalLinkType meLinkType; /// Type of this link object.
290 : : FunctionLibraryType meFuncLibType; /// Type of the function library, if link type is LINKTYPE_LIBRARY.
291 : : ::rtl::OUString maRelId; /// Relation identifier for the external link fragment.
292 : : ::rtl::OUString maClassName; /// DDE service, OLE class name.
293 : : ::rtl::OUString maTargetUrl; /// Target link, DDE topic, OLE target.
294 : : ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XExternalDocLink >
295 : : mxDocLink; /// Interface for an external document.
296 : : Int16Vector maCalcSheets; /// Internal sheet indexes.
297 : : Int32Vector maSheetCaches; /// External sheet cache indexes.
298 : : ExternalNameVector maExtNames; /// Defined names in external document.
299 : : };
300 : :
301 : : typedef ::boost::shared_ptr< ExternalLink > ExternalLinkRef;
302 : :
303 : : // ============================================================================
304 : :
305 : : /** Represents a REF entry in the BIFF12 EXTERNALSHEETS or in the BIFF8
306 : : EXTERNSHEET record.
307 : :
308 : : This struct is used to map ref identifiers to external books (BIFF12:
309 : : EXTERNALREF records, BIFF8: EXTERNALBOOK records), and provides sheet
310 : : indexes into the sheet list of the external document.
311 : : */
312 : : struct RefSheetsModel
313 : : {
314 : : sal_Int32 mnExtRefId; /// Zero-based index into list of external documents.
315 : : sal_Int32 mnTabId1; /// Zero-based index to first sheet in external document.
316 : : sal_Int32 mnTabId2; /// Zero-based index to last sheet in external document.
317 : :
318 : : explicit RefSheetsModel();
319 : :
320 : : void readBiff12Data( SequenceInputStream& rStrm );
321 : : };
322 : :
323 : : // ----------------------------------------------------------------------------
324 : :
325 [ + - ][ - + ]: 48 : class ExternalLinkBuffer : public WorkbookHelper
326 : : {
327 : : public:
328 : : explicit ExternalLinkBuffer( const WorkbookHelper& rHelper );
329 : :
330 : : /** Imports the externalReference element containing . */
331 : : ExternalLinkRef importExternalReference( const AttributeList& rAttribs );
332 : :
333 : : /** Imports the EXTERNALREF record from the passed stream. */
334 : : ExternalLinkRef importExternalRef( SequenceInputStream& rStrm );
335 : : /** Imports the EXTERNALSELF record from the passed stream. */
336 : : void importExternalSelf( SequenceInputStream& rStrm );
337 : : /** Imports the EXTERNALSAME record from the passed stream. */
338 : : void importExternalSame( SequenceInputStream& rStrm );
339 : : /** Imports the EXTERNALADDIN record from the passed stream. */
340 : : void importExternalAddin( SequenceInputStream& rStrm );
341 : : /** Imports the EXTERNALSHEETS record from the passed stream. */
342 : : void importExternalSheets( SequenceInputStream& rStrm );
343 : :
344 : : /** Returns the sequence of link infos needed by the XML formula parser. */
345 : : ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::ExternalLinkInfo >
346 : : getLinkInfos() const;
347 : :
348 : : /** Returns the external link for the passed reference identifier. */
349 : : ExternalLinkRef getExternalLink( sal_Int32 nRefId, bool bUseRefSheets = true ) const;
350 : :
351 : : /** Returns the sheet range for the specified reference (BIFF2-BIFF5 only). */
352 : : LinkSheetRange getSheetRange( sal_Int32 nRefId, sal_Int16 nTabId1, sal_Int16 nTabId2 ) const;
353 : : /** Returns the sheet range for the specified reference (BIFF8 only). */
354 : : LinkSheetRange getSheetRange( sal_Int32 nRefId ) const;
355 : :
356 : : private:
357 : : /** Creates a new external link and inserts it into the list of links. */
358 : : ExternalLinkRef createExternalLink();
359 : :
360 : : /** Returns the specified sheet indexes for a reference identifier. */
361 : : const RefSheetsModel* getRefSheets( sal_Int32 nRefId ) const;
362 : :
363 : : private:
364 : : typedef RefVector< ExternalLink > ExternalLinkVec;
365 : : typedef ::std::vector< RefSheetsModel > RefSheetsModelVec;
366 : :
367 : : ExternalLinkRef mxSelfRef; /// Implicit self reference at index 0.
368 : : ExternalLinkVec maLinks; /// List of link structures for all kinds of links.
369 : : ExternalLinkVec maExtLinks; /// Real external links needed for formula parser.
370 : : RefSheetsModelVec maRefSheets; /// Sheet indexes for reference ids.
371 : : bool mbUseRefSheets; /// True = use maRefSheets list (BIFF12 only).
372 : : };
373 : :
374 : : // ============================================================================
375 : :
376 : : } // namespace xls
377 : : } // namespace oox
378 : :
379 : : #endif
380 : :
381 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|