Line data Source code
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 "scitems.hxx"
21 : #include <editeng/eeitem.hxx>
22 :
23 : #include <editeng/editdata.hxx>
24 : #include <editeng/editeng.hxx>
25 : #include <editeng/editobj.hxx>
26 : #include <editeng/editstat.hxx>
27 :
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"
36 :
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"
46 :
47 : #include <vector>
48 :
49 156 : RootData::RootData()
50 : {
51 156 : eDateiTyp = BiffX;
52 156 : pExtSheetBuff = NULL;
53 156 : pShrfmlaBuff = NULL;
54 156 : pExtNameBuff = NULL;
55 156 : pFmlaConverter = NULL;
56 :
57 156 : pAutoFilterBuffer = NULL;
58 156 : pPrintRanges = new _ScRangeListTabs;
59 156 : pPrintTitles = new _ScRangeListTabs;
60 :
61 156 : pTabId = NULL;
62 156 : pUserBViewList = NULL;
63 :
64 156 : pIR = NULL;
65 156 : pER = NULL;
66 156 : pColRowBuff = NULL;
67 156 : }
68 :
69 156 : RootData::~RootData()
70 : {
71 156 : delete pExtSheetBuff;
72 156 : delete pShrfmlaBuff;
73 156 : delete pExtNameBuff;
74 156 : delete pAutoFilterBuffer;
75 156 : delete pPrintRanges;
76 156 : delete pPrintTitles;
77 156 : }
78 :
79 448 : XclImpOutlineBuffer::XclImpOutlineBuffer( SCSIZE nNewSize ) :
80 : maLevels(0, nNewSize, 0),
81 : mpOutlineArray(NULL),
82 : mnEndPos(nNewSize),
83 : mnMaxLevel(0),
84 448 : mbButtonAfter(true)
85 : {
86 448 : }
87 :
88 448 : XclImpOutlineBuffer::~XclImpOutlineBuffer()
89 : {
90 448 : }
91 :
92 267346 : void XclImpOutlineBuffer::SetLevel( SCSIZE nIndex, sal_uInt8 nVal, bool bCollapsed )
93 : {
94 267346 : maLevels.insert_back(nIndex, nIndex+1, nVal);
95 267346 : if (nVal > mnMaxLevel)
96 2 : mnMaxLevel = nVal;
97 267346 : if (bCollapsed)
98 4 : maCollapsedPosSet.insert(nIndex);
99 267346 : }
100 :
101 448 : void XclImpOutlineBuffer::SetOutlineArray( ScOutlineArray* pOArray )
102 : {
103 448 : mpOutlineArray = pOArray;
104 448 : }
105 :
106 448 : void XclImpOutlineBuffer::MakeScOutline()
107 : {
108 448 : if (!mpOutlineArray)
109 0 : return;
110 :
111 448 : ::std::vector<SCSIZE> aOutlineStack;
112 448 : aOutlineStack.reserve(mnMaxLevel);
113 448 : OutlineLevels::const_iterator itr = maLevels.begin(), itrEnd = maLevels.end();
114 903 : for (; itr != itrEnd; ++itr)
115 : {
116 903 : SCSIZE nPos = itr->first;
117 903 : if (nPos >= mnEndPos)
118 : {
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 448 : break;
122 : }
123 455 : sal_uInt8 nLevel = itr->second;
124 455 : sal_uInt8 nCurLevel = static_cast<sal_uInt8>(aOutlineStack.size());
125 455 : if (nLevel > nCurLevel)
126 : {
127 7 : for (sal_uInt8 i = 0; i < nLevel - nCurLevel; ++i)
128 4 : aOutlineStack.push_back(nPos);
129 : }
130 : else
131 : {
132 : OSL_ENSURE(nLevel < nCurLevel, "XclImpOutlineBuffer::MakeScOutline: unexpected level!");
133 456 : for (sal_uInt8 i = 0; i < nCurLevel - nLevel; ++i)
134 : {
135 4 : if (aOutlineStack.empty())
136 : {
137 : // Something is wrong.
138 0 : return;
139 : }
140 4 : SCSIZE nFirstPos = aOutlineStack.back();
141 4 : aOutlineStack.pop_back();
142 4 : bool bCollapsed = false;
143 4 : if (mbButtonAfter)
144 3 : bCollapsed = maCollapsedPosSet.count(nPos) > 0;
145 1 : else if (nFirstPos > 0)
146 1 : bCollapsed = maCollapsedPosSet.count(nFirstPos-1) > 0;
147 :
148 : bool bDummy;
149 4 : mpOutlineArray->Insert(nFirstPos, nPos-1, bDummy, bCollapsed);
150 : }
151 : }
152 448 : }
153 : }
154 :
155 416 : void XclImpOutlineBuffer::SetLevelRange( SCSIZE nF, SCSIZE nL, sal_uInt8 nVal, bool bCollapsed )
156 : {
157 416 : if (nF > nL)
158 : // invalid range
159 416 : return;
160 :
161 416 : maLevels.insert_back(nF, nL+1, nVal);
162 :
163 416 : if (bCollapsed)
164 0 : maCollapsedPosSet.insert(nF);
165 : }
166 :
167 446 : void XclImpOutlineBuffer::SetButtonMode( bool bRightOrUnder )
168 : {
169 446 : mbButtonAfter = bRightOrUnder;
170 446 : }
171 :
172 0 : ExcScenarioCell::ExcScenarioCell( const sal_uInt16 nC, const sal_uInt16 nR )
173 0 : : nCol( nC ), nRow( nR )
174 : {
175 0 : }
176 :
177 0 : ExcScenario::ExcScenario( XclImpStream& rIn, const RootData& rR )
178 0 : : nTab( rR.pIR->GetCurrScTab() )
179 : {
180 : sal_uInt16 nCref;
181 : sal_uInt8 nName, nComment;
182 :
183 0 : nCref = rIn.ReaduInt16();
184 0 : nProtected = rIn.ReaduInt8();
185 0 : rIn.Ignore( 1 ); // Hide
186 0 : nName = rIn.ReaduInt8();
187 0 : nComment = rIn.ReaduInt8();
188 0 : rIn.Ignore( 1 ); // statt nUser!
189 :
190 0 : if( nName )
191 0 : pName = new OUString( rIn.ReadUniString( nName ) );
192 : else
193 : {
194 0 : pName = new OUString( "Scenery" );
195 0 : rIn.Ignore( 1 );
196 : }
197 :
198 0 : pUserName = new OUString( rIn.ReadUniString() );
199 :
200 0 : if( nComment )
201 0 : pComment = new OUString( rIn.ReadUniString() );
202 : else
203 0 : pComment = new OUString;
204 :
205 0 : sal_uInt16 n = nCref;
206 : sal_uInt16 nC, nR;
207 0 : while( n )
208 : {
209 0 : nR = rIn.ReaduInt16();
210 0 : nC = rIn.ReaduInt16();
211 :
212 0 : aEntries.push_back(new ExcScenarioCell( nC, nR ));
213 :
214 0 : n--;
215 : }
216 :
217 0 : n = nCref;
218 :
219 0 : boost::ptr_vector<ExcScenarioCell>::iterator iter;
220 0 : for (iter = aEntries.begin(); iter != aEntries.end(); ++iter)
221 0 : iter->SetValue(rIn.ReadUniString());
222 0 : }
223 :
224 0 : ExcScenario::~ExcScenario()
225 : {
226 0 : if( pName )
227 0 : delete pName;
228 0 : if( pComment )
229 0 : delete pComment;
230 0 : if( pUserName )
231 0 : delete pUserName;
232 0 : }
233 :
234 0 : void ExcScenario::Apply( const XclImpRoot& rRoot, const bool bLast )
235 : {
236 0 : ScDocument& r = rRoot.GetDoc();
237 0 : OUString aSzenName( *pName );
238 0 : sal_uInt16 nNewTab = nTab + 1;
239 :
240 0 : if( !r.InsertTab( nNewTab, aSzenName ) )
241 0 : return;
242 :
243 0 : r.SetScenario( nNewTab, true );
244 : // do not show scenario frames
245 0 : r.SetScenarioData( nNewTab, *pComment, COL_LIGHTGRAY, /*SC_SCENARIO_SHOWFRAME|*/SC_SCENARIO_COPYALL|(nProtected ? SC_SCENARIO_PROTECT : 0) );
246 :
247 0 : boost::ptr_vector<ExcScenarioCell>::const_iterator iter;
248 0 : for (iter = aEntries.begin(); iter != aEntries.end(); ++iter)
249 : {
250 0 : sal_uInt16 nCol = iter->nCol;
251 0 : sal_uInt16 nRow = iter->nRow;
252 0 : OUString aVal = iter->GetValue();
253 :
254 0 : r.ApplyFlagsTab( nCol, nRow, nCol, nRow, nNewTab, SC_MF_SCENARIO );
255 :
256 0 : r.SetString( nCol, nRow, nNewTab, aVal );
257 0 : }
258 :
259 0 : if( bLast )
260 0 : r.SetActiveScenario( nNewTab, true );
261 :
262 : // modify what the Active tab is set to if the new
263 : // scenario tab occurs before the active tab.
264 0 : ScExtDocSettings& rDocSett = rRoot.GetExtDocOptions().GetDocSettings();
265 0 : if( (static_cast< SCCOL >( nTab ) < rDocSett.mnDisplTab) && (rDocSett.mnDisplTab < MAXTAB) )
266 0 : ++rDocSett.mnDisplTab;
267 0 : rRoot.GetTabInfo().InsertScTab( nNewTab );
268 : }
269 :
270 0 : void ExcScenarioList::Apply( const XclImpRoot& rRoot )
271 : {
272 0 : sal_uInt16 n = static_cast<sal_uInt16>(aEntries.size());
273 :
274 0 : boost::ptr_vector<ExcScenario>::reverse_iterator iter;
275 0 : for (iter = aEntries.rbegin(); iter != aEntries.rend(); ++iter)
276 : {
277 0 : n--;
278 0 : iter->Apply(rRoot, n == nLastScenario);
279 : }
280 30 : }
281 :
282 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|