fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / excel / exctools.cxx
blobc23c70dab191d1de11c9ce2c63fd5d863444e500
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()
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;
66 pColRowBuff = NULL;
69 RootData::~RootData()
71 delete pExtSheetBuff;
72 delete pShrfmlaBuff;
73 delete pExtNameBuff;
74 delete pAutoFilterBuffer;
75 delete pPrintRanges;
76 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 nCref = rIn.ReaduInt16();
184 nProtected = rIn.ReaduInt8();
185 rIn.Ignore( 1 ); // Hide
186 nName = rIn.ReaduInt8();
187 nComment = rIn.ReaduInt8();
188 rIn.Ignore( 1 ); // statt nUser!
190 if( nName )
191 pName = new OUString( rIn.ReadUniString( nName ) );
192 else
194 pName = new OUString( "Scenery" );
195 rIn.Ignore( 1 );
198 pUserName = new OUString( rIn.ReadUniString() );
200 if( nComment )
201 pComment = new OUString( rIn.ReadUniString() );
202 else
203 pComment = new OUString;
205 sal_uInt16 n = nCref;
206 sal_uInt16 nC, nR;
207 while( n )
209 nR = rIn.ReaduInt16();
210 nC = rIn.ReaduInt16();
212 aEntries.push_back(new ExcScenarioCell( nC, nR ));
214 n--;
217 n = nCref;
219 boost::ptr_vector<ExcScenarioCell>::iterator iter;
220 for (iter = aEntries.begin(); iter != aEntries.end(); ++iter)
221 iter->SetValue(rIn.ReadUniString());
224 ExcScenario::~ExcScenario()
226 if( pName )
227 delete pName;
228 if( pComment )
229 delete pComment;
230 if( pUserName )
231 delete pUserName;
234 void ExcScenario::Apply( const XclImpRoot& rRoot, const bool bLast )
236 ScDocument& r = rRoot.GetDoc();
237 OUString aSzenName( *pName );
238 sal_uInt16 nNewTab = nTab + 1;
240 if( !r.InsertTab( nNewTab, aSzenName ) )
241 return;
243 r.SetScenario( nNewTab, true );
244 // do not show scenario frames
245 r.SetScenarioData( nNewTab, *pComment, COL_LIGHTGRAY, /*SC_SCENARIO_SHOWFRAME|*/SC_SCENARIO_COPYALL|(nProtected ? SC_SCENARIO_PROTECT : 0) );
247 boost::ptr_vector<ExcScenarioCell>::const_iterator iter;
248 for (iter = aEntries.begin(); iter != aEntries.end(); ++iter)
250 sal_uInt16 nCol = iter->nCol;
251 sal_uInt16 nRow = iter->nRow;
252 OUString aVal = iter->GetValue();
254 r.ApplyFlagsTab( nCol, nRow, nCol, nRow, nNewTab, SC_MF_SCENARIO );
256 r.SetString( nCol, nRow, nNewTab, aVal );
259 if( bLast )
260 r.SetActiveScenario( nNewTab, true );
262 // modify what the Active tab is set to if the new
263 // scenario tab occurs before the active tab.
264 ScExtDocSettings& rDocSett = rRoot.GetExtDocOptions().GetDocSettings();
265 if( (static_cast< SCCOL >( nTab ) < rDocSett.mnDisplTab) && (rDocSett.mnDisplTab < MAXTAB) )
266 ++rDocSett.mnDisplTab;
267 rRoot.GetTabInfo().InsertScTab( nNewTab );
270 void ExcScenarioList::Apply( const XclImpRoot& rRoot )
272 sal_uInt16 n = static_cast<sal_uInt16>(aEntries.size());
274 boost::ptr_vector<ExcScenario>::reverse_iterator iter;
275 for (iter = aEntries.rbegin(); iter != aEntries.rend(); ++iter)
277 n--;
278 iter->Apply(rRoot, n == nLastScenario);
282 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */