1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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"
49 #include "globstr.hrc"
50 #include "scextopt.hxx"
51 #include "progress.hxx"
52 #include "rangenam.hxx"
53 #include "editutil.hxx"
55 #include "excrecds.hxx"
58 #include "excimp8.hxx"
59 #include "otlnbuff.hxx"
60 #include "xcl97rec.hxx"
63 #include "xecontent.hxx"
65 // - ALLGEMEINE ----------------------------------------------------------
67 RootData::RootData( void )
74 pFmlaConverter
= NULL
;
76 pAutoFilterBuffer
= NULL
;
77 pPrintRanges
= new _ScRangeListTabs
;
78 pPrintTitles
= new _ScRangeListTabs
;
81 pUserBViewList
= NULL
;
96 delete pAutoFilterBuffer
;
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
;
118 XclImpOutlineBuffer::~XclImpOutlineBuffer()
126 void XclImpOutlineBuffer::SetLevel( SCSIZE nIndex
, BYTE nVal
, BOOL bOuted
, BOOL bHidden
)
130 pLevel
[ nIndex
] = nVal
;
131 pOuted
[ nIndex
] = bOuted
;
132 pHidden
[ nIndex
] = bHidden
;
136 if( nVal
> nMaxLevel
)
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() )
154 const UINT16 nNumLev
= 8;
155 BOOL bPreOutedLevel
= FALSE
;
157 BOOL bMakeHidden
[ nNumLev
];
158 BOOL bMakeVisible
[ nNumLev
+ 1 ];
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) )
168 // search for hidden attributes at end of level, move them to begin
171 for( BYTE nWorkLevel
= 1; nWorkLevel
<= nMaxLevel
; nWorkLevel
++ )
173 UINT16 nStartPos
= 0;
174 BYTE nCurrLevel2
= 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
] )
188 pOuted
[ nStartPos
- 1 ] = TRUE
;
190 bPreOutedLevel
= TRUE
;
191 pOuted
[ nC
] = FALSE
;
198 bPreOutedLevel
= pHidden
[ 0 ];
200 // generate SC outlines
202 UINT16 nStart
[ nNumLev
];
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
];
217 while( nWorkLevel
> nCurrLevel
)
220 bMakeHidden
[ nCurrLevel
] = bPrevOuted
;
221 bMakeVisible
[ nCurrLevel
+ 1 ] =
222 bMakeVisible
[ nCurrLevel
] && !bMakeHidden
[ nCurrLevel
];
223 nStart
[ nCurrLevel
] = static_cast< sal_uInt16
>( nC
);
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
);
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!" );
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
)
276 void XclImpOutlineBuffer::Reset( void )
278 for( SCSIZE nC
= 0 ; nC
< nSize
; nC
++ )
281 pOuted
[ nC
] = pHidden
[ nC
] = FALSE
;
288 //___________________________________________________________________
291 ExcScenarioCell::ExcScenarioCell( const UINT16 nC
, const UINT16 nR
) : nCol( nC
), nRow( nR
)
296 void ExcScenarioCell::SetValue( const String
& 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() )
312 UINT8 nName
, nComment
;
316 rIn
.Ignore( 1 ); // Hide
317 rIn
>> nName
>> nComment
;
318 rIn
.Ignore( 1 ); // statt nUser!
321 pName
= new String( rIn
.ReadUniString( nName
) );
324 pName
= new String( RTL_CONSTASCII_USTRINGPARAM( "Scenery" ) );
328 pUserName
= new String( rIn
.ReadUniString() );
331 pComment
= new String( rIn
.ReadUniString() );
333 pComment
= new String
;
341 EXCSCAPPEND( new ExcScenarioCell( nC
, nR
) );
347 ExcScenarioCell
* p
= EXCSCFIRST();
350 p
->SetValue( rIn
.ReadUniString() );
357 ExcScenario::~ExcScenario()
359 ExcScenarioCell
* p
= EXCSCFIRST();
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
) )
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) );
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
);
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();
429 void ExcScenarioList::Apply( const XclImpRoot
& rRoot
)
431 ExcScenario
* p
= _Last();
432 UINT16 n
= ( UINT16
) Count();
437 p
->Apply( rRoot
, ( BOOL
) ( n
== nLastScenario
) );