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 "xerecord.hxx"
25 #include <externalrefmgr.hxx>
27 #include <o3tl/typed_flags_set.hxx>
29 struct ScSingleRefData
;
30 struct ScComplexRefData
;
31 struct XclExpRefLogEntry
;
33 /* ============================================================================
34 Classes for export of different kinds of internal/external references.
35 - 3D cell and cell range links
36 - External cell and cell range links
37 - External defined names
42 ============================================================================ */
44 // Excel sheet indexes ========================================================
46 enum class ExcTabBufFlags
: sal_uInt8
{
48 Ignore
= 0x01, /// Sheet will be ignored completely.
49 Extern
= 0x02, /// Sheet is linked externally.
50 SkipMask
= 0x03, /// Sheet will be skipped, if any flag is set.
51 Visible
= 0x10, /// Sheet is visible.
52 Selected
= 0x20, /// Sheet is selected.
53 Mirrored
= 0x40 /// Sheet is mirrored (right-to-left).
56 template<> struct typed_flags
<ExcTabBufFlags
> : is_typed_flags
<ExcTabBufFlags
, 0x73> {};
59 /** Stores the correct Excel sheet index for each Calc sheet.
60 @descr The class knows all sheets which will not exported
61 (i.e. external link sheets, scenario sheets). */
62 class XclExpTabInfo
: protected XclExpRoot
65 /** Initializes the complete buffer from the current exported document. */
66 explicit XclExpTabInfo( const XclExpRoot
& rRoot
);
68 /** Returns true, if the specified Calc sheet will be exported. */
69 bool IsExportTab( SCTAB nScTab
) const;
70 /** Returns true, if the specified Calc sheet is used to store external cell contents. */
71 bool IsExternalTab( SCTAB nScTab
) const;
72 /** Returns true, if the specified Calc sheet is visible and will be exported. */
73 bool IsVisibleTab( SCTAB nScTab
) const;
74 /** Returns true, if the specified Calc sheet is selected and will be exported. */
75 bool IsSelectedTab( SCTAB nScTab
) const;
76 /** Returns true, if the specified Calc sheet is the displayed (active) sheet. */
77 bool IsDisplayedTab( SCTAB nScTab
) const;
78 /** Returns true, if the specified Calc sheet is displayed in right-to-left mode. */
79 bool IsMirroredTab( SCTAB nScTab
) const;
80 /** Returns the Calc name of the specified sheet. */
81 OUString
GetScTabName( SCTAB nScTab
) const;
83 /** Returns the Excel sheet index for a given Calc sheet. */
84 sal_uInt16
GetXclTab( SCTAB nScTab
) const;
86 /** Returns the Calc sheet index of the nSortedTab-th entry in the sorted sheet names list. */
87 SCTAB
GetRealScTab( SCTAB nSortedScTab
) const;
89 /** Returns the number of Calc sheets. */
90 SCTAB
GetScTabCount() const { return mnScCnt
; }
92 /** Returns the number of Excel sheets to be exported. */
93 sal_uInt16
GetXclTabCount() const { return mnXclCnt
; }
94 /** Returns the number of external linked sheets. */
95 sal_uInt16
GetXclExtTabCount() const { return mnXclExtCnt
; }
96 /** Returns the number of exported selected sheets. */
97 sal_uInt16
GetXclSelectedCount() const { return mnXclSelCnt
; }
99 /** Returns the Excel index of the active, displayed sheet. */
100 sal_uInt16
GetDisplayedXclTab() const { return mnDisplXclTab
; }
101 /** Returns the Excel index of the first visible sheet. */
102 sal_uInt16
GetFirstVisXclTab() const { return mnFirstVisXclTab
; }
105 /** Returns true, if any of the passed flags is set for the specified Calc sheet. */
106 bool GetFlag( SCTAB nScTab
, ExcTabBufFlags nFlags
) const;
107 /** Sets or clears (depending on bSet) all passed flags for the specified Calc sheet. */
108 void SetFlag( SCTAB nScTab
, ExcTabBufFlags nFlags
, bool bSet
= true );
110 /** Searches for sheets not to be exported. */
111 void CalcXclIndexes();
112 /** Sorts the names of all tables and stores the indexes of the sorted indexes. */
113 void CalcSortedIndexes();
116 /** Data structure with information about one Calc sheet. */
117 struct XclExpTabInfoEntry
121 ExcTabBufFlags mnFlags
;
122 explicit XclExpTabInfoEntry() : mnXclTab( 0 ), mnFlags( ExcTabBufFlags::NONE
) {}
125 typedef ::std::vector
< XclExpTabInfoEntry
> XclExpTabInfoVec
;
126 typedef ::std::vector
< SCTAB
> ScTabVec
;
128 XclExpTabInfoVec maTabInfoVec
; /// Array of Calc sheet index information.
130 SCTAB mnScCnt
; /// Count of Calc sheets.
131 sal_uInt16 mnXclCnt
; /// Count of Excel sheets to be exported.
132 sal_uInt16 mnXclExtCnt
; /// Count of external link sheets.
133 sal_uInt16 mnXclSelCnt
; /// Count of selected and exported sheets.
134 sal_uInt16 mnDisplXclTab
; /// Displayed (active) sheet.
135 sal_uInt16 mnFirstVisXclTab
; /// First visible sheet.
137 ScTabVec maFromSortedVec
; /// Sorted Calc sheet index -> real Calc sheet index.
138 ScTabVec maToSortedVec
; /// Real Calc sheet index -> sorted Calc sheet index.
141 // Export link manager ========================================================
143 class XclExpLinkManagerImpl
;
145 /** Stores all data for internal/external references (the link table). */
146 class XclExpLinkManager
: public XclExpRecordBase
, protected XclExpRoot
149 explicit XclExpLinkManager( const XclExpRoot
& rRoot
);
150 virtual ~XclExpLinkManager() override
;
152 /** Searches for an EXTERNSHEET index for the given Calc sheet.
153 @descr See above for the meaning of EXTERNSHEET indexes.
154 @param rnExtSheet (out-param) Returns the EXTERNSHEET index.
155 @param rnXclTab (out-param) Returns the Excel sheet index.
156 @param nScTab The Calc sheet index to process.
157 param pRefLogEntry If not 0, data about the external link is stored here. */
158 void FindExtSheet( sal_uInt16
& rnExtSheet
,
159 sal_uInt16
& rnXclTab
, SCTAB nScTab
,
160 XclExpRefLogEntry
* pRefLogEntry
= nullptr );
161 /** Searches for an EXTERNSHEET index for the given Calc sheet range.
162 @descr See above for the meaning of EXTERNSHEET indexes.
163 @param rnExtSheet (out-param) Returns the EXTERNSHEET index.
164 @param rnFirstXclTab (out-param) Returns the Excel sheet index of the first sheet.
165 @param rnXclTab (out-param) Returns the Excel sheet index of the last sheet.
166 @param nFirstScTab The first Calc sheet index to process.
167 @param nLastScTab The last Calc sheet index to process.
168 param pRefLogEntry If not 0, data about the external link is stored here. */
169 void FindExtSheet( sal_uInt16
& rnExtSheet
,
170 sal_uInt16
& rnFirstXclTab
, sal_uInt16
& rnLastXclTab
,
171 SCTAB nFirstScTab
, SCTAB nLastScTab
,
172 XclExpRefLogEntry
* pRefLogEntry
);
173 /** Searches for a special EXTERNSHEET index for the own document. */
174 sal_uInt16
FindExtSheet( sal_Unicode cCode
);
176 void FindExtSheet( sal_uInt16 nFileId
, const OUString
& rTabName
, sal_uInt16 nXclTabSpan
,
177 sal_uInt16
& rnExtSheet
, sal_uInt16
& rnFirstSBTab
, sal_uInt16
& rnLastSBTab
,
178 XclExpRefLogEntry
* pRefLogEntry
);
180 /** Stores the cell with the given address in a CRN record list. */
181 void StoreCell( const ScSingleRefData
& rRef
, const ScAddress
& rPos
);
182 /** Stores all cells in the given range in a CRN record list. */
183 void StoreCellRange( const ScComplexRefData
& rRef
, const ScAddress
& rPos
);
185 void StoreCell( sal_uInt16 nFileId
, const OUString
& rTabName
, const ScAddress
& rPos
);
187 void StoreCellRange( sal_uInt16 nFileId
, const OUString
& rTabName
, const ScRange
& rRange
);
189 /** Finds or inserts an EXTERNNAME record for an add-in function name.
190 @param rnExtSheet (out-param) Returns the index of the EXTSHEET structure for the add-in function name.
191 @param rnExtName (out-param) Returns the 1-based EXTERNNAME record index.
192 @return true = add-in function inserted; false = error (i.e. not supported in current BIFF). */
194 sal_uInt16
& rnExtSheet
, sal_uInt16
& rnExtName
,
195 const OUString
& rName
);
196 /** InsertEuroTool */
198 sal_uInt16
& rnExtSheet
, sal_uInt16
& rnExtName
,
199 const OUString
& rName
);
200 /** Finds or inserts an EXTERNNAME record for DDE links.
201 @param rnExtSheet (out-param) Returns the index of the EXTSHEET structure for the DDE link.
202 @param rnExtName (out-param) Returns the 1-based EXTERNNAME record index.
203 @return true = DDE link inserted; false = error (i.e. not supported in current BIFF). */
205 sal_uInt16
& rnExtSheet
, sal_uInt16
& rnExtName
,
206 const OUString
& rApplic
, const OUString
& rTopic
, const OUString
& rItem
);
209 sal_uInt16
& rnExtSheet
, sal_uInt16
& rnExtName
, const OUString
& rUrl
,
210 const OUString
& rName
, const ScExternalRefCache::TokenArrayRef
& rArray
);
212 /** Writes the entire Link table. */
213 virtual void Save( XclExpStream
& rStrm
) override
;
215 /** Writes the entire Link table to OOXML. */
216 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
219 typedef std::shared_ptr
< XclExpLinkManagerImpl
> XclExpLinkMgrImplPtr
;
220 XclExpLinkMgrImplPtr mxImpl
;
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */