LCOV - code coverage report
Current view: top level - sc/source/filter/excel - exctools.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 72 139 51.8 %
Date: 2014-11-03 Functions: 11 16 68.8 %
Legend: Lines: hit not hit

          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         208 : RootData::RootData( void )
      50             : {
      51         208 :     eDateiTyp = BiffX;
      52         208 :     pExtSheetBuff = NULL;
      53         208 :     pShrfmlaBuff = NULL;
      54         208 :     pExtNameBuff = NULL;
      55         208 :     pFmlaConverter = NULL;
      56             : 
      57         208 :     pAutoFilterBuffer = NULL;
      58         208 :     pPrintRanges = new _ScRangeListTabs;
      59         208 :     pPrintTitles = new _ScRangeListTabs;
      60             : 
      61         208 :     pTabId = NULL;
      62         208 :     pUserBViewList = NULL;
      63             : 
      64         208 :     pIR = NULL;
      65         208 :     pER = NULL;
      66         208 :     pColRowBuff = NULL;
      67         208 : }
      68             : 
      69         208 : RootData::~RootData()
      70             : {
      71         208 :     delete pExtSheetBuff;
      72         208 :     delete pShrfmlaBuff;
      73         208 :     delete pExtNameBuff;
      74         208 :     delete pAutoFilterBuffer;
      75         208 :     delete pPrintRanges;
      76         208 :     delete pPrintTitles;
      77         208 : }
      78             : 
      79         832 : XclImpOutlineBuffer::XclImpOutlineBuffer( SCSIZE nNewSize ) :
      80             :     maLevels(0, nNewSize, 0),
      81             :     mpOutlineArray(NULL),
      82             :     mnEndPos(nNewSize),
      83             :     mnMaxLevel(0),
      84         832 :     mbButtonAfter(true)
      85             : {
      86         832 : }
      87             : 
      88         832 : XclImpOutlineBuffer::~XclImpOutlineBuffer()
      89             : {
      90         832 : }
      91             : 
      92      403336 : void XclImpOutlineBuffer::SetLevel( SCSIZE nIndex, sal_uInt8 nVal, bool bCollapsed )
      93             : {
      94      403336 :     maLevels.insert_back(nIndex, nIndex+1, nVal);
      95      403336 :     if (nVal > mnMaxLevel)
      96           4 :         mnMaxLevel = nVal;
      97      403336 :     if (bCollapsed)
      98           8 :         maCollapsedPosSet.insert(nIndex);
      99      403336 : }
     100             : 
     101         832 : void XclImpOutlineBuffer::SetOutlineArray( ScOutlineArray* pOArray )
     102             : {
     103         832 :     mpOutlineArray = pOArray;
     104         832 : }
     105             : 
     106         832 : void XclImpOutlineBuffer::MakeScOutline()
     107             : {
     108         832 :     if (!mpOutlineArray)
     109           0 :         return;
     110             : 
     111         832 :     ::std::vector<SCSIZE> aOutlineStack;
     112         832 :     aOutlineStack.reserve(mnMaxLevel);
     113         832 :     OutlineLevels::const_iterator itr = maLevels.begin(), itrEnd = maLevels.end();
     114        1678 :     for (; itr != itrEnd; ++itr)
     115             :     {
     116        1678 :         SCSIZE nPos = itr->first;
     117        1678 :         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         832 :             break;
     122             :         }
     123         846 :         sal_uInt8 nLevel = itr->second;
     124         846 :         sal_uInt8 nCurLevel = static_cast<sal_uInt8>(aOutlineStack.size());
     125         846 :         if (nLevel > nCurLevel)
     126             :         {
     127          14 :             for (sal_uInt8 i = 0; i < nLevel - nCurLevel; ++i)
     128           8 :                 aOutlineStack.push_back(nPos);
     129             :         }
     130             :         else
     131             :         {
     132             :             OSL_ENSURE(nLevel < nCurLevel, "XclImpOutlineBuffer::MakeScOutline: unexpected level!");
     133         848 :             for (sal_uInt8 i = 0; i < nCurLevel - nLevel; ++i)
     134             :             {
     135           8 :                 if (aOutlineStack.empty())
     136             :                 {
     137             :                     // Something is wrong.
     138           0 :                     return;
     139             :                 }
     140           8 :                 SCSIZE nFirstPos = aOutlineStack.back();
     141           8 :                 aOutlineStack.pop_back();
     142           8 :                 bool bCollapsed = false;
     143           8 :                 if (mbButtonAfter)
     144           6 :                     bCollapsed = maCollapsedPosSet.count(nPos) > 0;
     145           2 :                 else if (nFirstPos > 0)
     146           2 :                     bCollapsed = maCollapsedPosSet.count(nFirstPos-1) > 0;
     147             : 
     148             :                 bool bDummy;
     149           8 :                 mpOutlineArray->Insert(nFirstPos, nPos-1, bDummy, bCollapsed);
     150             :             }
     151             :         }
     152         832 :     }
     153             : }
     154             : 
     155         800 : void XclImpOutlineBuffer::SetLevelRange( SCSIZE nF, SCSIZE nL, sal_uInt8 nVal, bool bCollapsed )
     156             : {
     157         800 :     if (nF > nL)
     158             :         // invalid range
     159         800 :         return;
     160             : 
     161         800 :     maLevels.insert_back(nF, nL+1, nVal);
     162             : 
     163         800 :     if (bCollapsed)
     164           0 :         maCollapsedPosSet.insert(nF);
     165             : }
     166             : 
     167         828 : void XclImpOutlineBuffer::SetButtonMode( bool bRightOrUnder )
     168             : {
     169         828 :     mbButtonAfter = bRightOrUnder;
     170         828 : }
     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 OUString( rIn.ReadUniString( nName ) );
     191             :     else
     192             :     {
     193           0 :         pName = new OUString( "Scenery" );
     194           0 :         rIn.Ignore( 1 );
     195             :     }
     196             : 
     197           0 :     pUserName = new OUString( rIn.ReadUniString() );
     198             : 
     199           0 :     if( nComment )
     200           0 :         pComment = new OUString( rIn.ReadUniString() );
     201             :     else
     202           0 :         pComment = new OUString;
     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 bool bLast )
     233             : {
     234           0 :     ScDocument&         r = rRoot.GetDoc();
     235           0 :     OUString            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 :         OUString 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, 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          48 : }
     279             : 
     280             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10