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 #include <osl/diagnose.h>
21 #include <document.hxx>
23 #include <scextopt.hxx>
24 #include <olinetab.hxx>
27 #include <excimp8.hxx>
28 #include <namebuff.hxx>
29 #include <otlnbuff.hxx>
39 pFmlaConverter
= nullptr;
42 pUserBViewList
= nullptr;
46 pColRowBuff
= nullptr;
51 pExtSheetBuff
.reset();
54 pAutoFilterBuffer
.reset();
57 XclImpOutlineBuffer::XclImpOutlineBuffer( SCSIZE nNewSize
) :
58 maLevels(0, nNewSize
, 0),
59 mpOutlineArray(nullptr),
66 XclImpOutlineBuffer::~XclImpOutlineBuffer()
70 void XclImpOutlineBuffer::SetLevel( SCSIZE nIndex
, sal_uInt8 nVal
, bool bCollapsed
)
72 maLevels
.insert_back(nIndex
, nIndex
+1, nVal
);
73 if (nVal
> mnMaxLevel
)
76 maCollapsedPosSet
.insert(nIndex
);
79 void XclImpOutlineBuffer::SetOutlineArray( ScOutlineArray
* pOArray
)
81 mpOutlineArray
= pOArray
;
84 void XclImpOutlineBuffer::MakeScOutline()
89 ::std::vector
<SCSIZE
> aOutlineStack
;
90 aOutlineStack
.reserve(mnMaxLevel
);
91 for (const auto& [nPos
, nLevel
] : maLevels
)
95 // Don't go beyond the max allowed position.
96 OSL_ENSURE(aOutlineStack
.empty(), "XclImpOutlineBuffer::MakeScOutline: outline stack not empty but expected to be.");
99 sal_uInt8 nCurLevel
= static_cast<sal_uInt8
>(aOutlineStack
.size());
100 if (nLevel
> nCurLevel
)
102 for (sal_uInt8 i
= 0; i
< nLevel
- nCurLevel
; ++i
)
103 aOutlineStack
.push_back(nPos
);
107 OSL_ENSURE(nLevel
<= nCurLevel
, "XclImpOutlineBuffer::MakeScOutline: unexpected level!");
108 for (sal_uInt8 i
= 0; i
< nCurLevel
- nLevel
; ++i
)
110 if (aOutlineStack
.empty())
112 // Something is wrong.
115 SCSIZE nFirstPos
= aOutlineStack
.back();
116 aOutlineStack
.pop_back();
117 bool bCollapsed
= false;
119 bCollapsed
= maCollapsedPosSet
.count(nPos
) > 0;
120 else if (nFirstPos
> 0)
121 bCollapsed
= maCollapsedPosSet
.count(nFirstPos
-1) > 0;
124 mpOutlineArray
->Insert(nFirstPos
, nPos
-1, bDummy
, bCollapsed
);
130 void XclImpOutlineBuffer::SetLevelRange( SCSIZE nF
, SCSIZE nL
, sal_uInt8 nVal
, bool bCollapsed
)
136 maLevels
.insert_back(nF
, nL
+1, nVal
);
139 maCollapsedPosSet
.insert(nF
);
142 void XclImpOutlineBuffer::SetButtonMode( bool bRightOrUnder
)
144 mbButtonAfter
= bRightOrUnder
;
147 ExcScenarioCell::ExcScenarioCell( const sal_uInt16 nC
, const sal_uInt16 nR
)
148 : nCol( nC
), nRow( nR
)
152 ExcScenario::ExcScenario( XclImpStream
& rIn
, const RootData
& rR
)
153 : nTab( rR
.pIR
->GetCurrScTab() )
156 sal_uInt8 nName
, nComment
;
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!
166 aName
= rIn
.ReadUniString( nName
);
173 rIn
.ReadUniString(); // username
176 aComment
= rIn
.ReadUniString();
178 sal_uInt16 n
= nCref
;
183 nR
= rIn
.ReaduInt16();
184 nC
= rIn
.ReaduInt16();
186 aEntries
.emplace_back( nC
, nR
);
191 for (auto& rEntry
: aEntries
)
192 rEntry
.SetValue(rIn
.ReadUniString());
195 void ExcScenario::Apply( const XclImpRoot
& rRoot
, const bool bLast
)
197 ScDocument
& r
= rRoot
.GetDoc();
198 OUString
aSzenName( aName
);
199 sal_uInt16 nNewTab
= nTab
+ 1;
201 if( !r
.InsertTab( nNewTab
, aSzenName
) )
204 r
.SetScenario( nNewTab
, true );
205 // do not show scenario frames
206 const ScScenarioFlags nFlags
= ScScenarioFlags::CopyAll
207 | (nProtected
? ScScenarioFlags::Protected
: ScScenarioFlags::NONE
);
208 /* | ScScenarioFlags::ShowFrame*/
209 r
.SetScenarioData( nNewTab
, aComment
, COL_LIGHTGRAY
, nFlags
);
211 for (const auto& rEntry
: aEntries
)
213 sal_uInt16 nCol
= rEntry
.nCol
;
214 sal_uInt16 nRow
= rEntry
.nRow
;
215 OUString aVal
= rEntry
.GetValue();
217 r
.ApplyFlagsTab( nCol
, nRow
, nCol
, nRow
, nNewTab
, ScMF::Scenario
);
219 r
.SetString( nCol
, nRow
, nNewTab
, aVal
);
223 r
.SetActiveScenario( nNewTab
, true );
225 // modify what the Active tab is set to if the new
226 // scenario tab occurs before the active tab.
227 ScExtDocSettings
& rDocSett
= rRoot
.GetExtDocOptions().GetDocSettings();
228 if( (static_cast< SCCOL
>( nTab
) < rDocSett
.mnDisplTab
) && (rDocSett
.mnDisplTab
< MAXTAB
) )
229 ++rDocSett
.mnDisplTab
;
230 rRoot
.GetTabInfo().InsertScTab( nNewTab
);
233 void ExcScenarioList::Apply( const XclImpRoot
& rRoot
)
235 sal_uInt16 n
= static_cast<sal_uInt16
>(aEntries
.size());
237 std::vector
< std::unique_ptr
<ExcScenario
> >::reverse_iterator iter
;
238 for (iter
= aEntries
.rbegin(); iter
!= aEntries
.rend(); ++iter
)
241 (*iter
)->Apply(rRoot
, n
== nLastScenario
);
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */