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