1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_XELINK_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_XELINK_HXX
23 #include "markdata.hxx"
25 #include "xerecord.hxx"
26 #include "xehelper.hxx"
27 #include "xeformula.hxx"
28 #include "externalrefmgr.hxx"
29 #include <boost/shared_ptr.hpp>
31 struct ScSingleRefData
;
32 struct ScComplexRefData
;
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
43 ============================================================================ */
45 // Excel sheet indexes ========================================================
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 class XclExpTabInfo
: protected XclExpRoot
53 /** Initializes the complete buffer from the current exported document. */
54 explicit XclExpTabInfo( const XclExpRoot
& rRoot
);
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 OUString
GetScTabName( SCTAB nScTab
) const;
71 /** Returns the Excel sheet index for a given Calc sheet. */
72 sal_uInt16
GetXclTab( SCTAB nScTab
) const;
74 /** Returns the Calc sheet index of the nSortedTab-th entry in the sorted sheet names list. */
75 SCTAB
GetRealScTab( SCTAB nSortedScTab
) const;
77 /** Returns the number of Calc sheets. */
78 inline SCTAB
GetScTabCount() const { return mnScCnt
; }
80 /** Returns the number of Excel sheets to be exported. */
81 inline sal_uInt16
GetXclTabCount() const { return mnXclCnt
; }
82 /** Returns the number of external linked sheets. */
83 inline sal_uInt16
GetXclExtTabCount() const { return mnXclExtCnt
; }
84 /** Returns the number of exported selected sheets. */
85 inline sal_uInt16
GetXclSelectedCount() const { return mnXclSelCnt
; }
87 /** Returns the Excel index of the active, displayed sheet. */
88 inline sal_uInt16
GetDisplayedXclTab() const { return mnDisplXclTab
; }
89 /** Returns the Excel index of the first visible sheet. */
90 inline sal_uInt16
GetFirstVisXclTab() const { return mnFirstVisXclTab
; }
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 );
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();
104 /** Data structure with infoemation about one Calc sheet. */
105 struct XclExpTabInfoEntry
110 inline explicit XclExpTabInfoEntry() : mnXclTab( 0 ), mnFlags( 0 ) {}
113 typedef ::std::vector
< XclExpTabInfoEntry
> XclExpTabInfoVec
;
114 typedef ::std::vector
< SCTAB
> ScTabVec
;
116 XclExpTabInfoVec maTabInfoVec
; /// Array of Calc sheet index information.
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.
125 ScTabVec maFromSortedVec
; /// Sorted Calc sheet index -> real Calc sheet index.
126 ScTabVec maToSortedVec
; /// Real Calc sheet index -> sorted Calc sheet index.
129 // Export link manager ========================================================
131 class XclExpLinkManagerImpl
;
133 /** Stores all data for internal/external references (the link table). */
134 class XclExpLinkManager
: public XclExpRecordBase
, protected XclExpRoot
137 explicit XclExpLinkManager( const XclExpRoot
& rRoot
);
138 virtual ~XclExpLinkManager();
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
);
164 void FindExtSheet( sal_uInt16 nFileId
, const OUString
& rTabName
, sal_uInt16 nXclTabSpan
,
165 sal_uInt16
& rnExtSheet
, sal_uInt16
& rnFirstSBTab
, sal_uInt16
& rnLastSBTab
,
166 XclExpRefLogEntry
* pRefLogEntry
= NULL
);
168 /** Stores the cell with the given address in a CRN record list. */
169 void StoreCell( const ScSingleRefData
& rRef
, const ScAddress
& rPos
);
170 /** Stores all cells in the given range in a CRN record list. */
171 void StoreCellRange( const ScComplexRefData
& rRef
, const ScAddress
& rPos
);
173 void StoreCell( sal_uInt16 nFileId
, const OUString
& rTabName
, const ScAddress
& rPos
);
175 void StoreCellRange( sal_uInt16 nFileId
, const OUString
& rTabName
, const ScRange
& rRange
);
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). */
182 sal_uInt16
& rnExtSheet
, sal_uInt16
& rnExtName
,
183 const OUString
& rName
);
184 /** InsertEuroTool */
186 sal_uInt16
& rnExtSheet
, sal_uInt16
& rnExtName
,
187 const OUString
& 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). */
193 sal_uInt16
& rnExtSheet
, sal_uInt16
& rnExtName
,
194 const OUString
& rApplic
, const OUString
& rTopic
, const OUString
& rItem
);
197 sal_uInt16
& rnExtSheet
, sal_uInt16
& rnExtName
, const OUString
& rUrl
,
198 const OUString
& rName
, const ScExternalRefCache::TokenArrayRef
& rArray
);
200 /** Writes the entire Link table. */
201 virtual void Save( XclExpStream
& rStrm
) SAL_OVERRIDE
;
203 /** Writes the entire Link table to OOXML. */
204 virtual void SaveXml( XclExpXmlStream
& rStrm
) SAL_OVERRIDE
;
207 typedef boost::shared_ptr
< XclExpLinkManagerImpl
> XclExpLinkMgrImplPtr
;
208 XclExpLinkMgrImplPtr mxImpl
;
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */