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 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_EXTERNALLINKBUFFER_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_EXTERNALLINKBUFFER_HXX
22 
23 #include <ostream>
24 
25 #include <com/sun/star/sheet/ExternalLinkInfo.hpp>
27 #include "defnamesbuffer.hxx"
28 #include "formulabase.hxx"
29 
30 namespace com::sun::star {
31  namespace sheet { struct DDEItemInfo; }
32  namespace sheet { class XDDELink; }
33  namespace sheet { class XExternalDocLink; }
34  namespace sheet { class XExternalSheetCache; }
35 }
36 
37 namespace oox::core {
38  class Relations;
39 }
40 
41 namespace oox::xls {
42 
44 {
45  bool mbNotify;
46  bool mbPreferPic;
47  bool mbStdDocName;
48  bool mbOleObj;
49  bool mbIconified;
50 
51  explicit ExternalNameModel();
52 };
53 
54 class ExternalLink;
55 
57 {
58 public:
59  explicit ExternalName( const ExternalLink& rParentLink );
60 
62  template< typename Type >
63  void appendResultValue( const Type& rValue )
64  { if( maCurrIt != maResults.end() ) (*maCurrIt++) <<= rValue; }
65 
67  void importDefinedName( const AttributeList& rAttribs );
69  void importDdeItem( const AttributeList& rAttribs );
71  void importValues( const AttributeList& rAttribs );
73  void importOleItem( const AttributeList& rAttribs );
74 
89 
91  bool getDdeItemInfo(
92  css::sheet::DDEItemInfo& orItemInfo ) const;
93 
95  bool getDdeLinkData(
96  OUString& orDdeServer,
97  OUString& orDdeTopic,
98  OUString& orDdeItem );
99 
100 private:
102  void setResultSize( sal_Int32 nColumns, sal_Int32 nRows );
103 
104 private:
106 
109  ResultMatrix maResults;
111  css::uno::Reference< css::sheet::XDDELink >
114 };
115 
116 typedef std::shared_ptr< ExternalName > ExternalNameRef;
117 
120 {
121 public:
122  explicit LinkSheetRange() { setDeleted(); }
123 
125  void setDeleted();
127  void setSameSheet();
129  void setRange( sal_Int32 nFirst, sal_Int32 nLast );
131  void setExternalRange( sal_Int32 nDocLink, sal_Int32 nFirst, sal_Int32 nLast );
132 
134  bool isDeleted() const { return mnFirst < 0; }
136  bool isExternal() const { return !isDeleted() && (meType == LINKSHEETRANGE_EXTERNAL); }
138  bool isSameSheet() const { return meType == LINKSHEETRANGE_SAMESHEET; }
140  bool is3dRange() const { return (0 <= mnFirst) && (mnFirst < mnLast); }
141 
142  sal_Int32 getDocLinkIndex() const { return mnDocLink; }
143  sal_Int32 getFirstSheet() const { return mnFirst; }
144  sal_Int32 getLastSheet() const { return mnLast; }
145 
146 private:
148  {
152  };
153 
155  sal_Int32 mnDocLink;
156  sal_Int32 mnFirst;
157  sal_Int32 mnLast;
158 };
159 
161 {
162  Self,
163  Same,
164  External,
165  // let's ignore xlStartup and xlAlternateStartup for now
166  PathMissing,
167  Library,
168  DDE,
169  OLE,
170  Unknown
171 };
172 
173 template< typename charT, typename traits >
174 inline std::basic_ostream<charT, traits> & operator <<(
175  std::basic_ostream<charT, traits> & stream, const ExternalLinkType& type )
176 {
177  switch (type)
178  {
179  case ExternalLinkType::Self: return stream << "self";
180  case ExternalLinkType::Same: return stream << "same";
181  case ExternalLinkType::External: return stream << "external";
182  case ExternalLinkType::PathMissing: return stream << "pathmissing";
183  case ExternalLinkType::Library: return stream << "library";
184  case ExternalLinkType::DDE: return stream << "dde";
185  case ExternalLinkType::OLE: return stream << "ole";
186  case ExternalLinkType::Unknown: return stream << "unknown";
187  default: return stream << static_cast<int>(type);
188  }
189 }
190 
192 {
193 public:
194  explicit ExternalLink( const WorkbookHelper& rHelper );
195 
197  void importExternalReference( const AttributeList& rAttribs );
199  void importExternalBook( const ::oox::core::Relations& rRelations, const AttributeList& rAttribs );
201  void importSheetName( const AttributeList& rAttribs );
203  void importDefinedName( const AttributeList& rAttribs );
205  void importDdeLink( const AttributeList& rAttribs );
207  ExternalNameRef importDdeItem( const AttributeList& rAttribs );
209  void importOleLink( const ::oox::core::Relations& rRelations, const AttributeList& rAttribs );
211  ExternalNameRef importOleItem( const AttributeList& rAttribs );
212 
214  void importExternalBook( const ::oox::core::Relations& rRelations, SequenceInputStream& rStrm );
218  ExternalNameRef importExternalName( SequenceInputStream& rStrm );
220  void importExternalRef( SequenceInputStream& rStrm );
227 
230 
233 
235  const OUString& getRelId() const { return maRelId; }
237  const OUString& getClassName() const { return maClassName; }
239  const OUString& getTargetUrl() const { return maTargetUrl; }
241  css::sheet::ExternalLinkInfo getLinkInfo() const;
242 
245 
247  sal_Int32 getDocumentLinkIndex() const;
249  sal_Int32 getSheetCacheIndex( sal_Int32 nTabId ) const;
251  css::uno::Reference< css::sheet::XExternalSheetCache >
252  getSheetCache( sal_Int32 nTabId ) const;
253 
255  void getSheetRange( LinkSheetRange& orSheetRange, sal_Int32 nTabId1, sal_Int32 nTabId2 ) const;
256 
258  ExternalNameRef getNameByIndex( sal_Int32 nIndex ) const;
259 
260 private:
261  void setExternalTargetUrl( const OUString& rTargetUrl, const OUString& rTargetType );
262  void setDdeOleTargetUrl( const OUString& rClassName, const OUString& rTargetUrl, ExternalLinkType eLinkType );
263  void parseExternalReference( const ::oox::core::Relations& rRelations, const OUString& rRelId );
264 
266  void insertExternalSheet( const OUString& rSheetName );
267 
268  ExternalNameRef createExternalName();
269 
270 private:
273  OUString maRelId;
274  OUString maClassName;
275  OUString maTargetUrl;
276  css::uno::Reference< css::sheet::XExternalDocLink >
278  std::vector< sal_Int32 > maSheetCaches;
280 };
281 
282 typedef std::shared_ptr< ExternalLink > ExternalLinkRef;
283 
292 {
293  sal_Int32 mnExtRefId;
294  sal_Int32 mnTabId1;
295  sal_Int32 mnTabId2;
296 
297  explicit RefSheetsModel();
298 
299  void readBiff12Data( SequenceInputStream& rStrm );
300 };
301 
303 {
304 public:
305  explicit ExternalLinkBuffer( const WorkbookHelper& rHelper );
306 
308  ExternalLinkRef importExternalReference( const AttributeList& rAttribs );
309 
311  ExternalLinkRef importExternalRef( SequenceInputStream& rStrm );
320 
322  css::uno::Sequence< css::sheet::ExternalLinkInfo >
323  getLinkInfos() const;
324 
326  ExternalLinkRef getExternalLink( sal_Int32 nRefId, bool bUseRefSheets = true ) const;
327 
329  LinkSheetRange getSheetRange( sal_Int32 nRefId ) const;
330 
331 private:
333  ExternalLinkRef createExternalLink();
334 
336  const RefSheetsModel* getRefSheets( sal_Int32 nRefId ) const;
337 
338 private:
340  typedef ::std::vector< RefSheetsModel > RefSheetsModelVec;
341 
342  ExternalLinkRef mxSelfRef;
343  ExternalLinkVec maLinks;
344  ExternalLinkVec maExtLinks;
345  RefSheetsModelVec maRefSheets;
347 };
348 
349 } // namespace oox::xls
350 
351 #endif
352 
353 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Helper class to provide access to global workbook data.
void importDdeItem(const AttributeList &rAttribs)
Imports the ddeItem element describing an item of a DDE link.
css::uno::Reference< css::sheet::XDDELink > mxDdeLink
Current position in result matrix.
Type
void importExternalSelf(SequenceInputStream &rStrm)
Imports the EXTERNALSELF record from the passed stream.
bool getDdeLinkData(OUString &orDdeServer, OUString &orDdeTopic, OUString &orDdeItem)
Returns the complete DDE link data of this DDE item.
iterator end()
ExternalLinkRef getExternalLink(sal_Int32 nRefId, bool bUseRefSheets=true) const
Returns the external link for the passed reference identifier.
ExternalLinkVec maLinks
Implicit self reference at index 0.
std::shared_ptr< ExternalLink > ExternalLinkRef
bool isDeleted() const
Returns true, if the sheet indexes are valid and different.
Link refers to the current sheet.
sal_Int32 getLastSheet() const
void appendResultValue(const Type &rValue)
Appends the passed value to the result set.
ResultMatrix maResults
Additional name data.
Link refers to the current workbook.
void importExternalNameFlags(SequenceInputStream &rStrm)
Imports the EXTERNALNAMEFLAGS record containing the settings of an external name. ...
Link refers to an external add-in.
Link refers to an external spreadsheet document.
ExternalLinkVec maExtLinks
List of link structures for all kinds of links.
void importExternalName(SequenceInputStream &rStrm)
Imports the EXTERNALNAME record containing the name (only).
const ExternalLink & mrParentLink
bool mbOleObj
Name is the StdDocumentName for DDE.
bool mbIconified
Name is an OLE object.
exports com.sun.star. sheet
sal_Int32 mnTabId1
Zero-based index into list of external documents.
Base class for defined names and external names.
sal_Int32 mnTabId2
Zero-based index to first sheet in external document.
sal_Int32 mnDocLink
Link sheet range type.
container_type::iterator iterator
RefSheetsModel()
Zero-based index to last sheet in external document.
const RefSheetsModel * getRefSheets(sal_Int32 nRefId) const
Returns the specified sheet indexes for a reference identifier.
Just for round-tripping (FIXME: Functionality not actually implemented after all.) ...
ExternalName(const ExternalLink &rParentLink)
void importOleItem(const AttributeList &rAttribs)
Imports the oleItem element describing an object of an OLE link.
void setSameSheet()
Sets this struct to "use current sheet" state.
void importExternalAddin(SequenceInputStream &rStrm)
Imports the EXTERNALADDIN record from the passed stream.
RefVector< ExternalLink > ExternalLinkVec
bool mbUseRefSheets
Sheet indexes for reference ids.
sal_Int32 mnLast
Index of the first sheet or index of first external sheet cache.
Matrix< css::uno::Any > ResultMatrix
ExternalLinkBuffer(const WorkbookHelper &rHelper)
bool is3dRange() const
Returns true, if the sheet indexes are valid and different.
void readBiff12Data(SequenceInputStream &rStrm)
sal_Int32 mnFirst
Document link token index for external links.
sal_Int32 getDocLinkIndex() const
void setResultSize(sal_Int32 nColumns, sal_Int32 nRows)
Sets the size of the result matrix.
RefSheetsModelVec maRefSheets
Real external links needed for formula parser.
FunctionLibraryType
This enumeration contains constants for all known external libraries containing supported sheet funct...
sal_Int32 getFirstSheet() const
void importValues(const AttributeList &rAttribs)
Imports the values element containing the size of the DDE result matrix.
ExternalLinkRef importExternalReference(const AttributeList &rAttribs)
Imports the externalReference element containing .
bool mbPreferPic
Notify application on data change.
css::uno::Sequence< css::sheet::ExternalLinkInfo > getLinkInfos() const
Returns the sequence of link infos needed by the XML formula parser.
void setExternalRange(sal_Int32 nDocLink, sal_Int32 nFirst, sal_Int32 nLast)
Sets the passed external sheet cache range to the members of this struct.
void setDeleted()
Sets this struct to deleted state.
ExternalNameModel maExtNameModel
External link this name belongs to.
Represents a REF entry in the BIFF12 EXTERNALSHEETS or in the BIFF8 EXTERNSHEET record.
void importDdeItemValues(SequenceInputStream &rStrm)
Imports the DDEITEMVALUES record containing the size of the DDE result matrix.
void importExternalSame(SequenceInputStream &rStrm)
Imports the EXTERNALSAME record from the passed stream.
LinkSheetRange getSheetRange(sal_Int32 nRefId) const
Returns the sheet range for the specified reference (BIFF8 only).
void importDdeItemError(SequenceInputStream &rStrm)
Imports the DDEITEM_ERROR record containing an error code in a link result.
void importExternalSheets(SequenceInputStream &rStrm)
Imports the EXTERNALSHEETS record from the passed stream.
bool isExternal() const
Returns true, if the sheet range points to an external document.
Contains indexes for a range of sheets in the spreadsheet document.
ExternalLinkRef importExternalRef(SequenceInputStream &rStrm)
Imports the EXTERNALREF record from the passed stream.
void importDdeItemString(SequenceInputStream &rStrm)
Imports the DDEITEM_STRING record containing a string in a link result.
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &stream, const ExternalLinkType &type)
::std::vector< RefSheetsModel > RefSheetsModelVec
bool isSameSheet() const
Returns true, if the sheet indexes are valid and different.
bool mbDdeLinkCreated
Interface of a DDE link.
ExternalLinkRef createExternalLink()
Creates a new external link and inserts it into the list of links.
void importDdeItemBool(SequenceInputStream &rStrm)
Imports the DDEITEM_BOOL record containing a boolean value in a link result.
bool getDdeItemInfo(css::sheet::DDEItemInfo &orItemInfo) const
Returns the DDE item info needed by the XML formula parser.
void SvStream & rStrm
void setRange(sal_Int32 nFirst, sal_Int32 nLast)
Sets the passed absolute sheet range to the members of this struct.
void importDefinedName(const AttributeList &rAttribs)
Imports the definedName element.
std::shared_ptr< ExternalName > ExternalNameRef
ResultMatrix::iterator maCurrIt
DDE/OLE link results.
void importDdeItemDouble(SequenceInputStream &rStrm)
Imports the DDEITEM_DOUBLE record containing a double value in a link result.
ExternalNameModel()
Iconified object link.