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"
49 RootData::RootData( void )
55 pFmlaConverter
= NULL
;
57 pAutoFilterBuffer
= NULL
;
58 pPrintRanges
= new _ScRangeListTabs
;
59 pPrintTitles
= new _ScRangeListTabs
;
62 pUserBViewList
= NULL
;
73 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
;
185 rIn
.Ignore( 1 ); // Hide
186 rIn
>> nName
>> nComment
;
187 rIn
.Ignore( 1 ); // statt nUser!
190 pName
= new String( rIn
.ReadUniString( nName
) );
193 pName
= new String( RTL_CONSTASCII_USTRINGPARAM( "Scenery" ) );
197 pUserName
= new String( rIn
.ReadUniString() );
200 pComment
= new String( rIn
.ReadUniString() );
202 pComment
= new String
;
204 sal_uInt16 n
= nCref
;
210 aEntries
.push_back(new ExcScenarioCell( nC
, nR
));
217 boost::ptr_vector
<ExcScenarioCell
>::iterator iter
;
218 for (iter
= aEntries
.begin(); iter
!= aEntries
.end(); ++iter
)
219 iter
->SetValue(rIn
.ReadUniString());
222 ExcScenario::~ExcScenario()
232 void ExcScenario::Apply( const XclImpRoot
& rRoot
, const sal_Bool bLast
)
234 ScDocument
& r
= rRoot
.GetDoc();
235 String
aSzenName( *pName
);
236 sal_uInt16 nNewTab
= nTab
+ 1;
238 if( !r
.InsertTab( nNewTab
, aSzenName
) )
241 r
.SetScenario( nNewTab
, true );
242 // do not show scenario frames
243 r
.SetScenarioData( nNewTab
, *pComment
, COL_LIGHTGRAY
, /*SC_SCENARIO_SHOWFRAME|*/SC_SCENARIO_COPYALL
|(nProtected
? SC_SCENARIO_PROTECT
: 0) );
245 boost::ptr_vector
<ExcScenarioCell
>::const_iterator iter
;
246 for (iter
= aEntries
.begin(); iter
!= aEntries
.end(); ++iter
)
248 sal_uInt16 nCol
= iter
->nCol
;
249 sal_uInt16 nRow
= iter
->nRow
;
250 String aVal
= iter
->GetValue();
252 r
.ApplyFlagsTab( nCol
, nRow
, nCol
, nRow
, nNewTab
, SC_MF_SCENARIO
);
254 r
.SetString( nCol
, nRow
, nNewTab
, aVal
);
258 r
.SetActiveScenario( nNewTab
, sal_True
);
260 // modify what the Active tab is set to if the new
261 // scenario tab occurs before the active tab.
262 ScExtDocSettings
& rDocSett
= rRoot
.GetExtDocOptions().GetDocSettings();
263 if( (static_cast< SCCOL
>( nTab
) < rDocSett
.mnDisplTab
) && (rDocSett
.mnDisplTab
< MAXTAB
) )
264 ++rDocSett
.mnDisplTab
;
265 rRoot
.GetTabInfo().InsertScTab( nNewTab
);
268 void ExcScenarioList::Apply( const XclImpRoot
& rRoot
)
270 sal_uInt16 n
= static_cast<sal_uInt16
>(aEntries
.size());
272 boost::ptr_vector
<ExcScenario
>::reverse_iterator iter
;
273 for (iter
= aEntries
.rbegin(); iter
!= aEntries
.rend(); ++iter
)
276 iter
->Apply(rRoot
, n
== nLastScenario
);
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */