update dev300-m58
[ooovba.git] / sc / source / filter / excel / exctools.cxx
blob37509a23a2883ef7788e0596aa57b6b40f535f43
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: exctools.cxx,v $
10 * $Revision: 1.61.32.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 //------------------------------------------------------------------------
38 #include "scitems.hxx"
39 #include <svx/eeitem.hxx>
41 #include <svx/editdata.hxx>
42 #include <svx/editeng.hxx>
43 #include <svx/editobj.hxx>
44 #include <svx/editstat.hxx>
46 #include "document.hxx"
47 #include "patattr.hxx"
48 #include "attrib.hxx"
49 #include "globstr.hrc"
50 #include "scextopt.hxx"
51 #include "progress.hxx"
52 #include "rangenam.hxx"
53 #include "editutil.hxx"
55 #include "excrecds.hxx"
56 #include "root.hxx"
57 #include "imp_op.hxx"
58 #include "excimp8.hxx"
59 #include "otlnbuff.hxx"
60 #include "xcl97rec.hxx"
61 #include "formel.hxx"
62 #include "xilink.hxx"
63 #include "xecontent.hxx"
65 // - ALLGEMEINE ----------------------------------------------------------
67 RootData::RootData( void )
69 eDateiTyp = BiffX;
70 pExtSheetBuff = NULL;
71 pTabNameBuff = NULL;
72 pShrfmlaBuff = NULL;
73 pExtNameBuff = NULL;
74 pFmlaConverter = NULL;
76 pAutoFilterBuffer = NULL;
77 pPrintRanges = new _ScRangeListTabs;
78 pPrintTitles = new _ScRangeListTabs;
80 pTabId = NULL;
81 pUserBViewList = NULL;
83 pObjRecs = NULL;
84 pEscher = NULL;
86 pIR = NULL;
87 pER = NULL;
90 RootData::~RootData()
92 delete pExtSheetBuff;
93 delete pTabNameBuff;
94 delete pShrfmlaBuff;
95 delete pExtNameBuff;
96 delete pAutoFilterBuffer;
97 delete pPrintRanges;
98 delete pPrintTitles;
104 XclImpOutlineBuffer::XclImpOutlineBuffer( SCSIZE nNewSize )
106 DBG_ASSERT( nNewSize > 0, "-OutlineBuffer::Ctor: nNewSize == 0!" );
108 nSize = nNewSize + 1;
109 pLevel = new BYTE[ nSize ];
110 pOuted = new BOOL[ nSize ];
111 pHidden = new BOOL[ nSize ];
112 pOutlineArray = NULL;
114 Reset();
118 XclImpOutlineBuffer::~XclImpOutlineBuffer()
120 delete[] pLevel;
121 delete[] pOuted;
122 delete[] pHidden;
126 void XclImpOutlineBuffer::SetLevel( SCSIZE nIndex, BYTE nVal, BOOL bOuted, BOOL bHidden )
128 if( nIndex < nSize )
130 pLevel[ nIndex ] = nVal;
131 pOuted[ nIndex ] = bOuted;
132 pHidden[ nIndex ] = bHidden;
134 if( nIndex > nLast )
135 nLast = nIndex;
136 if( nVal > nMaxLevel )
137 nMaxLevel = nVal;
142 void XclImpOutlineBuffer::SetOutlineArray( ScOutlineArray* pOArray )
144 pOutlineArray = pOArray;
148 // transtorm xcl-outline into SC-outline
149 void XclImpOutlineBuffer::MakeScOutline( void )
151 if( !pOutlineArray || !HasOutline() )
152 return;
154 const UINT16 nNumLev = 8;
155 BOOL bPreOutedLevel = FALSE;
156 BYTE nCurrLevel = 0;
157 BOOL bMakeHidden[ nNumLev ];
158 BOOL bMakeVisible[ nNumLev + 1 ];
160 sal_uInt16 nLevel;
161 for( nLevel = 0; nLevel < nNumLev; ++nLevel )
162 bMakeHidden[ nLevel ] = FALSE;
163 for( nLevel = 0; nLevel <= nNumLev; ++nLevel )
164 bMakeVisible[ nLevel ] = TRUE;
165 if( nLast < (nSize - 1) )
166 nLast++;
168 // search for hidden attributes at end of level, move them to begin
169 if( bButtonNormal )
171 for( BYTE nWorkLevel = 1; nWorkLevel <= nMaxLevel; nWorkLevel++ )
173 UINT16 nStartPos = 0;
174 BYTE nCurrLevel2 = 0;
175 BYTE nPrevLevel = 0;
177 for( SCSIZE nC = 0 ; nC <= nLast ; nC++ )
179 nPrevLevel = nCurrLevel2;
180 nCurrLevel2 = pLevel[ nC ];
181 if( (nPrevLevel < nWorkLevel) && (nCurrLevel2 >= nWorkLevel) )
182 nStartPos = static_cast< sal_uInt16 >( nC );
183 else if( (nPrevLevel >= nWorkLevel) && (nCurrLevel2 < nWorkLevel) )
185 if( pOuted[ nC ] && pHidden[ nStartPos ] )
187 if( nStartPos )
188 pOuted[ nStartPos - 1 ] = TRUE;
189 else
190 bPreOutedLevel = TRUE;
191 pOuted[ nC ] = FALSE;
197 else
198 bPreOutedLevel = pHidden[ 0 ];
200 // generate SC outlines
201 UINT16 nPrevC;
202 UINT16 nStart[ nNumLev ];
203 BOOL bDummy;
204 BOOL bPrevOuted = bPreOutedLevel;
205 BOOL bCurrHidden = FALSE;
206 BOOL bPrevHidden = FALSE;
208 for( SCSIZE nC = 0; nC <= nLast; nC++ )
210 BYTE nWorkLevel = pLevel[ nC ];
212 nPrevC = static_cast< sal_uInt16 >( nC ? nC - 1 : 0 );
213 bPrevHidden = bCurrHidden;
214 bCurrHidden = pHidden[ nC ];
216 // open new levels
217 while( nWorkLevel > nCurrLevel )
219 nCurrLevel++;
220 bMakeHidden[ nCurrLevel ] = bPrevOuted;
221 bMakeVisible[ nCurrLevel + 1 ] =
222 bMakeVisible[ nCurrLevel ] && !bMakeHidden[ nCurrLevel ];
223 nStart[ nCurrLevel ] = static_cast< sal_uInt16 >( nC );
225 // close levels
226 while( nWorkLevel < nCurrLevel )
228 BOOL bLastLevel = (nWorkLevel == (nCurrLevel - 1));
229 BOOL bRealHidden = (bMakeHidden[ nCurrLevel ] && bPrevHidden );
230 BOOL bRealVisible = (bMakeVisible[ nCurrLevel ] ||
231 (!bCurrHidden && bLastLevel));
233 pOutlineArray->Insert( nStart[ nCurrLevel ], nPrevC , bDummy,
234 bRealHidden, bRealVisible );
235 nCurrLevel--;
238 bPrevOuted = pOuted[ nC ];
243 void XclImpOutlineBuffer::SetLevelRange( SCSIZE nF, SCSIZE nL, BYTE nVal,
244 BOOL bOuted, BOOL bHidden )
246 DBG_ASSERT( nF <= nL, "+OutlineBuffer::SetLevelRange(): Last < First!" );
248 if( nL < nSize )
250 if( nL > nLast )
251 nLast = nL;
253 BYTE* pLevelCount;
254 BYTE* pLast;
255 BOOL* pOutedCount;
256 BOOL* pHiddenCount;
258 pLevelCount = &pLevel[ nF ];
259 pLast = &pLevel[ nL ];
260 pOutedCount = &pOuted[ nF ];
261 pHiddenCount = &pHidden[ nF ];
263 while( pLevelCount <= pLast )
265 *( pLevelCount++ ) = nVal;
266 *( pOutedCount++ ) = bOuted;
267 *( pHiddenCount++ ) = bHidden;
270 if( nVal > nMaxLevel )
271 nMaxLevel = nVal;
276 void XclImpOutlineBuffer::Reset( void )
278 for( SCSIZE nC = 0 ; nC < nSize ; nC++ )
280 pLevel[ nC ] = 0;
281 pOuted[ nC ] = pHidden[ nC ] = FALSE;
283 nLast = 0;
284 nMaxLevel = 0;
288 //___________________________________________________________________
291 ExcScenarioCell::ExcScenarioCell( const UINT16 nC, const UINT16 nR ) : nCol( nC ), nRow( nR )
296 void ExcScenarioCell::SetValue( const String& r )
298 aValue = r;
304 #define EXCSCAPPEND(EXCSCCELL) (List::Insert(EXCSCCELL,LIST_APPEND))
305 #define EXCSCFIRST() ((ExcScenarioCell*)List::First())
306 #define EXCSCNEXT() ((ExcScenarioCell*)List::Next())
309 ExcScenario::ExcScenario( XclImpStream& rIn, const RootData& rR ) : nTab( rR.pIR->GetCurrScTab() )
311 UINT16 nCref;
312 UINT8 nName, nComment;
314 rIn >> nCref;
315 rIn >> nProtected;
316 rIn.Ignore( 1 ); // Hide
317 rIn >> nName >> nComment;
318 rIn.Ignore( 1 ); // statt nUser!
320 if( nName )
321 pName = new String( rIn.ReadUniString( nName ) );
322 else
324 pName = new String( RTL_CONSTASCII_USTRINGPARAM( "Scenery" ) );
325 rIn.Ignore( 1 );
328 pUserName = new String( rIn.ReadUniString() );
330 if( nComment )
331 pComment = new String( rIn.ReadUniString() );
332 else
333 pComment = new String;
335 UINT16 n = nCref;
336 UINT16 nC, nR;
337 while( n )
339 rIn >> nR >> nC;
341 EXCSCAPPEND( new ExcScenarioCell( nC, nR ) );
343 n--;
346 n = nCref;
347 ExcScenarioCell* p = EXCSCFIRST();
348 while( p )
350 p->SetValue( rIn.ReadUniString() );
352 p = EXCSCNEXT();
357 ExcScenario::~ExcScenario()
359 ExcScenarioCell* p = EXCSCFIRST();
361 while( p )
363 delete p;
364 p = EXCSCNEXT();
367 if( pName )
368 delete pName;
369 if( pComment )
370 delete pComment;
371 if( pUserName )
372 delete pUserName;
376 void ExcScenario::Apply( const XclImpRoot& rRoot, const BOOL bLast )
378 ScDocument& r = rRoot.GetDoc();
379 ExcScenarioCell* p = EXCSCFIRST();
380 String aSzenName( *pName );
381 UINT16 nNewTab = nTab + 1;
383 if( !r.InsertTab( nNewTab, aSzenName ) )
384 return;
386 r.SetScenario( nNewTab, TRUE );
387 // #112621# do not show scenario frames
388 r.SetScenarioData( nNewTab, *pComment, COL_LIGHTGRAY, /*SC_SCENARIO_SHOWFRAME|*/SC_SCENARIO_COPYALL|(nProtected ? SC_SCENARIO_PROTECT : 0) );
390 while( p )
392 UINT16 nCol = p->nCol;
393 UINT16 nRow = p->nRow;
394 String aVal = p->GetValue();
396 r.ApplyFlagsTab( nCol, nRow, nCol, nRow, nNewTab, SC_MF_SCENARIO );
398 r.SetString( nCol, nRow, nNewTab, aVal );
400 p = EXCSCNEXT();
403 if( bLast )
404 r.SetActiveScenario( nNewTab, TRUE );
406 // #111896# modify what the Active tab is set to if the new
407 // scenario tab occurs before the active tab.
408 ScExtDocSettings& rDocSett = rRoot.GetExtDocOptions().GetDocSettings();
409 if( (static_cast< SCCOL >( nTab ) < rDocSett.mnDisplTab) && (rDocSett.mnDisplTab < MAXTAB) )
410 ++rDocSett.mnDisplTab;
411 rRoot.GetTabInfo().InsertScTab( nNewTab );
417 ExcScenarioList::~ExcScenarioList()
419 ExcScenario* p = _First();
421 while( p )
423 delete p;
424 p = _Next();
429 void ExcScenarioList::Apply( const XclImpRoot& rRoot )
431 ExcScenario* p = _Last();
432 UINT16 n = ( UINT16 ) Count();
434 while( p )
436 n--;
437 p->Apply( rRoot, ( BOOL ) ( n == nLastScenario ) );
438 p = _Prev();