Update ooo320-m1
[ooovba.git] / sc / source / filter / inc / xilink.hxx
blobdbdf8837e9a4c941707d96e77fe12da08a50dac6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xilink.hxx,v $
10 * $Revision: 1.14.134.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_XILINK_HXX
32 #define SC_XILINK_HXX
34 #include <map>
35 #include "xllink.hxx"
36 #include "xiroot.hxx"
38 /* ============================================================================
39 Classes for import of different kinds of internal/external references.
40 - 3D cell and cell range links
41 - External cell and cell range links
42 - External defined names
43 - Add-in functions
44 - DDE links
45 - OLE object links
46 ============================================================================ */
48 // Excel sheet indexes ========================================================
50 /** A buffer containing information about names and creation order of sheets.
52 The first purpose of this buffer is to translate original Excel
53 sheet names into Calc sheet indexes. This is not trivial because the filter
54 may rename the Calc sheets during creation. This buffer stores the original
55 Excel sheet names with the corresponding Calc sheet indexes.
57 The second purpose is to store the creation order of all sheets inside the
58 Excel workbook. The creation order list is contained in the TABID record
59 and needed to import the change log. Example: If the list contains 3;1;2
60 this means that the second sheet in the file was created first, than the
61 third sheet in the file was created and finally the first sheet.
63 class XclImpTabInfo
65 public:
66 // original Excel sheet names ---------------------------------------------
68 /** Appends an original Excel sheet name with corresponding Calc sheet index. */
69 void AppendXclTabName( const String& rXclTabName, SCTAB nScTab );
70 /** Inserts a Calc sheet index (increases all following sheet indexes). */
71 void InsertScTab( SCTAB nScTab );
73 /** Returns the Calc sheet index from the passed original Excel sheet name. */
74 SCTAB GetScTabFromXclName( const String& rXclTabName ) const;
76 // record creation order - TABID record -----------------------------------
78 /** Reads the TABID record. */
79 void ReadTabid( XclImpStream& rStrm );
81 /** Returns the current sheet index calculated from creation index.
82 @param nCreatedId The creation index of the sheet (1-based).
83 @param nMaxTabId All values greater than this parameter are not used to find the index.
84 @return The 0-based index of the sheet nCreatedId if it is contained in the list.
85 Example: The buffer is 3;5;2;4;1, nCreatedId is 1 and nMaxTabId is 3. The function will
86 return 2 which is the 0-based index of sheet 1 in the list 3;2;1. */
87 sal_uInt16 GetCurrentIndex( sal_uInt16 nCreatedId, sal_uInt16 nMaxTabId = 0xFFFF ) const;
89 private:
90 typedef ::std::map< String, SCTAB > XclTabNameMap;
92 XclTabNameMap maTabNames; /// All Excel sheet names with Calc sheet index.
93 ScfUInt16Vec maTabIdVec; /// The vector with sheet indexes.
96 // External names =============================================================
98 /** Type of an external name. */
99 enum XclImpExtNameType
101 xlExtName, /// An external defined name.
102 xlExtAddIn, /// An add-in function name.
103 xlExtDDE, /// A DDE link range.
104 xlExtOLE, /// An OLE object link.
105 xlExtEuroConvert /// An external in Excel, but internal in OO function name.
108 // ----------------------------------------------------------------------------
110 class XclImpCachedMatrix;
111 class ScTokenArray;
112 class XclImpSupbook;
114 /** Stores contents of an external name.
115 @descr Supported: External defined names, AddIn names, DDE links and OLE objects. */
116 class XclImpExtName
118 public:
119 /** Reads the external name from the stream. */
120 explicit XclImpExtName( const XclImpSupbook& rSupbook, XclImpStream& rStrm,
121 XclSupbookType eSubType, ExcelToSc* pFormulaConv );
122 ~XclImpExtName();
124 /** Create and apply the cached list of this DDE Link to the document. */
125 void CreateDdeData( ScDocument& rDoc,
126 const String& rApplc, const String& rExtDoc ) const;
128 void CreateExtNameData( ScDocument& rDoc, sal_uInt16 nFileId ) const;
130 bool HasFormulaTokens() const;
132 inline XclImpExtNameType GetType() const { return meType; }
133 inline const String& GetName() const { return maName; }
134 inline sal_uInt32 GetStorageId() const { return mnStorageId; }
136 private:
137 typedef ::std::auto_ptr< XclImpCachedMatrix > XclImpCachedMatrixPtr;
138 typedef ::std::auto_ptr< ScTokenArray > TokenArrayPtr;
140 XclImpCachedMatrixPtr mxDdeMatrix; /// Cached results of the DDE link.
141 TokenArrayPtr mxArray; /// Formula tokens for external name.
142 String maName; /// The name of the external name.
143 sal_uInt32 mnStorageId; /// Storage ID for OLE object storages.
144 XclImpExtNameType meType; /// Type of the external name.
147 // Import link manager ========================================================
149 class XclImpLinkManagerImpl;
151 /** This is the central class for the import of all internal/external links.
152 @descr This manager stores all data about external documents with their sheets
153 and cached cell contents. Additionally it handles external names, such as add-in
154 function names, DDE links, and OLE object links.
155 File contents in BIFF8:
156 - Record SUPBOOK: Contains the name of an external document and the names of its sheets.
157 This record is optionally followed by NAME, EXTERNNAME, XCT and CRN records.
158 - Record XCT: Contains the number and sheet index of the following CRN records.
159 - Record CRN: Contains addresses (row and column) and values of external referenced cells.
160 - Record NAME: Contains defined names of the own workbook.
161 - Record EXTERNNAME: Contains external defined names, DDE links, or OLE object links.
162 - Record EXTERNSHEET: Contains indexes to URLs of external documents (SUPBOOKs)
163 and sheet indexes for each external reference used anywhere in the workbook.
164 This record follows a list of SUPBOOK records (with their attached records).
166 class XclImpLinkManager : protected XclImpRoot
168 public:
169 explicit XclImpLinkManager( const XclImpRoot& rRoot );
170 ~XclImpLinkManager();
172 /** Reads the EXTERNSHEET record. */
173 void ReadExternsheet( XclImpStream& rStrm );
174 /** Reads a SUPBOOK record. */
175 void ReadSupbook( XclImpStream& rStrm );
176 /** Reads an XCT record and appends it to the current SUPBOOK. */
177 void ReadXct( XclImpStream& rStrm );
178 /** Reads a CRN record and appends it to the current SUPBOOK. */
179 void ReadCrn( XclImpStream& rStrm );
180 /** Reads an EXTERNNAME record and appends it to the current SUPBOOK. */
181 void ReadExternname( XclImpStream& rStrm, ExcelToSc* pFormulaConv = NULL );
183 /** Returns true, if the specified XTI entry contains an internal reference. */
184 bool IsSelfRef( sal_uInt16 nXtiIndex ) const;
185 /** Returns the Calc sheet index range of the specified XTI entry.
186 @return true = XTI data found, returned sheet index range is valid. */
187 bool GetScTabRange(
188 SCTAB& rnFirstScTab, SCTAB& rnLastScTab,
189 sal_uInt16 nXtiIndex ) const;
190 /** Returns the specified external name or 0 on error. */
191 const XclImpExtName* GetExternName( sal_uInt16 nXtiIndex, sal_uInt16 nExtName ) const;
193 const String* GetSupbookUrl( sal_uInt16 nXtiIndex ) const;
195 const String& GetSupbookTabName( sal_uInt16 nXti, sal_uInt16 nXtiTab ) const;
197 /** Tries to decode the URL of the specified XTI entry to OLE or DDE link components.
198 @descr For DDE links: Decodes to application name and topic.
199 For OLE object links: Decodes to class name and document URL.
200 @return true = decoding was successful, returned strings are valid (not empty). */
201 bool GetLinkData( String& rApplic, String& rTopic, sal_uInt16 nXtiIndex ) const;
202 /** Returns the specified macro name or an empty string on error. */
203 const String& GetMacroName( sal_uInt16 nExtSheet, sal_uInt16 nExtName ) const;
205 private:
206 typedef ::std::auto_ptr< XclImpLinkManagerImpl > XclImpLinkMgrImplPtr;
207 XclImpLinkMgrImplPtr mxImpl;
210 // ============================================================================
212 #endif