LibreOffice Module sc (master)  1
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
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 .
18  */
23 #include <memory>
24 #include <map>
25 #include "xllink.hxx"
26 #include "xiroot.hxx"
27 #include "ftools.hxx"
28 #include <types.hxx>
30 namespace svl {
32 class SharedStringPool;
34 }
36 /* ============================================================================
37 Classes for import of different kinds of internal/external references.
38 - 3D cell and cell range links
39 - External cell and cell range links
40 - External defined names
41 - Add-in functions
42 - DDE links
43 - OLE object links
44 ============================================================================ */
46 // Excel sheet indexes ========================================================
62 {
63 public:
64  // original Excel sheet names ---------------------------------------------
67  void AppendXclTabName( const OUString& rXclTabName, SCTAB nScTab );
69  void InsertScTab( SCTAB nScTab );
72  SCTAB GetScTabFromXclName( const OUString& rXclTabName ) const;
74  // record creation order - TABID record -----------------------------------
77  void ReadTabid( XclImpStream& rStrm );
85  sal_uInt16 GetCurrentIndex( sal_uInt16 nCreatedId, sal_uInt16 nMaxTabId ) const;
87 private:
88  typedef ::std::map< OUString, SCTAB > XclTabNameMap;
90  XclTabNameMap maTabNames;
92 };
94 // External names =============================================================
98 {
104 };
106 class XclImpCachedMatrix;
107 class ScTokenArray;
108 class XclImpSupbook;
113 {
118  class MOper
119  {
120  public:
122  const ScMatrix& GetCache() const;
123  private:
125  };
127 public:
129  explicit XclImpExtName( XclImpSupbook& rSupbook, XclImpStream& rStrm,
130  XclSupbookType eSubType, ExcelToSc* pFormulaConv );
131  ~XclImpExtName();
134  void CreateDdeData( ScDocument& rDoc,
135  const OUString& rApplc, const OUString& rExtDoc ) const;
137  void CreateExtNameData( const ScDocument& rDoc, sal_uInt16 nFileId ) const;
144  bool CreateOleData(ScDocument& rDoc, const OUString& rUrl,
145  sal_uInt16& rFileId, OUString& rTabName, ScRange& rRange) const;
147  bool HasFormulaTokens() const;
149  XclImpExtNameType GetType() const { return meType; }
150  const OUString& GetName() const { return maName; }
151  sal_uInt32 GetStorageId() const { return mnStorageId; }
153 private:
154  typedef ::std::unique_ptr< XclImpCachedMatrix > XclImpCachedMatrixPtr;
155  typedef ::std::unique_ptr< ScTokenArray > TokenArrayPtr;
157  XclImpCachedMatrixPtr mxDdeMatrix;
158  std::unique_ptr<MOper> mpMOper;
159  TokenArrayPtr mxArray;
160  OUString maName;
161  sal_uInt32 mnStorageId;
163 };
165 // Import link manager ========================================================
184 class XclImpLinkManager : protected XclImpRoot
185 {
186 public:
187  explicit XclImpLinkManager( const XclImpRoot& rRoot );
188  virtual ~XclImpLinkManager() override;
193  void ReadSupbook( XclImpStream& rStrm );
195  void ReadXct( XclImpStream& rStrm );
197  void ReadCrn( XclImpStream& rStrm );
199  void ReadExternname( XclImpStream& rStrm, ExcelToSc* pFormulaConv );
202  bool IsSelfRef( sal_uInt16 nXtiIndex ) const;
205  bool GetScTabRange(
206  SCTAB& rnFirstScTab, SCTAB& rnLastScTab,
207  sal_uInt16 nXtiIndex ) const;
209  const XclImpExtName* GetExternName( sal_uInt16 nXtiIndex, sal_uInt16 nExtName ) const;
211  const OUString* GetSupbookUrl( sal_uInt16 nXtiIndex ) const;
213  const OUString& GetSupbookTabName( sal_uInt16 nXti, sal_uInt16 nXtiTab ) const;
219  bool GetLinkData( OUString& rApplic, OUString& rTopic, sal_uInt16 nXtiIndex ) const;
221  const OUString& GetMacroName( sal_uInt16 nExtSheet, sal_uInt16 nExtName ) const;
223 private:
224  typedef ::std::unique_ptr< XclImpLinkManagerImpl > XclImpLinkMgrImplPtr;
225  XclImpLinkMgrImplPtr mxImpl;
226 };
228 #endif
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Matrix data type that can store values of mixed types.
Definition: scmatrix.hxx:113
MOper, multiple operands, stores cached values of external range specified in the record...
Definition: xilink.hxx:118
void ReadExternsheet(XclImpStream &rStrm)
Reads the EXTERNSHEET record.
Definition: xilink.cxx:901
const OUString & GetMacroName(sal_uInt16 nExtSheet, sal_uInt16 nExtName) const
Returns the specified macro name or an empty string on error.
Definition: xilink.cxx:957
const ScMatrix & GetCache() const
Definition: xilink.cxx:339
bool CreateOleData(ScDocument &rDoc, const OUString &rUrl, sal_uInt16 &rFileId, OUString &rTabName, ScRange &rRange) const
Create OLE link data.
Definition: xilink.cxx:471
MOper(svl::SharedStringPool &rPool, XclImpStream &rStrm)
Definition: xilink.cxx:277
This class represents an external linked document (record SUPBOOK).
Definition: xilink.cxx:90
::std::unique_ptr< XclImpCachedMatrix > XclImpCachedMatrixPtr
Definition: xilink.hxx:154
XclImpExtNameType meType
Storage ID for OLE object storages.
Definition: xilink.hxx:162
void ReadTabid(XclImpStream &rStrm)
Reads the TABID record.
Definition: xilink.cxx:246
void ReadExternname(XclImpStream &rStrm, ExcelToSc *pFormulaConv)
Reads an EXTERNNAME record and appends it to the current SUPBOOK.
Definition: xilink.cxx:921
ScMatrixRef mxCached
Definition: xilink.hxx:124
bool GetScTabRange(SCTAB &rnFirstScTab, SCTAB &rnLastScTab, sal_uInt16 nXtiIndex) const
Returns the Calc sheet index range of the specified XTI entry.
Definition: xilink.cxx:931
void ReadXct(XclImpStream &rStrm)
Reads an XCT record and appends it to the current SUPBOOK.
Definition: xilink.cxx:911
::boost::intrusive_ptr< ScMatrix > ScMatrixRef
Definition: types.hxx:26
void CreateDdeData(ScDocument &rDoc, const OUString &rApplc, const OUString &rExtDoc) const
Create and apply the cached list of this DDE Link to the document.
Definition: xilink.cxx:412
XclImpExtNameType GetType() const
Definition: xilink.hxx:149
XclImpLinkManager(const XclImpRoot &rRoot)
Definition: xilink.cxx:891
sal_uInt16 GetCurrentIndex(sal_uInt16 nCreatedId, sal_uInt16 nMaxTabId) const
Returns the current sheet index calculated from creation index.
Definition: xilink.cxx:262
A buffer containing information about names and creation order of sheets.
Definition: xilink.hxx:61
Stores contents of an external name.
Definition: xilink.hxx:112
bool HasFormulaTokens() const
Definition: xilink.cxx:546
void InsertScTab(SCTAB nScTab)
Inserts a Calc sheet index (increases all following sheet indexes).
Definition: xilink.cxx:231
sal_uInt32 mnStorageId
The name of the external name.
Definition: xilink.hxx:161
XclTabNameMap maTabNames
Definition: xilink.hxx:90
Contains cached values in a 2-dimensional array.
Definition: xihelper.hxx:334
std::unique_ptr< MOper > mpMOper
Cached results of the DDE link.
Definition: xilink.hxx:158
const XclImpExtName * GetExternName(sal_uInt16 nXtiIndex, sal_uInt16 nExtName) const
Returns the specified external name or 0 on error.
Definition: xilink.cxx:937
bool GetLinkData(OUString &rApplic, OUString &rTopic, sal_uInt16 nXtiIndex) const
Tries to decode the URL of the specified XTI entry to OLE or DDE link components. ...
Definition: xilink.cxx:952
::std::unique_ptr< XclImpLinkManagerImpl > XclImpLinkMgrImplPtr
Definition: xilink.hxx:224
XclImpLinkMgrImplPtr mxImpl
Definition: xilink.hxx:225
virtual ~XclImpLinkManager() override
Definition: xilink.cxx:897
OUString maName
Formula tokens for external name.
Definition: xilink.hxx:160
::std::vector< sal_uInt16 > ScfUInt16Vec
Definition: ftools.hxx:253
void ReadSupbook(XclImpStream &rStrm)
Reads a SUPBOOK record.
Definition: xilink.cxx:906
sal_uInt32 GetStorageId() const
Definition: xilink.hxx:151
These need to be in global namespace just like their respective types are.
::std::map< OUString, SCTAB > XclTabNameMap
Definition: xilink.hxx:88
const OUString * GetSupbookUrl(sal_uInt16 nXtiIndex) const
Definition: xilink.cxx:942
XclImpExtName(XclImpSupbook &rSupbook, XclImpStream &rStrm, XclSupbookType eSubType, ExcelToSc *pFormulaConv)
Reads the external name from the stream.
Definition: xilink.cxx:344
SCTAB GetScTabFromXclName(const OUString &rXclTabName) const
Returns the Calc sheet index from the passed original Excel sheet name.
Definition: xilink.cxx:238
This class is used to import record oriented streams.
Definition: xistream.hxx:278
TokenArrayPtr mxArray
Cached values for OLE link.
Definition: xilink.hxx:159
XclImpCachedMatrixPtr mxDdeMatrix
Definition: xilink.hxx:157
Implementation of the link manager.
Definition: xilink.cxx:164
bool IsSelfRef(sal_uInt16 nXtiIndex) const
Returns true, if the specified XTI entry contains an internal reference.
Definition: xilink.cxx:926
void CreateExtNameData(const ScDocument &rDoc, sal_uInt16 nFileId) const
Definition: xilink.cxx:420
void SvStream & rStrm
Access to global data from other classes.
Definition: xiroot.hxx:126
ScfUInt16Vec maTabIdVec
All Excel sheet names with Calc sheet index.
Definition: xilink.hxx:91
const OUString & GetName() const
Definition: xilink.hxx:150
sal_Int16 SCTAB
Definition: types.hxx:23
const OUString & GetSupbookTabName(sal_uInt16 nXti, sal_uInt16 nXtiTab) const
Definition: xilink.cxx:947
This is the central class for the import of all internal/external links.
Definition: xilink.hxx:184
::std::unique_ptr< ScTokenArray > TokenArrayPtr
Definition: xilink.hxx:155
void ReadCrn(XclImpStream &rStrm)
Reads a CRN record and appends it to the current SUPBOOK.
Definition: xilink.cxx:916
void AppendXclTabName(const OUString &rXclTabName, SCTAB nScTab)
Appends an original Excel sheet name with corresponding Calc sheet index.
Definition: xilink.cxx:226