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