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