LCOV - code coverage report
Current view: top level - sc/source/core/data - global2.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 71 160 44.4 %
Date: 2012-08-25 Functions: 13 25 52.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 26 192 13.5 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <sfx2/docfile.hxx>
      30                 :            : #include <sfx2/objsh.hxx>
      31                 :            : #include <unotools/pathoptions.hxx>
      32                 :            : #include <unotools/useroptions.hxx>
      33                 :            : #include <tools/urlobj.hxx>
      34                 :            : #include <unotools/charclass.hxx>
      35                 :            : #include <stdlib.h>
      36                 :            : #include <ctype.h>
      37                 :            : #include <unotools/syslocale.hxx>
      38                 :            : 
      39                 :            : #include "global.hxx"
      40                 :            : #include "rangeutl.hxx"
      41                 :            : #include "rechead.hxx"
      42                 :            : #include "compiler.hxx"
      43                 :            : #include "paramisc.hxx"
      44                 :            : #include "pivot.hxx"
      45                 :            : 
      46                 :            : #include "sc.hrc"
      47                 :            : #include "globstr.hrc"
      48                 :            : 
      49                 :            : using ::std::vector;
      50                 :            : 
      51                 :            : // -----------------------------------------------------------------------
      52                 :            : 
      53                 :            : //------------------------------------------------------------------------
      54                 :            : // struct ScImportParam:
      55                 :            : 
      56                 :        105 : ScImportParam::ScImportParam() :
      57                 :            :     nCol1(0),
      58                 :            :     nRow1(0),
      59                 :            :     nCol2(0),
      60                 :            :     nRow2(0),
      61                 :            :     bImport(false),
      62                 :            :     bNative(false),
      63                 :            :     bSql(true),
      64                 :        105 :     nType(ScDbTable)
      65                 :            : {
      66                 :        105 : }
      67                 :            : 
      68                 :        694 : ScImportParam::ScImportParam( const ScImportParam& r ) :
      69                 :            :     nCol1       (r.nCol1),
      70                 :            :     nRow1       (r.nRow1),
      71                 :            :     nCol2       (r.nCol2),
      72                 :            :     nRow2       (r.nRow2),
      73                 :            :     bImport     (r.bImport),
      74                 :            :     aDBName     (r.aDBName),
      75                 :            :     aStatement  (r.aStatement),
      76                 :            :     bNative     (r.bNative),
      77                 :            :     bSql        (r.bSql),
      78                 :        694 :     nType       (r.nType)
      79                 :            : {
      80                 :        694 : }
      81                 :            : 
      82                 :        796 : ScImportParam::~ScImportParam()
      83                 :            : {
      84                 :        796 : }
      85                 :            : 
      86                 :          4 : ScImportParam& ScImportParam::operator=( const ScImportParam& r )
      87                 :            : {
      88                 :          4 :     nCol1           = r.nCol1;
      89                 :          4 :     nRow1           = r.nRow1;
      90                 :          4 :     nCol2           = r.nCol2;
      91                 :          4 :     nRow2           = r.nRow2;
      92                 :          4 :     bImport         = r.bImport;
      93                 :          4 :     aDBName         = r.aDBName;
      94                 :          4 :     aStatement      = r.aStatement;
      95                 :          4 :     bNative         = r.bNative;
      96                 :          4 :     bSql            = r.bSql;
      97                 :          4 :     nType           = r.nType;
      98                 :            : 
      99                 :          4 :     return *this;
     100                 :            : }
     101                 :            : 
     102                 :          0 : bool ScImportParam::operator==( const ScImportParam& rOther ) const
     103                 :            : {
     104                 :            :     return( nCol1       == rOther.nCol1 &&
     105                 :            :             nRow1       == rOther.nRow1 &&
     106                 :            :             nCol2       == rOther.nCol2 &&
     107                 :            :             nRow2       == rOther.nRow2 &&
     108                 :            :             bImport     == rOther.bImport &&
     109                 :          0 :             aDBName     == rOther.aDBName &&
     110                 :          0 :             aStatement  == rOther.aStatement &&
     111                 :            :             bNative     == rOther.bNative &&
     112                 :            :             bSql        == rOther.bSql &&
     113 [ #  # ][ #  # ]:          0 :             nType       == rOther.nType );
         [ #  # ][ #  # ]
           [ #  #  #  #  
           #  # ][ #  # ]
         [ #  # ][ #  # ]
     114                 :            : 
     115                 :            :     //! nQuerySh und pConnection sind gleich ?
     116                 :            : }
     117                 :            : 
     118                 :            : //------------------------------------------------------------------------
     119                 :            : // struct ScConsolidateParam:
     120                 :            : 
     121                 :         54 : ScConsolidateParam::ScConsolidateParam() :
     122                 :         54 :     ppDataAreas( NULL )
     123                 :            : {
     124                 :         54 :     Clear();
     125                 :         54 : }
     126                 :            : 
     127                 :            : //------------------------------------------------------------------------
     128                 :            : 
     129                 :          1 : ScConsolidateParam::ScConsolidateParam( const ScConsolidateParam& r ) :
     130                 :            :         nCol(r.nCol),nRow(r.nRow),nTab(r.nTab),
     131                 :            :         eFunction(r.eFunction),nDataAreaCount(0),
     132                 :            :         ppDataAreas( NULL ),
     133                 :          1 :         bByCol(r.bByCol),bByRow(r.bByRow),bReferenceData(r.bReferenceData)
     134                 :            : {
     135         [ -  + ]:          1 :     if ( r.nDataAreaCount > 0 )
     136                 :            :     {
     137                 :          0 :         nDataAreaCount = r.nDataAreaCount;
     138                 :          0 :         ppDataAreas = new ScArea*[nDataAreaCount];
     139         [ #  # ]:          0 :         for ( sal_uInt16 i=0; i<nDataAreaCount; i++ )
     140         [ #  # ]:          0 :             ppDataAreas[i] = new ScArea( *(r.ppDataAreas[i]) );
     141                 :            :     }
     142                 :          1 : }
     143                 :            : 
     144                 :            : //------------------------------------------------------------------------
     145                 :            : 
     146                 :         22 : ScConsolidateParam::~ScConsolidateParam()
     147                 :            : {
     148                 :         22 :     ClearDataAreas();
     149                 :         22 : }
     150                 :            : 
     151                 :            : //------------------------------------------------------------------------
     152                 :            : 
     153                 :         78 : void ScConsolidateParam::ClearDataAreas()
     154                 :            : {
     155         [ +  + ]:         78 :     if ( ppDataAreas )
     156                 :            :     {
     157         [ +  + ]:          2 :         for ( sal_uInt16 i=0; i<nDataAreaCount; i++ )
     158                 :          1 :             delete ppDataAreas[i];
     159         [ +  - ]:          1 :         delete [] ppDataAreas;
     160                 :          1 :         ppDataAreas = NULL;
     161                 :            :     }
     162                 :         78 :     nDataAreaCount = 0;
     163                 :         78 : }
     164                 :            : 
     165                 :            : //------------------------------------------------------------------------
     166                 :            : 
     167                 :         54 : void ScConsolidateParam::Clear()
     168                 :            : {
     169                 :         54 :     ClearDataAreas();
     170                 :            : 
     171                 :         54 :     nCol = 0;
     172                 :         54 :     nRow = 0;
     173                 :         54 :     nTab = 0;
     174                 :         54 :     bByCol = bByRow = bReferenceData    = false;
     175                 :         54 :     eFunction                           = SUBTOTAL_FUNC_SUM;
     176                 :         54 : }
     177                 :            : 
     178                 :            : //------------------------------------------------------------------------
     179                 :            : 
     180                 :          0 : ScConsolidateParam& ScConsolidateParam::operator=( const ScConsolidateParam& r )
     181                 :            : {
     182                 :          0 :     nCol            = r.nCol;
     183                 :          0 :     nRow            = r.nRow;
     184                 :          0 :     nTab            = r.nTab;
     185                 :          0 :     bByCol          = r.bByCol;
     186                 :          0 :     bByRow          = r.bByRow;
     187                 :          0 :     bReferenceData  = r.bReferenceData;
     188                 :          0 :     eFunction       = r.eFunction;
     189                 :          0 :     SetAreas( r.ppDataAreas, r.nDataAreaCount );
     190                 :            : 
     191                 :          0 :     return *this;
     192                 :            : }
     193                 :            : 
     194                 :            : //------------------------------------------------------------------------
     195                 :            : 
     196                 :          0 : sal_Bool ScConsolidateParam::operator==( const ScConsolidateParam& r ) const
     197                 :            : {
     198                 :            :     sal_Bool bEqual =   (nCol           == r.nCol)
     199                 :            :                  && (nRow           == r.nRow)
     200                 :            :                  && (nTab           == r.nTab)
     201                 :            :                  && (bByCol         == r.bByCol)
     202                 :            :                  && (bByRow         == r.bByRow)
     203                 :            :                  && (bReferenceData == r.bReferenceData)
     204                 :            :                  && (nDataAreaCount == r.nDataAreaCount)
     205 [ #  # ][ #  # ]:          0 :                  && (eFunction      == r.eFunction);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     206                 :            : 
     207         [ #  # ]:          0 :     if ( nDataAreaCount == 0 )
     208 [ #  # ][ #  # ]:          0 :         bEqual = bEqual && (ppDataAreas == NULL) && (r.ppDataAreas == NULL);
                 [ #  # ]
     209                 :            :     else
     210 [ #  # ][ #  # ]:          0 :         bEqual = bEqual && (ppDataAreas != NULL) && (r.ppDataAreas != NULL);
                 [ #  # ]
     211                 :            : 
     212 [ #  # ][ #  # ]:          0 :     if ( bEqual && (nDataAreaCount > 0) )
     213 [ #  # ][ #  # ]:          0 :         for ( sal_uInt16 i=0; i<nDataAreaCount && bEqual; i++ )
                 [ #  # ]
     214                 :          0 :             bEqual = *(ppDataAreas[i]) == *(r.ppDataAreas[i]);
     215                 :            : 
     216                 :          0 :     return bEqual;
     217                 :            : }
     218                 :            : 
     219                 :            : //------------------------------------------------------------------------
     220                 :            : 
     221                 :          1 : void ScConsolidateParam::SetAreas( ScArea* const* ppAreas, sal_uInt16 nCount )
     222                 :            : {
     223                 :          1 :     ClearDataAreas();
     224 [ +  - ][ +  - ]:          1 :     if ( ppAreas && nCount > 0 )
     225                 :            :     {
     226                 :          1 :         ppDataAreas = new ScArea*[nCount];
     227         [ +  + ]:          2 :         for ( sal_uInt16 i=0; i<nCount; i++ )
     228         [ +  - ]:          1 :             ppDataAreas[i] = new ScArea( *(ppAreas[i]) );
     229                 :          1 :         nDataAreaCount = nCount;
     230                 :            :     }
     231                 :          1 : }
     232                 :            : 
     233                 :            : //------------------------------------------------------------------------
     234                 :            : // struct ScSolveParam
     235                 :            : 
     236                 :         51 : ScSolveParam::ScSolveParam()
     237                 :         51 :     :   pStrTargetVal( NULL )
     238                 :            : {
     239                 :         51 : }
     240                 :            : 
     241                 :            : //------------------------------------------------------------------------
     242                 :            : 
     243                 :          0 : ScSolveParam::ScSolveParam( const ScSolveParam& r )
     244                 :            :     :   aRefFormulaCell ( r.aRefFormulaCell ),
     245                 :            :         aRefVariableCell( r.aRefVariableCell ),
     246                 :            :         pStrTargetVal   ( r.pStrTargetVal
     247         [ #  # ]:          0 :                             ? new String(*r.pStrTargetVal)
     248         [ #  # ]:          0 :                             : NULL )
     249                 :            : {
     250                 :          0 : }
     251                 :            : 
     252                 :            : //------------------------------------------------------------------------
     253                 :            : 
     254                 :          0 : ScSolveParam::ScSolveParam( const ScAddress& rFormulaCell,
     255                 :            :                             const ScAddress& rVariableCell,
     256                 :            :                             const String&   rTargetValStr )
     257                 :            :     :   aRefFormulaCell ( rFormulaCell ),
     258                 :            :         aRefVariableCell( rVariableCell ),
     259         [ #  # ]:          0 :         pStrTargetVal   ( new String(rTargetValStr) )
     260                 :            : {
     261                 :          0 : }
     262                 :            : 
     263                 :            : //------------------------------------------------------------------------
     264                 :            : 
     265                 :         18 : ScSolveParam::~ScSolveParam()
     266                 :            : {
     267         [ -  + ]:         18 :     delete pStrTargetVal;
     268                 :         18 : }
     269                 :            : 
     270                 :            : //------------------------------------------------------------------------
     271                 :            : 
     272                 :          0 : ScSolveParam& ScSolveParam::operator=( const ScSolveParam& r )
     273                 :            : {
     274         [ #  # ]:          0 :     delete pStrTargetVal;
     275                 :            : 
     276                 :          0 :     aRefFormulaCell  = r.aRefFormulaCell;
     277                 :          0 :     aRefVariableCell = r.aRefVariableCell;
     278                 :            :     pStrTargetVal    = r.pStrTargetVal
     279         [ #  # ]:          0 :                             ? new String(*r.pStrTargetVal)
     280         [ #  # ]:          0 :                             : NULL;
     281                 :          0 :     return *this;
     282                 :            : }
     283                 :            : 
     284                 :            : //------------------------------------------------------------------------
     285                 :            : 
     286                 :          0 : sal_Bool ScSolveParam::operator==( const ScSolveParam& r ) const
     287                 :            : {
     288                 :          0 :     sal_Bool bEqual =   (aRefFormulaCell  == r.aRefFormulaCell)
     289 [ #  # ][ #  # ]:          0 :                  && (aRefVariableCell == r.aRefVariableCell);
     290                 :            : 
     291         [ #  # ]:          0 :     if ( bEqual )
     292                 :            :     {
     293 [ #  # ][ #  # ]:          0 :         if ( !pStrTargetVal && !r.pStrTargetVal )
     294                 :          0 :             bEqual = sal_True;
     295 [ #  # ][ #  # ]:          0 :         else if ( !pStrTargetVal || !r.pStrTargetVal )
     296                 :          0 :             bEqual = false;
     297 [ #  # ][ #  # ]:          0 :         else if ( pStrTargetVal && r.pStrTargetVal )
     298                 :          0 :             bEqual = ( *pStrTargetVal == *(r.pStrTargetVal) );
     299                 :            :     }
     300                 :            : 
     301                 :          0 :     return bEqual;
     302                 :            : }
     303                 :            : 
     304                 :            : //------------------------------------------------------------------------
     305                 :            : // struct ScTabOpParam
     306                 :            : 
     307                 :          0 : ScTabOpParam::ScTabOpParam( const ScTabOpParam& r )
     308                 :            :     :   aRefFormulaCell ( r.aRefFormulaCell ),
     309                 :            :         aRefFormulaEnd  ( r.aRefFormulaEnd ),
     310                 :            :         aRefRowCell     ( r.aRefRowCell ),
     311                 :            :         aRefColCell     ( r.aRefColCell ),
     312                 :          0 :         nMode           ( r.nMode )
     313                 :            : {
     314                 :          0 : }
     315                 :            : 
     316                 :            : //------------------------------------------------------------------------
     317                 :            : 
     318                 :          0 : ScTabOpParam::ScTabOpParam( const ScRefAddress& rFormulaCell,
     319                 :            :                             const ScRefAddress& rFormulaEnd,
     320                 :            :                             const ScRefAddress& rRowCell,
     321                 :            :                             const ScRefAddress& rColCell,
     322                 :            :                                   sal_uInt8      nMd)
     323                 :            :     :   aRefFormulaCell ( rFormulaCell ),
     324                 :            :         aRefFormulaEnd  ( rFormulaEnd ),
     325                 :            :         aRefRowCell     ( rRowCell ),
     326                 :            :         aRefColCell     ( rColCell ),
     327                 :          0 :         nMode           ( nMd )
     328                 :            : {
     329                 :          0 : }
     330                 :            : 
     331                 :            : //------------------------------------------------------------------------
     332                 :            : 
     333                 :          0 : ScTabOpParam& ScTabOpParam::operator=( const ScTabOpParam& r )
     334                 :            : {
     335                 :          0 :     aRefFormulaCell  = r.aRefFormulaCell;
     336                 :          0 :     aRefFormulaEnd   = r.aRefFormulaEnd;
     337                 :          0 :     aRefRowCell      = r.aRefRowCell;
     338                 :          0 :     aRefColCell      = r.aRefColCell;
     339                 :          0 :     nMode            = r.nMode;
     340                 :          0 :     return *this;
     341                 :            : }
     342                 :            : 
     343                 :            : //------------------------------------------------------------------------
     344                 :            : 
     345                 :          0 : sal_Bool ScTabOpParam::operator==( const ScTabOpParam& r ) const
     346                 :            : {
     347                 :          0 :     return (        (aRefFormulaCell == r.aRefFormulaCell)
     348                 :          0 :                  && (aRefFormulaEnd  == r.aRefFormulaEnd)
     349                 :          0 :                  && (aRefRowCell     == r.aRefRowCell)
     350                 :          0 :                  && (aRefColCell     == r.aRefColCell)
     351 [ #  # ][ #  #  :          0 :                  && (nMode           == r.nMode) );
          #  #  #  #  #  
                      # ]
     352                 :            : }
     353                 :            : 
     354                 :        131 : String ScGlobal::GetAbsDocName( const String& rFileName,
     355                 :            :                                 SfxObjectShell* pShell )
     356                 :            : {
     357                 :        131 :     String aAbsName;
     358         [ +  - ]:        131 :     if ( !pShell->HasName() )
     359                 :            :     {   // maybe relative to document path working directory
     360         [ +  - ]:        131 :         INetURLObject aObj;
     361         [ +  - ]:        131 :         SvtPathOptions aPathOpt;
     362 [ +  - ][ +  - ]:        131 :         aObj.SetSmartURL( aPathOpt.GetWorkPath() );
                 [ +  - ]
     363         [ +  - ]:        131 :         aObj.setFinalSlash();       // it IS a path
     364                 :        131 :         bool bWasAbs = true;
     365 [ +  - ][ +  - ]:        131 :         aAbsName = aObj.smartRel2Abs( rFileName, bWasAbs ).GetMainURL(INetURLObject::NO_DECODE);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     366                 :            :         //  returned string must be encoded because it's used directly to create SfxMedium
     367                 :            :     }
     368                 :            :     else
     369                 :            :     {
     370                 :          0 :         const SfxMedium* pMedium = pShell->GetMedium();
     371         [ #  # ]:          0 :         if ( pMedium )
     372                 :            :         {
     373                 :          0 :             bool bWasAbs = true;
     374 [ #  # ][ #  # ]:          0 :             aAbsName = pMedium->GetURLObject().smartRel2Abs( rFileName, bWasAbs ).GetMainURL(INetURLObject::NO_DECODE);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     375                 :            :         }
     376                 :            :         else
     377                 :            :         {   // This can't happen, but ...
     378                 :            :             // just to be sure to have the same encoding
     379         [ #  # ]:          0 :             INetURLObject aObj;
     380 [ #  # ][ #  # ]:          0 :             aObj.SetSmartURL( aAbsName );
     381 [ #  # ][ #  # ]:          0 :             aAbsName = aObj.GetMainURL(INetURLObject::NO_DECODE);
                 [ #  # ]
     382                 :            :         }
     383                 :            :     }
     384                 :        131 :     return aAbsName;
     385                 :            : }
     386                 :            : 
     387                 :          0 : String ScGlobal::GetDocTabName( const String& rFileName,
     388                 :            :                                 const String& rTabName )
     389                 :            : {
     390         [ #  # ]:          0 :     String aDocTab(rtl::OUString('\''));
     391         [ #  # ]:          0 :     aDocTab += rFileName;
     392                 :          0 :     xub_StrLen nPos = 1;
     393 [ #  # ][ #  # ]:          0 :     while( (nPos = aDocTab.Search( '\'', nPos ))
     394                 :            :             != STRING_NOTFOUND )
     395                 :            :     {   // escape Quotes
     396         [ #  # ]:          0 :         aDocTab.Insert( '\\', nPos );
     397                 :          0 :         nPos += 2;
     398                 :            :     }
     399         [ #  # ]:          0 :     aDocTab += '\'';
     400         [ #  # ]:          0 :     aDocTab += SC_COMPILER_FILE_TAB_SEP;
     401         [ #  # ]:          0 :     aDocTab += rTabName;    // "'Doc'#Tab"
     402                 :          0 :     return aDocTab;
     403                 :            : }
     404                 :            : 
     405                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10