LibreOffice Module sc (master) 1
externallinkbuffer.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
22#include <ostream>
23
24#include <com/sun/star/sheet/ExternalLinkInfo.hpp>
26#include "defnamesbuffer.hxx"
27#include "formulabase.hxx"
28
29namespace com::sun::star {
30 namespace sheet { struct DDEItemInfo; }
31 namespace sheet { class XDDELink; }
32 namespace sheet { class XExternalDocLink; }
33 namespace sheet { class XExternalSheetCache; }
34}
35
36namespace oox::core {
37 class Relations;
38}
39
40namespace oox::xls {
41
43{
44 bool mbNotify;
47 bool mbOleObj;
49
50 explicit ExternalNameModel();
51};
52
53class ExternalLink;
54
56{
57public:
58 explicit ExternalName( const ExternalLink& rParentLink );
59
61 template< typename Type >
62 void appendResultValue( const Type& rValue )
63 { if( maCurrIt != maResults.end() ) (*maCurrIt++) <<= rValue; }
64
66 void importDefinedName( const AttributeList& rAttribs );
68 void importDdeItem( const AttributeList& rAttribs );
70 void importValues( const AttributeList& rAttribs );
72 void importOleItem( const AttributeList& rAttribs );
73
88
90 bool getDdeItemInfo(
91 css::sheet::DDEItemInfo& orItemInfo ) const;
92
94 bool getDdeLinkData(
95 OUString& orDdeServer,
96 OUString& orDdeTopic,
97 OUString& orDdeItem );
98
99private:
101 void setResultSize( sal_Int32 nColumns, sal_Int32 nRows );
102
103private:
105
110 css::uno::Reference< css::sheet::XDDELink >
113};
114
115typedef std::shared_ptr< ExternalName > ExternalNameRef;
116
119{
120public:
121 explicit LinkSheetRange() { setDeleted(); }
122
124 void setDeleted();
126 void setSameSheet();
128 void setRange( sal_Int32 nFirst, sal_Int32 nLast );
130 void setExternalRange( sal_Int32 nDocLink, sal_Int32 nFirst, sal_Int32 nLast );
131
133 bool isDeleted() const { return mnFirst < 0; }
135 bool isExternal() const { return !isDeleted() && (meType == LINKSHEETRANGE_EXTERNAL); }
137 bool isSameSheet() const { return meType == LINKSHEETRANGE_SAMESHEET; }
139 bool is3dRange() const { return (0 <= mnFirst) && (mnFirst < mnLast); }
140
141 sal_Int32 getDocLinkIndex() const { return mnDocLink; }
142 sal_Int32 getFirstSheet() const { return mnFirst; }
143 sal_Int32 getLastSheet() const { return mnLast; }
144
145private:
147 {
151 };
152
154 sal_Int32 mnDocLink;
155 sal_Int32 mnFirst;
156 sal_Int32 mnLast;
157};
158
160{
161 Self,
162 Same,
163 External,
164 // let's ignore xlStartup and xlAlternateStartup for now
166 Library,
167 DDE,
168 OLE,
169 Unknown
170};
171
172template< typename charT, typename traits >
173inline std::basic_ostream<charT, traits> & operator <<(
174 std::basic_ostream<charT, traits> & stream, const ExternalLinkType& type )
175{
176 switch (type)
177 {
178 case ExternalLinkType::Self: return stream << "self";
179 case ExternalLinkType::Same: return stream << "same";
180 case ExternalLinkType::External: return stream << "external";
181 case ExternalLinkType::PathMissing: return stream << "pathmissing";
182 case ExternalLinkType::Library: return stream << "library";
183 case ExternalLinkType::DDE: return stream << "dde";
184 case ExternalLinkType::OLE: return stream << "ole";
185 case ExternalLinkType::Unknown: return stream << "unknown";
186 default: return stream << static_cast<int>(type);
187 }
188}
189
191{
192public:
193 explicit ExternalLink( const WorkbookHelper& rHelper );
194
196 void importExternalReference( const AttributeList& rAttribs );
198 void importExternalBook( const ::oox::core::Relations& rRelations, const AttributeList& rAttribs );
200 void importSheetName( const AttributeList& rAttribs );
202 void importDefinedName( const AttributeList& rAttribs );
204 void importDdeLink( const AttributeList& rAttribs );
208 void importOleLink( const ::oox::core::Relations& rRelations, const AttributeList& rAttribs );
211
213 void importExternalBook( const ::oox::core::Relations& rRelations, SequenceInputStream& rStrm );
226
229
232
234 const OUString& getRelId() const { return maRelId; }
236 const OUString& getClassName() const { return maClassName; }
238 const OUString& getTargetUrl() const { return maTargetUrl; }
240 css::sheet::ExternalLinkInfo getLinkInfo() const;
241
244
246 sal_Int32 getDocumentLinkIndex() const;
248 sal_Int32 getSheetCacheIndex( sal_Int32 nTabId ) const;
250 css::uno::Reference< css::sheet::XExternalSheetCache >
251 getSheetCache( sal_Int32 nTabId ) const;
252
254 void getSheetRange( LinkSheetRange& orSheetRange, sal_Int32 nTabId1, sal_Int32 nTabId2 ) const;
255
257 ExternalNameRef getNameByIndex( sal_Int32 nIndex ) const;
258
259private:
260 void setExternalTargetUrl( const OUString& rTargetUrl, const OUString& rTargetType );
261 void setDdeOleTargetUrl( const OUString& rClassName, const OUString& rTargetUrl, ExternalLinkType eLinkType );
262 void parseExternalReference( const ::oox::core::Relations& rRelations, const OUString& rRelId );
263
265 void insertExternalSheet( const OUString& rSheetName );
266
268
269private:
272 OUString maRelId;
273 OUString maClassName;
274 OUString maTargetUrl;
275 css::uno::Reference< css::sheet::XExternalDocLink >
277 std::vector< sal_Int32 > maSheetCaches;
279};
280
281typedef std::shared_ptr< ExternalLink > ExternalLinkRef;
282
291{
292 sal_Int32 mnExtRefId;
293 sal_Int32 mnTabId1;
294 sal_Int32 mnTabId2;
295
296 explicit RefSheetsModel();
297
298 void readBiff12Data( SequenceInputStream& rStrm );
299};
300
302{
303public:
304 explicit ExternalLinkBuffer( const WorkbookHelper& rHelper );
305
308
319
321 css::uno::Sequence< css::sheet::ExternalLinkInfo >
322 getLinkInfos() const;
323
325 ExternalLinkRef getExternalLink( sal_Int32 nRefId, bool bUseRefSheets = true ) const;
326
328 LinkSheetRange getSheetRange( sal_Int32 nRefId ) const;
329
330private:
333
335 const RefSheetsModel* getRefSheets( sal_Int32 nRefId ) const;
336
337private:
339 typedef ::std::vector< RefSheetsModel > RefSheetsModelVec;
340
346};
347
348} // namespace oox::xls
349
350/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
iterator end()
container_type::iterator iterator
Base class for defined names and external names.
const RefSheetsModel * getRefSheets(sal_Int32 nRefId) const
Returns the specified sheet indexes for a reference identifier.
::std::vector< RefSheetsModel > RefSheetsModelVec
ExternalLinkRef createExternalLink()
Creates a new external link and inserts it into the list of links.
RefVector< ExternalLink > ExternalLinkVec
void importExternalAddin(SequenceInputStream &rStrm)
Imports the EXTERNALADDIN record from the passed stream.
void importExternalSelf(SequenceInputStream &rStrm)
Imports the EXTERNALSELF record from the passed stream.
ExternalLinkRef getExternalLink(sal_Int32 nRefId, bool bUseRefSheets=true) const
Returns the external link for the passed reference identifier.
css::uno::Sequence< css::sheet::ExternalLinkInfo > getLinkInfos() const
Returns the sequence of link infos needed by the XML formula parser.
void importExternalSheets(SequenceInputStream &rStrm)
Imports the EXTERNALSHEETS record from the passed stream.
bool mbUseRefSheets
Sheet indexes for reference ids.
void importExternalSame(SequenceInputStream &rStrm)
Imports the EXTERNALSAME record from the passed stream.
RefSheetsModelVec maRefSheets
Real external links needed for formula parser.
ExternalLinkRef importExternalReference(const AttributeList &rAttribs)
Imports the externalReference element containing .
ExternalLinkVec maLinks
Implicit self reference at index 0.
ExternalLinkBuffer(const WorkbookHelper &rHelper)
ExternalLinkRef importExternalRef(SequenceInputStream &rStrm)
Imports the EXTERNALREF record from the passed stream.
ExternalLinkVec maExtLinks
List of link structures for all kinds of links.
LinkSheetRange getSheetRange(sal_Int32 nRefId) const
Returns the sheet range for the specified reference (BIFF8 only).
void importExternalName(SequenceInputStream &rStrm)
Imports the EXTERNALNAME record containing the name (only).
void importDdeItemError(SequenceInputStream &rStrm)
Imports the DDEITEM_ERROR record containing an error code in a link result.
void importDefinedName(const AttributeList &rAttribs)
Imports the definedName element.
void importDdeItemBool(SequenceInputStream &rStrm)
Imports the DDEITEM_BOOL record containing a boolean value in a link result.
void importDdeItemValues(SequenceInputStream &rStrm)
Imports the DDEITEMVALUES record containing the size of the DDE result matrix.
void importDdeItemString(SequenceInputStream &rStrm)
Imports the DDEITEM_STRING record containing a string in a link result.
void importValues(const AttributeList &rAttribs)
Imports the values element containing the size of the DDE result matrix.
ResultMatrix::iterator maCurrIt
DDE/OLE link results.
void importDdeItemDouble(SequenceInputStream &rStrm)
Imports the DDEITEM_DOUBLE record containing a double value in a link result.
ExternalName(const ExternalLink &rParentLink)
ExternalNameModel maExtNameModel
External link this name belongs to.
void importDdeItem(const AttributeList &rAttribs)
Imports the ddeItem element describing an item of a DDE link.
const ExternalLink & mrParentLink
bool getDdeItemInfo(css::sheet::DDEItemInfo &orItemInfo) const
Returns the DDE item info needed by the XML formula parser.
void importExternalNameFlags(SequenceInputStream &rStrm)
Imports the EXTERNALNAMEFLAGS record containing the settings of an external name.
void importOleItem(const AttributeList &rAttribs)
Imports the oleItem element describing an object of an OLE link.
css::uno::Reference< css::sheet::XDDELink > mxDdeLink
Current position in result matrix.
ResultMatrix maResults
Additional name data.
bool mbDdeLinkCreated
Interface of a DDE link.
bool getDdeLinkData(OUString &orDdeServer, OUString &orDdeTopic, OUString &orDdeItem)
Returns the complete DDE link data of this DDE item.
Matrix< css::uno::Any > ResultMatrix
void appendResultValue(const Type &rValue)
Appends the passed value to the result set.
void setResultSize(sal_Int32 nColumns, sal_Int32 nRows)
Sets the size of the result matrix.
Contains indexes for a range of sheets in the spreadsheet document.
void setSameSheet()
Sets this struct to "use current sheet" state.
sal_Int32 mnFirst
Document link token index for external links.
bool isDeleted() const
Returns true, if the sheet indexes are valid and different.
void setExternalRange(sal_Int32 nDocLink, sal_Int32 nFirst, sal_Int32 nLast)
Sets the passed external sheet cache range to the members of this struct.
bool isExternal() const
Returns true, if the sheet range points to an external document.
sal_Int32 mnDocLink
Link sheet range type.
sal_Int32 mnLast
Index of the first sheet or index of first external sheet cache.
sal_Int32 getDocLinkIndex() const
void setRange(sal_Int32 nFirst, sal_Int32 nLast)
Sets the passed absolute sheet range to the members of this struct.
void setDeleted()
Sets this struct to deleted state.
bool is3dRange() const
Returns true, if the sheet indexes are valid and different.
bool isSameSheet() const
Returns true, if the sheet indexes are valid and different.
@ LINKSHEETRANGE_SAMESHEET
Sheet range in an external document.
@ LINKSHEETRANGE_EXTERNAL
Sheet range in the own document.
Helper class to provide access to global workbook data.
Reference< XOutputStream > stream
Type
Unknown
void SvStream & rStrm
std::shared_ptr< ExternalName > ExternalNameRef
std::shared_ptr< ExternalLink > ExternalLinkRef
@ PathMissing
Link refers to an external spreadsheet document.
@ Library
Just for round-tripping (FIXME: Functionality not actually implemented after all.)
@ External
Link refers to the current sheet.
@ Same
Link refers to the current workbook.
@ DDE
Link refers to an external add-in.
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &stream, const ExternalLinkType &type)
FunctionLibraryType
This enumeration contains constants for all known external libraries containing supported sheet funct...
ExternalNameModel()
Iconified object link.
bool mbOleObj
Name is the StdDocumentName for DDE.
bool mbPreferPic
Notify application on data change.
bool mbIconified
Name is an OLE object.
Represents a REF entry in the BIFF12 EXTERNALSHEETS or in the BIFF8 EXTERNSHEET record.
sal_Int32 mnTabId1
Zero-based index into list of external documents.
void readBiff12Data(SequenceInputStream &rStrm)
RefSheetsModel()
Zero-based index to last sheet in external document.
sal_Int32 mnTabId2
Zero-based index to first sheet in external document.