LibreOffice Module sc (master) 1
exctools.cxx
Go to the documentation of this file.
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#include <osl/diagnose.h>
21#include <document.hxx>
22#include <attrib.hxx>
23#include <scextopt.hxx>
24#include <olinetab.hxx>
25
26#include <root.hxx>
27#include <excimp8.hxx>
28#include <namebuff.hxx>
29#include <otlnbuff.hxx>
30#include <formel.hxx>
31#include <xilink.hxx>
32
33#include <memory>
34#include <vector>
35
37{
39 pFmlaConverter = nullptr;
40
41 pTabId = nullptr;
42 pUserBViewList = nullptr;
43
44 pIR = nullptr;
45 pER = nullptr;
46 pColRowBuff = nullptr;
47}
48
50{
51 pExtSheetBuff.reset();
52 pShrfmlaBuff.reset();
53 pExtNameBuff.reset();
54 pAutoFilterBuffer.reset();
55}
56
58 maLevels(0, nNewSize, 0),
59 mpOutlineArray(nullptr),
60 mnEndPos(nNewSize),
61 mnMaxLevel(0),
62 mbButtonAfter(true)
63{
64}
65
67{
68}
69
70void XclImpOutlineBuffer::SetLevel( SCSIZE nIndex, sal_uInt8 nVal, bool bCollapsed )
71{
72 maLevels.insert_back(nIndex, nIndex+1, nVal);
73 if (nVal > mnMaxLevel)
74 mnMaxLevel = nVal;
75 if (bCollapsed)
77}
78
80{
81 mpOutlineArray = pOArray;
82}
83
85{
86 if (!mpOutlineArray)
87 return;
88
89 ::std::vector<SCSIZE> aOutlineStack;
90 aOutlineStack.reserve(mnMaxLevel);
91 for (const auto& [nPos, nLevel] : maLevels)
92 {
93 if (nPos >= mnEndPos)
94 {
95 // Don't go beyond the max allowed position.
96 OSL_ENSURE(aOutlineStack.empty(), "XclImpOutlineBuffer::MakeScOutline: outline stack not empty but expected to be.");
97 break;
98 }
99 sal_uInt8 nCurLevel = static_cast<sal_uInt8>(aOutlineStack.size());
100 if (nLevel > nCurLevel)
101 {
102 for (sal_uInt8 i = 0; i < nLevel - nCurLevel; ++i)
103 aOutlineStack.push_back(nPos);
104 }
105 else
106 {
107 OSL_ENSURE(nLevel <= nCurLevel, "XclImpOutlineBuffer::MakeScOutline: unexpected level!");
108 for (sal_uInt8 i = 0; i < nCurLevel - nLevel; ++i)
109 {
110 if (aOutlineStack.empty())
111 {
112 // Something is wrong.
113 return;
114 }
115 SCSIZE nFirstPos = aOutlineStack.back();
116 aOutlineStack.pop_back();
117 bool bCollapsed = false;
118 if (mbButtonAfter)
119 bCollapsed = maCollapsedPosSet.count(nPos) > 0;
120 else if (nFirstPos > 0)
121 bCollapsed = maCollapsedPosSet.count(nFirstPos-1) > 0;
122
123 bool bDummy;
124 mpOutlineArray->Insert(nFirstPos, nPos-1, bDummy, bCollapsed);
125 }
126 }
127 }
128}
129
130void XclImpOutlineBuffer::SetLevelRange( SCSIZE nF, SCSIZE nL, sal_uInt8 nVal, bool bCollapsed )
131{
132 if (nF > nL)
133 // invalid range
134 return;
135
136 maLevels.insert_back(nF, nL+1, nVal);
137
138 if (bCollapsed)
139 maCollapsedPosSet.insert(nF);
140}
141
142void XclImpOutlineBuffer::SetButtonMode( bool bRightOrUnder )
143{
144 mbButtonAfter = bRightOrUnder;
145}
146
147ExcScenarioCell::ExcScenarioCell( const sal_uInt16 nC, const sal_uInt16 nR )
148 : nCol( nC ), nRow( nR )
149{
150}
151
153 : nTab( rR.pIR->GetCurrScTab() )
154{
155 sal_uInt16 nCref;
156 sal_uInt8 nName, nComment;
157
158 nCref = rIn.ReaduInt16();
159 nProtected = rIn.ReaduInt8();
160 rIn.Ignore( 1 ); // Hide
161 nName = rIn.ReaduInt8();
162 nComment = rIn.ReaduInt8();
163 rIn.Ignore( 1 ); // instead of nUser!
164
165 if( nName )
166 aName = rIn.ReadUniString( nName );
167 else
168 {
169 aName = "Scenery";
170 rIn.Ignore( 1 );
171 }
172
173 rIn.ReadUniString(); // username
174
175 if( nComment )
176 aComment = rIn.ReadUniString();
177
178 sal_uInt16 n = nCref;
179 sal_uInt16 nC, nR;
180 aEntries.reserve(n);
181 while( n )
182 {
183 nR = rIn.ReaduInt16();
184 nC = rIn.ReaduInt16();
185
186 aEntries.emplace_back( nC, nR );
187
188 n--;
189 }
190
191 for (auto& rEntry : aEntries)
192 rEntry.SetValue(rIn.ReadUniString());
193}
194
195void ExcScenario::Apply( const XclImpRoot& rRoot, const bool bLast )
196{
197 ScDocument& r = rRoot.GetDoc();
198 OUString aSzenName( aName );
199 sal_uInt16 nNewTab = nTab + 1;
200
201 if( !r.InsertTab( nNewTab, aSzenName ) )
202 return;
203
204 r.SetScenario( nNewTab, true );
205 // do not show scenario frames
208 /* | ScScenarioFlags::ShowFrame*/
209 r.SetScenarioData( nNewTab, aComment, COL_LIGHTGRAY, nFlags);
210
211 for (const auto& rEntry : aEntries)
212 {
213 sal_uInt16 nCol = rEntry.nCol;
214 sal_uInt16 nRow = rEntry.nRow;
215 OUString aVal = rEntry.GetValue();
216
217 r.ApplyFlagsTab( nCol, nRow, nCol, nRow, nNewTab, ScMF::Scenario );
218
219 r.SetString( nCol, nRow, nNewTab, aVal );
220 }
221
222 if( bLast )
223 r.SetActiveScenario( nNewTab, true );
224
225 // modify what the Active tab is set to if the new
226 // scenario tab occurs before the active tab.
228 if( (static_cast< SCCOL >( nTab ) < rDocSett.mnDisplTab) && (rDocSett.mnDisplTab < MAXTAB) )
229 ++rDocSett.mnDisplTab;
230 rRoot.GetTabInfo().InsertScTab( nNewTab );
231}
232
234{
235 sal_uInt16 n = static_cast<sal_uInt16>(aEntries.size());
236
237 std::vector< std::unique_ptr<ExcScenario> >::reverse_iterator iter;
238 for (iter = aEntries.rbegin(); iter != aEntries.rend(); ++iter)
239 {
240 n--;
241 (*iter)->Apply(rRoot, n == nLastScenario);
242 }
243}
244
245/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SCTAB MAXTAB
Definition: address.hxx:70
size_t SCSIZE
size_t typedef to be able to find places where code was changed from USHORT to size_t and is used to ...
Definition: address.hxx:44
@ Scenario
field button for datapilot
ExcScenarioCell(const sal_uInt16 nC, const sal_uInt16 nR)
Definition: exctools.cxx:147
OUString aName
Definition: excscen.hxx:53
ExcScenario(XclImpStream &rIn, const RootData &rRoot)
Definition: exctools.cxx:152
std::vector< ExcScenarioCell > aEntries
Definition: excscen.hxx:57
OUString aComment
Definition: excscen.hxx:54
void Apply(const XclImpRoot &rRoot, const bool bLast)
Definition: exctools.cxx:195
sal_uInt8 nProtected
Definition: excscen.hxx:55
const sal_uInt16 nTab
Definition: excscen.hxx:56
SC_DLLPUBLIC bool InsertTab(SCTAB nPos, const OUString &rName, bool bExternalDocument=false, bool bUndoDeleteTab=false)
Definition: document.cxx:485
SC_DLLPUBLIC void SetScenarioData(SCTAB nTab, const OUString &rComment, const Color &rColor, ScScenarioFlags nFlags)
Definition: documen3.cxx:438
SC_DLLPUBLIC bool ApplyFlagsTab(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab, ScMF nFlags)
Definition: document.cxx:4970
SC_DLLPUBLIC bool SetString(SCCOL nCol, SCROW nRow, SCTAB nTab, const OUString &rString, const ScSetStringParam *pParam=nullptr)
Definition: document.cxx:3391
SC_DLLPUBLIC void SetActiveScenario(SCTAB nTab, bool bActive)
Definition: documen3.cxx:886
SC_DLLPUBLIC void SetScenario(SCTAB nTab, bool bFlag)
Definition: documen3.cxx:426
const ScExtDocSettings & GetDocSettings() const
Definition: scextopt.cxx:170
bool Insert(SCCOLROW nStartPos, SCCOLROW nEndPos, bool &rSizeChanged, bool bHidden=false)
Definition: olinetab.cxx:197
void SetButtonMode(bool bRightOrUnder)
Definition: exctools.cxx:142
sal_uInt8 mnMaxLevel
Definition: otlnbuff.hxx:46
void SetLevelRange(SCSIZE nF, SCSIZE nL, sal_uInt8 nVal, bool bCollapsed)
Definition: exctools.cxx:130
ScOutlineArray * mpOutlineArray
Definition: otlnbuff.hxx:44
void SetOutlineArray(ScOutlineArray *pOArray)
Definition: exctools.cxx:79
::std::set< SCSIZE > maCollapsedPosSet
Definition: otlnbuff.hxx:43
void SetLevel(SCSIZE nIndex, sal_uInt8 nVal, bool bCollapsed)
Definition: exctools.cxx:70
OutlineLevels maLevels
Definition: otlnbuff.hxx:42
XclImpOutlineBuffer(SCSIZE nNewSize)
Definition: exctools.cxx:57
Access to global data from other classes.
Definition: xiroot.hxx:129
XclImpTabInfo & GetTabInfo() const
Returns the buffer that contains the sheet creation order.
Definition: xiroot.cxx:180
This class is used to import record oriented streams.
Definition: xistream.hxx:278
sal_uInt8 ReaduInt8()
Definition: xistream.cxx:617
OUString ReadUniString(sal_uInt16 nChars, sal_uInt8 nFlags)
Reads ext.
Definition: xistream.cxx:891
void Ignore(std::size_t nBytes)
Seeks forward inside the current record.
Definition: xistream.cxx:798
sal_uInt16 ReaduInt16()
Definition: xistream.cxx:649
void InsertScTab(SCTAB nScTab)
Inserts a Calc sheet index (increases all following sheet indexes).
Definition: xilink.cxx:232
ScExtDocOptions & GetExtDocOptions() const
Returns the extended document options.
Definition: xlroot.cxx:429
ScDocument & GetDoc() const
Returns reference to the destination document (import) or source document (export).
Definition: xlroot.cxx:285
constexpr ::Color COL_LIGHTGRAY(0xC0, 0xC0, 0xC0)
@ BiffX
Definition: flttypes.hxx:24
ScScenarioFlags
Definition: global.hxx:226
sal_Int32 nIndex
sal_Int64 n
sal_uInt16 nPos
int i
std::vector< std::unique_ptr< ExcScenario > > aEntries
Definition: excscen.hxx:67
sal_uInt16 nLastScenario
Definition: excscen.hxx:66
void Apply(const XclImpRoot &rRoot)
Definition: exctools.cxx:233
RootData()
Definition: exctools.cxx:36
XclImpRoot * pIR
Definition: root.hxx:59
BiffTyp eDateiTyp
Definition: root.hxx:45
std::unique_ptr< ExtNameBuff > pExtNameBuff
Definition: root.hxx:48
XclExpChTrTabId * pTabId
Definition: root.hxx:56
std::unique_ptr< XclImpAutoFilterBuffer > pAutoFilterBuffer
Definition: root.hxx:53
XclExpRoot * pER
Definition: root.hxx:60
XclExpUserBViewList * pUserBViewList
Definition: root.hxx:57
~RootData()
Definition: exctools.cxx:49
XclImpColRowSettings * pColRowBuff
Definition: root.hxx:50
ExcelToSc * pFmlaConverter
Definition: root.hxx:49
std::unique_ptr< SharedFormulaBuffer > pShrfmlaBuff
Definition: root.hxx:47
std::unique_ptr< ExtSheetBuffer > pExtSheetBuff
Definition: root.hxx:46
Extended settings for the document, used in import/export filters.
Definition: scextopt.hxx:28
SCTAB mnDisplTab
Index of displayed sheet.
Definition: scextopt.hxx:32
unsigned char sal_uInt8
sal_Int16 SCCOL
Definition: types.hxx:21