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 
29 namespace 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 
36 namespace oox::core {
37  class Relations;
38 }
39 
40 namespace oox::xls {
41 
43 {
44  bool mbNotify;
45  bool mbPreferPic;
46  bool mbStdDocName;
47  bool mbOleObj;
48  bool mbIconified;
49 
50  explicit ExternalNameModel();
51 };
52 
53 class ExternalLink;
54 
56 {
57 public:
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 
99 private:
101  void setResultSize( sal_Int32 nColumns, sal_Int32 nRows );
102 
103 private:
105 
108  ResultMatrix maResults;
110  css::uno::Reference< css::sheet::XDDELink >
113 };
114 
115 typedef std::shared_ptr< ExternalName > ExternalNameRef;
116 
119 {
120 public:
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 
145 private:
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
165  PathMissing,
166  Library,
167  DDE,
168  OLE,
169  Unknown
170 };
171 
172 template< typename charT, typename traits >
173 inline 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 {
192 public:
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 );
206  ExternalNameRef importDdeItem( const AttributeList& rAttribs );
208  void importOleLink( const ::oox::core::Relations& rRelations, const AttributeList& rAttribs );
210  ExternalNameRef importOleItem( const AttributeList& rAttribs );
211 
213  void importExternalBook( const ::oox::core::Relations& rRelations, SequenceInputStream& rStrm );
217  ExternalNameRef importExternalName( SequenceInputStream& rStrm );
219  void importExternalRef( 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 
259 private:
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 
267  ExternalNameRef createExternalName();
268 
269 private:
272  OUString maRelId;
273  OUString maClassName;
274  OUString maTargetUrl;
275  css::uno::Reference< css::sheet::XExternalDocLink >
277  std::vector< sal_Int32 > maSheetCaches;
279 };
280 
281 typedef 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 {
303 public:
304  explicit ExternalLinkBuffer( const WorkbookHelper& rHelper );
305 
307  ExternalLinkRef importExternalReference( const AttributeList& rAttribs );
308 
310  ExternalLinkRef importExternalRef( SequenceInputStream& rStrm );
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 
330 private:
332  ExternalLinkRef createExternalLink();
333 
335  const RefSheetsModel* getRefSheets( sal_Int32 nRefId ) const;
336 
337 private:
339  typedef ::std::vector< RefSheetsModel > RefSheetsModelVec;
340 
341  ExternalLinkRef mxSelfRef;
342  ExternalLinkVec maLinks;
343  ExternalLinkVec maExtLinks;
344  RefSheetsModelVec maRefSheets;
346 };
347 
348 } // namespace oox::xls
349 
350 /* 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.