bump product version to 4.1.6.2
[LibreOffice.git] / sc / source / filter / excel / exctools.cxx
blobe0bbfebefe6ba9768605dcaee9c9cc6291dc26d7
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 #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"
30 #include "attrib.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"
38 #include "root.hxx"
39 #include "imp_op.hxx"
40 #include "excimp8.hxx"
41 #include "otlnbuff.hxx"
42 #include "xcl97rec.hxx"
43 #include "formel.hxx"
44 #include "xilink.hxx"
45 #include "xecontent.hxx"
47 #include <vector>
49 RootData::RootData( void )
51 eDateiTyp = BiffX;
52 pExtSheetBuff = NULL;
53 pShrfmlaBuff = NULL;
54 pExtNameBuff = NULL;
55 pFmlaConverter = NULL;
57 pAutoFilterBuffer = NULL;
58 pPrintRanges = new _ScRangeListTabs;
59 pPrintTitles = new _ScRangeListTabs;
61 pTabId = NULL;
62 pUserBViewList = NULL;
64 pIR = NULL;
65 pER = NULL;
68 RootData::~RootData()
70 delete pExtSheetBuff;
71 delete pShrfmlaBuff;
72 delete pExtNameBuff;
73 delete pAutoFilterBuffer;
74 delete pPrintRanges;
75 delete pPrintTitles;
79 XclImpOutlineBuffer::XclImpOutlineBuffer( SCSIZE nNewSize ) :
80 maLevels(0, nNewSize, 0),
81 mpOutlineArray(NULL),
82 mnEndPos(nNewSize),
83 mnMaxLevel(0),
84 mbButtonAfter(true)
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)
96 mnMaxLevel = nVal;
97 if (bCollapsed)
98 maCollapsedPosSet.insert(nIndex);
101 void XclImpOutlineBuffer::SetOutlineArray( ScOutlineArray* pOArray )
103 mpOutlineArray = pOArray;
106 void XclImpOutlineBuffer::MakeScOutline()
108 if (!mpOutlineArray)
109 return;
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.");
121 break;
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);
130 else
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.
138 return;
140 SCSIZE nFirstPos = aOutlineStack.back();
141 aOutlineStack.pop_back();
142 bool bCollapsed = false;
143 if (mbButtonAfter)
144 bCollapsed = maCollapsedPosSet.count(nPos) > 0;
145 else if (nFirstPos > 0)
146 bCollapsed = maCollapsedPosSet.count(nFirstPos-1) > 0;
148 bool bDummy;
149 mpOutlineArray->Insert(nFirstPos, nPos-1, bDummy, bCollapsed);
155 void XclImpOutlineBuffer::SetLevelRange( SCSIZE nF, SCSIZE nL, sal_uInt8 nVal, bool bCollapsed )
157 if (nF > nL)
158 // invalid range
159 return;
161 maLevels.insert_back(nF, nL+1, nVal);
163 if (bCollapsed)
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() )
180 sal_uInt16 nCref;
181 sal_uInt8 nName, nComment;
183 rIn >> nCref;
184 rIn >> nProtected;
185 rIn.Ignore( 1 ); // Hide
186 rIn >> nName >> nComment;
187 rIn.Ignore( 1 ); // statt nUser!
189 if( nName )
190 pName = new String( rIn.ReadUniString( nName ) );
191 else
193 pName = new String( RTL_CONSTASCII_USTRINGPARAM( "Scenery" ) );
194 rIn.Ignore( 1 );
197 pUserName = new String( rIn.ReadUniString() );
199 if( nComment )
200 pComment = new String( rIn.ReadUniString() );
201 else
202 pComment = new String;
204 sal_uInt16 n = nCref;
205 sal_uInt16 nC, nR;
206 while( n )
208 rIn >> nR >> nC;
210 aEntries.push_back(new ExcScenarioCell( nC, nR ));
212 n--;
215 n = nCref;
217 boost::ptr_vector<ExcScenarioCell>::iterator iter;
218 for (iter = aEntries.begin(); iter != aEntries.end(); ++iter)
219 iter->SetValue(rIn.ReadUniString());
222 ExcScenario::~ExcScenario()
224 if( pName )
225 delete pName;
226 if( pComment )
227 delete pComment;
228 if( pUserName )
229 delete pUserName;
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 ) )
239 return;
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 );
257 if( bLast )
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)
275 n--;
276 iter->Apply(rRoot, n == nLastScenario);
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */