Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / sc / source / filter / inc / xelink.hxx
blob1c816d21fbecc2140aefc478a474b408e2df33f4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
22 #include "xerecord.hxx"
23 #include "xeroot.hxx"
24 #include <externalrefmgr.hxx>
25 #include <memory>
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
37 - Macro calls
38 - Add-in functions
39 - DDE links
40 - OLE object links
41 ============================================================================ */
43 // Excel sheet indexes ========================================================
45 enum class ExcTabBufFlags : sal_uInt8 {
46 NONE = 0x00,
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).
54 namespace o3tl {
55 template<> struct typed_flags<ExcTabBufFlags> : is_typed_flags<ExcTabBufFlags, 0x73> {};
58 /** Stores the correct Excel sheet index for each Calc sheet.
59 @descr The class knows all sheets which will not exported
60 (i.e. external link sheets, scenario sheets). */
61 class XclExpTabInfo : protected XclExpRoot
63 public:
64 /** Initializes the complete buffer from the current exported document. */
65 explicit XclExpTabInfo( const XclExpRoot& rRoot );
67 /** Returns true, if the specified Calc sheet will be exported. */
68 bool IsExportTab( SCTAB nScTab ) const;
69 /** Returns true, if the specified Calc sheet is used to store external cell contents. */
70 bool IsExternalTab( SCTAB nScTab ) const;
71 /** Returns true, if the specified Calc sheet is visible and will be exported. */
72 bool IsVisibleTab( SCTAB nScTab ) const;
73 /** Returns true, if the specified Calc sheet is selected and will be exported. */
74 bool IsSelectedTab( SCTAB nScTab ) const;
75 /** Returns true, if the specified Calc sheet is the displayed (active) sheet. */
76 bool IsDisplayedTab( SCTAB nScTab ) const;
77 /** Returns true, if the specified Calc sheet is displayed in right-to-left mode. */
78 bool IsMirroredTab( SCTAB nScTab ) const;
79 /** Returns the Calc name of the specified sheet. */
80 OUString GetScTabName( SCTAB nScTab ) const;
82 /** Returns the Excel sheet index for a given Calc sheet. */
83 sal_uInt16 GetXclTab( SCTAB nScTab ) const;
85 /** Returns the Calc sheet index of the nSortedTab-th entry in the sorted sheet names list. */
86 SCTAB GetRealScTab( SCTAB nSortedScTab ) const;
88 /** Returns the number of Calc sheets. */
89 SCTAB GetScTabCount() const { return mnScCnt; }
91 /** Returns the number of Excel sheets to be exported. */
92 sal_uInt16 GetXclTabCount() const { return mnXclCnt; }
93 /** Returns the number of external linked sheets. */
94 sal_uInt16 GetXclExtTabCount() const { return mnXclExtCnt; }
95 /** Returns the number of exported selected sheets. */
96 sal_uInt16 GetXclSelectedCount() const { return mnXclSelCnt; }
98 /** Returns the Excel index of the active, displayed sheet. */
99 sal_uInt16 GetDisplayedXclTab() const { return mnDisplXclTab; }
100 /** Returns the Excel index of the first visible sheet. */
101 sal_uInt16 GetFirstVisXclTab() const { return mnFirstVisXclTab; }
103 private:
104 /** Returns true, if any of the passed flags is set for the specified Calc sheet. */
105 bool GetFlag( SCTAB nScTab, ExcTabBufFlags nFlags ) const;
106 /** Sets or clears (depending on bSet) all passed flags for the specified Calc sheet. */
107 void SetFlag( SCTAB nScTab, ExcTabBufFlags nFlags, bool bSet = true );
109 /** Searches for sheets not to be exported. */
110 void CalcXclIndexes();
111 /** Sorts the names of all tables and stores the indexes of the sorted indexes. */
112 void CalcSortedIndexes();
114 private:
115 /** Data structure with information about one Calc sheet. */
116 struct XclExpTabInfoEntry
118 OUString maScName;
119 sal_uInt16 mnXclTab;
120 ExcTabBufFlags mnFlags;
121 explicit XclExpTabInfoEntry() : mnXclTab( 0 ), mnFlags( ExcTabBufFlags::NONE ) {}
124 typedef ::std::vector< SCTAB > ScTabVec;
126 std::vector< XclExpTabInfoEntry >
127 maTabInfoVec; /// Array of Calc sheet index information.
129 SCTAB mnScCnt; /// Count of Calc sheets.
130 sal_uInt16 mnXclCnt; /// Count of Excel sheets to be exported.
131 sal_uInt16 mnXclExtCnt; /// Count of external link sheets.
132 sal_uInt16 mnXclSelCnt; /// Count of selected and exported sheets.
133 sal_uInt16 mnDisplXclTab; /// Displayed (active) sheet.
134 sal_uInt16 mnFirstVisXclTab; /// First visible sheet.
136 ScTabVec maFromSortedVec; /// Sorted Calc sheet index -> real Calc sheet index.
137 ScTabVec maToSortedVec; /// Real Calc sheet index -> sorted Calc sheet index.
140 // Export link manager ========================================================
142 class XclExpLinkManagerImpl;
144 /** Stores all data for internal/external references (the link table). */
145 class XclExpLinkManager : public XclExpRecordBase, protected XclExpRoot
147 public:
148 explicit XclExpLinkManager( const XclExpRoot& rRoot );
149 virtual ~XclExpLinkManager() override;
151 /** Searches for an EXTERNSHEET index for the given Calc sheet.
152 @descr See above for the meaning of EXTERNSHEET indexes.
153 @param rnExtSheet (out-param) Returns the EXTERNSHEET index.
154 @param rnXclTab (out-param) Returns the Excel sheet index.
155 @param nScTab The 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& rnXclTab, SCTAB nScTab,
159 XclExpRefLogEntry* pRefLogEntry = nullptr );
160 /** Searches for an EXTERNSHEET index for the given Calc sheet range.
161 @descr See above for the meaning of EXTERNSHEET indexes.
162 @param rnExtSheet (out-param) Returns the EXTERNSHEET index.
163 @param rnFirstXclTab (out-param) Returns the Excel sheet index of the first sheet.
164 @param rnXclTab (out-param) Returns the Excel sheet index of the last sheet.
165 @param nFirstScTab The first Calc sheet index to process.
166 @param nLastScTab The last Calc sheet index to process.
167 param pRefLogEntry If not 0, data about the external link is stored here. */
168 void FindExtSheet( sal_uInt16& rnExtSheet,
169 sal_uInt16& rnFirstXclTab, sal_uInt16& rnLastXclTab,
170 SCTAB nFirstScTab, SCTAB nLastScTab,
171 XclExpRefLogEntry* pRefLogEntry );
172 /** Searches for a special EXTERNSHEET index for the own document. */
173 sal_uInt16 FindExtSheet( sal_Unicode cCode );
175 void FindExtSheet( sal_uInt16 nFileId, const OUString& rTabName, sal_uInt16 nXclTabSpan,
176 sal_uInt16& rnExtSheet, sal_uInt16& rnFirstSBTab, sal_uInt16& rnLastSBTab,
177 XclExpRefLogEntry* pRefLogEntry );
179 /** Stores the cell with the given address in a CRN record list. */
180 void StoreCell( const ScSingleRefData& rRef, const ScAddress& rPos );
181 /** Stores all cells in the given range in a CRN record list. */
182 void StoreCellRange( const ScComplexRefData& rRef, const ScAddress& rPos );
184 void StoreCell( sal_uInt16 nFileId, const OUString& rTabName, const ScAddress& rPos );
186 void StoreCellRange( sal_uInt16 nFileId, const OUString& rTabName, const ScRange& rRange );
188 /** Finds or inserts an EXTERNNAME record for an add-in function name.
189 @param rnExtSheet (out-param) Returns the index of the EXTSHEET structure for the add-in function name.
190 @param rnExtName (out-param) Returns the 1-based EXTERNNAME record index.
191 @return true = add-in function inserted; false = error (i.e. not supported in current BIFF). */
192 bool InsertAddIn(
193 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
194 const OUString& rName );
195 /** InsertEuroTool */
196 bool InsertEuroTool(
197 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
198 const OUString& rName );
199 /** Finds or inserts an EXTERNNAME record for DDE links.
200 @param rnExtSheet (out-param) Returns the index of the EXTSHEET structure for the DDE link.
201 @param rnExtName (out-param) Returns the 1-based EXTERNNAME record index.
202 @return true = DDE link inserted; false = error (i.e. not supported in current BIFF). */
203 bool InsertDde(
204 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
205 const OUString& rApplic, const OUString& rTopic, const OUString& rItem );
207 bool InsertExtName(
208 sal_uInt16& rnExtSheet, sal_uInt16& rnExtName, const OUString& rUrl,
209 const OUString& rName, const ScExternalRefCache::TokenArrayRef& rArray );
211 /** Writes the entire Link table. */
212 virtual void Save( XclExpStream& rStrm ) override;
214 /** Writes the entire Link table to OOXML. */
215 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
217 private:
218 typedef std::shared_ptr< XclExpLinkManagerImpl > XclExpLinkMgrImplPtr;
219 XclExpLinkMgrImplPtr mxImpl;
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */