Line data Source code
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_XILINK_HXX
21 : #define INCLUDED_SC_SOURCE_FILTER_INC_XILINK_HXX
22 :
23 : #include <map>
24 : #include "xllink.hxx"
25 : #include "xiroot.hxx"
26 : #include "types.hxx"
27 :
28 : namespace svl {
29 :
30 : class SharedStringPool;
31 :
32 : }
33 :
34 : /* ============================================================================
35 : Classes for import of different kinds of internal/external references.
36 : - 3D cell and cell range links
37 : - External cell and cell range links
38 : - External defined names
39 : - Add-in functions
40 : - DDE links
41 : - OLE object links
42 : ============================================================================ */
43 :
44 : // Excel sheet indexes ========================================================
45 :
46 : /** A buffer containing information about names and creation order of sheets.
47 :
48 : The first purpose of this buffer is to translate original Excel
49 : sheet names into Calc sheet indexes. This is not trivial because the filter
50 : may rename the Calc sheets during creation. This buffer stores the original
51 : Excel sheet names with the corresponding Calc sheet indexes.
52 :
53 : The second purpose is to store the creation order of all sheets inside the
54 : Excel workbook. The creation order list is contained in the TABID record
55 : and needed to import the change log. Example: If the list contains 3;1;2
56 : this means that the second sheet in the file was created first, than the
57 : third sheet in the file was created and finally the first sheet.
58 : */
59 168 : class XclImpTabInfo
60 : {
61 : public:
62 : // original Excel sheet names ---------------------------------------------
63 :
64 : /** Appends an original Excel sheet name with corresponding Calc sheet index. */
65 : void AppendXclTabName( const OUString& rXclTabName, SCTAB nScTab );
66 : /** Inserts a Calc sheet index (increases all following sheet indexes). */
67 : void InsertScTab( SCTAB nScTab );
68 :
69 : /** Returns the Calc sheet index from the passed original Excel sheet name. */
70 : SCTAB GetScTabFromXclName( const OUString& rXclTabName ) const;
71 :
72 : // record creation order - TABID record -----------------------------------
73 :
74 : /** Reads the TABID record. */
75 : void ReadTabid( XclImpStream& rStrm );
76 :
77 : /** Returns the current sheet index calculated from creation index.
78 : @param nCreatedId The creation index of the sheet (1-based).
79 : @param nMaxTabId All values greater than this parameter are not used to find the index.
80 : @return The 0-based index of the sheet nCreatedId if it is contained in the list.
81 : Example: The buffer is 3;5;2;4;1, nCreatedId is 1 and nMaxTabId is 3. The function will
82 : return 2 which is the 0-based index of sheet 1 in the list 3;2;1. */
83 : sal_uInt16 GetCurrentIndex( sal_uInt16 nCreatedId, sal_uInt16 nMaxTabId = 0xFFFF ) const;
84 :
85 : private:
86 : typedef ::std::map< OUString, SCTAB > XclTabNameMap;
87 :
88 : XclTabNameMap maTabNames; /// All Excel sheet names with Calc sheet index.
89 : ScfUInt16Vec maTabIdVec; /// The vector with sheet indexes.
90 : };
91 :
92 : // External names =============================================================
93 :
94 : /** Type of an external name. */
95 : enum XclImpExtNameType
96 : {
97 : xlExtName, /// An external defined name.
98 : xlExtAddIn, /// An add-in function name.
99 : xlExtDDE, /// A DDE link range.
100 : xlExtOLE, /// An OLE object link.
101 : xlExtEuroConvert /// An external in Excel, but internal in OO function name.
102 : };
103 :
104 : class XclImpCachedMatrix;
105 : class ScTokenArray;
106 : class XclImpSupbook;
107 :
108 : /** Stores contents of an external name.
109 : @descr Supported: External defined names, AddIn names, DDE links and OLE objects. */
110 : class XclImpExtName
111 : {
112 : /**
113 : * MOper, multiple operands, stores cached values of external range
114 : * specified in the record.
115 : */
116 0 : class MOper
117 : {
118 : public:
119 : MOper(svl::SharedStringPool& rPool, XclImpStream& rStrm);
120 : const ScMatrix& GetCache() const;
121 : private:
122 : ScMatrixRef mxCached;
123 : };
124 :
125 : public:
126 : /** Reads the external name from the stream. */
127 : explicit XclImpExtName( XclImpSupbook& rSupbook, XclImpStream& rStrm,
128 : XclSupbookType eSubType, ExcelToSc* pFormulaConv );
129 : ~XclImpExtName();
130 :
131 : /** Create and apply the cached list of this DDE Link to the document. */
132 : void CreateDdeData( ScDocument& rDoc,
133 : const OUString& rApplc, const OUString& rExtDoc ) const;
134 :
135 : void CreateExtNameData( ScDocument& rDoc, sal_uInt16 nFileId ) const;
136 :
137 : /**
138 : * Create OLE link data. OLE link data is converted to external
139 : * reference, since OLE link doesn't work cross-platform, and is not very
140 : * reliable even on Windows.
141 : */
142 : bool CreateOleData(ScDocument& rDoc, const OUString& rUrl,
143 : sal_uInt16& rFileId, OUString& rTabName, ScRange& rRange) const;
144 :
145 : bool HasFormulaTokens() const;
146 :
147 0 : XclImpExtNameType GetType() const { return meType; }
148 0 : const OUString& GetName() const { return maName; }
149 0 : sal_uInt32 GetStorageId() const { return mnStorageId; }
150 :
151 : private:
152 : typedef ::std::unique_ptr< XclImpCachedMatrix > XclImpCachedMatrixPtr;
153 : typedef ::std::unique_ptr< ScTokenArray > TokenArrayPtr;
154 :
155 : XclImpCachedMatrixPtr mxDdeMatrix; /// Cached results of the DDE link.
156 : MOper* mpMOper; /// Cached values for OLE link
157 : TokenArrayPtr mxArray; /// Formula tokens for external name.
158 : OUString maName; /// The name of the external name.
159 : sal_uInt32 mnStorageId; /// Storage ID for OLE object storages.
160 : XclImpExtNameType meType; /// Type of the external name.
161 : };
162 :
163 : // Import link manager ========================================================
164 :
165 : class XclImpLinkManagerImpl;
166 :
167 : /** This is the central class for the import of all internal/external links.
168 : @descr This manager stores all data about external documents with their sheets
169 : and cached cell contents. Additionally it handles external names, such as add-in
170 : function names, DDE links, and OLE object links.
171 : File contents in BIFF8:
172 : - Record SUPBOOK: Contains the name of an external document and the names of its sheets.
173 : This record is optionally followed by NAME, EXTERNNAME, XCT and CRN records.
174 : - Record XCT: Contains the number and sheet index of the following CRN records.
175 : - Record CRN: Contains addresses (row and column) and values of external referenced cells.
176 : - Record NAME: Contains defined names of the own workbook.
177 : - Record EXTERNNAME: Contains external defined names, DDE links, or OLE object links.
178 : - Record EXTERNSHEET: Contains indexes to URLs of external documents (SUPBOOKs)
179 : and sheet indexes for each external reference used anywhere in the workbook.
180 : This record follows a list of SUPBOOK records (with their attached records).
181 : */
182 : class XclImpLinkManager : protected XclImpRoot
183 : {
184 : public:
185 : explicit XclImpLinkManager( const XclImpRoot& rRoot );
186 : virtual ~XclImpLinkManager();
187 :
188 : /** Reads the EXTERNSHEET record. */
189 : void ReadExternsheet( XclImpStream& rStrm );
190 : /** Reads a SUPBOOK record. */
191 : void ReadSupbook( XclImpStream& rStrm );
192 : /** Reads an XCT record and appends it to the current SUPBOOK. */
193 : void ReadXct( XclImpStream& rStrm );
194 : /** Reads a CRN record and appends it to the current SUPBOOK. */
195 : void ReadCrn( XclImpStream& rStrm );
196 : /** Reads an EXTERNNAME record and appends it to the current SUPBOOK. */
197 : void ReadExternname( XclImpStream& rStrm, ExcelToSc* pFormulaConv = NULL );
198 :
199 : /** Returns true, if the specified XTI entry contains an internal reference. */
200 : bool IsSelfRef( sal_uInt16 nXtiIndex ) const;
201 : /** Returns the Calc sheet index range of the specified XTI entry.
202 : @return true = XTI data found, returned sheet index range is valid. */
203 : bool GetScTabRange(
204 : SCTAB& rnFirstScTab, SCTAB& rnLastScTab,
205 : sal_uInt16 nXtiIndex ) const;
206 : /** Returns the specified external name or 0 on error. */
207 : const XclImpExtName* GetExternName( sal_uInt16 nXtiIndex, sal_uInt16 nExtName ) const;
208 :
209 : const OUString* GetSupbookUrl( sal_uInt16 nXtiIndex ) const;
210 :
211 : const OUString& GetSupbookTabName( sal_uInt16 nXti, sal_uInt16 nXtiTab ) const;
212 :
213 : /** Tries to decode the URL of the specified XTI entry to OLE or DDE link components.
214 : @descr For DDE links: Decodes to application name and topic.
215 : For OLE object links: Decodes to class name and document URL.
216 : @return true = decoding was successful, returned strings are valid (not empty). */
217 : bool GetLinkData( OUString& rApplic, OUString& rTopic, sal_uInt16 nXtiIndex ) const;
218 : /** Returns the specified macro name or an empty string on error. */
219 : const OUString& GetMacroName( sal_uInt16 nExtSheet, sal_uInt16 nExtName ) const;
220 :
221 : private:
222 : typedef ::std::unique_ptr< XclImpLinkManagerImpl > XclImpLinkMgrImplPtr;
223 : XclImpLinkMgrImplPtr mxImpl;
224 : };
225 :
226 : #endif
227 :
228 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|