LCOV - code coverage report
Current view: top level - sc/source/core/data - global2.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 77 176 43.8 %
Date: 2015-06-13 12:38:46 Functions: 16 28 57.1 %
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             : // struct ScImportParam:
      42             : 
      43         105 : ScImportParam::ScImportParam() :
      44             :     nCol1(0),
      45             :     nRow1(0),
      46             :     nCol2(0),
      47             :     nRow2(0),
      48             :     bImport(false),
      49             :     bNative(false),
      50             :     bSql(true),
      51         105 :     nType(ScDbTable)
      52             : {
      53         105 : }
      54             : 
      55         503 : ScImportParam::ScImportParam( const ScImportParam& r ) :
      56             :     nCol1       (r.nCol1),
      57             :     nRow1       (r.nRow1),
      58             :     nCol2       (r.nCol2),
      59             :     nRow2       (r.nRow2),
      60             :     bImport     (r.bImport),
      61             :     aDBName     (r.aDBName),
      62             :     aStatement  (r.aStatement),
      63             :     bNative     (r.bNative),
      64             :     bSql        (r.bSql),
      65         503 :     nType       (r.nType)
      66             : {
      67         503 : }
      68             : 
      69         605 : ScImportParam::~ScImportParam()
      70             : {
      71         605 : }
      72             : 
      73          11 : ScImportParam& ScImportParam::operator=( const ScImportParam& r )
      74             : {
      75          11 :     nCol1           = r.nCol1;
      76          11 :     nRow1           = r.nRow1;
      77          11 :     nCol2           = r.nCol2;
      78          11 :     nRow2           = r.nRow2;
      79          11 :     bImport         = r.bImport;
      80          11 :     aDBName         = r.aDBName;
      81          11 :     aStatement      = r.aStatement;
      82          11 :     bNative         = r.bNative;
      83          11 :     bSql            = r.bSql;
      84          11 :     nType           = r.nType;
      85             : 
      86          11 :     return *this;
      87             : }
      88             : 
      89           0 : bool ScImportParam::operator==( const ScImportParam& rOther ) const
      90             : {
      91           0 :     return( nCol1       == rOther.nCol1 &&
      92           0 :             nRow1       == rOther.nRow1 &&
      93           0 :             nCol2       == rOther.nCol2 &&
      94           0 :             nRow2       == rOther.nRow2 &&
      95           0 :             bImport     == rOther.bImport &&
      96           0 :             aDBName     == rOther.aDBName &&
      97           0 :             aStatement  == rOther.aStatement &&
      98           0 :             bNative     == rOther.bNative &&
      99           0 :             bSql        == rOther.bSql &&
     100           0 :             nType       == rOther.nType );
     101             : 
     102             :     //TODO: are nQuerySh and pConnection equal ?
     103             : }
     104             : 
     105             : // struct ScConsolidateParam:
     106             : 
     107          55 : ScConsolidateParam::ScConsolidateParam() :
     108          55 :     ppDataAreas( NULL )
     109             : {
     110          55 :     Clear();
     111          55 : }
     112             : 
     113           1 : ScConsolidateParam::ScConsolidateParam( const ScConsolidateParam& r ) :
     114             :         nCol(r.nCol),nRow(r.nRow),nTab(r.nTab),
     115             :         eFunction(r.eFunction),nDataAreaCount(0),
     116             :         ppDataAreas( NULL ),
     117           1 :         bByCol(r.bByCol),bByRow(r.bByRow),bReferenceData(r.bReferenceData)
     118             : {
     119           1 :     if ( r.nDataAreaCount > 0 )
     120             :     {
     121           0 :         nDataAreaCount = r.nDataAreaCount;
     122           0 :         ppDataAreas = new ScArea*[nDataAreaCount];
     123           0 :         for ( sal_uInt16 i=0; i<nDataAreaCount; i++ )
     124           0 :             ppDataAreas[i] = new ScArea( *(r.ppDataAreas[i]) );
     125             :     }
     126           1 : }
     127             : 
     128          20 : ScConsolidateParam::~ScConsolidateParam()
     129             : {
     130          20 :     ClearDataAreas();
     131          20 : }
     132             : 
     133          77 : void ScConsolidateParam::ClearDataAreas()
     134             : {
     135          77 :     if ( ppDataAreas )
     136             :     {
     137           2 :         for ( sal_uInt16 i=0; i<nDataAreaCount; i++ )
     138           1 :             delete ppDataAreas[i];
     139           1 :         delete [] ppDataAreas;
     140           1 :         ppDataAreas = NULL;
     141             :     }
     142          77 :     nDataAreaCount = 0;
     143          77 : }
     144             : 
     145          55 : void ScConsolidateParam::Clear()
     146             : {
     147          55 :     ClearDataAreas();
     148             : 
     149          55 :     nCol = 0;
     150          55 :     nRow = 0;
     151          55 :     nTab = 0;
     152          55 :     bByCol = bByRow = bReferenceData    = false;
     153          55 :     eFunction                           = SUBTOTAL_FUNC_SUM;
     154          55 : }
     155             : 
     156           0 : ScConsolidateParam& ScConsolidateParam::operator=( const ScConsolidateParam& r )
     157             : {
     158           0 :     nCol            = r.nCol;
     159           0 :     nRow            = r.nRow;
     160           0 :     nTab            = r.nTab;
     161           0 :     bByCol          = r.bByCol;
     162           0 :     bByRow          = r.bByRow;
     163           0 :     bReferenceData  = r.bReferenceData;
     164           0 :     eFunction       = r.eFunction;
     165           0 :     SetAreas( r.ppDataAreas, r.nDataAreaCount );
     166             : 
     167           0 :     return *this;
     168             : }
     169             : 
     170           0 : bool ScConsolidateParam::operator==( const ScConsolidateParam& r ) const
     171             : {
     172           0 :     bool bEqual =   (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 :                  && (nDataAreaCount == r.nDataAreaCount)
     179           0 :                  && (eFunction      == r.eFunction);
     180             : 
     181           0 :     if ( nDataAreaCount == 0 )
     182           0 :         bEqual = bEqual && (ppDataAreas == NULL) && (r.ppDataAreas == NULL);
     183             :     else
     184           0 :         bEqual = bEqual && (ppDataAreas != NULL) && (r.ppDataAreas != NULL);
     185             : 
     186           0 :     if ( bEqual && (nDataAreaCount > 0) )
     187           0 :         for ( sal_uInt16 i=0; i<nDataAreaCount && bEqual; i++ )
     188           0 :             bEqual = *(ppDataAreas[i]) == *(r.ppDataAreas[i]);
     189             : 
     190           0 :     return bEqual;
     191             : }
     192             : 
     193           1 : void ScConsolidateParam::SetAreas( ScArea* const* ppAreas, sal_uInt16 nCount )
     194             : {
     195           1 :     ClearDataAreas();
     196           1 :     if ( ppAreas && nCount > 0 )
     197             :     {
     198           1 :         ppDataAreas = new ScArea*[nCount];
     199           2 :         for ( sal_uInt16 i=0; i<nCount; i++ )
     200           1 :             ppDataAreas[i] = new ScArea( *(ppAreas[i]) );
     201           1 :         nDataAreaCount = nCount;
     202             :     }
     203           1 : }
     204             : 
     205             : // struct ScSolveParam
     206             : 
     207          52 : ScSolveParam::ScSolveParam()
     208          52 :     :   pStrTargetVal( NULL )
     209             : {
     210          52 : }
     211             : 
     212           0 : ScSolveParam::ScSolveParam( const ScSolveParam& r )
     213             :     :   aRefFormulaCell ( r.aRefFormulaCell ),
     214             :         aRefVariableCell( r.aRefVariableCell ),
     215             :         pStrTargetVal   ( r.pStrTargetVal
     216           0 :                             ? new OUString(*r.pStrTargetVal)
     217           0 :                             : NULL )
     218             : {
     219           0 : }
     220             : 
     221           0 : ScSolveParam::ScSolveParam( const ScAddress& rFormulaCell,
     222             :                             const ScAddress& rVariableCell,
     223             :                             const OUString&   rTargetValStr )
     224             :     :   aRefFormulaCell ( rFormulaCell ),
     225             :         aRefVariableCell( rVariableCell ),
     226           0 :         pStrTargetVal   ( new OUString(rTargetValStr) )
     227             : {
     228           0 : }
     229             : 
     230          16 : ScSolveParam::~ScSolveParam()
     231             : {
     232          16 :     delete pStrTargetVal;
     233          16 : }
     234             : 
     235           0 : ScSolveParam& ScSolveParam::operator=( const ScSolveParam& r )
     236             : {
     237           0 :     delete pStrTargetVal;
     238             : 
     239           0 :     aRefFormulaCell  = r.aRefFormulaCell;
     240           0 :     aRefVariableCell = r.aRefVariableCell;
     241             :     pStrTargetVal    = r.pStrTargetVal
     242           0 :                             ? new OUString(*r.pStrTargetVal)
     243           0 :                             : NULL;
     244           0 :     return *this;
     245             : }
     246             : 
     247           0 : bool ScSolveParam::operator==( const ScSolveParam& r ) const
     248             : {
     249           0 :     bool bEqual =   (aRefFormulaCell  == r.aRefFormulaCell)
     250           0 :                  && (aRefVariableCell == r.aRefVariableCell);
     251             : 
     252           0 :     if ( bEqual )
     253             :     {
     254           0 :         if ( !pStrTargetVal && !r.pStrTargetVal )
     255           0 :             bEqual = true;
     256           0 :         else if ( !pStrTargetVal || !r.pStrTargetVal )
     257           0 :             bEqual = false;
     258           0 :         else if ( pStrTargetVal && r.pStrTargetVal )
     259           0 :             bEqual = ( *pStrTargetVal == *(r.pStrTargetVal) );
     260             :     }
     261             : 
     262           0 :     return bEqual;
     263             : }
     264             : 
     265             : // struct ScTabOpParam
     266             : 
     267           9 : ScTabOpParam::ScTabOpParam() : meMode(Column) {}
     268             : 
     269           0 : ScTabOpParam::ScTabOpParam( const ScTabOpParam& r )
     270             :     :   aRefFormulaCell ( r.aRefFormulaCell ),
     271             :         aRefFormulaEnd  ( r.aRefFormulaEnd ),
     272             :         aRefRowCell     ( r.aRefRowCell ),
     273             :         aRefColCell     ( r.aRefColCell ),
     274           0 :     meMode(r.meMode)
     275             : {
     276           0 : }
     277             : 
     278           0 : ScTabOpParam::ScTabOpParam( const ScRefAddress& rFormulaCell,
     279             :                             const ScRefAddress& rFormulaEnd,
     280             :                             const ScRefAddress& rRowCell,
     281             :                             const ScRefAddress& rColCell,
     282             :                             Mode eMode )
     283             :     :   aRefFormulaCell ( rFormulaCell ),
     284             :         aRefFormulaEnd  ( rFormulaEnd ),
     285             :         aRefRowCell     ( rRowCell ),
     286             :         aRefColCell     ( rColCell ),
     287           0 :     meMode(eMode)
     288             : {
     289           0 : }
     290             : 
     291           0 : ScTabOpParam& ScTabOpParam::operator=( const ScTabOpParam& r )
     292             : {
     293           0 :     aRefFormulaCell  = r.aRefFormulaCell;
     294           0 :     aRefFormulaEnd   = r.aRefFormulaEnd;
     295           0 :     aRefRowCell      = r.aRefRowCell;
     296           0 :     aRefColCell      = r.aRefColCell;
     297           0 :     meMode = r.meMode;
     298           0 :     return *this;
     299             : }
     300             : 
     301           0 : bool ScTabOpParam::operator==( const ScTabOpParam& r ) const
     302             : {
     303           0 :     return (        (aRefFormulaCell == r.aRefFormulaCell)
     304           0 :                  && (aRefFormulaEnd  == r.aRefFormulaEnd)
     305           0 :                  && (aRefRowCell     == r.aRefRowCell)
     306           0 :                  && (aRefColCell     == r.aRefColCell)
     307           0 :                  && (meMode == r.meMode) );
     308             : }
     309             : 
     310         162 : OUString ScGlobal::GetAbsDocName( const OUString& rFileName,
     311             :                                 SfxObjectShell* pShell )
     312             : {
     313         162 :     OUString aAbsName;
     314         162 :     if ( !pShell->HasName() )
     315             :     {   // maybe relative to document path working directory
     316         154 :         INetURLObject aObj;
     317         308 :         SvtPathOptions aPathOpt;
     318         154 :         aObj.SetSmartURL( aPathOpt.GetWorkPath() );
     319         154 :         aObj.setFinalSlash();       // it IS a path
     320         154 :         bool bWasAbs = true;
     321         308 :         aAbsName = aObj.smartRel2Abs( rFileName, bWasAbs ).GetMainURL(INetURLObject::NO_DECODE);
     322             :         //  returned string must be encoded because it's used directly to create SfxMedium
     323             :     }
     324             :     else
     325             :     {
     326           8 :         const SfxMedium* pMedium = pShell->GetMedium();
     327           8 :         if ( pMedium )
     328             :         {
     329           8 :             bool bWasAbs = true;
     330           8 :             aAbsName = pMedium->GetURLObject().smartRel2Abs( rFileName, bWasAbs ).GetMainURL(INetURLObject::NO_DECODE);
     331             :         }
     332             :         else
     333             :         {   // This can't happen, but ...
     334             :             // just to be sure to have the same encoding
     335           0 :             INetURLObject aObj;
     336           0 :             aObj.SetSmartURL( aAbsName );
     337           0 :             aAbsName = aObj.GetMainURL(INetURLObject::NO_DECODE);
     338             :         }
     339             :     }
     340         162 :     return aAbsName;
     341             : }
     342             : 
     343           0 : OUString ScGlobal::GetDocTabName( const OUString& rFileName,
     344             :                                 const OUString& rTabName )
     345             : {
     346           0 :     OUString  aDocTab('\'');
     347           0 :     aDocTab += rFileName;
     348           0 :     sal_Int32 nPos = 1;
     349           0 :     while( (nPos = aDocTab.indexOf( '\'', nPos )) != -1 )
     350             :     {   // escape Quotes
     351           0 :         aDocTab = aDocTab.replaceAt( nPos, 0, "\\" );
     352           0 :         nPos += 2;
     353             :     }
     354           0 :     aDocTab += "'";
     355           0 :     aDocTab += OUString(SC_COMPILER_FILE_TAB_SEP);
     356           0 :     aDocTab += rTabName;    // "'Doc'#Tab"
     357           0 :     return aDocTab;
     358         156 : }
     359             : 
     360             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11