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_XELINK_HXX
30 : : #define SC_XELINK_HXX
31 : :
32 : : #include "markdata.hxx"
33 : : #include "xllink.hxx"
34 : : #include "xerecord.hxx"
35 : : #include "xehelper.hxx"
36 : : #include "xeformula.hxx"
37 : : #include "externalrefmgr.hxx"
38 : : #include <boost/shared_ptr.hpp>
39 : :
40 : : struct ScSingleRefData;
41 : : struct ScComplexRefData;
42 : :
43 : : /* ============================================================================
44 : : Classes for export of different kinds of internal/external references.
45 : : - 3D cell and cell range links
46 : : - External cell and cell range links
47 : : - External defined names
48 : : - Macro calls
49 : : - Add-in functions
50 : : - DDE links
51 : : - OLE object links
52 : : ============================================================================ */
53 : :
54 : : // Excel sheet indexes ========================================================
55 : :
56 : : /** Stores the correct Excel sheet index for each Calc sheet.
57 : : @descr The class knows all sheets which will not exported
58 : : (i.e. external link sheets, scenario sheets). */
59 [ # # ]: 0 : class XclExpTabInfo : protected XclExpRoot
60 : : {
61 : : public:
62 : : /** Initializes the complete buffer from the current exported document. */
63 : : explicit XclExpTabInfo( const XclExpRoot& rRoot );
64 : :
65 : : /** Returns true, if the specified Calc sheet will be exported. */
66 : : bool IsExportTab( SCTAB nScTab ) const;
67 : : /** Returns true, if the specified Calc sheet is used to store external cell contents. */
68 : : bool IsExternalTab( SCTAB nScTab ) const;
69 : : /** Returns true, if the specified Calc sheet is visible and will be exported. */
70 : : bool IsVisibleTab( SCTAB nScTab ) const;
71 : : /** Returns true, if the specified Calc sheet is selected and will be exported. */
72 : : bool IsSelectedTab( SCTAB nScTab ) const;
73 : : /** Returns true, if the specified Calc sheet is the displayed (active) sheet. */
74 : : bool IsDisplayedTab( SCTAB nScTab ) const;
75 : : /** Returns true, if the specified Calc sheet is displayed in right-to-left mode. */
76 : : bool IsMirroredTab( SCTAB nScTab ) const;
77 : : /** Returns the Calc name of the specified sheet. */
78 : : rtl::OUString GetScTabName( SCTAB nScTab ) const;
79 : :
80 : : /** Returns the Excel sheet index for a given Calc sheet. */
81 : : sal_uInt16 GetXclTab( SCTAB nScTab ) const;
82 : :
83 : : /** Returns the Calc sheet index of the nSortedTab-th entry in the sorted sheet names list. */
84 : : SCTAB GetRealScTab( SCTAB nSortedScTab ) const;
85 : :
86 : : /** Returns the number of Calc sheets. */
87 : 0 : inline SCTAB GetScTabCount() const { return mnScCnt; }
88 : :
89 : : /** Returns the number of Excel sheets to be exported. */
90 : 0 : inline sal_uInt16 GetXclTabCount() const { return mnXclCnt; }
91 : : /** Returns the number of external linked sheets. */
92 : 0 : inline sal_uInt16 GetXclExtTabCount() const { return mnXclExtCnt; }
93 : : /** Returns the number of exported selected sheets. */
94 : 0 : inline sal_uInt16 GetXclSelectedCount() const { return mnXclSelCnt; }
95 : :
96 : : /** Returns the Excel index of the active, displayed sheet. */
97 : 0 : inline sal_uInt16 GetDisplayedXclTab() const { return mnDisplXclTab; }
98 : : /** Returns the Excel index of the first visible sheet. */
99 : 0 : inline sal_uInt16 GetFirstVisXclTab() const { return mnFirstVisXclTab; }
100 : :
101 : : private:
102 : : /** Returns true, if any of the passed flags is set for the specified Calc sheet. */
103 : : bool GetFlag( SCTAB nScTab, sal_uInt8 nFlags ) const;
104 : : /** Sets or clears (depending on bSet) all passed flags for the specified Calc sheet. */
105 : : void SetFlag( SCTAB nScTab, sal_uInt8 nFlags, bool bSet = true );
106 : :
107 : : /** Searches for sheets not to be exported. */
108 : : void CalcXclIndexes();
109 : : /** Sorts the names of all tables and stores the indexes of the sorted indexes. */
110 : : void CalcSortedIndexes();
111 : :
112 : : private:
113 : : /** Data structure with infoemation about one Calc sheet. */
114 : 0 : struct XclExpTabInfoEntry
115 : : {
116 : : rtl::OUString maScName;
117 : : sal_uInt16 mnXclTab;
118 : : sal_uInt8 mnFlags;
119 : 0 : inline explicit XclExpTabInfoEntry() : mnXclTab( 0 ), mnFlags( 0 ) {}
120 : : };
121 : :
122 : : typedef ::std::vector< XclExpTabInfoEntry > XclExpTabInfoVec;
123 : : typedef ::std::vector< SCTAB > ScTabVec;
124 : :
125 : : XclExpTabInfoVec maTabInfoVec; /// Array of Calc sheet index information.
126 : :
127 : : SCTAB mnScCnt; /// Count of Calc sheets.
128 : : sal_uInt16 mnXclCnt; /// Count of Excel sheets to be exported.
129 : : sal_uInt16 mnXclExtCnt; /// Count of external link sheets.
130 : : sal_uInt16 mnXclSelCnt; /// Count of selected and exported sheets.
131 : : sal_uInt16 mnDisplXclTab; /// Displayed (active) sheet.
132 : : sal_uInt16 mnFirstVisXclTab; /// First visible sheet.
133 : :
134 : : ScTabVec maFromSortedVec; /// Sorted Calc sheet index -> real Calc sheet index.
135 : : ScTabVec maToSortedVec; /// Real Calc sheet index -> sorted Calc sheet index.
136 : : };
137 : :
138 : : // Export link manager ========================================================
139 : :
140 : : class XclExpLinkManagerImpl;
141 : :
142 : : /** Stores all data for internal/external references (the link table). */
143 : : class XclExpLinkManager : public XclExpRecordBase, protected XclExpRoot
144 : : {
145 : : public:
146 : : explicit XclExpLinkManager( const XclExpRoot& rRoot );
147 : : virtual ~XclExpLinkManager();
148 : :
149 : : /** Searches for an EXTERNSHEET index for the given Calc sheet.
150 : : @descr See above for the meaning of EXTERNSHEET indexes.
151 : : @param rnExtSheet (out-param) Returns the EXTERNSHEET index.
152 : : @param rnXclTab (out-param) Returns the Excel sheet index.
153 : : @param nScTab The Calc sheet index to process.
154 : : param pRefLogEntry If not 0, data about the external link is stored here. */
155 : : void FindExtSheet( sal_uInt16& rnExtSheet,
156 : : sal_uInt16& rnXclTab, SCTAB nScTab,
157 : : XclExpRefLogEntry* pRefLogEntry = 0 );
158 : : /** Searches for an EXTERNSHEET index for the given Calc sheet range.
159 : : @descr See above for the meaning of EXTERNSHEET indexes.
160 : : @param rnExtSheet (out-param) Returns the EXTERNSHEET index.
161 : : @param rnFirstXclTab (out-param) Returns the Excel sheet index of the first sheet.
162 : : @param rnXclTab (out-param) Returns the Excel sheet index of the last sheet.
163 : : @param nFirstScTab The first Calc sheet index to process.
164 : : @param nLastScTab The last Calc sheet index to process.
165 : : param pRefLogEntry If not 0, data about the external link is stored here. */
166 : : void FindExtSheet( sal_uInt16& rnExtSheet,
167 : : sal_uInt16& rnFirstXclTab, sal_uInt16& rnLastXclTab,
168 : : SCTAB nFirstScTab, SCTAB nLastScTab,
169 : : XclExpRefLogEntry* pRefLogEntry = 0 );
170 : : /** Searches for a special EXTERNSHEET index for the own document. */
171 : : sal_uInt16 FindExtSheet( sal_Unicode cCode );
172 : :
173 : : void FindExtSheet( sal_uInt16 nFileId, const String& rTabName, sal_uInt16 nXclTabSpan,
174 : : sal_uInt16& rnExtSheet, sal_uInt16& rnFirstSBTab, sal_uInt16& rnLastSBTab,
175 : : XclExpRefLogEntry* pRefLogEntry = NULL );
176 : :
177 : : /** Stores the cell with the given address in a CRN record list. */
178 : : void StoreCell( const ScSingleRefData& rRef );
179 : : /** Stores all cells in the given range in a CRN record list. */
180 : : void StoreCellRange( const ScComplexRefData& rRef );
181 : :
182 : : void StoreCell( sal_uInt16 nFileId, const String& rTabName, const ScSingleRefData& rRef );
183 : :
184 : : void StoreCellRange( sal_uInt16 nFileId, const String& rTabName, const ScComplexRefData& rRef );
185 : :
186 : : /** Finds or inserts an EXTERNNAME record for an add-in function name.
187 : : @param rnExtSheet (out-param) Returns the index of the EXTSHEET structure for the add-in function name.
188 : : @param rnExtName (out-param) Returns the 1-based EXTERNNAME record index.
189 : : @return true = add-in function inserted; false = error (i.e. not supported in current BIFF). */
190 : : bool InsertAddIn(
191 : : sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
192 : : const String& rName );
193 : : /** InsertEuroTool */
194 : : bool InsertEuroTool(
195 : : sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
196 : : const String& rName );
197 : : /** Finds or inserts an EXTERNNAME record for DDE links.
198 : : @param rnExtSheet (out-param) Returns the index of the EXTSHEET structure for the DDE link.
199 : : @param rnExtName (out-param) Returns the 1-based EXTERNNAME record index.
200 : : @return true = DDE link inserted; false = error (i.e. not supported in current BIFF). */
201 : : bool InsertDde(
202 : : sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
203 : : const String& rApplic, const String& rTopic, const String& rItem );
204 : :
205 : : bool InsertExtName(
206 : : sal_uInt16& rnExtSheet, sal_uInt16& rnExtName, const String& rUrl,
207 : : const String& rName, const ScExternalRefCache::TokenArrayRef pArray );
208 : :
209 : : /** Writes the entire Link table. */
210 : : virtual void Save( XclExpStream& rStrm );
211 : :
212 : : private:
213 : : typedef boost::shared_ptr< XclExpLinkManagerImpl > XclExpLinkMgrImplPtr;
214 : : XclExpLinkMgrImplPtr mxImpl;
215 : : };
216 : :
217 : : // ============================================================================
218 : :
219 : : #endif
220 : :
221 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|