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 "scitems.hxx"
21 #include <editeng/eeitem.hxx>
23 #include <editeng/editdata.hxx>
24 #include <editeng/editeng.hxx>
25 #include <editeng/editobj.hxx>
26 #include <editeng/editstat.hxx>
28 #include "document.hxx"
29 #include "patattr.hxx"
31 #include "globstr.hrc"
32 #include "scextopt.hxx"
33 #include "progress.hxx"
34 #include "rangenam.hxx"
35 #include "editutil.hxx"
37 #include "excrecds.hxx"
40 #include "excimp8.hxx"
41 #include "otlnbuff.hxx"
42 #include "xcl97rec.hxx"
45 #include "xecontent.hxx"
55 pFmlaConverter
= NULL
;
57 pAutoFilterBuffer
= NULL
;
58 pPrintRanges
= new _ScRangeListTabs
;
59 pPrintTitles
= new _ScRangeListTabs
;
62 pUserBViewList
= NULL
;
74 delete pAutoFilterBuffer
;
79 XclImpOutlineBuffer::XclImpOutlineBuffer( SCSIZE nNewSize
) :
80 maLevels(0, nNewSize
, 0),
88 XclImpOutlineBuffer::~XclImpOutlineBuffer()
92 void XclImpOutlineBuffer::SetLevel( SCSIZE nIndex
, sal_uInt8 nVal
, bool bCollapsed
)
94 maLevels
.insert_back(nIndex
, nIndex
+1, nVal
);
95 if (nVal
> mnMaxLevel
)
98 maCollapsedPosSet
.insert(nIndex
);
101 void XclImpOutlineBuffer::SetOutlineArray( ScOutlineArray
* pOArray
)
103 mpOutlineArray
= pOArray
;
106 void XclImpOutlineBuffer::MakeScOutline()
111 ::std::vector
<SCSIZE
> aOutlineStack
;
112 aOutlineStack
.reserve(mnMaxLevel
);
113 OutlineLevels::const_iterator itr
= maLevels
.begin(), itrEnd
= maLevels
.end();
114 for (; itr
!= itrEnd
; ++itr
)
116 SCSIZE nPos
= itr
->first
;
117 if (nPos
>= mnEndPos
)
119 // Don't go beyond the max allowed position.
120 OSL_ENSURE(aOutlineStack
.empty(), "XclImpOutlineBuffer::MakeScOutline: outline stack not empty but expected to be.");
123 sal_uInt8 nLevel
= itr
->second
;
124 sal_uInt8 nCurLevel
= static_cast<sal_uInt8
>(aOutlineStack
.size());
125 if (nLevel
> nCurLevel
)
127 for (sal_uInt8 i
= 0; i
< nLevel
- nCurLevel
; ++i
)
128 aOutlineStack
.push_back(nPos
);
132 OSL_ENSURE(nLevel
< nCurLevel
, "XclImpOutlineBuffer::MakeScOutline: unexpected level!");
133 for (sal_uInt8 i
= 0; i
< nCurLevel
- nLevel
; ++i
)
135 if (aOutlineStack
.empty())
137 // Something is wrong.
140 SCSIZE nFirstPos
= aOutlineStack
.back();
141 aOutlineStack
.pop_back();
142 bool bCollapsed
= false;
144 bCollapsed
= maCollapsedPosSet
.count(nPos
) > 0;
145 else if (nFirstPos
> 0)
146 bCollapsed
= maCollapsedPosSet
.count(nFirstPos
-1) > 0;
149 mpOutlineArray
->Insert(nFirstPos
, nPos
-1, bDummy
, bCollapsed
);
155 void XclImpOutlineBuffer::SetLevelRange( SCSIZE nF
, SCSIZE nL
, sal_uInt8 nVal
, bool bCollapsed
)
161 maLevels
.insert_back(nF
, nL
+1, nVal
);
164 maCollapsedPosSet
.insert(nF
);
167 void XclImpOutlineBuffer::SetButtonMode( bool bRightOrUnder
)
169 mbButtonAfter
= bRightOrUnder
;
172 ExcScenarioCell::ExcScenarioCell( const sal_uInt16 nC
, const sal_uInt16 nR
)
173 : nCol( nC
), nRow( nR
)
177 ExcScenario::ExcScenario( XclImpStream
& rIn
, const RootData
& rR
)
178 : nTab( rR
.pIR
->GetCurrScTab() )
181 sal_uInt8 nName
, nComment
;
183 nCref
= rIn
.ReaduInt16();
184 nProtected
= rIn
.ReaduInt8();
185 rIn
.Ignore( 1 ); // Hide
186 nName
= rIn
.ReaduInt8();
187 nComment
= rIn
.ReaduInt8();
188 rIn
.Ignore( 1 ); // statt nUser!
191 pName
= new OUString( rIn
.ReadUniString( nName
) );
194 pName
= new OUString( "Scenery" );
198 pUserName
= new OUString( rIn
.ReadUniString() );
201 pComment
= new OUString( rIn
.ReadUniString() );
203 pComment
= new OUString
;
205 sal_uInt16 n
= nCref
;
209 nR
= rIn
.ReaduInt16();
210 nC
= rIn
.ReaduInt16();
212 aEntries
.push_back(new ExcScenarioCell( nC
, nR
));
219 boost::ptr_vector
<ExcScenarioCell
>::iterator iter
;
220 for (iter
= aEntries
.begin(); iter
!= aEntries
.end(); ++iter
)
221 iter
->SetValue(rIn
.ReadUniString());
224 ExcScenario::~ExcScenario()
234 void ExcScenario::Apply( const XclImpRoot
& rRoot
, const bool bLast
)
236 ScDocument
& r
= rRoot
.GetDoc();
237 OUString
aSzenName( *pName
);
238 sal_uInt16 nNewTab
= nTab
+ 1;
240 if( !r
.InsertTab( nNewTab
, aSzenName
) )
243 r
.SetScenario( nNewTab
, true );
244 // do not show scenario frames
245 r
.SetScenarioData( nNewTab
, *pComment
, COL_LIGHTGRAY
, /*SC_SCENARIO_SHOWFRAME|*/SC_SCENARIO_COPYALL
|(nProtected
? SC_SCENARIO_PROTECT
: 0) );
247 boost::ptr_vector
<ExcScenarioCell
>::const_iterator iter
;
248 for (iter
= aEntries
.begin(); iter
!= aEntries
.end(); ++iter
)
250 sal_uInt16 nCol
= iter
->nCol
;
251 sal_uInt16 nRow
= iter
->nRow
;
252 OUString aVal
= iter
->GetValue();
254 r
.ApplyFlagsTab( nCol
, nRow
, nCol
, nRow
, nNewTab
, SC_MF_SCENARIO
);
256 r
.SetString( nCol
, nRow
, nNewTab
, aVal
);
260 r
.SetActiveScenario( nNewTab
, true );
262 // modify what the Active tab is set to if the new
263 // scenario tab occurs before the active tab.
264 ScExtDocSettings
& rDocSett
= rRoot
.GetExtDocOptions().GetDocSettings();
265 if( (static_cast< SCCOL
>( nTab
) < rDocSett
.mnDisplTab
) && (rDocSett
.mnDisplTab
< MAXTAB
) )
266 ++rDocSett
.mnDisplTab
;
267 rRoot
.GetTabInfo().InsertScTab( nNewTab
);
270 void ExcScenarioList::Apply( const XclImpRoot
& rRoot
)
272 sal_uInt16 n
= static_cast<sal_uInt16
>(aEntries
.size());
274 boost::ptr_vector
<ExcScenario
>::reverse_iterator iter
;
275 for (iter
= aEntries
.rbegin(); iter
!= aEntries
.rend(); ++iter
)
278 iter
->Apply(rRoot
, n
== nLastScenario
);
282 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */