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