LCOV - code coverage report
Current view: top level - libreoffice/sc/source/core/data - global2.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 37 160 23.1 %
Date: 2012-12-27 Functions: 8 25 32.0 %
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 <sfx2/docfile.hxx>
      21             : #include <sfx2/objsh.hxx>
      22             : #include <unotools/pathoptions.hxx>
      23             : #include <unotools/useroptions.hxx>
      24             : #include <tools/urlobj.hxx>
      25             : #include <unotools/charclass.hxx>
      26             : #include <stdlib.h>
      27             : #include <ctype.h>
      28             : #include <unotools/syslocale.hxx>
      29             : 
      30             : #include "global.hxx"
      31             : #include "rangeutl.hxx"
      32             : #include "rechead.hxx"
      33             : #include "compiler.hxx"
      34             : #include "paramisc.hxx"
      35             : 
      36             : #include "sc.hrc"
      37             : #include "globstr.hrc"
      38             : 
      39             : using ::std::vector;
      40             : 
      41             : // -----------------------------------------------------------------------
      42             : 
      43             : //------------------------------------------------------------------------
      44             : // struct ScImportParam:
      45             : 
      46          17 : ScImportParam::ScImportParam() :
      47             :     nCol1(0),
      48             :     nRow1(0),
      49             :     nCol2(0),
      50             :     nRow2(0),
      51             :     bImport(false),
      52             :     bNative(false),
      53             :     bSql(true),
      54          17 :     nType(ScDbTable)
      55             : {
      56          17 : }
      57             : 
      58          20 : ScImportParam::ScImportParam( const ScImportParam& r ) :
      59             :     nCol1       (r.nCol1),
      60             :     nRow1       (r.nRow1),
      61             :     nCol2       (r.nCol2),
      62             :     nRow2       (r.nRow2),
      63             :     bImport     (r.bImport),
      64             :     aDBName     (r.aDBName),
      65             :     aStatement  (r.aStatement),
      66             :     bNative     (r.bNative),
      67             :     bSql        (r.bSql),
      68          20 :     nType       (r.nType)
      69             : {
      70          20 : }
      71             : 
      72          36 : ScImportParam::~ScImportParam()
      73             : {
      74          36 : }
      75             : 
      76           0 : ScImportParam& ScImportParam::operator=( const ScImportParam& r )
      77             : {
      78           0 :     nCol1           = r.nCol1;
      79           0 :     nRow1           = r.nRow1;
      80           0 :     nCol2           = r.nCol2;
      81           0 :     nRow2           = r.nRow2;
      82           0 :     bImport         = r.bImport;
      83           0 :     aDBName         = r.aDBName;
      84           0 :     aStatement      = r.aStatement;
      85           0 :     bNative         = r.bNative;
      86           0 :     bSql            = r.bSql;
      87           0 :     nType           = r.nType;
      88             : 
      89           0 :     return *this;
      90             : }
      91             : 
      92           0 : bool ScImportParam::operator==( const ScImportParam& rOther ) const
      93             : {
      94             :     return( nCol1       == rOther.nCol1 &&
      95             :             nRow1       == rOther.nRow1 &&
      96             :             nCol2       == rOther.nCol2 &&
      97             :             nRow2       == rOther.nRow2 &&
      98             :             bImport     == rOther.bImport &&
      99           0 :             aDBName     == rOther.aDBName &&
     100           0 :             aStatement  == rOther.aStatement &&
     101             :             bNative     == rOther.bNative &&
     102             :             bSql        == rOther.bSql &&
     103           0 :             nType       == rOther.nType );
     104             : 
     105             :     //! nQuerySh und pConnection sind gleich ?
     106             : }
     107             : 
     108             : //------------------------------------------------------------------------
     109             : // struct ScConsolidateParam:
     110             : 
     111           5 : ScConsolidateParam::ScConsolidateParam() :
     112           5 :     ppDataAreas( NULL )
     113             : {
     114           5 :     Clear();
     115           5 : }
     116             : 
     117             : //------------------------------------------------------------------------
     118             : 
     119           0 : ScConsolidateParam::ScConsolidateParam( const ScConsolidateParam& r ) :
     120             :         nCol(r.nCol),nRow(r.nRow),nTab(r.nTab),
     121             :         eFunction(r.eFunction),nDataAreaCount(0),
     122             :         ppDataAreas( NULL ),
     123           0 :         bByCol(r.bByCol),bByRow(r.bByRow),bReferenceData(r.bReferenceData)
     124             : {
     125           0 :     if ( r.nDataAreaCount > 0 )
     126             :     {
     127           0 :         nDataAreaCount = r.nDataAreaCount;
     128           0 :         ppDataAreas = new ScArea*[nDataAreaCount];
     129           0 :         for ( sal_uInt16 i=0; i<nDataAreaCount; i++ )
     130           0 :             ppDataAreas[i] = new ScArea( *(r.ppDataAreas[i]) );
     131             :     }
     132           0 : }
     133             : 
     134             : //------------------------------------------------------------------------
     135             : 
     136           0 : ScConsolidateParam::~ScConsolidateParam()
     137             : {
     138           0 :     ClearDataAreas();
     139           0 : }
     140             : 
     141             : //------------------------------------------------------------------------
     142             : 
     143           5 : void ScConsolidateParam::ClearDataAreas()
     144             : {
     145           5 :     if ( ppDataAreas )
     146             :     {
     147           0 :         for ( sal_uInt16 i=0; i<nDataAreaCount; i++ )
     148           0 :             delete ppDataAreas[i];
     149           0 :         delete [] ppDataAreas;
     150           0 :         ppDataAreas = NULL;
     151             :     }
     152           5 :     nDataAreaCount = 0;
     153           5 : }
     154             : 
     155             : //------------------------------------------------------------------------
     156             : 
     157           5 : void ScConsolidateParam::Clear()
     158             : {
     159           5 :     ClearDataAreas();
     160             : 
     161           5 :     nCol = 0;
     162           5 :     nRow = 0;
     163           5 :     nTab = 0;
     164           5 :     bByCol = bByRow = bReferenceData    = false;
     165           5 :     eFunction                           = SUBTOTAL_FUNC_SUM;
     166           5 : }
     167             : 
     168             : //------------------------------------------------------------------------
     169             : 
     170           0 : ScConsolidateParam& ScConsolidateParam::operator=( const ScConsolidateParam& r )
     171             : {
     172           0 :     nCol            = r.nCol;
     173           0 :     nRow            = r.nRow;
     174           0 :     nTab            = r.nTab;
     175           0 :     bByCol          = r.bByCol;
     176           0 :     bByRow          = r.bByRow;
     177           0 :     bReferenceData  = r.bReferenceData;
     178           0 :     eFunction       = r.eFunction;
     179           0 :     SetAreas( r.ppDataAreas, r.nDataAreaCount );
     180             : 
     181           0 :     return *this;
     182             : }
     183             : 
     184             : //------------------------------------------------------------------------
     185             : 
     186           0 : sal_Bool ScConsolidateParam::operator==( const ScConsolidateParam& r ) const
     187             : {
     188             :     sal_Bool bEqual =   (nCol           == r.nCol)
     189             :                  && (nRow           == r.nRow)
     190             :                  && (nTab           == r.nTab)
     191             :                  && (bByCol         == r.bByCol)
     192             :                  && (bByRow         == r.bByRow)
     193             :                  && (bReferenceData == r.bReferenceData)
     194             :                  && (nDataAreaCount == r.nDataAreaCount)
     195           0 :                  && (eFunction      == r.eFunction);
     196             : 
     197           0 :     if ( nDataAreaCount == 0 )
     198           0 :         bEqual = bEqual && (ppDataAreas == NULL) && (r.ppDataAreas == NULL);
     199             :     else
     200           0 :         bEqual = bEqual && (ppDataAreas != NULL) && (r.ppDataAreas != NULL);
     201             : 
     202           0 :     if ( bEqual && (nDataAreaCount > 0) )
     203           0 :         for ( sal_uInt16 i=0; i<nDataAreaCount && bEqual; i++ )
     204           0 :             bEqual = *(ppDataAreas[i]) == *(r.ppDataAreas[i]);
     205             : 
     206           0 :     return bEqual;
     207             : }
     208             : 
     209             : //------------------------------------------------------------------------
     210             : 
     211           0 : void ScConsolidateParam::SetAreas( ScArea* const* ppAreas, sal_uInt16 nCount )
     212             : {
     213           0 :     ClearDataAreas();
     214           0 :     if ( ppAreas && nCount > 0 )
     215             :     {
     216           0 :         ppDataAreas = new ScArea*[nCount];
     217           0 :         for ( sal_uInt16 i=0; i<nCount; i++ )
     218           0 :             ppDataAreas[i] = new ScArea( *(ppAreas[i]) );
     219           0 :         nDataAreaCount = nCount;
     220             :     }
     221           0 : }
     222             : 
     223             : //------------------------------------------------------------------------
     224             : // struct ScSolveParam
     225             : 
     226           5 : ScSolveParam::ScSolveParam()
     227           5 :     :   pStrTargetVal( NULL )
     228             : {
     229           5 : }
     230             : 
     231             : //------------------------------------------------------------------------
     232             : 
     233           0 : ScSolveParam::ScSolveParam( const ScSolveParam& r )
     234             :     :   aRefFormulaCell ( r.aRefFormulaCell ),
     235             :         aRefVariableCell( r.aRefVariableCell ),
     236             :         pStrTargetVal   ( r.pStrTargetVal
     237           0 :                             ? new String(*r.pStrTargetVal)
     238           0 :                             : NULL )
     239             : {
     240           0 : }
     241             : 
     242             : //------------------------------------------------------------------------
     243             : 
     244           0 : ScSolveParam::ScSolveParam( const ScAddress& rFormulaCell,
     245             :                             const ScAddress& rVariableCell,
     246             :                             const String&   rTargetValStr )
     247             :     :   aRefFormulaCell ( rFormulaCell ),
     248             :         aRefVariableCell( rVariableCell ),
     249           0 :         pStrTargetVal   ( new String(rTargetValStr) )
     250             : {
     251           0 : }
     252             : 
     253             : //------------------------------------------------------------------------
     254             : 
     255           0 : ScSolveParam::~ScSolveParam()
     256             : {
     257           0 :     delete pStrTargetVal;
     258           0 : }
     259             : 
     260             : //------------------------------------------------------------------------
     261             : 
     262           0 : ScSolveParam& ScSolveParam::operator=( const ScSolveParam& r )
     263             : {
     264           0 :     delete pStrTargetVal;
     265             : 
     266           0 :     aRefFormulaCell  = r.aRefFormulaCell;
     267           0 :     aRefVariableCell = r.aRefVariableCell;
     268             :     pStrTargetVal    = r.pStrTargetVal
     269           0 :                             ? new String(*r.pStrTargetVal)
     270           0 :                             : NULL;
     271           0 :     return *this;
     272             : }
     273             : 
     274             : //------------------------------------------------------------------------
     275             : 
     276           0 : sal_Bool ScSolveParam::operator==( const ScSolveParam& r ) const
     277             : {
     278           0 :     sal_Bool bEqual =   (aRefFormulaCell  == r.aRefFormulaCell)
     279           0 :                  && (aRefVariableCell == r.aRefVariableCell);
     280             : 
     281           0 :     if ( bEqual )
     282             :     {
     283           0 :         if ( !pStrTargetVal && !r.pStrTargetVal )
     284           0 :             bEqual = sal_True;
     285           0 :         else if ( !pStrTargetVal || !r.pStrTargetVal )
     286           0 :             bEqual = false;
     287           0 :         else if ( pStrTargetVal && r.pStrTargetVal )
     288           0 :             bEqual = ( *pStrTargetVal == *(r.pStrTargetVal) );
     289             :     }
     290             : 
     291           0 :     return bEqual;
     292             : }
     293             : 
     294             : //------------------------------------------------------------------------
     295             : // struct ScTabOpParam
     296             : 
     297           0 : ScTabOpParam::ScTabOpParam( const ScTabOpParam& r )
     298             :     :   aRefFormulaCell ( r.aRefFormulaCell ),
     299             :         aRefFormulaEnd  ( r.aRefFormulaEnd ),
     300             :         aRefRowCell     ( r.aRefRowCell ),
     301             :         aRefColCell     ( r.aRefColCell ),
     302           0 :         nMode           ( r.nMode )
     303             : {
     304           0 : }
     305             : 
     306             : //------------------------------------------------------------------------
     307             : 
     308           0 : ScTabOpParam::ScTabOpParam( const ScRefAddress& rFormulaCell,
     309             :                             const ScRefAddress& rFormulaEnd,
     310             :                             const ScRefAddress& rRowCell,
     311             :                             const ScRefAddress& rColCell,
     312             :                                   sal_uInt8      nMd)
     313             :     :   aRefFormulaCell ( rFormulaCell ),
     314             :         aRefFormulaEnd  ( rFormulaEnd ),
     315             :         aRefRowCell     ( rRowCell ),
     316             :         aRefColCell     ( rColCell ),
     317           0 :         nMode           ( nMd )
     318             : {
     319           0 : }
     320             : 
     321             : //------------------------------------------------------------------------
     322             : 
     323           0 : ScTabOpParam& ScTabOpParam::operator=( const ScTabOpParam& r )
     324             : {
     325           0 :     aRefFormulaCell  = r.aRefFormulaCell;
     326           0 :     aRefFormulaEnd   = r.aRefFormulaEnd;
     327           0 :     aRefRowCell      = r.aRefRowCell;
     328           0 :     aRefColCell      = r.aRefColCell;
     329           0 :     nMode            = r.nMode;
     330           0 :     return *this;
     331             : }
     332             : 
     333             : //------------------------------------------------------------------------
     334             : 
     335           0 : sal_Bool ScTabOpParam::operator==( const ScTabOpParam& r ) const
     336             : {
     337           0 :     return (        (aRefFormulaCell == r.aRefFormulaCell)
     338           0 :                  && (aRefFormulaEnd  == r.aRefFormulaEnd)
     339           0 :                  && (aRefRowCell     == r.aRefRowCell)
     340           0 :                  && (aRefColCell     == r.aRefColCell)
     341           0 :                  && (nMode           == r.nMode) );
     342             : }
     343             : 
     344          35 : String ScGlobal::GetAbsDocName( const String& rFileName,
     345             :                                 SfxObjectShell* pShell )
     346             : {
     347          35 :     String aAbsName;
     348          35 :     if ( !pShell->HasName() )
     349             :     {   // maybe relative to document path working directory
     350          35 :         INetURLObject aObj;
     351          35 :         SvtPathOptions aPathOpt;
     352          35 :         aObj.SetSmartURL( aPathOpt.GetWorkPath() );
     353          35 :         aObj.setFinalSlash();       // it IS a path
     354          35 :         bool bWasAbs = true;
     355          35 :         aAbsName = aObj.smartRel2Abs( rFileName, bWasAbs ).GetMainURL(INetURLObject::NO_DECODE);
     356             :         //  returned string must be encoded because it's used directly to create SfxMedium
     357             :     }
     358             :     else
     359             :     {
     360           0 :         const SfxMedium* pMedium = pShell->GetMedium();
     361           0 :         if ( pMedium )
     362             :         {
     363           0 :             bool bWasAbs = true;
     364           0 :             aAbsName = pMedium->GetURLObject().smartRel2Abs( rFileName, bWasAbs ).GetMainURL(INetURLObject::NO_DECODE);
     365             :         }
     366             :         else
     367             :         {   // This can't happen, but ...
     368             :             // just to be sure to have the same encoding
     369           0 :             INetURLObject aObj;
     370           0 :             aObj.SetSmartURL( aAbsName );
     371           0 :             aAbsName = aObj.GetMainURL(INetURLObject::NO_DECODE);
     372             :         }
     373             :     }
     374          35 :     return aAbsName;
     375             : }
     376             : 
     377           0 : String ScGlobal::GetDocTabName( const String& rFileName,
     378             :                                 const String& rTabName )
     379             : {
     380           0 :     String aDocTab(rtl::OUString('\''));
     381           0 :     aDocTab += rFileName;
     382           0 :     xub_StrLen nPos = 1;
     383           0 :     while( (nPos = aDocTab.Search( '\'', nPos ))
     384             :             != STRING_NOTFOUND )
     385             :     {   // escape Quotes
     386           0 :         aDocTab.Insert( '\\', nPos );
     387           0 :         nPos += 2;
     388             :     }
     389           0 :     aDocTab += '\'';
     390           0 :     aDocTab += SC_COMPILER_FILE_TAB_SEP;
     391           0 :     aDocTab += rTabName;    // "'Doc'#Tab"
     392           0 :     return aDocTab;
     393             : }
     394             : 
     395             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10