LCOV - code coverage report
Current view: top level - sc/source/core/data - global2.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 77 176 43.8 %
Date: 2014-11-03 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         186 : ScImportParam::ScImportParam() :
      44             :     nCol1(0),
      45             :     nRow1(0),
      46             :     nCol2(0),
      47             :     nRow2(0),
      48             :     bImport(false),
      49             :     bNative(false),
      50             :     bSql(true),
      51         186 :     nType(ScDbTable)
      52             : {
      53         186 : }
      54             : 
      55         996 : 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         996 :     nType       (r.nType)
      66             : {
      67         996 : }
      68             : 
      69        1182 : ScImportParam::~ScImportParam()
      70             : {
      71        1182 : }
      72             : 
      73          22 : ScImportParam& ScImportParam::operator=( const ScImportParam& r )
      74             : {
      75          22 :     nCol1           = r.nCol1;
      76          22 :     nRow1           = r.nRow1;
      77          22 :     nCol2           = r.nCol2;
      78          22 :     nRow2           = r.nRow2;
      79          22 :     bImport         = r.bImport;
      80          22 :     aDBName         = r.aDBName;
      81          22 :     aStatement      = r.aStatement;
      82          22 :     bNative         = r.bNative;
      83          22 :     bSql            = r.bSql;
      84          22 :     nType           = r.nType;
      85             : 
      86          22 :     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             :     //! nQuerySh und pConnection sind gleich ?
     103             : }
     104             : 
     105             : // struct ScConsolidateParam:
     106             : 
     107          82 : ScConsolidateParam::ScConsolidateParam() :
     108          82 :     ppDataAreas( NULL )
     109             : {
     110          82 :     Clear();
     111          82 : }
     112             : 
     113           2 : 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           2 :         bByCol(r.bByCol),bByRow(r.bByRow),bReferenceData(r.bReferenceData)
     118             : {
     119           2 :     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           2 : }
     127             : 
     128          28 : ScConsolidateParam::~ScConsolidateParam()
     129             : {
     130          28 :     ClearDataAreas();
     131          28 : }
     132             : 
     133         114 : void ScConsolidateParam::ClearDataAreas()
     134             : {
     135         114 :     if ( ppDataAreas )
     136             :     {
     137           4 :         for ( sal_uInt16 i=0; i<nDataAreaCount; i++ )
     138           2 :             delete ppDataAreas[i];
     139           2 :         delete [] ppDataAreas;
     140           2 :         ppDataAreas = NULL;
     141             :     }
     142         114 :     nDataAreaCount = 0;
     143         114 : }
     144             : 
     145          82 : void ScConsolidateParam::Clear()
     146             : {
     147          82 :     ClearDataAreas();
     148             : 
     149          82 :     nCol = 0;
     150          82 :     nRow = 0;
     151          82 :     nTab = 0;
     152          82 :     bByCol = bByRow = bReferenceData    = false;
     153          82 :     eFunction                           = SUBTOTAL_FUNC_SUM;
     154          82 : }
     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           2 : void ScConsolidateParam::SetAreas( ScArea* const* ppAreas, sal_uInt16 nCount )
     194             : {
     195           2 :     ClearDataAreas();
     196           2 :     if ( ppAreas && nCount > 0 )
     197             :     {
     198           2 :         ppDataAreas = new ScArea*[nCount];
     199           4 :         for ( sal_uInt16 i=0; i<nCount; i++ )
     200           2 :             ppDataAreas[i] = new ScArea( *(ppAreas[i]) );
     201           2 :         nDataAreaCount = nCount;
     202             :     }
     203           2 : }
     204             : 
     205             : // struct ScSolveParam
     206             : 
     207          76 : ScSolveParam::ScSolveParam()
     208          76 :     :   pStrTargetVal( NULL )
     209             : {
     210          76 : }
     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          20 : ScSolveParam::~ScSolveParam()
     231             : {
     232          20 :     delete pStrTargetVal;
     233          20 : }
     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          18 : 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         186 : OUString ScGlobal::GetAbsDocName( const OUString& rFileName,
     311             :                                 SfxObjectShell* pShell )
     312             : {
     313         186 :     OUString aAbsName;
     314         186 :     if ( !pShell->HasName() )
     315             :     {   // maybe relative to document path working directory
     316         174 :         INetURLObject aObj;
     317         348 :         SvtPathOptions aPathOpt;
     318         174 :         aObj.SetSmartURL( aPathOpt.GetWorkPath() );
     319         174 :         aObj.setFinalSlash();       // it IS a path
     320         174 :         bool bWasAbs = true;
     321         348 :         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          12 :         const SfxMedium* pMedium = pShell->GetMedium();
     327          12 :         if ( pMedium )
     328             :         {
     329          12 :             bool bWasAbs = true;
     330          12 :             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         186 :     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         228 : }
     359             : 
     360             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10