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